L2Character.java 225 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package net.sf.l2j.gameserver.model;
  16. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
  17. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_FOLLOW;
  18. import java.util.Collection;
  19. import java.util.Collections;
  20. import java.util.List;
  21. import java.util.Map;
  22. import java.util.concurrent.Future;
  23. import java.util.logging.Level;
  24. import java.util.logging.Logger;
  25. import javolution.util.FastList;
  26. import javolution.util.FastMap;
  27. import net.sf.l2j.Config;
  28. import net.sf.l2j.gameserver.GameTimeController;
  29. import net.sf.l2j.gameserver.GeoData;
  30. import net.sf.l2j.gameserver.ThreadPoolManager;
  31. import net.sf.l2j.gameserver.ai.CtrlEvent;
  32. import net.sf.l2j.gameserver.ai.CtrlIntention;
  33. import net.sf.l2j.gameserver.ai.L2AttackableAI;
  34. import net.sf.l2j.gameserver.ai.L2CharacterAI;
  35. import net.sf.l2j.gameserver.datatables.DoorTable;
  36. import net.sf.l2j.gameserver.datatables.MapRegionTable;
  37. import net.sf.l2j.gameserver.datatables.SkillTable;
  38. import net.sf.l2j.gameserver.datatables.MapRegionTable.TeleportWhereType;
  39. import net.sf.l2j.gameserver.handler.ISkillHandler;
  40. import net.sf.l2j.gameserver.handler.SkillHandler;
  41. import net.sf.l2j.gameserver.instancemanager.DimensionalRiftManager;
  42. import net.sf.l2j.gameserver.instancemanager.TownManager;
  43. import net.sf.l2j.gameserver.model.L2Skill.SkillTargetType;
  44. import net.sf.l2j.gameserver.model.actor.instance.L2ArtefactInstance;
  45. import net.sf.l2j.gameserver.model.actor.instance.L2BoatInstance;
  46. import net.sf.l2j.gameserver.model.actor.instance.L2ControlTowerInstance;
  47. import net.sf.l2j.gameserver.model.actor.instance.L2DecoyInstance;
  48. import net.sf.l2j.gameserver.model.actor.instance.L2DoorInstance;
  49. import net.sf.l2j.gameserver.model.actor.instance.L2EffectPointInstance;
  50. import net.sf.l2j.gameserver.model.actor.instance.L2FolkInstance;
  51. import net.sf.l2j.gameserver.model.actor.instance.L2FortCommanderInstance;
  52. import net.sf.l2j.gameserver.model.actor.instance.L2FortSiegeGuardInstance;
  53. import net.sf.l2j.gameserver.model.actor.instance.L2FriendlyMobInstance;
  54. import net.sf.l2j.gameserver.model.actor.instance.L2GuardInstance;
  55. import net.sf.l2j.gameserver.model.actor.instance.L2MinionInstance;
  56. import net.sf.l2j.gameserver.model.actor.instance.L2MonsterInstance;
  57. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  58. import net.sf.l2j.gameserver.model.actor.instance.L2NpcWalkerInstance;
  59. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  60. import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
  61. import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
  62. import net.sf.l2j.gameserver.model.actor.instance.L2RiftInvaderInstance;
  63. import net.sf.l2j.gameserver.model.actor.instance.L2SiegeFlagInstance;
  64. import net.sf.l2j.gameserver.model.actor.instance.L2SiegeGuardInstance;
  65. import net.sf.l2j.gameserver.model.actor.instance.L2SiegeSummonInstance;
  66. import net.sf.l2j.gameserver.model.actor.instance.L2SummonInstance;
  67. import net.sf.l2j.gameserver.model.actor.instance.L2TrapInstance;
  68. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance.SkillDat;
  69. import net.sf.l2j.gameserver.model.actor.knownlist.CharKnownList;
  70. import net.sf.l2j.gameserver.model.actor.stat.CharStat;
  71. import net.sf.l2j.gameserver.model.actor.status.CharStatus;
  72. import net.sf.l2j.gameserver.model.itemcontainer.Inventory;
  73. import net.sf.l2j.gameserver.model.quest.Quest;
  74. import net.sf.l2j.gameserver.model.quest.QuestState;
  75. import net.sf.l2j.gameserver.network.SystemMessageId;
  76. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  77. import net.sf.l2j.gameserver.network.serverpackets.Attack;
  78. import net.sf.l2j.gameserver.network.serverpackets.ChangeMoveType;
  79. import net.sf.l2j.gameserver.network.serverpackets.ChangeWaitType;
  80. import net.sf.l2j.gameserver.network.serverpackets.EtcStatusUpdate;
  81. import net.sf.l2j.gameserver.network.serverpackets.FlyToLocation;
  82. import net.sf.l2j.gameserver.network.serverpackets.L2GameServerPacket;
  83. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillCanceld;
  84. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillLaunched;
  85. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  86. import net.sf.l2j.gameserver.network.serverpackets.MoveToLocation;
  87. import net.sf.l2j.gameserver.network.serverpackets.NpcInfo;
  88. import net.sf.l2j.gameserver.network.serverpackets.PetInfo;
  89. import net.sf.l2j.gameserver.network.serverpackets.Revive;
  90. import net.sf.l2j.gameserver.network.serverpackets.SetupGauge;
  91. import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
  92. import net.sf.l2j.gameserver.network.serverpackets.StopMove;
  93. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  94. import net.sf.l2j.gameserver.network.serverpackets.TeleportToLocation;
  95. import net.sf.l2j.gameserver.network.serverpackets.FlyToLocation.FlyType;
  96. import net.sf.l2j.gameserver.pathfinding.AbstractNodeLoc;
  97. import net.sf.l2j.gameserver.pathfinding.PathFinding;
  98. import net.sf.l2j.gameserver.skills.Calculator;
  99. import net.sf.l2j.gameserver.skills.Formulas;
  100. import net.sf.l2j.gameserver.skills.Stats;
  101. import net.sf.l2j.gameserver.skills.effects.EffectCharge;
  102. import net.sf.l2j.gameserver.skills.funcs.Func;
  103. import net.sf.l2j.gameserver.skills.l2skills.L2SkillAgathion;
  104. import net.sf.l2j.gameserver.templates.chars.L2CharTemplate;
  105. import net.sf.l2j.gameserver.templates.chars.L2NpcTemplate;
  106. import net.sf.l2j.gameserver.templates.item.L2Weapon;
  107. import net.sf.l2j.gameserver.templates.item.L2WeaponType;
  108. import net.sf.l2j.gameserver.templates.skills.L2EffectType;
  109. import net.sf.l2j.gameserver.templates.skills.L2SkillType;
  110. import net.sf.l2j.gameserver.util.Util;
  111. import net.sf.l2j.util.Point3D;
  112. import net.sf.l2j.util.Rnd;
  113. /**
  114. * Mother class of all character objects of the world (PC, NPC...)<BR><BR>
  115. *
  116. * L2Character :<BR><BR>
  117. * <li>L2CastleGuardInstance</li>
  118. * <li>L2DoorInstance</li>
  119. * <li>L2NpcInstance</li>
  120. * <li>L2PlayableInstance </li><BR><BR>
  121. *
  122. *
  123. * <B><U> Concept of L2CharTemplate</U> :</B><BR><BR>
  124. * Each L2Character owns generic and static properties (ex : all Keltir have the same number of HP...).
  125. * All of those properties are stored in a different template for each type of L2Character.
  126. * Each template is loaded once in the server cache memory (reduce memory use).
  127. * When a new instance of L2Character is spawned, server just create a link between the instance and the template.
  128. * This link is stored in <B>_template</B><BR><BR>
  129. *
  130. *
  131. * @version $Revision: 1.53.2.45.2.34 $ $Date: 2005/04/11 10:06:08 $
  132. */
  133. public abstract class L2Character extends L2Object
  134. {
  135. public static final Logger _log = Logger.getLogger(L2Character.class.getName());
  136. // =========================================================
  137. // Data Field
  138. private List<L2Character> _attackByList;
  139. private volatile boolean _isCastingNow = false;
  140. private volatile boolean _isCastingSimultaneouslyNow = false;
  141. private L2Skill _lastSkillCast;
  142. private L2Skill _lastSimultaneousSkillCast;
  143. private boolean _isAfraid = false; // Flee in a random direction
  144. private boolean _isConfused = false; // Attack anyone randomly
  145. private boolean _isMuted = false; // Cannot use magic
  146. private boolean _isPhysicalMuted = false; // Cannot use physical skills
  147. private boolean _isPhysicalAttackMuted = false; // Cannot use attack
  148. private boolean _isDead = false;
  149. private boolean _isImmobilized = false;
  150. private boolean _isOverloaded = false; // the char is carrying too much
  151. private boolean _isParalyzed = false;
  152. private boolean _isDisarmed = false;
  153. private boolean _isPendingRevive = false;
  154. private boolean _isRooted = false; // Cannot move until root timed out
  155. private boolean _isRunning = false;
  156. private boolean _isImmobileUntilAttacked = false; // Is in immobile until attacked.
  157. private boolean _isSleeping = false; // Cannot move/attack until sleep timed out or monster is attacked
  158. private boolean _isStunned = false; // Cannot move/attack until stun timed out
  159. private boolean _isBetrayed = false; // Betrayed by own summon
  160. protected boolean _showSummonAnimation = false;
  161. protected boolean _isTeleporting = false;
  162. private L2Character _lastBuffer = null;
  163. protected boolean _isInvul = false;
  164. private int _lastHealAmount = 0;
  165. private CharStat _stat;
  166. private CharStatus _status;
  167. private L2CharTemplate _template; // The link on the L2CharTemplate object containing generic and static properties of this L2Character type (ex : Max HP, Speed...)
  168. private String _title;
  169. private String _aiClass = "default";
  170. private double _hpUpdateIncCheck = .0;
  171. private double _hpUpdateDecCheck = .0;
  172. private double _hpUpdateInterval = .0;
  173. private boolean _champion = false;
  174. /** Table of Calculators containing all used calculator */
  175. private Calculator[] _calculators;
  176. /** FastMap(Integer, L2Skill) containing all skills of the L2Character */
  177. protected final Map<Integer, L2Skill> _skills;
  178. /** FastMap containing the active chance skills on this character */
  179. protected ChanceSkillList _chanceSkills;
  180. /** Current force buff this caster is casting to a target */
  181. protected ForceBuff _forceBuff;
  182. /** Zone system */
  183. public static final byte ZONE_PVP = 0;
  184. public static final byte ZONE_PEACE = 1;
  185. public static final byte ZONE_SIEGE = 2;
  186. public static final byte ZONE_MOTHERTREE = 3;
  187. public static final byte ZONE_CLANHALL = 4;
  188. public static final byte ZONE_UNUSED = 5;
  189. public static final byte ZONE_NOLANDING = 6;
  190. public static final byte ZONE_WATER = 7;
  191. public static final byte ZONE_JAIL = 8;
  192. public static final byte ZONE_MONSTERTRACK = 9;
  193. public static final byte ZONE_CASTLE = 10;
  194. public static final byte ZONE_SWAMP = 11;
  195. public static final byte ZONE_NOSUMMONFRIEND = 12;
  196. public static final byte ZONE_FORT = 13;
  197. private final byte[] _zones = new byte[14];
  198. protected byte _zoneValidateCounter = 4;
  199. private boolean _isRaid = false;
  200. /**
  201. * Returns character inventory, default null, overridden in L2Playable types and in L2NPcInstance
  202. */
  203. public Inventory getInventory()
  204. {
  205. return null;
  206. }
  207. public boolean destroyItemByItemId(String process, int itemId, int count, L2Object reference, boolean sendMessage)
  208. {
  209. // Default: NPCs consume virtual items for their skills
  210. // TODO: should be logged if even happens.. should be false
  211. return true;
  212. }
  213. public boolean destroyItem(String process, int objectId, int count, L2Object reference, boolean sendMessage)
  214. {
  215. // Default: NPCs consume virtual items for their skills
  216. // TODO: should be logged if even happens.. should be false
  217. return true;
  218. }
  219. /**
  220. *
  221. * @param zone
  222. * @return
  223. */
  224. public final boolean isInsideZone(final byte zone)
  225. {
  226. return zone == ZONE_PVP ? _zones[ZONE_PVP] > 0 && _zones[ZONE_PEACE] == 0 : _zones[zone] > 0;
  227. }
  228. /**
  229. *
  230. * @param zone
  231. * @param state
  232. */
  233. public final void setInsideZone(final byte zone, final boolean state)
  234. {
  235. if (state)
  236. _zones[zone]++;
  237. else
  238. {
  239. _zones[zone]--;
  240. if (_zones[zone] < 0)
  241. _zones[zone] = 0;
  242. }
  243. }
  244. /**
  245. * This will return true if the player is transformed,<br>
  246. * but if the player is not transformed it will return false.
  247. * @return transformation status
  248. */
  249. public boolean isTransformed()
  250. {
  251. return false;
  252. }
  253. /**
  254. * This will untransform a player if they are an instance of L2Pcinstance
  255. * and if they are transformed.
  256. * @return untransform
  257. */
  258. public void untransform()
  259. {
  260. // Just a place holder
  261. }
  262. /**
  263. * This will return true if the player is GM,<br>
  264. * but if the player is not GM it will return false.
  265. * @return GM status
  266. */
  267. public boolean isGM()
  268. {
  269. return false;
  270. }
  271. // =========================================================
  272. // Constructor
  273. /**
  274. * Constructor of L2Character.<BR><BR>
  275. *
  276. * <B><U> Concept</U> :</B><BR><BR>
  277. * Each L2Character owns generic and static properties (ex : all Keltir have the same number of HP...).
  278. * All of those properties are stored in a different template for each type of L2Character.
  279. * Each template is loaded once in the server cache memory (reduce memory use).
  280. * When a new instance of L2Character is spawned, server just create a link between the instance and the template
  281. * This link is stored in <B>_template</B><BR><BR>
  282. *
  283. * <B><U> Actions</U> :</B><BR><BR>
  284. * <li>Set the _template of the L2Character </li>
  285. * <li>Set _overloaded to false (the charcater can take more items)</li><BR><BR>
  286. *
  287. * <li>If L2Character is a L2NPCInstance, copy skills from template to object</li>
  288. * <li>If L2Character is a L2NPCInstance, link _calculators to NPC_STD_CALCULATOR</li><BR><BR>
  289. *
  290. * <li>If L2Character is NOT a L2NPCInstance, create an empty _skills slot</li>
  291. * <li>If L2Character is a L2PcInstance or L2Summon, copy basic Calculator set to object</li><BR><BR>
  292. *
  293. * @param objectId Identifier of the object to initialized
  294. * @param template The L2CharTemplate to apply to the object
  295. */
  296. public L2Character(int objectId, L2CharTemplate template)
  297. {
  298. super(objectId);
  299. getKnownList();
  300. // Set its template to the new L2Character
  301. _template = template;
  302. if (template != null && this instanceof L2NpcInstance)
  303. {
  304. // Copy the Standard Calcultors of the L2NPCInstance in _calculators
  305. if (this instanceof L2DoorInstance)
  306. _calculators = Formulas.getInstance().getStdDoorCalculators();
  307. else
  308. _calculators = NPC_STD_CALCULATOR;
  309. // Copy the skills of the L2NPCInstance from its template to the L2Character Instance
  310. // The skills list can be affected by spell effects so it's necessary to make a copy
  311. // to avoid that a spell affecting a L2NPCInstance, affects others L2NPCInstance of the same type too.
  312. _skills = ((L2NpcTemplate)template).getSkills();
  313. if (_skills != null)
  314. {
  315. for(Map.Entry<Integer, L2Skill> skill : _skills.entrySet())
  316. addStatFuncs(skill.getValue().getStatFuncs(null, this));
  317. }
  318. }
  319. else
  320. {
  321. // Initialize the FastMap _skills to null
  322. _skills = new FastMap<Integer,L2Skill>().setShared(true);
  323. // If L2Character is a L2PcInstance or a L2Summon, create the basic calculator set
  324. _calculators = new Calculator[Stats.NUM_STATS];
  325. Formulas.getInstance().addFuncsToNewCharacter(this);
  326. }
  327. if (!(this instanceof L2PcInstance) && !(this instanceof L2MonsterInstance) &&
  328. !(this instanceof L2GuardInstance) && !(this instanceof L2SiegeGuardInstance) &&
  329. !(this instanceof L2ControlTowerInstance) && !(this instanceof L2DoorInstance) &&
  330. !(this instanceof L2TrapInstance) && !(this instanceof L2FriendlyMobInstance) &&
  331. !(this instanceof L2DecoyInstance) && !(this instanceof L2SiegeSummonInstance) &&
  332. !(this instanceof L2PetInstance) && !(this instanceof L2SummonInstance) &&
  333. !(this instanceof L2SiegeFlagInstance) && !(this instanceof L2EffectPointInstance) &&
  334. !(this instanceof L2FortCommanderInstance) && !(this instanceof L2FolkInstance) &&
  335. !(this instanceof L2FortSiegeGuardInstance))
  336. setIsInvul(true);
  337. }
  338. protected void initCharStatusUpdateValues()
  339. {
  340. _hpUpdateInterval = getMaxHp()/352.0; // MAX_HP div MAX_HP_BAR_PX
  341. _hpUpdateIncCheck = getMaxHp();
  342. _hpUpdateDecCheck = getMaxHp()-_hpUpdateInterval;
  343. }
  344. // =========================================================
  345. // Event - Public
  346. /**
  347. * Remove the L2Character from the world when the decay task is launched.<BR><BR>
  348. *
  349. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T REMOVE the object from _allObjects of L2World </B></FONT><BR>
  350. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T SEND Server->Client packets to players</B></FONT><BR><BR>
  351. *
  352. */
  353. public void onDecay()
  354. {
  355. L2WorldRegion reg = getWorldRegion();
  356. decayMe();
  357. if(reg != null) reg.removeFromZones(this);
  358. }
  359. @Override
  360. public void onSpawn()
  361. {
  362. super.onSpawn();
  363. this.revalidateZone(true);
  364. }
  365. public void onTeleported()
  366. {
  367. if (!isTeleporting())
  368. return;
  369. spawnMe(getPosition().getX(), getPosition().getY(), getPosition().getZ());
  370. setIsTeleporting(false);
  371. if (_isPendingRevive)
  372. doRevive();
  373. }
  374. // =========================================================
  375. // Method - Public
  376. /**
  377. * Add L2Character instance that is attacking to the attacker list.<BR><BR>
  378. * @param player The L2Character that attcks this one
  379. */
  380. public void addAttackerToAttackByList (L2Character player)
  381. {
  382. if (player == null || player == this || getAttackByList() == null || getAttackByList().contains(player)) return;
  383. getAttackByList().add(player);
  384. }
  385. /**
  386. * Send a packet to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character.<BR><BR>
  387. *
  388. * <B><U> Concept</U> :</B><BR><BR>
  389. * L2PcInstance in the detection area of the L2Character are identified in <B>_knownPlayers</B>.
  390. * In order to inform other players of state modification on the L2Character, server just need to go through _knownPlayers to send Server->Client Packet<BR><BR>
  391. *
  392. */
  393. public void broadcastPacket(L2GameServerPacket mov)
  394. {
  395. Collection<L2PcInstance> plrs = getKnownList().getKnownPlayers().values();
  396. //synchronized (getKnownList().getKnownPlayers())
  397. {
  398. for (L2PcInstance player : plrs)
  399. player.sendPacket(mov);
  400. }
  401. }
  402. /**
  403. * Send a packet to the L2Character AND to all L2PcInstance in the radius (max knownlist radius) from the L2Character.<BR><BR>
  404. *
  405. * <B><U> Concept</U> :</B><BR><BR>
  406. * L2PcInstance in the detection area of the L2Character are identified in <B>_knownPlayers</B>.
  407. * In order to inform other players of state modification on the L2Character, server just need to go through _knownPlayers to send Server->Client Packet<BR><BR>
  408. *
  409. */
  410. public void broadcastPacket(L2GameServerPacket mov, int radiusInKnownlist)
  411. {
  412. Collection<L2PcInstance> plrs = getKnownList().getKnownPlayers().values();
  413. //synchronized (getKnownList().getKnownPlayers())
  414. {
  415. for (L2PcInstance player : plrs)
  416. {
  417. if (isInsideRadius(player, radiusInKnownlist, false, false))
  418. player.sendPacket(mov);
  419. }
  420. }
  421. }
  422. /**
  423. * Returns true if hp update should be done, false if not
  424. * @return boolean
  425. */
  426. protected boolean needHpUpdate(int barPixels)
  427. {
  428. double currentHp = getCurrentHp();
  429. if (currentHp <= 1.0 || getMaxHp() < barPixels)
  430. return true;
  431. if (currentHp <= _hpUpdateDecCheck || currentHp >= _hpUpdateIncCheck)
  432. {
  433. if (currentHp == getMaxHp())
  434. {
  435. _hpUpdateIncCheck = currentHp + 1;
  436. _hpUpdateDecCheck = currentHp - _hpUpdateInterval;
  437. }
  438. else
  439. {
  440. double doubleMulti = currentHp / _hpUpdateInterval;
  441. int intMulti = (int)doubleMulti;
  442. _hpUpdateDecCheck = _hpUpdateInterval * (doubleMulti < intMulti ? intMulti-- : intMulti);
  443. _hpUpdateIncCheck = _hpUpdateDecCheck + _hpUpdateInterval;
  444. }
  445. return true;
  446. }
  447. return false;
  448. }
  449. /**
  450. * Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform.<BR><BR>
  451. *
  452. * <B><U> Actions</U> :</B><BR><BR>
  453. * <li>Create the Server->Client packet StatusUpdate with current HP and MP </li>
  454. * <li>Send the Server->Client packet StatusUpdate with current HP and MP to all
  455. * L2Character called _statusListener that must be informed of HP/MP updates of this L2Character </li><BR><BR>
  456. *
  457. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T SEND CP information</B></FONT><BR><BR>
  458. *
  459. * <B><U> Overridden in </U> :</B><BR><BR>
  460. * <li> L2PcInstance : Send current HP,MP and CP to the L2PcInstance and only current HP, MP and Level to all other L2PcInstance of the Party</li><BR><BR>
  461. *
  462. */
  463. public void broadcastStatusUpdate()
  464. {
  465. if (getStatus().getStatusListener().isEmpty()) return;
  466. if (!needHpUpdate(352))
  467. return;
  468. if (Config.DEBUG)
  469. _log.fine("Broadcast Status Update for " + getObjectId() + "(" + getName() + "). HP: " + getCurrentHp());
  470. // Create the Server->Client packet StatusUpdate with current HP and MP
  471. StatusUpdate su = new StatusUpdate(getObjectId());
  472. su.addAttribute(StatusUpdate.CUR_HP, (int)getCurrentHp());
  473. su.addAttribute(StatusUpdate.CUR_MP, (int)getCurrentMp());
  474. // Go through the StatusListener
  475. // Send the Server->Client packet StatusUpdate with current HP and MP
  476. synchronized (getStatus().getStatusListener())
  477. {
  478. for (L2Character temp : getStatus().getStatusListener())
  479. {
  480. try { temp.sendPacket(su); } catch (NullPointerException e) {}
  481. }
  482. }
  483. }
  484. /**
  485. * Not Implemented.<BR><BR>
  486. *
  487. * <B><U> Overridden in </U> :</B><BR><BR>
  488. * <li> L2PcInstance</li><BR><BR>
  489. */
  490. public void sendPacket(L2GameServerPacket mov)
  491. {
  492. // default implementation
  493. }
  494. /**
  495. * Not Implemented.<BR><BR>
  496. *
  497. * <B><U> Overridden in </U> :</B><BR><BR>
  498. * <li> L2PcInstance</li><BR><BR>
  499. */
  500. public void sendMessage(String text)
  501. {
  502. // default implementation
  503. }
  504. /**
  505. * Teleport a L2Character and its pet if necessary.<BR><BR>
  506. *
  507. * <B><U> Actions</U> :</B><BR><BR>
  508. * <li>Stop the movement of the L2Character</li>
  509. * <li>Set the x,y,z position of the L2Object and if necessary modify its _worldRegion</li>
  510. * <li>Send a Server->Client packet TeleportToLocationt to the L2Character AND to all L2PcInstance in its _KnownPlayers</li>
  511. * <li>Modify the position of the pet if necessary</li><BR><BR>
  512. *
  513. */
  514. public void teleToLocation(int x, int y, int z, boolean allowRandomOffset)
  515. {
  516. // Stop movement
  517. stopMove(null, false);
  518. abortAttack();
  519. abortCast();
  520. setIsTeleporting(true);
  521. setTarget(null);
  522. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  523. if (Config.RESPAWN_RANDOM_ENABLED && allowRandomOffset)
  524. {
  525. x += Rnd.get(-Config.RESPAWN_RANDOM_MAX_OFFSET, Config.RESPAWN_RANDOM_MAX_OFFSET);
  526. y += Rnd.get(-Config.RESPAWN_RANDOM_MAX_OFFSET, Config.RESPAWN_RANDOM_MAX_OFFSET);
  527. }
  528. z += 5;
  529. if (Config.DEBUG)
  530. _log.fine("Teleporting to: " + x + ", " + y + ", " + z);
  531. // remove the object from its old location
  532. decayMe();
  533. // Send a Server->Client packet TeleportToLocationt to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
  534. broadcastPacket(new TeleportToLocation(this, x, y, z));
  535. // Set the x,y,z position of the L2Object and if necessary modify its _worldRegion
  536. getPosition().setXYZ(x, y, z);
  537. if (!(this instanceof L2PcInstance))
  538. onTeleported();
  539. }
  540. public void teleToLocation(int x, int y, int z) { teleToLocation(x, y, z, false); }
  541. public void teleToLocation(Location loc, boolean allowRandomOffset)
  542. {
  543. int x = loc.getX();
  544. int y = loc.getY();
  545. int z = loc.getZ();
  546. if (this instanceof L2PcInstance && DimensionalRiftManager.getInstance().checkIfInRiftZone(getX(), getY(), getZ(), true)) // true -> ignore waiting room :)
  547. {
  548. L2PcInstance player = (L2PcInstance)this;
  549. player.sendMessage("You have been sent to the waiting room.");
  550. if(player.isInParty() && player.getParty().isInDimensionalRift())
  551. {
  552. player.getParty().getDimensionalRift().usedTeleport(player);
  553. }
  554. int[] newCoords = DimensionalRiftManager.getInstance().getRoom((byte) 0, (byte) 0).getTeleportCoords();
  555. x = newCoords[0];
  556. y = newCoords[1];
  557. z = newCoords[2];
  558. }
  559. teleToLocation(x, y, z, allowRandomOffset);
  560. }
  561. public void teleToLocation(TeleportWhereType teleportWhere) { teleToLocation(MapRegionTable.getInstance().getTeleToLocation(this, teleportWhere), true); }
  562. // =========================================================
  563. // Method - Private
  564. /**
  565. * Launch a physical attack against a target (Simple, Bow, Pole or Dual).<BR><BR>
  566. *
  567. * <B><U> Actions</U> :</B><BR><BR>
  568. * <li>Get the active weapon (always equiped in the right hand) </li><BR><BR>
  569. * <li>If weapon is a bow, check for arrows, MP and bow re-use delay (if necessary, equip the L2PcInstance with arrows in left hand)</li>
  570. * <li>If weapon is a bow, consume MP and set the new period of bow non re-use </li><BR><BR>
  571. * <li>Get the Attack Speed of the L2Character (delay (in milliseconds) before next attack) </li>
  572. * <li>Select the type of attack to start (Simple, Bow, Pole or Dual) and verify if SoulShot are charged then start calculation</li>
  573. * <li>If the Server->Client packet Attack contains at least 1 hit, send the Server->Client packet Attack to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character</li>
  574. * <li>Notify AI with EVT_READY_TO_ACT</li><BR><BR>
  575. *
  576. * @param target The L2Character targeted
  577. *
  578. */
  579. protected void doAttack(L2Character target)
  580. {
  581. if (Config.DEBUG)
  582. _log.fine(getName()+" doAttack: target="+target);
  583. if (!isAlikeDead() && target != null)
  584. {
  585. if (this instanceof L2NpcInstance && target.isAlikeDead()
  586. || !getKnownList().knowsObject(target))
  587. {
  588. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  589. sendPacket(ActionFailed.STATIC_PACKET);
  590. return;
  591. }
  592. else if (this instanceof L2PcInstance)
  593. {
  594. if (target.isDead())
  595. {
  596. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  597. sendPacket(ActionFailed.STATIC_PACKET);
  598. return;
  599. }
  600. }
  601. }
  602. if (isAttackingDisabled())
  603. return;
  604. if (this instanceof L2PcInstance)
  605. {
  606. if (((L2PcInstance)this).inObserverMode())
  607. {
  608. sendPacket(new SystemMessage(SystemMessageId.OBSERVERS_CANNOT_PARTICIPATE));
  609. sendPacket(ActionFailed.STATIC_PACKET);
  610. return;
  611. }
  612. if (target instanceof L2PcInstance)
  613. {
  614. if (((L2PcInstance)target).isCursedWeaponEquipped() && ((L2PcInstance)this).getLevel()<=20){
  615. ((L2PcInstance)this).sendMessage("Can't attack a cursed player when under level 21.");
  616. sendPacket(ActionFailed.STATIC_PACKET);
  617. return;
  618. }
  619. if (((L2PcInstance)this).isCursedWeaponEquipped() && ((L2PcInstance)target).getLevel()<=20){
  620. ((L2PcInstance)this).sendMessage("Can't attack a newbie player using a cursed weapon.");
  621. sendPacket(ActionFailed.STATIC_PACKET);
  622. return;
  623. }
  624. }
  625. // Checking if target has moved to peace zone
  626. if (target.isInsidePeaceZone((L2PcInstance)this))
  627. {
  628. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  629. sendPacket(ActionFailed.STATIC_PACKET);
  630. return;
  631. }
  632. // TODO: unhardcode this to support boolean if with that weapon u can attack or not (for ex transform weapons)
  633. if (((L2PcInstance)this).getActiveWeaponItem() != null && ((L2PcInstance)this).getActiveWeaponItem().getItemId() == 9819)
  634. {
  635. sendPacket(new SystemMessage(SystemMessageId.THAT_WEAPON_CANT_ATTACK));
  636. sendPacket(ActionFailed.STATIC_PACKET);
  637. return;
  638. }
  639. }
  640. else if (isInsidePeaceZone(this, target))
  641. {
  642. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  643. sendPacket(ActionFailed.STATIC_PACKET);
  644. return;
  645. }
  646. // Get the active weapon instance (always equiped in the right hand)
  647. L2ItemInstance weaponInst = getActiveWeaponInstance();
  648. // Get the active weapon item corresponding to the active weapon instance (always equiped in the right hand)
  649. L2Weapon weaponItem = getActiveWeaponItem();
  650. if (weaponItem != null && weaponItem.getItemType() == L2WeaponType.ROD)
  651. {
  652. // You can't make an attack with a fishing pole.
  653. sendPacket(new SystemMessage(SystemMessageId.CANNOT_ATTACK_WITH_FISHING_POLE));
  654. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  655. ActionFailed af = ActionFailed.STATIC_PACKET;
  656. sendPacket(af);
  657. return;
  658. }
  659. // GeoData Los Check here (or dz > 1000)
  660. if (!GeoData.getInstance().canSeeTarget(this, target))
  661. {
  662. sendPacket(new SystemMessage(SystemMessageId.CANT_SEE_TARGET));
  663. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  664. sendPacket(ActionFailed.STATIC_PACKET);
  665. return;
  666. }
  667. // BOW and CROSSBOW checks
  668. if (weaponItem != null && !isTransformed())
  669. {
  670. if (weaponItem.getItemType() == L2WeaponType.BOW)
  671. {
  672. //Check for arrows and MP
  673. if (this instanceof L2PcInstance)
  674. {
  675. // Verify if the bow can be use
  676. if (_disableBowAttackEndTime <= GameTimeController.getGameTicks())
  677. {
  678. // Verify if L2PcInstance owns enough MP
  679. int saMpConsume = (int)getStat().calcStat(Stats.MP_CONSUME, 0, null, null);
  680. int mpConsume = saMpConsume == 0 ? weaponItem.getMpConsume() : saMpConsume;
  681. if (getCurrentMp() < mpConsume)
  682. {
  683. // If L2PcInstance doesn't have enough MP, stop the attack
  684. ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_READY_TO_ACT), 1000);
  685. sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_MP));
  686. sendPacket(ActionFailed.STATIC_PACKET);
  687. return;
  688. }
  689. // If L2PcInstance have enough MP, the bow consumes it
  690. getStatus().reduceMp(mpConsume);
  691. // Set the period of bow no re-use
  692. _disableBowAttackEndTime = 5 * GameTimeController.TICKS_PER_SECOND + GameTimeController.getGameTicks();
  693. }
  694. else
  695. {
  696. // Cancel the action because the bow can't be re-use at this moment
  697. ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_READY_TO_ACT), 1000);
  698. sendPacket(ActionFailed.STATIC_PACKET);
  699. return;
  700. }
  701. // Equip arrows needed in left hand and send a Server->Client packet ItemList to the L2PcINstance then return True
  702. if (!checkAndEquipArrows())
  703. {
  704. // Cancel the action because the L2PcInstance have no arrow
  705. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  706. sendPacket(ActionFailed.STATIC_PACKET);
  707. sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_ARROWS));
  708. return;
  709. }
  710. }
  711. }
  712. if (weaponItem.getItemType() == L2WeaponType.CROSSBOW)
  713. {
  714. //Check for bolts
  715. if (this instanceof L2PcInstance)
  716. {
  717. // Checking if target has moved to peace zone - only for player-crossbow attacks at the moment
  718. // Other melee is checked in movement code and for offensive spells a check is done every time
  719. if (target.isInsidePeaceZone((L2PcInstance)this))
  720. {
  721. getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  722. sendPacket(ActionFailed.STATIC_PACKET);
  723. return;
  724. }
  725. // Verify if the crossbow can be use
  726. if (_disableCrossBowAttackEndTime <= GameTimeController.getGameTicks())
  727. {
  728. // Set the period of crossbow no re-use
  729. _disableCrossBowAttackEndTime = 5 * GameTimeController.TICKS_PER_SECOND + GameTimeController.getGameTicks();
  730. }
  731. else
  732. {
  733. // Cancel the action because the crossbow can't be re-use at this moment
  734. ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_READY_TO_ACT), 1000);
  735. sendPacket(ActionFailed.STATIC_PACKET);
  736. return;
  737. }
  738. // Equip bolts needed in left hand and send a Server->Client packet ItemList to the L2PcINstance then return True
  739. if (!checkAndEquipBolts())
  740. {
  741. // Cancel the action because the L2PcInstance have no arrow
  742. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  743. sendPacket(ActionFailed.STATIC_PACKET);
  744. sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_BOLTS));
  745. return;
  746. }
  747. }
  748. else if (this instanceof L2NpcInstance)
  749. {
  750. if (_disableCrossBowAttackEndTime > GameTimeController.getGameTicks())
  751. return;
  752. }
  753. }
  754. }
  755. // Add the L2PcInstance to _knownObjects and _knownPlayer of the target
  756. target.getKnownList().addKnownObject(this);
  757. // Reduce the current CP if TIREDNESS configuration is activated
  758. if (Config.ALT_GAME_TIREDNESS)
  759. setCurrentCp(getCurrentCp() - 10);
  760. // Recharge any active auto soulshot tasks for player (or player's summon if one exists).
  761. if (this instanceof L2PcInstance)
  762. ((L2PcInstance)this).rechargeAutoSoulShot(true, false, false);
  763. else if (this instanceof L2Summon)
  764. ((L2Summon)this).getOwner().rechargeAutoSoulShot(true, false, true);
  765. // Verify if soulshots are charged.
  766. boolean wasSSCharged;
  767. if (this instanceof L2NpcInstance)
  768. wasSSCharged = ((L2NpcInstance)this).rechargeAutoSoulShot(true, false);
  769. else if (this instanceof L2Summon && !(this instanceof L2PetInstance))
  770. wasSSCharged = (((L2Summon)this).getChargedSoulShot() != L2ItemInstance.CHARGED_NONE);
  771. else
  772. wasSSCharged = (weaponInst != null && weaponInst.getChargedSoulshot() != L2ItemInstance.CHARGED_NONE);
  773. // Get the Attack Speed of the L2Character (delay (in milliseconds) before next attack)
  774. int timeAtk = calculateTimeBetweenAttacks(target, weaponItem);
  775. // the hit is calculated to happen halfway to the animation - might need further tuning e.g. in bow case
  776. int timeToHit = timeAtk/2;
  777. _attackEndTime = GameTimeController.getGameTicks();
  778. _attackEndTime += (timeAtk / GameTimeController.MILLIS_IN_TICK);
  779. _attackEndTime -= 1;
  780. int ssGrade = 0;
  781. if (weaponItem != null)
  782. {
  783. ssGrade = weaponItem.getCrystalType();
  784. if (ssGrade == 6)
  785. ssGrade = 5;
  786. }
  787. // Create a Server->Client packet Attack
  788. Attack attack = new Attack(this, wasSSCharged, ssGrade);
  789. // Set the Attacking Body part to CHEST
  790. setAttackingBodypart();
  791. // Make sure that char is facing selected target
  792. // also works: setHeading(Util.convertDegreeToClientHeading(Util.calculateAngleFrom(this, target)));
  793. setHeading(Util.calculateHeadingFrom(this, target));
  794. // Get the Attack Reuse Delay of the L2Weapon
  795. int reuse = calculateReuseTime(target, weaponItem);
  796. boolean hitted;
  797. // Select the type of attack to start
  798. if (weaponItem == null || isTransformed())
  799. hitted = doAttackHitSimple(attack, target, timeToHit);
  800. else if (weaponItem.getItemType() == L2WeaponType.BOW)
  801. hitted = doAttackHitByBow(attack, target, timeAtk, reuse);
  802. else if (weaponItem.getItemType() == L2WeaponType.CROSSBOW)
  803. hitted = doAttackHitByCrossBow(attack, target, timeAtk, reuse);
  804. else if (weaponItem.getItemType() == L2WeaponType.POLE)
  805. hitted = doAttackHitByPole(attack, target, timeToHit);
  806. else if (isUsingDualWeapon())
  807. hitted = doAttackHitByDual(attack, target, timeToHit);
  808. else
  809. hitted = doAttackHitSimple(attack, target, timeToHit);
  810. // Flag the attacker if it's a L2PcInstance outside a PvP area
  811. L2PcInstance player = getActingPlayer();
  812. if (player != null)
  813. player.updatePvPStatus(target);
  814. // Check if hit isn't missed
  815. if (!hitted)
  816. // Abort the attack of the L2Character and send Server->Client ActionFailed packet
  817. abortAttack();
  818. else
  819. {
  820. /* ADDED BY nexus - 2006-08-17
  821. *
  822. * As soon as we know that our hit landed, we must discharge any active soulshots.
  823. * This must be done so to avoid unwanted soulshot consumption.
  824. */
  825. // If we didn't miss the hit, discharge the shoulshots, if any
  826. if (this instanceof L2Summon && !(this instanceof L2PetInstance))
  827. ((L2Summon)this).setChargedSoulShot(L2ItemInstance.CHARGED_NONE);
  828. else
  829. if (weaponInst != null)
  830. weaponInst.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
  831. if (player != null)
  832. {
  833. if (player.isCursedWeaponEquipped())
  834. {
  835. // If hitted by a cursed weapon, Cp is reduced to 0
  836. if (!target.isInvul())
  837. target.setCurrentCp(0);
  838. } else if (player.isHero())
  839. {
  840. if (target instanceof L2PcInstance && ((L2PcInstance)target).isCursedWeaponEquipped())
  841. // If a cursed weapon is hitted by a Hero, Cp is reduced to 0
  842. target.setCurrentCp(0);
  843. }
  844. }
  845. }
  846. // If the Server->Client packet Attack contains at least 1 hit, send the Server->Client packet Attack
  847. // to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
  848. if (attack.hasHits())
  849. broadcastPacket(attack);
  850. // Notify AI with EVT_READY_TO_ACT
  851. ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_READY_TO_ACT), timeAtk+reuse);
  852. }
  853. /**
  854. * Launch a Bow attack.<BR><BR>
  855. *
  856. * <B><U> Actions</U> :</B><BR><BR>
  857. * <li>Calculate if hit is missed or not </li>
  858. * <li>Consume arrows </li>
  859. * <li>If hit isn't missed, calculate if shield defense is efficient </li>
  860. * <li>If hit isn't missed, calculate if hit is critical </li>
  861. * <li>If hit isn't missed, calculate physical damages </li>
  862. * <li>If the L2Character is a L2PcInstance, Send a Server->Client packet SetupGauge </li>
  863. * <li>Create a new hit task with Medium priority</li>
  864. * <li>Calculate and set the disable delay of the bow in function of the Attack Speed</li>
  865. * <li>Add this hit to the Server-Client packet Attack </li><BR><BR>
  866. *
  867. * @param attack Server->Client packet Attack in which the hit will be added
  868. * @param target The L2Character targeted
  869. * @param sAtk The Attack Speed of the attacker
  870. *
  871. * @return True if the hit isn't missed
  872. *
  873. */
  874. private boolean doAttackHitByBow(Attack attack, L2Character target, int sAtk, int reuse)
  875. {
  876. int damage1 = 0;
  877. byte shld1 = 0;
  878. boolean crit1 = false;
  879. // Calculate if hit is missed or not
  880. boolean miss1 = Formulas.getInstance().calcHitMiss(this, target);
  881. // Consume arrows
  882. reduceArrowCount(false);
  883. _move = null;
  884. // Check if hit isn't missed
  885. if (!miss1)
  886. {
  887. // Calculate if shield defense is efficient
  888. shld1 = Formulas.getInstance().calcShldUse(this, target);
  889. // Calculate if hit is critical
  890. crit1 = Formulas.getInstance().calcCrit(getStat().getCriticalHit(target, null));
  891. // Calculate physical damages
  892. damage1 = (int)Formulas.getInstance().calcPhysDam(this, target, null, shld1, crit1, false, attack.soulshot);
  893. }
  894. // Check if the L2Character is a L2PcInstance
  895. if (this instanceof L2PcInstance)
  896. {
  897. // Send a system message
  898. sendPacket(new SystemMessage(SystemMessageId.GETTING_READY_TO_SHOOT_AN_ARROW));
  899. // Send a Server->Client packet SetupGauge
  900. SetupGauge sg = new SetupGauge(SetupGauge.RED, sAtk+reuse);
  901. sendPacket(sg);
  902. }
  903. // Create a new hit task with Medium priority
  904. ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk);
  905. // Calculate and set the disable delay of the bow in function of the Attack Speed
  906. _disableBowAttackEndTime = (sAtk+reuse)/GameTimeController.MILLIS_IN_TICK + GameTimeController.getGameTicks();
  907. // Add this hit to the Server-Client packet Attack
  908. attack.addHit(target, damage1, miss1, crit1, shld1);
  909. // Return true if hit isn't missed
  910. return !miss1;
  911. }
  912. /**
  913. * Launch a CrossBow attack.<BR><BR>
  914. *
  915. * <B><U> Actions</U> :</B><BR><BR>
  916. * <li>Calculate if hit is missed or not </li>
  917. * <li>Consume bolts </li>
  918. * <li>If hit isn't missed, calculate if shield defense is efficient </li>
  919. * <li>If hit isn't missed, calculate if hit is critical </li>
  920. * <li>If hit isn't missed, calculate physical damages </li>
  921. * <li>If the L2Character is a L2PcInstance, Send a Server->Client packet SetupGauge </li>
  922. * <li>Create a new hit task with Medium priority</li>
  923. * <li>Calculate and set the disable delay of the crossbow in function of the Attack Speed</li>
  924. * <li>Add this hit to the Server-Client packet Attack </li><BR><BR>
  925. *
  926. * @param attack Server->Client packet Attack in which the hit will be added
  927. * @param target The L2Character targeted
  928. * @param sAtk The Attack Speed of the attacker
  929. *
  930. * @return True if the hit isn't missed
  931. *
  932. */
  933. private boolean doAttackHitByCrossBow(Attack attack, L2Character target, int sAtk, int reuse)
  934. {
  935. int damage1 = 0;
  936. byte shld1 = 0;
  937. boolean crit1 = false;
  938. // Calculate if hit is missed or not
  939. boolean miss1 = Formulas.getInstance().calcHitMiss(this, target);
  940. // Consume bolts
  941. reduceArrowCount(true);
  942. _move = null;
  943. // Check if hit isn't missed
  944. if (!miss1)
  945. {
  946. // Calculate if shield defense is efficient
  947. shld1 = Formulas.getInstance().calcShldUse(this, target);
  948. // Calculate if hit is critical
  949. crit1 = Formulas.getInstance().calcCrit(getStat().getCriticalHit(target, null));
  950. // Calculate physical damages
  951. damage1 = (int)Formulas.getInstance().calcPhysDam(this, target, null, shld1, crit1, false, attack.soulshot);
  952. }
  953. // Check if the L2Character is a L2PcInstance
  954. if (this instanceof L2PcInstance)
  955. {
  956. // Send a system message
  957. sendPacket(new SystemMessage(SystemMessageId.CROSSBOW_PREPARING_TO_FIRE));
  958. // Send a Server->Client packet SetupGauge
  959. SetupGauge sg = new SetupGauge(SetupGauge.RED, sAtk+reuse);
  960. sendPacket(sg);
  961. }
  962. // Create a new hit task with Medium priority
  963. ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk);
  964. // Calculate and set the disable delay of the bow in function of the Attack Speed
  965. _disableCrossBowAttackEndTime = (sAtk+reuse)/GameTimeController.MILLIS_IN_TICK + GameTimeController.getGameTicks();
  966. // Add this hit to the Server-Client packet Attack
  967. attack.addHit(target, damage1, miss1, crit1, shld1);
  968. // Return true if hit isn't missed
  969. return !miss1;
  970. }
  971. /**
  972. * Launch a Dual attack.<BR><BR>
  973. *
  974. * <B><U> Actions</U> :</B><BR><BR>
  975. * <li>Calculate if hits are missed or not </li>
  976. * <li>If hits aren't missed, calculate if shield defense is efficient </li>
  977. * <li>If hits aren't missed, calculate if hit is critical </li>
  978. * <li>If hits aren't missed, calculate physical damages </li>
  979. * <li>Create 2 new hit tasks with Medium priority</li>
  980. * <li>Add those hits to the Server-Client packet Attack </li><BR><BR>
  981. *
  982. * @param attack Server->Client packet Attack in which the hit will be added
  983. * @param target The L2Character targeted
  984. *
  985. * @return True if hit 1 or hit 2 isn't missed
  986. *
  987. */
  988. private boolean doAttackHitByDual(Attack attack, L2Character target, int sAtk)
  989. {
  990. int damage1 = 0;
  991. int damage2 = 0;
  992. byte shld1 = 0;
  993. byte shld2 = 0;
  994. boolean crit1 = false;
  995. boolean crit2 = false;
  996. // Calculate if hits are missed or not
  997. boolean miss1 = Formulas.getInstance().calcHitMiss(this, target);
  998. boolean miss2 = Formulas.getInstance().calcHitMiss(this, target);
  999. // Check if hit 1 isn't missed
  1000. if (!miss1)
  1001. {
  1002. // Calculate if shield defense is efficient against hit 1
  1003. shld1 = Formulas.getInstance().calcShldUse(this, target);
  1004. // Calculate if hit 1 is critical
  1005. crit1 = Formulas.getInstance().calcCrit(getStat().getCriticalHit(target, null));
  1006. // Calculate physical damages of hit 1
  1007. damage1 = (int)Formulas.getInstance().calcPhysDam(this, target, null, shld1, crit1, true, attack.soulshot);
  1008. damage1 /= 2;
  1009. }
  1010. // Check if hit 2 isn't missed
  1011. if (!miss2)
  1012. {
  1013. // Calculate if shield defense is efficient against hit 2
  1014. shld2 = Formulas.getInstance().calcShldUse(this, target);
  1015. // Calculate if hit 2 is critical
  1016. crit2 = Formulas.getInstance().calcCrit(getStat().getCriticalHit(target, null));
  1017. // Calculate physical damages of hit 2
  1018. damage2 = (int)Formulas.getInstance().calcPhysDam(this, target, null, shld2, crit2, true, attack.soulshot);
  1019. damage2 /= 2;
  1020. }
  1021. // Create a new hit task with Medium priority for hit 1
  1022. ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk/2);
  1023. // Create a new hit task with Medium priority for hit 2 with a higher delay
  1024. ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage2, crit2, miss2, attack.soulshot, shld2), sAtk);
  1025. // Add those hits to the Server-Client packet Attack
  1026. attack.addHit(target, damage1, miss1, crit1, shld1);
  1027. attack.addHit(target, damage2, miss2, crit2, shld2);
  1028. // Return true if hit 1 or hit 2 isn't missed
  1029. return (!miss1 || !miss2);
  1030. }
  1031. /**
  1032. * Launch a Pole attack.<BR><BR>
  1033. *
  1034. * <B><U> Actions</U> :</B><BR><BR>
  1035. * <li>Get all visible objects in a spherical area near the L2Character to obtain possible targets </li>
  1036. * <li>If possible target is the L2Character targeted, launch a simple attack against it </li>
  1037. * <li>If possible target isn't the L2Character targeted but is attackable, launch a simple attack against it </li><BR><BR>
  1038. *
  1039. * @param attack Server->Client packet Attack in which the hit will be added
  1040. *
  1041. * @return True if one hit isn't missed
  1042. *
  1043. */
  1044. private boolean doAttackHitByPole(Attack attack, L2Character target, int sAtk)
  1045. {
  1046. double angleChar;
  1047. int maxRadius = getPhysicalAttackRange();
  1048. int maxAngleDiff = (int)getStat().calcStat(Stats.POWER_ATTACK_ANGLE, 120, null, null);
  1049. if (Config.DEBUG)
  1050. {
  1051. _log.info("doAttackHitByPole: Max radius = " + maxRadius);
  1052. _log.info("doAttackHitByPole: Max angle = " + maxAngleDiff);
  1053. }
  1054. // o1 x: 83420 y: 148158 (Giran)
  1055. // o2 x: 83379 y: 148081 (Giran)
  1056. // dx = -41
  1057. // dy = -77
  1058. // distance between o1 and o2 = 87.24
  1059. // arctan2 = -120 (240) degree (excel arctan2(dx, dy); java arctan2(dy, dx))
  1060. //
  1061. // o2
  1062. //
  1063. // o1 ----- (heading)
  1064. // In the diagram above:
  1065. // o1 has a heading of 0/360 degree from horizontal (facing East)
  1066. // Degree of o2 in respect to o1 = -120 (240) degree
  1067. //
  1068. // o2 / (heading)
  1069. // /
  1070. // o1
  1071. // In the diagram above
  1072. // o1 has a heading of -80 (280) degree from horizontal (facing north east)
  1073. // Degree of o2 in respect to 01 = -40 (320) degree
  1074. // Get char's heading degree
  1075. angleChar = Util.convertHeadingToDegree(getHeading());
  1076. int attackRandomCountMax = (int)getStat().calcStat(Stats.ATTACK_COUNT_MAX, 3, null, null) - 1;
  1077. int attackcount = 0;
  1078. if (angleChar <= 0)
  1079. angleChar += 360;
  1080. // ===========================================================
  1081. boolean hitted = doAttackHitSimple(attack, target, 100, sAtk);
  1082. double attackpercent = 85;
  1083. L2Character temp;
  1084. Collection<L2Object> objs = getKnownList().getKnownObjects().values();
  1085. //synchronized (getKnownList().getKnownObjects())
  1086. {
  1087. for (L2Object obj : objs)
  1088. {
  1089. if (obj == target)
  1090. continue; // do not hit twice
  1091. // Check if the L2Object is a L2Character
  1092. if (obj instanceof L2Character)
  1093. {
  1094. if (obj instanceof L2PetInstance
  1095. && this instanceof L2PcInstance
  1096. && ((L2PetInstance) obj).getOwner() == ((L2PcInstance) this))
  1097. continue;
  1098. if (!Util.checkIfInRange(maxRadius, this, obj, false))
  1099. continue;
  1100. // otherwise hit too high/low. 650 because mob z coord
  1101. // sometimes wrong on hills
  1102. if (Math.abs(obj.getZ() - getZ()) > 650)
  1103. continue;
  1104. if (!isFacing(obj, maxAngleDiff))
  1105. continue;
  1106. temp = (L2Character) obj;
  1107. // Launch a simple attack against the L2Character targeted
  1108. if (!temp.isAlikeDead())
  1109. {
  1110. attackcount += 1;
  1111. if (attackcount <= attackRandomCountMax)
  1112. {
  1113. if (temp == getAI().getAttackTarget()
  1114. || temp.isAutoAttackable(this))
  1115. {
  1116. hitted |= doAttackHitSimple(attack, temp, attackpercent, sAtk);
  1117. attackpercent /= 1.15;
  1118. }
  1119. }
  1120. }
  1121. }
  1122. }
  1123. }
  1124. // Return true if one hit isn't missed
  1125. return hitted;
  1126. }
  1127. /**
  1128. * Launch a simple attack.<BR><BR>
  1129. *
  1130. * <B><U> Actions</U> :</B><BR><BR>
  1131. * <li>Calculate if hit is missed or not </li>
  1132. * <li>If hit isn't missed, calculate if shield defense is efficient </li>
  1133. * <li>If hit isn't missed, calculate if hit is critical </li>
  1134. * <li>If hit isn't missed, calculate physical damages </li>
  1135. * <li>Create a new hit task with Medium priority</li>
  1136. * <li>Add this hit to the Server-Client packet Attack </li><BR><BR>
  1137. *
  1138. * @param attack Server->Client packet Attack in which the hit will be added
  1139. * @param target The L2Character targeted
  1140. *
  1141. * @return True if the hit isn't missed
  1142. *
  1143. */
  1144. private boolean doAttackHitSimple(Attack attack, L2Character target, int sAtk)
  1145. {
  1146. return doAttackHitSimple(attack, target, 100, sAtk);
  1147. }
  1148. private boolean doAttackHitSimple(Attack attack, L2Character target, double attackpercent, int sAtk)
  1149. {
  1150. int damage1 = 0;
  1151. byte shld1 = 0;
  1152. boolean crit1 = false;
  1153. // Calculate if hit is missed or not
  1154. boolean miss1 = Formulas.getInstance().calcHitMiss(this, target);
  1155. // Check if hit isn't missed
  1156. if (!miss1)
  1157. {
  1158. // Calculate if shield defense is efficient
  1159. shld1 = Formulas.getInstance().calcShldUse(this, target);
  1160. // Calculate if hit is critical
  1161. crit1 = Formulas.getInstance().calcCrit(getStat().getCriticalHit(target, null));
  1162. // Calculate physical damages
  1163. damage1 = (int)Formulas.getInstance().calcPhysDam(this, target, null, shld1, crit1, false, attack.soulshot);
  1164. if (attackpercent != 100)
  1165. damage1 = (int)(damage1*attackpercent/100);
  1166. }
  1167. // Create a new hit task with Medium priority
  1168. ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk);
  1169. // Add this hit to the Server-Client packet Attack
  1170. attack.addHit(target, damage1, miss1, crit1, shld1);
  1171. // Return true if hit isn't missed
  1172. return !miss1;
  1173. }
  1174. /**
  1175. * Manage the casting task (casting and interrupt time, re-use delay...) and display the casting bar and animation on client.<BR><BR>
  1176. *
  1177. * <B><U> Actions</U> :</B><BR><BR>
  1178. * <li>Verify the possibilty of the the cast : skill is a spell, caster isn't muted... </li>
  1179. * <li>Get the list of all targets (ex : area effects) and define the L2Charcater targeted (its stats will be used in calculation)</li>
  1180. * <li>Calculate the casting time (base + modifier of MAtkSpd), interrupt time and re-use delay</li>
  1181. * <li>Send a Server->Client packet MagicSkillUser (to diplay casting animation), a packet SetupGauge (to display casting bar) and a system message </li>
  1182. * <li>Disable all skills during the casting time (create a task EnableAllSkills)</li>
  1183. * <li>Disable the skill during the re-use delay (create a task EnableSkill)</li>
  1184. * <li>Create a task MagicUseTask (that will call method onMagicUseTimer) to launch the Magic Skill at the end of the casting time</li><BR><BR>
  1185. *
  1186. * @param skill The L2Skill to use
  1187. *
  1188. */
  1189. public void doCast(L2Skill skill)
  1190. {
  1191. beginCast(skill, false);
  1192. }
  1193. public void doSimultaneousCast(L2Skill skill)
  1194. {
  1195. beginCast(skill, true);
  1196. }
  1197. private void beginCast(L2Skill skill, boolean simultaneously)
  1198. {
  1199. if (!checkDoCastConditions(skill))
  1200. {
  1201. if (simultaneously)
  1202. setIsCastingSimultaneouslyNow(false);
  1203. else
  1204. setIsCastingNow(false);
  1205. if (this instanceof L2PcInstance)
  1206. {
  1207. getAI().setIntention(AI_INTENTION_ACTIVE);
  1208. }
  1209. return;
  1210. }
  1211. //Recharge AutoSoulShot
  1212. if (skill.useSoulShot())
  1213. {
  1214. if (this instanceof L2NpcInstance)
  1215. ((L2NpcInstance)this).rechargeAutoSoulShot(true, false);
  1216. else if (this instanceof L2PcInstance)
  1217. ((L2PcInstance)this).rechargeAutoSoulShot(true, false, false);
  1218. else if (this instanceof L2Summon)
  1219. ((L2Summon)this).getOwner().rechargeAutoSoulShot(true, false, true);
  1220. }
  1221. else if (skill.useSpiritShot())
  1222. {
  1223. if (this instanceof L2PcInstance)
  1224. ((L2PcInstance)this).rechargeAutoSoulShot(false, true, false);
  1225. else if (this instanceof L2Summon)
  1226. ((L2Summon)this).getOwner().rechargeAutoSoulShot(false, true, true);
  1227. }
  1228. // Set the target of the skill in function of Skill Type and Target Type
  1229. L2Character target = null;
  1230. // Get all possible targets of the skill in a table in function of the skill target type
  1231. L2Object[] targets = skill.getTargetList(this);
  1232. // AURA skills should always be using caster as target
  1233. if (skill.getTargetType() == SkillTargetType.TARGET_AURA
  1234. || skill.getTargetType() == SkillTargetType.TARGET_FRONT_AURA
  1235. || skill.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
  1236. || skill.getTargetType() == SkillTargetType.TARGET_GROUND)
  1237. {
  1238. target = this;
  1239. }
  1240. else
  1241. {
  1242. if (targets == null || targets.length == 0)
  1243. {
  1244. if (simultaneously)
  1245. setIsCastingSimultaneouslyNow(false);
  1246. else
  1247. setIsCastingNow(false);
  1248. // Send a Server->Client packet ActionFailed to the L2PcInstance
  1249. if (this instanceof L2PcInstance)
  1250. {
  1251. sendPacket(ActionFailed.STATIC_PACKET);
  1252. getAI().setIntention(AI_INTENTION_ACTIVE);
  1253. }
  1254. return;
  1255. }
  1256. if( skill.getSkillType() == L2SkillType.BUFF ||
  1257. skill.getSkillType() == L2SkillType.HEAL ||
  1258. skill.getSkillType() == L2SkillType.COMBATPOINTHEAL ||
  1259. skill.getSkillType() == L2SkillType.MANAHEAL ||
  1260. skill.getSkillType() == L2SkillType.REFLECT ||
  1261. skill.getTargetType() == L2Skill.SkillTargetType.TARGET_SELF ||
  1262. skill.getTargetType() == L2Skill.SkillTargetType.TARGET_PET ||
  1263. skill.getTargetType() == L2Skill.SkillTargetType.TARGET_PARTY ||
  1264. skill.getTargetType() == L2Skill.SkillTargetType.TARGET_CLAN ||
  1265. skill.getTargetType() == L2Skill.SkillTargetType.TARGET_ALLY)
  1266. {
  1267. target = (L2Character) targets[0];
  1268. if (this instanceof L2PcInstance && target instanceof L2PcInstance
  1269. && target.getAI().getIntention() == CtrlIntention.AI_INTENTION_ATTACK)
  1270. {
  1271. if(skill.getSkillType() == L2SkillType.BUFF || skill.getSkillType() == L2SkillType.HOT
  1272. || skill.getSkillType() == L2SkillType.HEAL || skill.getSkillType() == L2SkillType.HEAL_PERCENT
  1273. || skill.getSkillType() == L2SkillType.MANAHEAL
  1274. || skill.getSkillType() == L2SkillType.MANAHEAL_PERCENT || skill.getSkillType() == L2SkillType.BALANCE_LIFE)
  1275. target.setLastBuffer(this);
  1276. if (((L2PcInstance)this).isInParty() && skill.getTargetType() == L2Skill.SkillTargetType.TARGET_PARTY)
  1277. {
  1278. for (L2PcInstance member : ((L2PcInstance)this).getParty().getPartyMembers())
  1279. member.setLastBuffer(this);
  1280. }
  1281. }
  1282. }
  1283. else target = (L2Character) getTarget();
  1284. }
  1285. if (target == null)
  1286. {
  1287. if (simultaneously)
  1288. setIsCastingSimultaneouslyNow(false);
  1289. else
  1290. setIsCastingNow(false);
  1291. if (this instanceof L2PcInstance)
  1292. {
  1293. sendPacket(ActionFailed.STATIC_PACKET);
  1294. getAI().setIntention(AI_INTENTION_ACTIVE);
  1295. }
  1296. return;
  1297. }
  1298. // Get the Identifier of the skill
  1299. int magicId = skill.getId();
  1300. // Get the Display Identifier for a skill that client can't display
  1301. int displayId = skill.getDisplayId();
  1302. // Get the level of the skill
  1303. int level = skill.getLevel();
  1304. if (level < 1)
  1305. level = 1;
  1306. // Get the casting time of the skill (base)
  1307. int hitTime = skill.getHitTime();
  1308. int coolTime = skill.getCoolTime();
  1309. boolean effectWhileCasting = skill.getSkillType() == L2SkillType.FORCE_BUFF
  1310. || skill.getSkillType() == L2SkillType.SIGNET_CASTTIME;
  1311. // Calculate the casting time of the skill (base + modifier of MAtkSpd)
  1312. // Don't modify the skill time for FORCE_BUFF skills. The skill time for those skills represent the buff time.
  1313. if(!effectWhileCasting)
  1314. {
  1315. hitTime = Formulas.getInstance().calcAtkSpd(this, skill, hitTime);
  1316. if (coolTime > 0)
  1317. coolTime = Formulas.getInstance().calcAtkSpd(this, skill, coolTime);
  1318. }
  1319. // Calculate altered Cast Speed due to BSpS/SpS
  1320. L2ItemInstance weaponInst = getActiveWeaponInstance();
  1321. if (weaponInst != null && skill.isMagic() && !effectWhileCasting && skill.getTargetType() != SkillTargetType.TARGET_SELF)
  1322. {
  1323. if ((weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  1324. || (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT))
  1325. {
  1326. //Only takes 70% of the time to cast a BSpS/SpS cast
  1327. hitTime = (int)(0.70 * hitTime);
  1328. coolTime = (int)(0.70 * coolTime);
  1329. //Because the following are magic skills that do not actively 'eat' BSpS/SpS,
  1330. //I must 'eat' them here so players don't take advantage of infinite speed increase
  1331. switch (skill.getSkillType())
  1332. {
  1333. case BUFF:
  1334. case MANAHEAL:
  1335. case RESURRECT:
  1336. case RECALL:
  1337. case DOT:
  1338. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  1339. break;
  1340. }
  1341. }
  1342. }
  1343. else if (this instanceof L2NpcInstance && skill.useSpiritShot() && !effectWhileCasting)
  1344. {
  1345. if(((L2NpcInstance)this).rechargeAutoSoulShot(false, true))
  1346. {
  1347. hitTime = (int)(0.70 * hitTime);
  1348. coolTime = (int)(0.70 * coolTime);
  1349. }
  1350. }
  1351. // Don't modify skills HitTime if staticHitTime is specified for skill in datapack.
  1352. if (skill.isStaticHitTime())
  1353. {
  1354. hitTime = skill.getHitTime();
  1355. coolTime = skill.getCoolTime();
  1356. }
  1357. // queue herbs and potions
  1358. if (isCastingSimultaneouslyNow() && simultaneously)
  1359. {
  1360. ThreadPoolManager.getInstance().scheduleAi(new UsePotionTask(this, skill), 100 );
  1361. return;
  1362. }
  1363. // Set the _castInterruptTime and casting status (L2PcInstance already has this true)
  1364. if (simultaneously)
  1365. setIsCastingSimultaneouslyNow(true);
  1366. else
  1367. setIsCastingNow(true);
  1368. // Note: _castEndTime = GameTimeController.getGameTicks() + (coolTime + hitTime) / GameTimeController.MILLIS_IN_TICK;
  1369. if (!simultaneously)
  1370. {
  1371. _castInterruptTime = -2 + GameTimeController.getGameTicks() + hitTime / GameTimeController.MILLIS_IN_TICK;
  1372. setLastSkillCast(skill);
  1373. }
  1374. else
  1375. setLastSimultaneousSkillCast(skill);
  1376. // Init the reuse time of the skill
  1377. int reuseDelay;
  1378. if (skill.isStaticReuse())
  1379. {
  1380. reuseDelay = (skill.getReuseDelay());
  1381. }
  1382. else
  1383. {
  1384. if(skill.isMagic())
  1385. {
  1386. reuseDelay = (int)(skill.getReuseDelay() * getStat().getMReuseRate(skill));
  1387. }
  1388. else
  1389. {
  1390. reuseDelay = (int)(skill.getReuseDelay() * getStat().getPReuseRate(skill));
  1391. }
  1392. reuseDelay *= 333.0 / (skill.isMagic() ? getMAtkSpd() : getPAtkSpd());
  1393. }
  1394. boolean skillMastery = Formulas.getInstance().calcSkillMastery(this, skill);
  1395. // Skill reuse check
  1396. if (reuseDelay > 30000 && !skillMastery) addTimeStamp(skill.getId(),reuseDelay);
  1397. // Check if this skill consume mp on start casting
  1398. int initmpcons = getStat().getMpInitialConsume(skill);
  1399. if (initmpcons > 0)
  1400. {
  1401. StatusUpdate su = new StatusUpdate(getObjectId());
  1402. if (skill.isDance())
  1403. {
  1404. getStatus().reduceMp(calcStat(Stats.DANCE_MP_CONSUME_RATE, initmpcons, null, null));
  1405. }
  1406. else if (skill.isMagic())
  1407. {
  1408. getStatus().reduceMp(calcStat(Stats.MAGICAL_MP_CONSUME_RATE, initmpcons, null, null));
  1409. }
  1410. else
  1411. {
  1412. getStatus().reduceMp(calcStat(Stats.PHYSICAL_MP_CONSUME_RATE, initmpcons, null, null));
  1413. }
  1414. su.addAttribute(StatusUpdate.CUR_MP, (int) getCurrentMp());
  1415. sendPacket(su);
  1416. }
  1417. // Disable the skill during the re-use delay and create a task EnableSkill with Medium priority to enable it at the end of the re-use delay
  1418. if (reuseDelay > 10)
  1419. {
  1420. if (skillMastery)
  1421. {
  1422. reuseDelay = 100;
  1423. if (getActingPlayer() != null)
  1424. {
  1425. SystemMessage sm = new SystemMessage(SystemMessageId.SKILL_READY_TO_USE_AGAIN);
  1426. getActingPlayer().sendPacket(sm);
  1427. sm = null;
  1428. }
  1429. }
  1430. disableSkill(skill.getId(), reuseDelay);
  1431. }
  1432. // Make sure that char is facing selected target
  1433. if (target != this)
  1434. setHeading(Util.calculateHeadingFrom(this, target));
  1435. // For force buff skills, start the effect as long as the player is casting.
  1436. if(effectWhileCasting)
  1437. {
  1438. // Consume Items if necessary and Send the Server->Client packet InventoryUpdate with Item modification to all the L2Character
  1439. if (skill.getItemConsume() > 0)
  1440. {
  1441. if (!destroyItemByItemId("Consume", skill.getItemConsumeId(), skill.getItemConsume(), null, false))
  1442. {
  1443. sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_ITEMS));
  1444. if (simultaneously)
  1445. setIsCastingSimultaneouslyNow(false);
  1446. else
  1447. setIsCastingNow(false);
  1448. if (this instanceof L2PcInstance)
  1449. getAI().setIntention(AI_INTENTION_ACTIVE);
  1450. return;
  1451. }
  1452. }
  1453. // Consume Souls if necessary
  1454. if (skill.getSoulConsumeCount() > 0 || skill.getMaxSoulConsumeCount() > 0)
  1455. {
  1456. if (this instanceof L2PcInstance)
  1457. {
  1458. ((L2PcInstance)this).decreaseSouls(skill.getSoulConsumeCount(),skill);
  1459. sendPacket(new EtcStatusUpdate((L2PcInstance)this));
  1460. }
  1461. }
  1462. if (skill.getSkillType() == L2SkillType.FORCE_BUFF)
  1463. startForceBuff(target, skill);
  1464. else
  1465. callSkill(skill, targets);
  1466. }
  1467. // Send a Server->Client packet MagicSkillUser with target, displayId, level, skillTime, reuseDelay
  1468. // to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
  1469. broadcastPacket(new MagicSkillUse(this, target, displayId, level, hitTime, reuseDelay));
  1470. // Send a system message USE_S1 to the L2Character
  1471. if (this instanceof L2PcInstance && magicId != 1312)
  1472. {
  1473. SystemMessage sm = new SystemMessage(SystemMessageId.USE_S1);
  1474. sm.addSkillName(skill);
  1475. sendPacket(sm);
  1476. }
  1477. // Before start AI Cast Broadcast Fly Effect is Need
  1478. if (skill.getFlyType() != null && (this instanceof L2PcInstance))
  1479. {
  1480. ThreadPoolManager.getInstance().scheduleEffect(new FlyToLocationTask(this, target, skill), 50);
  1481. }
  1482. // launch the magic in hitTime milliseconds
  1483. if (hitTime > 210)
  1484. {
  1485. // Send a Server->Client packet SetupGauge with the color of the gauge and the casting time
  1486. if (this instanceof L2PcInstance && !effectWhileCasting)
  1487. {
  1488. SetupGauge sg = new SetupGauge(SetupGauge.BLUE, hitTime);
  1489. sendPacket(sg);
  1490. }
  1491. if (simultaneously)
  1492. {
  1493. if (_skillCast2 != null)
  1494. {
  1495. _skillCast2.cancel(true);
  1496. _skillCast2 = null;
  1497. }
  1498. // Create a task MagicUseTask to launch the MagicSkill at the end of the casting time (hitTime)
  1499. // For client animation reasons (party buffs especially) 200 ms before!
  1500. if (effectWhileCasting)
  1501. _skillCast2 = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 2, simultaneously), hitTime);
  1502. else
  1503. _skillCast2 = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 1, simultaneously), hitTime-200);
  1504. }
  1505. else
  1506. {
  1507. if (_skillCast != null)
  1508. {
  1509. _skillCast.cancel(true);
  1510. _skillCast = null;
  1511. }
  1512. // Create a task MagicUseTask to launch the MagicSkill at the end of the casting time (hitTime)
  1513. // For client animation reasons (party buffs especially) 200 ms before!
  1514. if (effectWhileCasting)
  1515. _skillCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 2, simultaneously), hitTime);
  1516. else
  1517. _skillCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 1, simultaneously), hitTime-200);
  1518. }
  1519. }
  1520. else
  1521. {
  1522. onMagicLaunchedTimer(targets, skill, coolTime, true, simultaneously);
  1523. }
  1524. }
  1525. private boolean checkDoCastConditions(L2Skill skill)
  1526. {
  1527. if (skill == null || isSkillDisabled(skill.getId()))
  1528. {
  1529. // Send a Server->Client packet ActionFailed to the L2PcInstance
  1530. sendPacket(ActionFailed.STATIC_PACKET);
  1531. return false;
  1532. }
  1533. // Check if the caster has enough MP
  1534. if (getCurrentMp() < getStat().getMpConsume(skill) + getStat().getMpInitialConsume(skill))
  1535. {
  1536. // Send a System Message to the caster
  1537. sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_MP));
  1538. // Send a Server->Client packet ActionFailed to the L2PcInstance
  1539. sendPacket(ActionFailed.STATIC_PACKET);
  1540. return false;
  1541. }
  1542. // Check if the caster has enough HP
  1543. if (getCurrentHp() <= skill.getHpConsume())
  1544. {
  1545. // Send a System Message to the caster
  1546. sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_HP));
  1547. // Send a Server->Client packet ActionFailed to the L2PcInstance
  1548. sendPacket(ActionFailed.STATIC_PACKET);
  1549. return false;
  1550. }
  1551. switch (skill.getSkillType())
  1552. {
  1553. case SUMMON_TRAP:
  1554. {
  1555. if (isInsideZone(ZONE_PEACE))
  1556. {
  1557. if (this instanceof L2PcInstance)
  1558. ((L2PcInstance)this).sendPacket(new SystemMessage(SystemMessageId.A_MALICIOUS_SKILL_CANNOT_BE_USED_IN_PEACE_ZONE));
  1559. return false;
  1560. }
  1561. if (this instanceof L2PcInstance && ((L2PcInstance)this).getTrap() != null)
  1562. {
  1563. // Send a Server->Client packet ActionFailed to the L2PcInstance
  1564. sendPacket(ActionFailed.STATIC_PACKET);
  1565. return false;
  1566. }
  1567. break;
  1568. }
  1569. case SUMMON:
  1570. {
  1571. if (!skill.isCubic() && this instanceof L2PcInstance &&(((L2PcInstance)this).getPet() != null || ((L2PcInstance)this).isMounted()))
  1572. {
  1573. if (Config.DEBUG)
  1574. _log.fine("player has a pet already. ignore summon skill");
  1575. sendPacket(new SystemMessage(SystemMessageId.YOU_ALREADY_HAVE_A_PET));
  1576. return false;
  1577. }
  1578. }
  1579. }
  1580. if(!skill.isPotion())
  1581. {
  1582. // Check if the skill is a magic spell and if the L2Character is not muted
  1583. if (skill.isMagic())
  1584. {
  1585. if(isMuted())
  1586. {
  1587. // Send a Server->Client packet ActionFailed to the L2PcInstance
  1588. sendPacket(ActionFailed.STATIC_PACKET);
  1589. return false;
  1590. }
  1591. }
  1592. else
  1593. {
  1594. // Check if the skill is physical and if the L2Character is not physical_muted
  1595. if (isPhysicalMuted())
  1596. {
  1597. // Send a Server->Client packet ActionFailed to the L2PcInstance
  1598. sendPacket(ActionFailed.STATIC_PACKET);
  1599. return false;
  1600. }
  1601. else if (isPhysicalAttackMuted()) // Prevent use attack
  1602. {
  1603. // Send a Server->Client packet ActionFailed to the L2PcInstance
  1604. sendPacket(ActionFailed.STATIC_PACKET);
  1605. return false;
  1606. }
  1607. }
  1608. }
  1609. // TODO: Should possibly be checked only in L2PcInstance's useMagic
  1610. // Can't use Hero and resurrect skills during Olympiad
  1611. if (this instanceof L2PcInstance && ((L2PcInstance)this).isInOlympiadMode() &&
  1612. (skill.isHeroSkill() || skill.getSkillType() == L2SkillType.RESURRECT))
  1613. {
  1614. SystemMessage sm = new SystemMessage(SystemMessageId.THIS_SKILL_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
  1615. sendPacket(sm);
  1616. return false;
  1617. }
  1618. // prevent casting signets to peace zone
  1619. if (skill.getSkillType() == L2SkillType.SIGNET || skill.getSkillType() == L2SkillType.SIGNET_CASTTIME)
  1620. {
  1621. L2WorldRegion region = getWorldRegion();
  1622. if (region == null)
  1623. return false;
  1624. boolean canCast = true;
  1625. if (skill.getTargetType() == SkillTargetType.TARGET_GROUND && this instanceof L2PcInstance)
  1626. {
  1627. Point3D wp = ((L2PcInstance) this).getCurrentSkillWorldPosition();
  1628. if (!region.checkEffectRangeInsidePeaceZone(skill, wp.getX(), wp.getY(), wp.getZ()))
  1629. canCast = false;
  1630. }
  1631. else if (!region.checkEffectRangeInsidePeaceZone(skill, getX(), getY(), getZ()))
  1632. canCast = false;
  1633. if (!canCast)
  1634. {
  1635. SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  1636. sm.addSkillName(skill);
  1637. sendPacket(sm);
  1638. return false;
  1639. }
  1640. }
  1641. // Check if the caster owns the weapon needed
  1642. if (!skill.getWeaponDependancy(this))
  1643. {
  1644. // Send a Server->Client packet ActionFailed to the L2PcInstance
  1645. sendPacket(ActionFailed.STATIC_PACKET);
  1646. return false;
  1647. }
  1648. // Check if the spell consumes an Item
  1649. // TODO: combine check and consume
  1650. if (skill.getItemConsume() > 0 && getInventory() != null)
  1651. {
  1652. // Get the L2ItemInstance consumed by the spell
  1653. L2ItemInstance requiredItems = getInventory().getItemByItemId(skill.getItemConsumeId());
  1654. // Check if the caster owns enough consumed Item to cast
  1655. if (requiredItems == null || requiredItems.getCount() < skill.getItemConsume())
  1656. {
  1657. // Checked: when a summon skill failed, server show required consume item count
  1658. if (skill.getSkillType() == L2SkillType.SUMMON)
  1659. {
  1660. SystemMessage sm = new SystemMessage(SystemMessageId.SUMMONING_SERVITOR_COSTS_S2_S1);
  1661. sm.addItemName(skill.getItemConsumeId());
  1662. sm.addNumber(skill.getItemConsume());
  1663. sendPacket(sm);
  1664. return false;
  1665. }
  1666. else
  1667. {
  1668. // Send a System Message to the caster
  1669. sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_ITEMS));
  1670. return false;
  1671. }
  1672. }
  1673. }
  1674. return true;
  1675. }
  1676. /**
  1677. * Index according to skill id the current timestamp of use.<br><br>
  1678. *
  1679. * @param skill id
  1680. * @param reuse delay
  1681. * <BR><B>Overridden in :</B> (L2PcInstance)
  1682. */
  1683. public void addTimeStamp(int s, int r) {/***/}
  1684. /**
  1685. * Index according to skill id the current timestamp of use.<br><br>
  1686. *
  1687. * @param skill id
  1688. * <BR><B>Overridden in :</B> (L2PcInstance)
  1689. */
  1690. public void removeTimeStamp(int s) {/***/}
  1691. public void startForceBuff(L2Character target, L2Skill skill)
  1692. {
  1693. if (skill.getSkillType() != L2SkillType.FORCE_BUFF)
  1694. return;
  1695. if (_forceBuff == null)
  1696. _forceBuff = new ForceBuff(this, target, skill);
  1697. }
  1698. /**
  1699. * Kill the L2Character.<BR><BR>
  1700. *
  1701. * <B><U> Actions</U> :</B><BR><BR>
  1702. * <li>Set target to null and cancel Attack or Cast </li>
  1703. * <li>Stop movement </li>
  1704. * <li>Stop HP/MP/CP Regeneration task </li>
  1705. * <li>Stop all active skills effects in progress on the L2Character </li>
  1706. * <li>Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform </li>
  1707. * <li>Notify L2Character AI </li><BR><BR>
  1708. *
  1709. * <B><U> Overridden in </U> :</B><BR><BR>
  1710. * <li> L2NpcInstance : Create a DecayTask to remove the corpse of the L2NpcInstance after 7 seconds </li>
  1711. * <li> L2Attackable : Distribute rewards (EXP, SP, Drops...) and notify Quest Engine </li>
  1712. * <li> L2PcInstance : Apply Death Penalty, Manage gain/loss Karma and Item Drop </li><BR><BR>
  1713. *
  1714. * @param killer The L2Character who killed it
  1715. *
  1716. */
  1717. public boolean doDie(L2Character killer)
  1718. {
  1719. // killing is only possible one time
  1720. synchronized (this)
  1721. {
  1722. if (isDead()) return false;
  1723. // now reset currentHp to zero
  1724. setCurrentHp(0);
  1725. setIsDead(true);
  1726. }
  1727. // Set target to null and cancel Attack or Cast
  1728. setTarget(null);
  1729. // Stop movement
  1730. stopMove(null);
  1731. // Stop HP/MP/CP Regeneration task
  1732. getStatus().stopHpMpRegeneration();
  1733. // Stop all active skills effects in progress on the L2Character,
  1734. // if the Character isn't affected by Soul of The Phoenix or Salvation
  1735. if (this instanceof L2PlayableInstance && ((L2PlayableInstance)this).isPhoenixBlessed())
  1736. {
  1737. if (((L2PlayableInstance)this).getCharmOfLuck()) //remove Lucky Charm if player has SoulOfThePhoenix/Salvation buff
  1738. ((L2PlayableInstance)this).stopCharmOfLuck(null);
  1739. if (((L2PlayableInstance)this).isNoblesseBlessed())
  1740. ((L2PlayableInstance)this).stopNoblesseBlessing(null);
  1741. }
  1742. // Same thing if the Character isn't a Noblesse Blessed L2PlayableInstance
  1743. else if (this instanceof L2PlayableInstance && ((L2PlayableInstance)this).isNoblesseBlessed())
  1744. {
  1745. ((L2PlayableInstance)this).stopNoblesseBlessing(null);
  1746. untransform(); // Untransforms character if transformed.
  1747. stopTransformation(null);
  1748. if (((L2PlayableInstance)this).getCharmOfLuck()) //remove Lucky Charm if player have Nobless blessing buff
  1749. ((L2PlayableInstance)this).stopCharmOfLuck(null);
  1750. }
  1751. else
  1752. stopAllEffectsExceptThoseThatLastThroughDeath();
  1753. if (this instanceof L2PcInstance && ((L2PcInstance)this).getAgathionId() != 0)
  1754. ((L2PcInstance)this).setAgathionId(0);
  1755. calculateRewards(killer);
  1756. // Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
  1757. broadcastStatusUpdate();
  1758. // Notify L2Character AI
  1759. getAI().notifyEvent(CtrlEvent.EVT_DEAD);
  1760. if (getWorldRegion() != null)
  1761. getWorldRegion().onDeath(this);
  1762. // Notify Quest of character's death
  1763. for (QuestState qs: getNotifyQuestOfDeath())
  1764. {
  1765. qs.getQuest().notifyDeath( (killer==null?this:killer) , this, qs);
  1766. }
  1767. getNotifyQuestOfDeath().clear();
  1768. getAttackByList().clear();
  1769. // If character is PhoenixBlessed
  1770. // or has charm of courage inside siege battlefield (exact operation to be confirmed)
  1771. // a resurrection popup will show up
  1772. if (this instanceof L2Summon)
  1773. {
  1774. if (((L2Summon)this).isPhoenixBlessed() && ((L2Summon)this).getOwner() != null)
  1775. ((L2Summon)this).getOwner().reviveRequest(((L2Summon)this).getOwner(), null, true);
  1776. }
  1777. if (this instanceof L2PcInstance)
  1778. {
  1779. if(((L2PlayableInstance)this).isPhoenixBlessed())
  1780. ((L2PcInstance)this).reviveRequest(((L2PcInstance)this),null,false);
  1781. else if (((L2PcInstance)this).getCharmOfCourage()
  1782. && this.isInsideZone(ZONE_SIEGE)
  1783. && ((L2PcInstance)this).getSiegeState() != 0) // could check it more accurately too
  1784. {
  1785. ((L2PcInstance)this).reviveRequest(((L2PcInstance)this),null,false);
  1786. }
  1787. }
  1788. return true;
  1789. }
  1790. protected void calculateRewards(L2Character killer)
  1791. {
  1792. }
  1793. /** Sets HP, MP and CP and revives the L2Character. */
  1794. public void doRevive()
  1795. {
  1796. if (!isDead()) return;
  1797. if (!isTeleporting())
  1798. {
  1799. setIsPendingRevive(false);
  1800. setIsDead(false);
  1801. boolean restorefull = false;
  1802. if (this instanceof L2PlayableInstance && ((L2PlayableInstance)this).isPhoenixBlessed())
  1803. {
  1804. restorefull = true;
  1805. ((L2PlayableInstance)this).stopPhoenixBlessing(null);
  1806. }
  1807. if(restorefull)
  1808. {
  1809. //_status.setCurrentCp(getMaxCp()); //this is not confirmed...
  1810. _status.setCurrentHp(getMaxHp()); //confirmed
  1811. _status.setCurrentMp(getMaxMp()); //and also confirmed
  1812. }
  1813. else
  1814. _status.setCurrentHp(getMaxHp() * Config.RESPAWN_RESTORE_HP);
  1815. //_status.setCurrentCp(getMaxCp() * Config.RESPAWN_RESTORE_CP);
  1816. //_Status.setCurrentMp(getMaxMp() * Config.RESPAWN_RESTORE_MP);
  1817. // Start broadcast status
  1818. broadcastPacket(new Revive(this));
  1819. if (getWorldRegion() != null)
  1820. getWorldRegion().onRevive(this);
  1821. }
  1822. else
  1823. setIsPendingRevive(true);
  1824. }
  1825. /** Revives the L2Character using skill. */
  1826. public void doRevive(double revivePower) { doRevive(); }
  1827. // =========================================================
  1828. // Property - Public
  1829. /**
  1830. * Return the L2CharacterAI of the L2Character and if its null create a new one.
  1831. */
  1832. public L2CharacterAI getAI()
  1833. {
  1834. L2CharacterAI ai = _ai; // copy handle
  1835. if (ai == null)
  1836. {
  1837. synchronized(this)
  1838. {
  1839. if (_ai == null) _ai = new L2CharacterAI(new AIAccessor());
  1840. return _ai;
  1841. }
  1842. }
  1843. return ai;
  1844. }
  1845. public void setAI(L2CharacterAI newAI)
  1846. {
  1847. L2CharacterAI oldAI = getAI();
  1848. if(oldAI != null && oldAI != newAI && oldAI instanceof L2AttackableAI)
  1849. ((L2AttackableAI)oldAI).stopAITask();
  1850. _ai = newAI;
  1851. }
  1852. /** Return True if the L2Character has a L2CharacterAI. */
  1853. public boolean hasAI() { return _ai != null; }
  1854. /** Return True if the L2Character is RaidBoss or his minion. */
  1855. public boolean isRaid()
  1856. {
  1857. return _isRaid ;
  1858. }
  1859. /**
  1860. * Set this Npc as a Raid instance.<BR><BR>
  1861. * @param isRaid
  1862. */
  1863. public void setIsRaid(boolean isRaid)
  1864. {
  1865. _isRaid = isRaid;
  1866. }
  1867. /** Return a list of L2Character that attacked. */
  1868. public final List<L2Character> getAttackByList ()
  1869. {
  1870. if (_attackByList == null) _attackByList = new FastList<L2Character>();
  1871. return _attackByList;
  1872. }
  1873. public final L2Skill getLastSimultaneousSkillCast() { return _lastSimultaneousSkillCast; }
  1874. public void setLastSimultaneousSkillCast (L2Skill skill) { _lastSimultaneousSkillCast = skill; }
  1875. public final L2Skill getLastSkillCast() { return _lastSkillCast; }
  1876. public void setLastSkillCast (L2Skill skill) { _lastSkillCast = skill; }
  1877. public final boolean isAfraid() { return _isAfraid; }
  1878. public final void setIsAfraid(boolean value) { _isAfraid = value; }
  1879. /** Return True if the L2Character can't use its skills (ex : stun, sleep...). */
  1880. public final boolean isAllSkillsDisabled() { return _allSkillsDisabled || isImmobileUntilAttacked() || isStunned() || isSleeping() || isParalyzed(); }
  1881. /** Return True if the L2Character can't attack (stun, sleep, attackEndTime, fakeDeath, paralyse, attackMute). */
  1882. public boolean isAttackingDisabled() { return isStunned() || isImmobileUntilAttacked() || isSleeping() || _attackEndTime > GameTimeController.getGameTicks() || isAlikeDead() || isParalyzed() || isPhysicalAttackMuted() || isCoreAIDisabled(); }
  1883. public final Calculator[] getCalculators() { return _calculators; }
  1884. public final boolean isConfused() { return _isConfused; }
  1885. public final void setIsConfused(boolean value) { _isConfused = value; }
  1886. /** Return True if the L2Character is dead or use fake death. */
  1887. public boolean isAlikeDead() { return _isDead; }
  1888. /** Return True if the L2Character is dead. */
  1889. public final boolean isDead() { return _isDead; }
  1890. public final void setIsDead(boolean value) { _isDead = value; }
  1891. public boolean isImmobilized() { return _isImmobilized; }
  1892. public void setIsImmobilized(boolean value){ _isImmobilized = value; }
  1893. public final boolean isMuted() { return _isMuted; }
  1894. public final void setIsMuted(boolean value) { _isMuted = value; }
  1895. public final boolean isPhysicalMuted() { return _isPhysicalMuted; }
  1896. public final void setIsPhysicalMuted(boolean value) { _isPhysicalMuted = value; }
  1897. public final boolean isPhysicalAttackMuted() { return _isPhysicalAttackMuted; }
  1898. public final void setIsPhysicalAttackMuted(boolean value) { _isPhysicalAttackMuted = value; }
  1899. /** Return True if the L2Character can't move (stun, root, sleep, overload, paralyzed). */
  1900. public boolean isMovementDisabled()
  1901. {
  1902. // check for isTeleporting to prevent teleport cheating (if appear packet not received)
  1903. return isStunned() || isRooted() || isSleeping() || isOverloaded() || isParalyzed()
  1904. || isImmobilized() || isAlikeDead() || isTeleporting();
  1905. }
  1906. /** Return True if the L2Character can not be controlled by the player (confused, afraid). */
  1907. public final boolean isOutOfControl() { return isConfused() || isAfraid(); }
  1908. public final boolean isOverloaded() { return _isOverloaded; }
  1909. /** Set the overloaded status of the L2Character is overloaded (if True, the L2PcInstance can't take more item). */
  1910. public final void setIsOverloaded(boolean value) { _isOverloaded = value; }
  1911. public final boolean isParalyzed() { return _isParalyzed; }
  1912. public final void setIsParalyzed(boolean value) { _isParalyzed = value; }
  1913. public final boolean isPendingRevive() { return isDead() && _isPendingRevive; }
  1914. public final void setIsPendingRevive(boolean value) { _isPendingRevive = value; }
  1915. public final boolean isDisarmed() { return _isDisarmed; }
  1916. public final void setIsDisarmed(boolean value) { _isDisarmed = value; }
  1917. /**
  1918. * Return the L2Summon of the L2Character.<BR><BR>
  1919. * <B><U> Overridden in </U> :</B><BR><BR>
  1920. * <li> L2PcInstance</li><BR><BR>
  1921. */
  1922. public L2Summon getPet() { return null; }
  1923. public final boolean isRooted() { return _isRooted; }
  1924. public final void setIsRooted(boolean value) { _isRooted = value; }
  1925. /** Return True if the L2Character is running. */
  1926. public final boolean isRunning() { return _isRunning; }
  1927. public final void setIsRunning(boolean value)
  1928. {
  1929. _isRunning = value;
  1930. broadcastPacket(new ChangeMoveType(this));
  1931. }
  1932. /** Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance. */
  1933. public final void setRunning() { if (!isRunning()) setIsRunning(true); }
  1934. public final boolean isImmobileUntilAttacked() {return _isImmobileUntilAttacked; }
  1935. public final void setIsImmobileUntilAttacked(boolean value) { _isImmobileUntilAttacked = value; }
  1936. public final boolean isSleeping() { return _isSleeping; }
  1937. public final void setIsSleeping(boolean value) { _isSleeping = value; }
  1938. public final boolean isStunned() { return _isStunned; }
  1939. public final void setIsStunned(boolean value) { _isStunned = value; }
  1940. public final boolean isBetrayed() { return _isBetrayed; }
  1941. public final void setIsBetrayed(boolean value) { _isBetrayed = value; }
  1942. public final boolean isTeleporting() { return _isTeleporting; }
  1943. public final void setIsTeleporting(boolean value) { _isTeleporting = value; }
  1944. public void setIsInvul(boolean b){_isInvul = b;}
  1945. public boolean isInvul(){return _isInvul || _isTeleporting;}
  1946. public boolean isUndead() { return _template.isUndead; }
  1947. public boolean isFlying() { return false; }
  1948. @Override
  1949. public CharKnownList getKnownList()
  1950. {
  1951. if(super.getKnownList() == null || !(super.getKnownList() instanceof CharKnownList))
  1952. setKnownList(new CharKnownList(this));
  1953. return ((CharKnownList)super.getKnownList());
  1954. }
  1955. public CharStat getStat()
  1956. {
  1957. if (_stat == null) _stat = new CharStat(this);
  1958. return _stat;
  1959. }
  1960. public final void setStat(CharStat value) { _stat = value; }
  1961. public CharStatus getStatus()
  1962. {
  1963. if (_status == null) _status = new CharStatus(this);
  1964. return _status;
  1965. }
  1966. public final void setStatus(CharStatus value) { _status = value; }
  1967. public L2CharTemplate getTemplate() { return _template; }
  1968. /**
  1969. * Set the template of the L2Character.<BR><BR>
  1970. *
  1971. * <B><U> Concept</U> :</B><BR><BR>
  1972. * Each L2Character owns generic and static properties (ex : all Keltir have the same number of HP...).
  1973. * All of those properties are stored in a different template for each type of L2Character.
  1974. * Each template is loaded once in the server cache memory (reduce memory use).
  1975. * When a new instance of L2Character is spawned, server just create a link between the instance and the template
  1976. * This link is stored in <B>_template</B><BR><BR>
  1977. *
  1978. * <B><U> Assert </U> :</B><BR><BR>
  1979. * <li> this instanceof L2Character</li><BR><BR
  1980. */
  1981. protected final void setTemplate(L2CharTemplate template) { _template = template; }
  1982. /** Return the Title of the L2Character. */
  1983. public final String getTitle() { return _title; }
  1984. /** Set the Title of the L2Character. */
  1985. public final void setTitle(String value) { _title = value.length()>16? value.substring(0,15):value; }
  1986. /** Set the L2Character movement type to walk and send Server->Client packet ChangeMoveType to all others L2PcInstance. */
  1987. public final void setWalking() { if (isRunning()) setIsRunning(false); }
  1988. /** Task lauching the function enableSkill() */
  1989. class EnableSkill implements Runnable
  1990. {
  1991. int _skillId;
  1992. public EnableSkill(int skillId)
  1993. {
  1994. _skillId = skillId;
  1995. }
  1996. public void run()
  1997. {
  1998. try
  1999. {
  2000. enableSkill(_skillId);
  2001. }
  2002. catch (Exception e)
  2003. {
  2004. _log.log(Level.SEVERE, "Failed executing enableSkill().", e);
  2005. }
  2006. }
  2007. }
  2008. /**
  2009. * Task lauching the function onHitTimer().<BR><BR>
  2010. *
  2011. * <B><U> Actions</U> :</B><BR><BR>
  2012. * <li>If the attacker/target is dead or use fake death, notify the AI with EVT_CANCEL and send a Server->Client packet ActionFailed (if attacker is a L2PcInstance)</li>
  2013. * <li>If attack isn't aborted, send a message system (critical hit, missed...) to attacker/target if they are L2PcInstance </li>
  2014. * <li>If attack isn't aborted and hit isn't missed, reduce HP of the target and calculate reflection damage to reduce HP of attacker if necessary </li>
  2015. * <li>if attack isn't aborted and hit isn't missed, manage attack or cast break of the target (calculating rate, sending message...) </li><BR><BR>
  2016. *
  2017. */
  2018. class HitTask implements Runnable
  2019. {
  2020. L2Character _hitTarget;
  2021. int _damage;
  2022. boolean _crit;
  2023. boolean _miss;
  2024. byte _shld;
  2025. boolean _soulshot;
  2026. public HitTask(L2Character target, int damage, boolean crit, boolean miss, boolean soulshot, byte shld)
  2027. {
  2028. _hitTarget = target;
  2029. _damage = damage;
  2030. _crit = crit;
  2031. _shld = shld;
  2032. _miss = miss;
  2033. _soulshot = soulshot;
  2034. }
  2035. public void run()
  2036. {
  2037. try
  2038. {
  2039. onHitTimer(_hitTarget, _damage, _crit, _miss, _soulshot, _shld);
  2040. }
  2041. catch (Exception e)
  2042. {
  2043. _log.log(Level.SEVERE, "Failed executing HitTask.", e);
  2044. }
  2045. }
  2046. }
  2047. /** Task lauching the magic skill phases */
  2048. class MagicUseTask implements Runnable
  2049. {
  2050. L2Object[] _targets;
  2051. L2Skill _skill;
  2052. int _coolTime;
  2053. int _phase;
  2054. boolean _simultaneously;
  2055. public MagicUseTask(L2Object[] targets, L2Skill skill, int coolTime, int phase, boolean simultaneously)
  2056. {
  2057. _targets = targets;
  2058. _skill = skill;
  2059. _coolTime = coolTime;
  2060. _phase = phase;
  2061. _simultaneously = simultaneously;
  2062. }
  2063. public void run()
  2064. {
  2065. try
  2066. {
  2067. switch (_phase)
  2068. {
  2069. case 1:
  2070. onMagicLaunchedTimer(_targets, _skill, _coolTime, false, _simultaneously);
  2071. break;
  2072. case 2:
  2073. onMagicHitTimer(_targets, _skill, _coolTime, false, _simultaneously);
  2074. break;
  2075. case 3:
  2076. onMagicFinalizer(_skill, _targets[0], _simultaneously);
  2077. break;
  2078. default:
  2079. break;
  2080. }
  2081. }
  2082. catch (Exception e)
  2083. {
  2084. _log.log(Level.SEVERE, "Failed executing MagicUseTask.", e);
  2085. if (_simultaneously)
  2086. setIsCastingSimultaneouslyNow(false);
  2087. else
  2088. setIsCastingNow(false);
  2089. }
  2090. }
  2091. }
  2092. /** Task launching the function useMagic() */
  2093. class QueuedMagicUseTask implements Runnable
  2094. {
  2095. L2PcInstance _currPlayer;
  2096. L2Skill _queuedSkill;
  2097. boolean _isCtrlPressed;
  2098. boolean _isShiftPressed;
  2099. public QueuedMagicUseTask(L2PcInstance currPlayer, L2Skill queuedSkill, boolean isCtrlPressed, boolean isShiftPressed)
  2100. {
  2101. _currPlayer = currPlayer;
  2102. _queuedSkill = queuedSkill;
  2103. _isCtrlPressed = isCtrlPressed;
  2104. _isShiftPressed = isShiftPressed;
  2105. }
  2106. public void run()
  2107. {
  2108. try
  2109. {
  2110. _currPlayer.useMagic(_queuedSkill, _isCtrlPressed, _isShiftPressed);
  2111. }
  2112. catch (Exception e)
  2113. {
  2114. _log.log(Level.SEVERE, "Failed executing QueuedMagicUseTask.", e);
  2115. }
  2116. }
  2117. }
  2118. /** Task of AI notification */
  2119. public class NotifyAITask implements Runnable
  2120. {
  2121. private final CtrlEvent _evt;
  2122. NotifyAITask(CtrlEvent evt)
  2123. {
  2124. _evt = evt;
  2125. }
  2126. public void run()
  2127. {
  2128. try
  2129. {
  2130. getAI().notifyEvent(_evt, null);
  2131. }
  2132. catch (Exception e)
  2133. {
  2134. _log.log(Level.WARNING, "", e);
  2135. }
  2136. }
  2137. }
  2138. /** Task lauching the function stopPvPFlag() */
  2139. class PvPFlag implements Runnable
  2140. {
  2141. public PvPFlag()
  2142. {
  2143. }
  2144. public void run()
  2145. {
  2146. try
  2147. {
  2148. if (System.currentTimeMillis() > getPvpFlagLasts())
  2149. {
  2150. stopPvPFlag();
  2151. }
  2152. else if (System.currentTimeMillis() > (getPvpFlagLasts() - 20000))
  2153. {
  2154. updatePvPFlag(2);
  2155. }
  2156. else
  2157. {
  2158. updatePvPFlag(1);
  2159. // Start a new PvP timer check
  2160. //checkPvPFlag();
  2161. }
  2162. }
  2163. catch (Exception e)
  2164. {
  2165. _log.log(Level.WARNING, "error in pvp flag task:", e);
  2166. }
  2167. }
  2168. }
  2169. // =========================================================
  2170. /** Task lauching the magic skill phases */
  2171. class FlyToLocationTask implements Runnable
  2172. {
  2173. @SuppressWarnings("hiding")
  2174. L2Object _target;
  2175. L2Character _actor;
  2176. L2Skill _skill;
  2177. public FlyToLocationTask(L2Character actor, L2Object target, L2Skill skill)
  2178. {
  2179. _actor = actor;
  2180. _target = target;
  2181. _skill = skill;
  2182. }
  2183. public void run()
  2184. {
  2185. try
  2186. {
  2187. FlyType _flyType;
  2188. _flyType = FlyType.valueOf(_skill.getFlyType());
  2189. broadcastPacket(new FlyToLocation(_actor,_target,_flyType));
  2190. }
  2191. catch (Exception e)
  2192. {
  2193. _log.log(Level.SEVERE, "Failed executing FlyToLocationTask.", e);
  2194. }
  2195. }
  2196. }
  2197. // =========================================================
  2198. // Abnormal Effect - NEED TO REMOVE ONCE L2CHARABNORMALEFFECT IS COMPLETE
  2199. // Data Field
  2200. /** Map 32 bits (0x0000) containing all abnormal effect in progress */
  2201. private int _AbnormalEffects;
  2202. private CharEffectList _effects = new CharEffectList(this);
  2203. public static final int ABNORMAL_EFFECT_BLEEDING = 0x000001;
  2204. public static final int ABNORMAL_EFFECT_POISON = 0x000002;
  2205. public static final int ABNORMAL_EFFECT_UNKNOWN_3 = 0x000004;
  2206. public static final int ABNORMAL_EFFECT_UNKNOWN_4 = 0x000008;
  2207. public static final int ABNORMAL_EFFECT_UNKNOWN_5 = 0x000010;
  2208. public static final int ABNORMAL_EFFECT_UNKNOWN_6 = 0x000020;
  2209. public static final int ABNORMAL_EFFECT_STUN = 0x000040;
  2210. public static final int ABNORMAL_EFFECT_SLEEP = 0x000080;
  2211. public static final int ABNORMAL_EFFECT_MUTED = 0x000100;
  2212. public static final int ABNORMAL_EFFECT_ROOT = 0x000200;
  2213. public static final int ABNORMAL_EFFECT_HOLD_1 = 0x000400;
  2214. public static final int ABNORMAL_EFFECT_HOLD_2 = 0x000800;
  2215. public static final int ABNORMAL_EFFECT_UNKNOWN_13 = 0x001000;
  2216. public static final int ABNORMAL_EFFECT_BIG_HEAD = 0x002000;
  2217. public static final int ABNORMAL_EFFECT_FLAME = 0x004000;
  2218. public static final int ABNORMAL_EFFECT_UNKNOWN_16 = 0x008000;
  2219. public static final int ABNORMAL_EFFECT_GROW = 0x010000;
  2220. public static final int ABNORMAL_EFFECT_FLOATING_ROOT = 0x020000;
  2221. public static final int ABNORMAL_EFFECT_DANCE_STUNNED = 0x040000;
  2222. public static final int ABNORMAL_EFFECT_FIREROOT_STUN = 0x080000;
  2223. public static final int ABNORMAL_EFFECT_STEALTH = 0x100000;
  2224. public static final int ABNORMAL_EFFECT_IMPRISIONING_1 = 0x200000;
  2225. public static final int ABNORMAL_EFFECT_IMPRISIONING_2 = 0x400000;
  2226. public static final int ABNORMAL_EFFECT_MAGIC_CIRCLE = 0x800000;
  2227. // XXX TEMP HACKS (get the proper mask for these effects)
  2228. public static final int ABNORMAL_EFFECT_CONFUSED = 0x0020;
  2229. public static final int ABNORMAL_EFFECT_AFRAID = 0x0010;
  2230. // Method - Public
  2231. /**
  2232. * Launch and add L2Effect (including Stack Group management) to L2Character and update client magic icon.<BR><BR>
  2233. *
  2234. * <B><U> Concept</U> :</B><BR><BR>
  2235. * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>.
  2236. * The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR><BR>
  2237. *
  2238. * Several same effect can't be used on a L2Character at the same time.
  2239. * Indeed, effects are not stackable and the last cast will replace the previous in progress.
  2240. * More, some effects belong to the same Stack Group (ex WindWald and Haste Potion).
  2241. * If 2 effects of a same group are used at the same time on a L2Character, only the more efficient (identified by its priority order) will be preserve.<BR><BR>
  2242. *
  2243. * <B><U> Actions</U> :</B><BR><BR>
  2244. * <li>Add the L2Effect to the L2Character _effects</li>
  2245. * <li>If this effect doesn't belong to a Stack Group, add its Funcs to the Calculator set of the L2Character (remove the old one if necessary)</li>
  2246. * <li>If this effect has higher priority in its Stack Group, add its Funcs to the Calculator set of the L2Character (remove previous stacked effect Funcs if necessary)</li>
  2247. * <li>If this effect has NOT higher priority in its Stack Group, set the effect to Not In Use</li>
  2248. * <li>Update active skills in progress icons on player client</li><BR>
  2249. *
  2250. */
  2251. public void addEffect(L2Effect newEffect)
  2252. {
  2253. _effects.addEffect(newEffect);
  2254. // Update active skills in progress (In Use and Not In Use because stacked) icons on client
  2255. updateEffectIcons();
  2256. }
  2257. /**
  2258. * Stop and remove L2Effect (including Stack Group management) from L2Character and update client magic icon.<BR><BR>
  2259. *
  2260. * <B><U> Concept</U> :</B><BR><BR>
  2261. * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>.
  2262. * The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR><BR>
  2263. *
  2264. * Several same effect can't be used on a L2Character at the same time.
  2265. * Indeed, effects are not stackable and the last cast will replace the previous in progress.
  2266. * More, some effects belong to the same Stack Group (ex WindWald and Haste Potion).
  2267. * If 2 effects of a same group are used at the same time on a L2Character, only the more efficient (identified by its priority order) will be preserve.<BR><BR>
  2268. *
  2269. * <B><U> Actions</U> :</B><BR><BR>
  2270. * <li>Remove Func added by this effect from the L2Character Calculator (Stop L2Effect)</li>
  2271. * <li>If the L2Effect belongs to a not empty Stack Group, replace theses Funcs by next stacked effect Funcs</li>
  2272. * <li>Remove the L2Effect from _effects of the L2Character</li>
  2273. * <li>Update active skills in progress icons on player client</li><BR>
  2274. *
  2275. */
  2276. public final void removeEffect(L2Effect effect)
  2277. {
  2278. _effects.removeEffect(effect);
  2279. // Update active skills in progress (In Use and Not In Use because stacked) icons on client
  2280. updateEffectIcons();
  2281. }
  2282. /**
  2283. * Active abnormal effects flags in the binary mask and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2284. */
  2285. public final void startAbnormalEffect(int mask)
  2286. {
  2287. _AbnormalEffects |= mask;
  2288. updateAbnormalEffect();
  2289. }
  2290. /**
  2291. * Active the abnormal effect Confused flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2292. */
  2293. public final void startConfused()
  2294. {
  2295. setIsConfused(true);
  2296. getAI().notifyEvent(CtrlEvent.EVT_CONFUSED);
  2297. updateAbnormalEffect();
  2298. }
  2299. /**
  2300. * Active the abnormal effect Fake Death flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2301. */
  2302. public final void startFakeDeath()
  2303. {
  2304. if (!(this instanceof L2PcInstance))
  2305. return;
  2306. ((L2PcInstance)this).setIsFakeDeath(true);
  2307. /* Aborts any attacks/casts if fake dead */
  2308. abortAttack();
  2309. abortCast();
  2310. getAI().notifyEvent(CtrlEvent.EVT_FAKE_DEATH);
  2311. broadcastPacket(new ChangeWaitType(this,ChangeWaitType.WT_START_FAKEDEATH));
  2312. }
  2313. /**
  2314. * Active the abnormal effect Fear flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2315. */
  2316. public final void startFear()
  2317. {
  2318. setIsAfraid(true);
  2319. getAI().notifyEvent(CtrlEvent.EVT_AFRAID);
  2320. updateAbnormalEffect();
  2321. }
  2322. /**
  2323. * Active the abnormal effect Muted flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2324. */
  2325. public final void startMuted()
  2326. {
  2327. setIsMuted(true);
  2328. /* Aborts any casts if muted */
  2329. abortCast();
  2330. getAI().notifyEvent(CtrlEvent.EVT_MUTED);
  2331. updateAbnormalEffect();
  2332. }
  2333. /**
  2334. * Active the abnormal effect Psychical_Muted flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2335. */
  2336. public final void startPsychicalMuted()
  2337. {
  2338. setIsPhysicalMuted(true);
  2339. getAI().notifyEvent(CtrlEvent.EVT_MUTED);
  2340. updateAbnormalEffect();
  2341. }
  2342. /**
  2343. * Active the abnormal effect Root flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2344. */
  2345. public final void startRooted()
  2346. {
  2347. setIsRooted(true);
  2348. getAI().notifyEvent(CtrlEvent.EVT_ROOTED);
  2349. updateAbnormalEffect();
  2350. }
  2351. /**
  2352. * Active the abnormal effect Sleep flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2353. */
  2354. public final void startImmobileUntilAttacked()
  2355. {
  2356. setIsImmobileUntilAttacked(true);
  2357. abortAttack();
  2358. abortCast();
  2359. getAI().notifyEvent(CtrlEvent.EVT_SLEEPING);
  2360. updateAbnormalEffect();
  2361. }
  2362. /**
  2363. * Active the abnormal effect Sleep flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
  2364. */
  2365. public final void startSleeping()
  2366. {
  2367. setIsSleeping(true);
  2368. /* Aborts any attacks/casts if sleeped */
  2369. abortAttack();
  2370. abortCast();
  2371. getAI().notifyEvent(CtrlEvent.EVT_SLEEPING);
  2372. updateAbnormalEffect();
  2373. }
  2374. /**
  2375. * Launch a Stun Abnormal Effect on the L2Character.<BR><BR>
  2376. *
  2377. * <B><U> Actions</U> :</B><BR><BR>
  2378. * <li>Calculate the success rate of the Stun Abnormal Effect on this L2Character</li>
  2379. * <li>If Stun succeed, active the abnormal effect Stun flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet</li>
  2380. * <li>If Stun NOT succeed, send a system message Failed to the L2PcInstance attacker</li><BR><BR>
  2381. *
  2382. */
  2383. public final void startStunning()
  2384. {
  2385. setIsStunned(true);
  2386. /* Aborts any attacks/casts if stunned */
  2387. abortAttack();
  2388. abortCast();
  2389. getAI().notifyEvent(CtrlEvent.EVT_STUNNED);
  2390. updateAbnormalEffect();
  2391. }
  2392. public final void startParalyze()
  2393. {
  2394. setIsParalyzed(true);
  2395. /* Aborts any attacks/casts if paralyzed */
  2396. abortAttack();
  2397. abortCast();
  2398. getAI().notifyEvent(CtrlEvent.EVT_PARALYZED);
  2399. updateAbnormalEffect();
  2400. }
  2401. public final void startBetray()
  2402. {
  2403. setIsBetrayed(true);
  2404. getAI().notifyEvent(CtrlEvent.EVT_BETRAYED);
  2405. updateAbnormalEffect();
  2406. }
  2407. public final void stopBetray()
  2408. {
  2409. stopEffects(L2EffectType.BETRAY);
  2410. setIsBetrayed(false);
  2411. updateAbnormalEffect();
  2412. }
  2413. /**
  2414. * Modify the abnormal effect map according to the mask.<BR><BR>
  2415. */
  2416. public final void stopAbnormalEffect(int mask)
  2417. {
  2418. _AbnormalEffects &= ~mask;
  2419. updateAbnormalEffect();
  2420. }
  2421. /**
  2422. * Stop all active skills effects in progress on the L2Character.<BR><BR>
  2423. */
  2424. public final void stopAllEffects()
  2425. {
  2426. _effects.stopAllEffects();
  2427. if (this instanceof L2PcInstance) ((L2PcInstance)this).updateAndBroadcastStatus(2);
  2428. }
  2429. public final void stopAllEffectsExceptThoseThatLastThroughDeath()
  2430. {
  2431. _effects.stopAllEffectsExceptThoseThatLastThroughDeath();
  2432. if (this instanceof L2PcInstance) ((L2PcInstance)this).updateAndBroadcastStatus(2);
  2433. }
  2434. /**
  2435. * Stop a specified/all Confused abnormal L2Effect.<BR><BR>
  2436. *
  2437. * <B><U> Actions</U> :</B><BR><BR>
  2438. * <li>Delete a specified/all (if effect=null) Confused abnormal L2Effect from L2Character and update client magic icon </li>
  2439. * <li>Set the abnormal effect flag _confused to False </li>
  2440. * <li>Notify the L2Character AI</li>
  2441. * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
  2442. *
  2443. */
  2444. public final void stopConfused(L2Effect effect)
  2445. {
  2446. if (effect == null)
  2447. stopEffects(L2EffectType.CONFUSION);
  2448. else
  2449. removeEffect(effect);
  2450. setIsConfused(false);
  2451. getAI().notifyEvent(CtrlEvent.EVT_THINK);
  2452. updateAbnormalEffect();
  2453. }
  2454. /**
  2455. * Stop and remove the L2Effects corresponding to the L2Skill Identifier and update client magic icon.<BR><BR>
  2456. *
  2457. * <B><U> Concept</U> :</B><BR><BR>
  2458. * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>.
  2459. * The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR><BR>
  2460. *
  2461. * @param effectId The L2Skill Identifier of the L2Effect to remove from _effects
  2462. *
  2463. */
  2464. public final void stopSkillEffects(int skillId)
  2465. {
  2466. _effects.stopSkillEffects(skillId);
  2467. }
  2468. /**
  2469. * Stop and remove all L2Effect of the selected type (ex : BUFF, DMG_OVER_TIME...) from the L2Character and update client magic icon.<BR><BR>
  2470. *
  2471. * <B><U> Concept</U> :</B><BR><BR>
  2472. * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>.
  2473. * The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR><BR>
  2474. *
  2475. * <B><U> Actions</U> :</B><BR><BR>
  2476. * <li>Remove Func added by this effect from the L2Character Calculator (Stop L2Effect)</li>
  2477. * <li>Remove the L2Effect from _effects of the L2Character</li>
  2478. * <li>Update active skills in progress icons on player client</li><BR><BR>
  2479. *
  2480. * @param type The type of effect to stop ((ex : BUFF, DMG_OVER_TIME...)
  2481. *
  2482. */
  2483. public final void stopEffects(L2EffectType type)
  2484. {
  2485. _effects.stopEffects(type);
  2486. }
  2487. /**
  2488. * Stop a specified/all Fake Death abnormal L2Effect.<BR><BR>
  2489. *
  2490. * <B><U> Actions</U> :</B><BR><BR>
  2491. * <li>Delete a specified/all (if effect=null) Fake Death abnormal L2Effect from L2Character and update client magic icon </li>
  2492. * <li>Set the abnormal effect flag _fake_death to False </li>
  2493. * <li>Notify the L2Character AI</li><BR><BR>
  2494. *
  2495. */
  2496. public final void stopFakeDeath(L2Effect effect)
  2497. {
  2498. if (effect == null)
  2499. stopEffects(L2EffectType.FAKE_DEATH);
  2500. else
  2501. removeEffect(effect);
  2502. // if this is a player instance, start the grace period for this character (grace from mobs only)!
  2503. if (this instanceof L2PcInstance)
  2504. {
  2505. ((L2PcInstance) this).setIsFakeDeath(false);
  2506. ((L2PcInstance) this).setRecentFakeDeath(true);
  2507. }
  2508. ChangeWaitType revive = new ChangeWaitType(this,ChangeWaitType.WT_STOP_FAKEDEATH);
  2509. broadcastPacket(revive);
  2510. //TODO: Temp hack: players see FD on ppl that are moving: Teleport to someone who uses FD - if he gets up he will fall down again for that client -
  2511. // even tho he is actually standing... Probably bad info in CharInfo packet?
  2512. broadcastPacket(new Revive(this));
  2513. getAI().notifyEvent(CtrlEvent.EVT_THINK);
  2514. }
  2515. /**
  2516. * Stop a specified/all Fear abnormal L2Effect.<BR><BR>
  2517. *
  2518. * <B><U> Actions</U> :</B><BR><BR>
  2519. * <li>Delete a specified/all (if effect=null) Fear abnormal L2Effect from L2Character and update client magic icon </li>
  2520. * <li>Set the abnormal effect flag _affraid to False </li>
  2521. * <li>Notify the L2Character AI</li>
  2522. * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
  2523. *
  2524. */
  2525. public final void stopFear(L2Effect effect)
  2526. {
  2527. if (effect == null)
  2528. stopEffects(L2EffectType.FEAR);
  2529. else
  2530. removeEffect(effect);
  2531. setIsAfraid(false);
  2532. updateAbnormalEffect();
  2533. }
  2534. /**
  2535. * Stop a specified/all Muted abnormal L2Effect.<BR><BR>
  2536. *
  2537. * <B><U> Actions</U> :</B><BR><BR>
  2538. * <li>Delete a specified/all (if effect=null) Muted abnormal L2Effect from L2Character and update client magic icon </li>
  2539. * <li>Set the abnormal effect flag _muted to False </li>
  2540. * <li>Notify the L2Character AI</li>
  2541. * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
  2542. *
  2543. */
  2544. public final void stopMuted(L2Effect effect)
  2545. {
  2546. if (effect == null)
  2547. stopEffects(L2EffectType.MUTE);
  2548. else
  2549. removeEffect(effect);
  2550. setIsMuted(false);
  2551. updateAbnormalEffect();
  2552. }
  2553. public final void stopPsychicalMuted(L2Effect effect)
  2554. {
  2555. if (effect == null)
  2556. stopEffects(L2EffectType.PHYSICAL_MUTE);
  2557. else
  2558. removeEffect(effect);
  2559. setIsPhysicalMuted(false);
  2560. updateAbnormalEffect();
  2561. }
  2562. /**
  2563. * Stop a specified/all Root abnormal L2Effect.<BR><BR>
  2564. *
  2565. * <B><U> Actions</U> :</B><BR><BR>
  2566. * <li>Delete a specified/all (if effect=null) Root abnormal L2Effect from L2Character and update client magic icon </li>
  2567. * <li>Set the abnormal effect flag _rooted to False </li>
  2568. * <li>Notify the L2Character AI</li>
  2569. * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
  2570. *
  2571. */
  2572. public final void stopRooting(L2Effect effect)
  2573. {
  2574. if (effect == null)
  2575. stopEffects(L2EffectType.ROOT);
  2576. else
  2577. removeEffect(effect);
  2578. setIsRooted(false);
  2579. getAI().notifyEvent(CtrlEvent.EVT_THINK);
  2580. updateAbnormalEffect();
  2581. }
  2582. /**
  2583. * Stop immobilization until attacked abnormal L2Effect.<BR><BR>
  2584. *
  2585. * <B><U> Actions</U> :</B><BR><BR>
  2586. * <li>Delete a specified/all (if effect=null) immobilization until attacked abnormal L2Effect from L2Character and update client magic icon </li>
  2587. * <li>Set the abnormal effect flag _muted to False </li>
  2588. * <li>Notify the L2Character AI</li>
  2589. * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
  2590. *
  2591. */
  2592. public final void stopImmobileUntilAttacked(L2Effect effect)
  2593. {
  2594. if (effect == null)
  2595. stopEffects(L2EffectType.IMMOBILEUNTILATTACKED);
  2596. else
  2597. {
  2598. removeEffect(effect);
  2599. stopSkillEffects(effect.getSkill().getNegateId());
  2600. }
  2601. setIsImmobileUntilAttacked(false);
  2602. getAI().notifyEvent(CtrlEvent.EVT_THINK);
  2603. updateAbnormalEffect();
  2604. }
  2605. /**
  2606. * Stop a specified/all Sleep abnormal L2Effect.<BR><BR>
  2607. *
  2608. * <B><U> Actions</U> :</B><BR><BR>
  2609. * <li>Delete a specified/all (if effect=null) Sleep abnormal L2Effect from L2Character and update client magic icon </li>
  2610. * <li>Set the abnormal effect flag _sleeping to False </li>
  2611. * <li>Notify the L2Character AI</li>
  2612. * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
  2613. *
  2614. */
  2615. public final void stopSleeping(L2Effect effect)
  2616. {
  2617. if (effect == null)
  2618. stopEffects(L2EffectType.SLEEP);
  2619. else
  2620. removeEffect(effect);
  2621. setIsSleeping(false);
  2622. getAI().notifyEvent(CtrlEvent.EVT_THINK);
  2623. updateAbnormalEffect();
  2624. }
  2625. /**
  2626. * Stop a specified/all Stun abnormal L2Effect.<BR><BR>
  2627. *
  2628. * <B><U> Actions</U> :</B><BR><BR>
  2629. * <li>Delete a specified/all (if effect=null) Stun abnormal L2Effect from L2Character and update client magic icon </li>
  2630. * <li>Set the abnormal effect flag _stuned to False </li>
  2631. * <li>Notify the L2Character AI</li>
  2632. * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
  2633. *
  2634. */
  2635. public final void stopStunning(L2Effect effect)
  2636. {
  2637. if (effect == null)
  2638. stopEffects(L2EffectType.STUN);
  2639. else
  2640. removeEffect(effect);
  2641. setIsStunned(false);
  2642. getAI().notifyEvent(CtrlEvent.EVT_THINK);
  2643. updateAbnormalEffect();
  2644. }
  2645. public final void stopParalyze(L2Effect effect)
  2646. {
  2647. if (effect == null)
  2648. stopEffects(L2EffectType.PARALYZE);
  2649. else
  2650. removeEffect(effect);
  2651. setIsParalyzed(false);
  2652. getAI().notifyEvent(CtrlEvent.EVT_THINK);
  2653. updateAbnormalEffect();
  2654. }
  2655. /**
  2656. * Stop L2Effect: Transformation<BR><BR>
  2657. *
  2658. * <B><U> Actions</U> :</B><BR><BR>
  2659. * <li>Remove Transformation Effect</li>
  2660. * <li>Notify the L2Character AI</li>
  2661. * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
  2662. *
  2663. */
  2664. public final void stopTransformation(L2Effect effect)
  2665. {
  2666. if (effect == null)
  2667. {
  2668. stopEffects(L2EffectType.TRANSFORMATION);
  2669. }
  2670. else
  2671. {
  2672. removeEffect(effect);
  2673. }
  2674. // if this is a player instance, then untransform, also set the transform_id column equal to 0 if not cursed.
  2675. if (this instanceof L2PcInstance)
  2676. {
  2677. if (((L2PcInstance) this).getTransformation() != null)
  2678. {
  2679. ((L2PcInstance) this).untransform();
  2680. }
  2681. }
  2682. getAI().notifyEvent(CtrlEvent.EVT_THINK);
  2683. updateAbnormalEffect();
  2684. }
  2685. /**
  2686. * Not Implemented.<BR><BR>
  2687. *
  2688. * <B><U> Overridden in</U> :</B><BR><BR>
  2689. * <li>L2NPCInstance</li>
  2690. * <li>L2PcInstance</li>
  2691. * <li>L2Summon</li>
  2692. * <li>L2DoorInstance</li><BR><BR>
  2693. *
  2694. */
  2695. public abstract void updateAbnormalEffect();
  2696. /**
  2697. * Update active skills in progress (In Use and Not In Use because stacked) icons on client.<BR><BR>
  2698. *
  2699. * <B><U> Concept</U> :</B><BR><BR>
  2700. * All active skills effects in progress (In Use and Not In Use because stacked) are represented by an icon on the client.<BR><BR>
  2701. *
  2702. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method ONLY UPDATE the client of the player and not clients of all players in the party.</B></FONT><BR><BR>
  2703. *
  2704. */
  2705. public final void updateEffectIcons()
  2706. {
  2707. updateEffectIcons(false);
  2708. }
  2709. /**
  2710. * Updates Effect Icons for this character(palyer/summon) and his party if any<BR>
  2711. *
  2712. * Overridden in:<BR>
  2713. * L2PcInstance<BR>
  2714. * L2Summon<BR>
  2715. *
  2716. * @param partyOnly
  2717. */
  2718. public void updateEffectIcons(boolean partyOnly)
  2719. {
  2720. // overridden
  2721. }
  2722. // Property - Public
  2723. /**
  2724. * Return a map of 16 bits (0x0000) containing all abnormal effect in progress for this L2Character.<BR><BR>
  2725. *
  2726. * <B><U> Concept</U> :</B><BR><BR>
  2727. * In Server->Client packet, each effect is represented by 1 bit of the map (ex : BLEEDING = 0x0001 (bit 1), SLEEP = 0x0080 (bit 8)...).
  2728. * The map is calculated by applying a BINARY OR operation on each effect.<BR><BR>
  2729. *
  2730. * <B><U> Example of use </U> :</B><BR><BR>
  2731. * <li> Server Packet : CharInfo, NpcInfo, NpcInfoPoly, UserInfo...</li><BR><BR>
  2732. */
  2733. public int getAbnormalEffect()
  2734. {
  2735. int ae = _AbnormalEffects;
  2736. if (isStunned()) ae |= ABNORMAL_EFFECT_STUN;
  2737. if (isRooted()) ae |= ABNORMAL_EFFECT_ROOT;
  2738. if (isSleeping()) ae |= ABNORMAL_EFFECT_SLEEP;
  2739. if (isConfused()) ae |= ABNORMAL_EFFECT_CONFUSED;
  2740. if (isMuted()) ae |= ABNORMAL_EFFECT_MUTED;
  2741. if (isAfraid()) ae |= ABNORMAL_EFFECT_AFRAID;
  2742. if (isPhysicalMuted()) ae |= ABNORMAL_EFFECT_MUTED;
  2743. return ae;
  2744. }
  2745. /**
  2746. * Return all active skills effects in progress on the L2Character.<BR><BR>
  2747. *
  2748. * <B><U> Concept</U> :</B><BR><BR>
  2749. * All active skills effects in progress on the L2Character are identified in <B>_effects</B>.
  2750. * The Integer key of _effects is the L2Skill Identifier that has created the effect.<BR><BR>
  2751. *
  2752. * @return A table containing all active skills effect in progress on the L2Character
  2753. *
  2754. */
  2755. public final L2Effect[] getAllEffects()
  2756. {
  2757. return _effects.getAllEffects();
  2758. }
  2759. /**
  2760. * Return L2Effect in progress on the L2Character corresponding to the L2Skill Identifier.<BR><BR>
  2761. *
  2762. * <B><U> Concept</U> :</B><BR><BR>
  2763. * All active skills effects in progress on the L2Character are identified in <B>_effects</B>.
  2764. *
  2765. * @param index The L2Skill Identifier of the L2Effect to return from the _effects
  2766. *
  2767. * @return The L2Effect corresponding to the L2Skill Identifier
  2768. *
  2769. */
  2770. public final L2Effect getFirstEffect(int index)
  2771. {
  2772. return _effects.getFirstEffect(index);
  2773. }
  2774. /**
  2775. * Return the first L2Effect in progress on the L2Character created by the L2Skill.<BR><BR>
  2776. *
  2777. * <B><U> Concept</U> :</B><BR><BR>
  2778. * All active skills effects in progress on the L2Character are identified in <B>_effects</B>.
  2779. *
  2780. * @param skill The L2Skill whose effect must be returned
  2781. *
  2782. * @return The first L2Effect created by the L2Skill
  2783. *
  2784. */
  2785. public final L2Effect getFirstEffect(L2Skill skill)
  2786. {
  2787. return _effects.getFirstEffect(skill);
  2788. }
  2789. /**
  2790. * Return the first L2Effect in progress on the L2Character corresponding to the Effect Type (ex : BUFF, STUN, ROOT...).<BR><BR>
  2791. *
  2792. * <B><U> Concept</U> :</B><BR><BR>
  2793. * All active skills effects in progress on the L2Character are identified in <B>_effects</B>.
  2794. *
  2795. * @param tp The Effect Type of skills whose effect must be returned
  2796. *
  2797. * @return The first L2Effect corresponding to the Effect Type
  2798. *
  2799. */
  2800. public final L2Effect getFirstEffect(L2EffectType tp)
  2801. {
  2802. return _effects.getFirstEffect(tp);
  2803. }
  2804. public EffectCharge getChargeEffect()
  2805. {
  2806. return _effects.getChargeEffect();
  2807. }
  2808. // =========================================================
  2809. // =========================================================
  2810. // NEED TO ORGANIZE AND MOVE TO PROPER PLACE
  2811. /** This class permit to the L2Character AI to obtain informations and uses L2Character method */
  2812. public class AIAccessor
  2813. {
  2814. public AIAccessor() {}
  2815. /**
  2816. * Return the L2Character managed by this Accessor AI.<BR><BR>
  2817. */
  2818. public L2Character getActor()
  2819. {
  2820. return L2Character.this;
  2821. }
  2822. /**
  2823. * Accessor to L2Character moveToLocation() method with an interaction area.<BR><BR>
  2824. */
  2825. public void moveTo(int x, int y, int z, int offset)
  2826. {
  2827. L2Character.this.moveToLocation(x, y, z, offset);
  2828. }
  2829. /**
  2830. * Accessor to L2Character moveToLocation() method without interaction area.<BR><BR>
  2831. */
  2832. public void moveTo(int x, int y, int z)
  2833. {
  2834. L2Character.this.moveToLocation(x, y, z, 0);
  2835. }
  2836. /**
  2837. * Accessor to L2Character stopMove() method.<BR><BR>
  2838. */
  2839. public void stopMove(L2CharPosition pos)
  2840. {
  2841. L2Character.this.stopMove(pos);
  2842. }
  2843. /**
  2844. * Accessor to L2Character doAttack() method.<BR><BR>
  2845. */
  2846. public void doAttack(L2Character target)
  2847. {
  2848. L2Character.this.doAttack(target);
  2849. }
  2850. /**
  2851. * Accessor to L2Character doCast() method.<BR><BR>
  2852. */
  2853. public void doCast(L2Skill skill)
  2854. {
  2855. L2Character.this.doCast(skill);
  2856. }
  2857. /**
  2858. * Create a NotifyAITask.<BR><BR>
  2859. */
  2860. public NotifyAITask newNotifyTask(CtrlEvent evt)
  2861. {
  2862. return new NotifyAITask(evt);
  2863. }
  2864. /**
  2865. * Cancel the AI.<BR><BR>
  2866. */
  2867. public void detachAI()
  2868. {
  2869. _ai = null;
  2870. }
  2871. }
  2872. /**
  2873. * This class group all mouvement data.<BR><BR>
  2874. *
  2875. * <B><U> Data</U> :</B><BR><BR>
  2876. * <li>_moveTimestamp : Last time position update</li>
  2877. * <li>_xDestination, _yDestination, _zDestination : Position of the destination</li>
  2878. * <li>_xMoveFrom, _yMoveFrom, _zMoveFrom : Position of the origin</li>
  2879. * <li>_moveStartTime : Start time of the movement</li>
  2880. * <li>_ticksToMove : Nb of ticks between the start and the destination</li>
  2881. * <li>_xSpeedTicks, _ySpeedTicks : Speed in unit/ticks</li><BR><BR>
  2882. *
  2883. * */
  2884. public static class MoveData
  2885. {
  2886. // when we retrieve x/y/z we use GameTimeControl.getGameTicks()
  2887. // if we are moving, but move timestamp==gameticks, we don't need
  2888. // to recalculate position
  2889. public int _moveStartTime;
  2890. public int _moveTimestamp; // last update
  2891. public int _xDestination;
  2892. public int _yDestination;
  2893. public int _zDestination;
  2894. public double _xAccurate; // otherwise there would be rounding errors
  2895. public double _yAccurate;
  2896. public double _zAccurate;
  2897. public int _heading;
  2898. public boolean disregardingGeodata;
  2899. public int onGeodataPathIndex;
  2900. public List<AbstractNodeLoc> geoPath;
  2901. public int geoPathAccurateTx;
  2902. public int geoPathAccurateTy;
  2903. public int geoPathGtx;
  2904. public int geoPathGty;
  2905. }
  2906. /** Table containing all skillId that are disabled */
  2907. protected List<Integer> _disabledSkills;
  2908. private boolean _allSkillsDisabled;
  2909. // private int _flyingRunSpeed;
  2910. // private int _floatingWalkSpeed;
  2911. // private int _flyingWalkSpeed;
  2912. // private int _floatingRunSpeed;
  2913. /** Movement data of this L2Character */
  2914. protected MoveData _move;
  2915. /** Orientation of the L2Character */
  2916. private int _heading;
  2917. /** L2Charcater targeted by the L2Character */
  2918. private L2Object _target;
  2919. // set by the start of attack, in game ticks
  2920. private int _attackEndTime;
  2921. private int _attacking;
  2922. private int _disableBowAttackEndTime;
  2923. private int _disableCrossBowAttackEndTime;
  2924. private int _castInterruptTime;
  2925. /** Table of calculators containing all standard NPC calculator (ex : ACCURACY_COMBAT, EVASION_RATE */
  2926. private static final Calculator[] NPC_STD_CALCULATOR;
  2927. static {NPC_STD_CALCULATOR = Formulas.getInstance().getStdNPCCalculators();}
  2928. protected L2CharacterAI _ai;
  2929. /** Future Skill Cast */
  2930. protected Future<?> _skillCast;
  2931. protected Future<?> _skillCast2;
  2932. /** Char Coords from Client */
  2933. private int _clientX;
  2934. private int _clientY;
  2935. private int _clientZ;
  2936. private int _clientHeading;
  2937. /** List of all QuestState instance that needs to be notified of this character's death */
  2938. private List<QuestState> _NotifyQuestOfDeathList = new FastList<QuestState>();
  2939. /**
  2940. * Add QuestState instance that is to be notified of character's death.<BR><BR>
  2941. *
  2942. * @param qs The QuestState that subscribe to this event
  2943. *
  2944. */
  2945. public void addNotifyQuestOfDeath (QuestState qs)
  2946. {
  2947. if (qs == null || _NotifyQuestOfDeathList.contains(qs))
  2948. return;
  2949. _NotifyQuestOfDeathList.add(qs);
  2950. }
  2951. /**
  2952. * Return a list of L2Character that attacked.<BR><BR>
  2953. */
  2954. public final List<QuestState> getNotifyQuestOfDeath ()
  2955. {
  2956. if (_NotifyQuestOfDeathList == null)
  2957. _NotifyQuestOfDeathList = new FastList<QuestState>();
  2958. return _NotifyQuestOfDeathList;
  2959. }
  2960. /**
  2961. * Add a Func to the Calculator set of the L2Character.<BR><BR>
  2962. *
  2963. * <B><U> Concept</U> :</B><BR><BR>
  2964. * A L2Character owns a table of Calculators called <B>_calculators</B>.
  2965. * Each Calculator (a calculator per state) own a table of Func object.
  2966. * A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...).
  2967. * To reduce cache memory use, L2NPCInstances who don't have skills share the same Calculator set called <B>NPC_STD_CALCULATOR</B>.<BR><BR>
  2968. *
  2969. * That's why, if a L2NPCInstance is under a skill/spell effect that modify one of its state, a copy of the NPC_STD_CALCULATOR
  2970. * must be create in its _calculators before addind new Func object.<BR><BR>
  2971. *
  2972. * <B><U> Actions</U> :</B><BR><BR>
  2973. * <li>If _calculators is linked to NPC_STD_CALCULATOR, create a copy of NPC_STD_CALCULATOR in _calculators</li>
  2974. * <li>Add the Func object to _calculators</li><BR><BR>
  2975. *
  2976. * @param f The Func object to add to the Calculator corresponding to the state affected
  2977. */
  2978. public final void addStatFunc(Func f)
  2979. {
  2980. if (f == null)
  2981. return;
  2982. synchronized(_calculators)
  2983. {
  2984. // Check if Calculator set is linked to the standard Calculator set of NPC
  2985. if (_calculators == NPC_STD_CALCULATOR)
  2986. {
  2987. // Create a copy of the standard NPC Calculator set
  2988. _calculators = new Calculator[Stats.NUM_STATS];
  2989. for (int i=0; i < Stats.NUM_STATS; i++)
  2990. {
  2991. if (NPC_STD_CALCULATOR[i] != null)
  2992. _calculators[i] = new Calculator(NPC_STD_CALCULATOR[i]);
  2993. }
  2994. }
  2995. // Select the Calculator of the affected state in the Calculator set
  2996. int stat = f.stat.ordinal();
  2997. if (_calculators[stat] == null)
  2998. _calculators[stat] = new Calculator();
  2999. // Add the Func to the calculator corresponding to the state
  3000. _calculators[stat].addFunc(f);
  3001. }
  3002. }
  3003. /**
  3004. * Add a list of Funcs to the Calculator set of the L2Character.<BR><BR>
  3005. *
  3006. * <B><U> Concept</U> :</B><BR><BR>
  3007. * A L2Character owns a table of Calculators called <B>_calculators</B>.
  3008. * Each Calculator (a calculator per state) own a table of Func object.
  3009. * A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...). <BR><BR>
  3010. *
  3011. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method is ONLY for L2PcInstance</B></FONT><BR><BR>
  3012. *
  3013. * <B><U> Example of use </U> :</B><BR><BR>
  3014. * <li> Equip an item from inventory</li>
  3015. * <li> Learn a new passive skill</li>
  3016. * <li> Use an active skill</li><BR><BR>
  3017. *
  3018. * @param funcs The list of Func objects to add to the Calculator corresponding to the state affected
  3019. */
  3020. public final void addStatFuncs(Func[] funcs)
  3021. {
  3022. FastList<Stats> modifiedStats = new FastList<Stats>();
  3023. for (Func f : funcs)
  3024. {
  3025. modifiedStats.add(f.stat);
  3026. addStatFunc(f);
  3027. }
  3028. broadcastModifiedStats(modifiedStats);
  3029. }
  3030. /**
  3031. * Remove a Func from the Calculator set of the L2Character.<BR><BR>
  3032. *
  3033. * <B><U> Concept</U> :</B><BR><BR>
  3034. * A L2Character owns a table of Calculators called <B>_calculators</B>.
  3035. * Each Calculator (a calculator per state) own a table of Func object.
  3036. * A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...).
  3037. * To reduce cache memory use, L2NPCInstances who don't have skills share the same Calculator set called <B>NPC_STD_CALCULATOR</B>.<BR><BR>
  3038. *
  3039. * That's why, if a L2NPCInstance is under a skill/spell effect that modify one of its state, a copy of the NPC_STD_CALCULATOR
  3040. * must be create in its _calculators before addind new Func object.<BR><BR>
  3041. *
  3042. * <B><U> Actions</U> :</B><BR><BR>
  3043. * <li>Remove the Func object from _calculators</li><BR><BR>
  3044. * <li>If L2Character is a L2NPCInstance and _calculators is equal to NPC_STD_CALCULATOR,
  3045. * free cache memory and just create a link on NPC_STD_CALCULATOR in _calculators</li><BR><BR>
  3046. *
  3047. * @param f The Func object to remove from the Calculator corresponding to the state affected
  3048. */
  3049. public final void removeStatFunc(Func f)
  3050. {
  3051. if (f == null)
  3052. return;
  3053. // Select the Calculator of the affected state in the Calculator set
  3054. int stat = f.stat.ordinal();
  3055. synchronized(_calculators)
  3056. {
  3057. if (_calculators[stat] == null)
  3058. return;
  3059. // Remove the Func object from the Calculator
  3060. _calculators[stat].removeFunc(f);
  3061. if (_calculators[stat].size() == 0)
  3062. _calculators[stat] = null;
  3063. // If possible, free the memory and just create a link on NPC_STD_CALCULATOR
  3064. if (this instanceof L2NpcInstance)
  3065. {
  3066. int i = 0;
  3067. for (; i < Stats.NUM_STATS; i++)
  3068. {
  3069. if (!Calculator.equalsCals(_calculators[i], NPC_STD_CALCULATOR[i]))
  3070. break;
  3071. }
  3072. if (i >= Stats.NUM_STATS)
  3073. _calculators = NPC_STD_CALCULATOR;
  3074. }
  3075. }
  3076. }
  3077. /**
  3078. * Remove a list of Funcs from the Calculator set of the L2PcInstance.<BR><BR>
  3079. *
  3080. * <B><U> Concept</U> :</B><BR><BR>
  3081. * A L2Character owns a table of Calculators called <B>_calculators</B>.
  3082. * Each Calculator (a calculator per state) own a table of Func object.
  3083. * A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...). <BR><BR>
  3084. *
  3085. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method is ONLY for L2PcInstance</B></FONT><BR><BR>
  3086. *
  3087. * <B><U> Example of use </U> :</B><BR><BR>
  3088. * <li> Unequip an item from inventory</li>
  3089. * <li> Stop an active skill</li><BR><BR>
  3090. *
  3091. * @param funcs The list of Func objects to add to the Calculator corresponding to the state affected
  3092. */
  3093. public final void removeStatFuncs(Func[] funcs)
  3094. {
  3095. FastList<Stats> modifiedStats = new FastList<Stats>();
  3096. for (Func f : funcs)
  3097. {
  3098. modifiedStats.add(f.stat);
  3099. removeStatFunc(f);
  3100. }
  3101. broadcastModifiedStats(modifiedStats);
  3102. }
  3103. /**
  3104. * Remove all Func objects with the selected owner from the Calculator set of the L2Character.<BR><BR>
  3105. *
  3106. * <B><U> Concept</U> :</B><BR><BR>
  3107. * A L2Character owns a table of Calculators called <B>_calculators</B>.
  3108. * Each Calculator (a calculator per state) own a table of Func object.
  3109. * A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...).
  3110. * To reduce cache memory use, L2NPCInstances who don't have skills share the same Calculator set called <B>NPC_STD_CALCULATOR</B>.<BR><BR>
  3111. *
  3112. * That's why, if a L2NPCInstance is under a skill/spell effect that modify one of its state, a copy of the NPC_STD_CALCULATOR
  3113. * must be create in its _calculators before addind new Func object.<BR><BR>
  3114. *
  3115. * <B><U> Actions</U> :</B><BR><BR>
  3116. * <li>Remove all Func objects of the selected owner from _calculators</li><BR><BR>
  3117. * <li>If L2Character is a L2NPCInstance and _calculators is equal to NPC_STD_CALCULATOR,
  3118. * free cache memory and just create a link on NPC_STD_CALCULATOR in _calculators</li><BR><BR>
  3119. *
  3120. * <B><U> Example of use </U> :</B><BR><BR>
  3121. * <li> Unequip an item from inventory</li>
  3122. * <li> Stop an active skill</li><BR><BR>
  3123. *
  3124. * @param owner The Object(Skill, Item...) that has created the effect
  3125. */
  3126. public final void removeStatsOwner(Object owner)
  3127. {
  3128. FastList<Stats> modifiedStats = null;
  3129. int i = 0;
  3130. // Go through the Calculator set
  3131. synchronized(_calculators)
  3132. {
  3133. for (Calculator calc: _calculators)
  3134. {
  3135. if (calc != null)
  3136. {
  3137. // Delete all Func objects of the selected owner
  3138. if (modifiedStats != null)
  3139. modifiedStats.addAll(calc.removeOwner(owner));
  3140. else
  3141. modifiedStats = calc.removeOwner(owner);
  3142. if (calc.size() == 0)
  3143. _calculators[i] = null;
  3144. }
  3145. i++;
  3146. }
  3147. // If possible, free the memory and just create a link on NPC_STD_CALCULATOR
  3148. if (this instanceof L2NpcInstance)
  3149. {
  3150. i = 0;
  3151. for (; i < Stats.NUM_STATS; i++)
  3152. {
  3153. if (!Calculator.equalsCals(_calculators[i], NPC_STD_CALCULATOR[i]))
  3154. break;
  3155. }
  3156. if (i >= Stats.NUM_STATS)
  3157. _calculators = NPC_STD_CALCULATOR;
  3158. }
  3159. if (owner instanceof L2Effect && !((L2Effect)owner).preventExitUpdate)
  3160. broadcastModifiedStats(modifiedStats);
  3161. }
  3162. }
  3163. private void broadcastModifiedStats(FastList<Stats> stats)
  3164. {
  3165. if (stats == null || stats.isEmpty()) return;
  3166. boolean broadcastFull = false;
  3167. boolean otherStats = false;
  3168. StatusUpdate su = null;
  3169. for (Stats stat : stats)
  3170. {
  3171. if (stat==Stats.POWER_ATTACK_SPEED)
  3172. {
  3173. if (su == null) su = new StatusUpdate(getObjectId());
  3174. su.addAttribute(StatusUpdate.ATK_SPD, getPAtkSpd());
  3175. }
  3176. else if (stat==Stats.MAGIC_ATTACK_SPEED)
  3177. {
  3178. if (su == null) su = new StatusUpdate(getObjectId());
  3179. su.addAttribute(StatusUpdate.CAST_SPD, getMAtkSpd());
  3180. }
  3181. //else if (stat==Stats.MAX_HP) // TODO: self only and add more stats...
  3182. //{
  3183. // if (su == null) su = new StatusUpdate(getObjectId());
  3184. // su.addAttribute(StatusUpdate.MAX_HP, getMaxHp());
  3185. //}
  3186. else if (stat==Stats.MAX_CP)
  3187. {
  3188. if (this instanceof L2PcInstance)
  3189. {
  3190. if (su == null) su = new StatusUpdate(getObjectId());
  3191. su.addAttribute(StatusUpdate.MAX_CP, getMaxCp());
  3192. }
  3193. }
  3194. //else if (stat==Stats.MAX_MP)
  3195. //{
  3196. // if (su == null) su = new StatusUpdate(getObjectId());
  3197. // su.addAttribute(StatusUpdate.MAX_MP, getMaxMp());
  3198. //}
  3199. else if (stat==Stats.RUN_SPEED)
  3200. {
  3201. broadcastFull = true;
  3202. }
  3203. else
  3204. otherStats = true;
  3205. }
  3206. if (this instanceof L2PcInstance)
  3207. {
  3208. if (broadcastFull)
  3209. ((L2PcInstance)this).updateAndBroadcastStatus(2);
  3210. else
  3211. {
  3212. if (otherStats)
  3213. {
  3214. ((L2PcInstance)this).updateAndBroadcastStatus(1);
  3215. if (su != null)
  3216. {
  3217. Collection<L2PcInstance> plrs = getKnownList().getKnownPlayers().values();
  3218. //synchronized (getKnownList().getKnownPlayers())
  3219. {
  3220. for (L2PcInstance player : plrs)
  3221. {
  3222. try
  3223. {
  3224. player.sendPacket(su);
  3225. }
  3226. catch (NullPointerException e)
  3227. {
  3228. }
  3229. }
  3230. }
  3231. }
  3232. }
  3233. else if (su != null) broadcastPacket(su);
  3234. }
  3235. }
  3236. else if (this instanceof L2NpcInstance)
  3237. {
  3238. if (broadcastFull)
  3239. {
  3240. Collection<L2PcInstance> plrs = getKnownList().getKnownPlayers().values();
  3241. //synchronized (getKnownList().getKnownPlayers())
  3242. {
  3243. for (L2PcInstance player : plrs)
  3244. player.sendPacket(new NpcInfo((L2NpcInstance)this, player));
  3245. }
  3246. }
  3247. else if (su != null)
  3248. broadcastPacket(su);
  3249. }
  3250. else if (this instanceof L2Summon)
  3251. {
  3252. if (broadcastFull)
  3253. {
  3254. Collection<L2PcInstance> plrs = getKnownList().getKnownPlayers().values();
  3255. //synchronized (getKnownList().getKnownPlayers())
  3256. {
  3257. for (L2PcInstance player : plrs)
  3258. player.sendPacket(new NpcInfo((L2Summon)this, player));
  3259. }
  3260. }
  3261. else if (su != null)
  3262. broadcastPacket(su);
  3263. }
  3264. else if (su != null)
  3265. broadcastPacket(su);
  3266. }
  3267. /**
  3268. * Return the orientation of the L2Character.<BR><BR>
  3269. */
  3270. public final int getHeading()
  3271. {
  3272. return _heading;
  3273. }
  3274. /**
  3275. * Set the orientation of the L2Character.<BR><BR>
  3276. */
  3277. public final void setHeading(int heading)
  3278. {
  3279. _heading = heading;
  3280. }
  3281. /**
  3282. * Return the X destination of the L2Character or the X position if not in movement.<BR><BR>
  3283. */
  3284. public final int getClientX()
  3285. {
  3286. return _clientX;
  3287. }
  3288. public final int getClientY()
  3289. {
  3290. return _clientY;
  3291. }
  3292. public final int getClientZ()
  3293. {
  3294. return _clientZ;
  3295. }
  3296. public final int getClientHeading()
  3297. {
  3298. return _clientHeading;
  3299. }
  3300. public final void setClientX(int val)
  3301. {
  3302. _clientX=val;
  3303. }
  3304. public final void setClientY(int val)
  3305. {
  3306. _clientY=val;
  3307. }
  3308. public final void setClientZ(int val)
  3309. {
  3310. _clientZ=val;
  3311. }
  3312. public final void setClientHeading(int val)
  3313. {
  3314. _clientHeading=val;
  3315. }
  3316. public final int getXdestination()
  3317. {
  3318. MoveData m = _move;
  3319. if (m != null)
  3320. return m._xDestination;
  3321. return getX();
  3322. }
  3323. /**
  3324. * Return the Y destination of the L2Character or the Y position if not in movement.<BR><BR>
  3325. */
  3326. public final int getYdestination()
  3327. {
  3328. MoveData m = _move;
  3329. if (m != null)
  3330. return m._yDestination;
  3331. return getY();
  3332. }
  3333. /**
  3334. * Return the Z destination of the L2Character or the Z position if not in movement.<BR><BR>
  3335. */
  3336. public final int getZdestination()
  3337. {
  3338. MoveData m = _move;
  3339. if (m != null)
  3340. return m._zDestination;
  3341. return getZ();
  3342. }
  3343. /**
  3344. * Return True if the L2Character is in combat.<BR><BR>
  3345. */
  3346. public final boolean isInCombat()
  3347. {
  3348. return (getAI().getAttackTarget() != null || getAI().isAutoAttacking());
  3349. }
  3350. /**
  3351. * Return True if the L2Character is moving.<BR><BR>
  3352. */
  3353. public final boolean isMoving()
  3354. {
  3355. return _move != null;
  3356. }
  3357. /**
  3358. * Return True if the L2Character is travelling a calculated path.<BR><BR>
  3359. */
  3360. public final boolean isOnGeodataPath()
  3361. {
  3362. MoveData m = _move;
  3363. if (m == null)
  3364. return false;
  3365. if (m.onGeodataPathIndex == -1)
  3366. return false;
  3367. if (m.onGeodataPathIndex == m.geoPath.size()-1)
  3368. return false;
  3369. return true;
  3370. }
  3371. /**
  3372. * Return True if the L2Character is casting.<BR><BR>
  3373. */
  3374. public final boolean isCastingNow()
  3375. {
  3376. return _isCastingNow;
  3377. }
  3378. public void setIsCastingNow(boolean value)
  3379. {
  3380. _isCastingNow = value;
  3381. }
  3382. public final boolean isCastingSimultaneouslyNow()
  3383. {
  3384. return _isCastingSimultaneouslyNow;
  3385. }
  3386. public void setIsCastingSimultaneouslyNow(boolean value)
  3387. {
  3388. _isCastingSimultaneouslyNow = value;
  3389. }
  3390. /**
  3391. * Return True if the cast of the L2Character can be aborted.<BR><BR>
  3392. */
  3393. public final boolean canAbortCast()
  3394. {
  3395. return _castInterruptTime > GameTimeController.getGameTicks();
  3396. }
  3397. public int getCastInterruptTime()
  3398. {
  3399. return _castInterruptTime;
  3400. }
  3401. /**
  3402. * Return True if the L2Character is attacking.<BR><BR>
  3403. */
  3404. public final boolean isAttackingNow()
  3405. {
  3406. return _attackEndTime > GameTimeController.getGameTicks();
  3407. }
  3408. /**
  3409. * Return True if the L2Character has aborted its attack.<BR><BR>
  3410. */
  3411. public final boolean isAttackAborted()
  3412. {
  3413. return _attacking <= 0;
  3414. }
  3415. /**
  3416. * Abort the attack of the L2Character and send Server->Client ActionFailed packet.<BR><BR>
  3417. */
  3418. public final void abortAttack()
  3419. {
  3420. if (isAttackingNow())
  3421. {
  3422. _attacking = 0;
  3423. sendPacket(ActionFailed.STATIC_PACKET);
  3424. }
  3425. }
  3426. /**
  3427. * Returns body part (paperdoll slot) we are targeting right now
  3428. */
  3429. public final int getAttackingBodyPart()
  3430. {
  3431. return _attacking;
  3432. }
  3433. /**
  3434. * Abort the cast of the L2Character and send Server->Client MagicSkillCanceld/ActionFailed packet.<BR><BR>
  3435. */
  3436. public final void abortCast()
  3437. {
  3438. if (isCastingNow() || isCastingSimultaneouslyNow())
  3439. {
  3440. // cancels the skill hit scheduled task
  3441. if (_skillCast != null)
  3442. {
  3443. try
  3444. {
  3445. _skillCast.cancel(true);
  3446. }
  3447. catch (NullPointerException e) {}
  3448. _skillCast = null;
  3449. }
  3450. if (_skillCast2 != null)
  3451. {
  3452. try
  3453. {
  3454. _skillCast2.cancel(true);
  3455. }
  3456. catch (NullPointerException e) {}
  3457. _skillCast2 = null;
  3458. }
  3459. if (getForceBuff() != null)
  3460. getForceBuff().onCastAbort();
  3461. L2Effect mog = getFirstEffect(L2EffectType.SIGNET_GROUND);
  3462. if (mog != null)
  3463. mog.exit();
  3464. if (_allSkillsDisabled) enableAllSkills(); // this remains for forced skill use, e.g. scroll of escape
  3465. setIsCastingNow(false);
  3466. setIsCastingSimultaneouslyNow(false);
  3467. // safeguard for cannot be interrupt any more
  3468. _castInterruptTime = 0;
  3469. if (this instanceof L2PcInstance) getAI().notifyEvent(CtrlEvent.EVT_FINISH_CASTING); // setting back previous intention
  3470. broadcastPacket(new MagicSkillCanceld(getObjectId())); // broadcast packet to stop animations client-side
  3471. sendPacket(ActionFailed.STATIC_PACKET); // send an "action failed" packet to the caster
  3472. }
  3473. }
  3474. /**
  3475. * Update the position of the L2Character during a movement and return True if the movement is finished.<BR><BR>
  3476. *
  3477. * <B><U> Concept</U> :</B><BR><BR>
  3478. * At the beginning of the move action, all properties of the movement are stored in the MoveData object called <B>_move</B> of the L2Character.
  3479. * The position of the start point and of the destination permit to estimated in function of the movement speed the time to achieve the destination.<BR><BR>
  3480. *
  3481. * When the movement is started (ex : by MovetoLocation), this method will be called each 0.1 sec to estimate and update the L2Character position on the server.
  3482. * Note, that the current server position can differe from the current client position even if each movement is straight foward.
  3483. * That's why, client send regularly a Client->Server ValidatePosition packet to eventually correct the gap on the server.
  3484. * But, it's always the server position that is used in range calculation.<BR><BR>
  3485. *
  3486. * At the end of the estimated movement time, the L2Character position is automatically set to the destination position even if the movement is not finished.<BR><BR>
  3487. *
  3488. * <FONT COLOR=#FF0000><B> <U>Caution</U> : The current Z position is obtained FROM THE CLIENT by the Client->Server ValidatePosition Packet.
  3489. * But x and y positions must be calculated to avoid that players try to modify their movement speed.</B></FONT><BR><BR>
  3490. *
  3491. * @param gameTicks Nb of ticks since the server start
  3492. * @return True if the movement is finished
  3493. */
  3494. public boolean updatePosition(int gameTicks)
  3495. {
  3496. // Get movement data
  3497. MoveData m = _move;
  3498. if (m == null)
  3499. return true;
  3500. if (!isVisible())
  3501. {
  3502. _move = null;
  3503. return true;
  3504. }
  3505. // Check if this is the first update
  3506. if (m._moveTimestamp == 0)
  3507. {
  3508. m._moveTimestamp = m._moveStartTime;
  3509. m._xAccurate = getX();
  3510. m._yAccurate = getY();
  3511. }
  3512. // Check if the position has already been calculated
  3513. if (m._moveTimestamp == gameTicks)
  3514. return false;
  3515. int xPrev = getX();
  3516. int yPrev = getY();
  3517. int zPrev = getZ(); // the z coordinate may be modified by coordinate synchronizations
  3518. double dx, dy, dz, distFraction;
  3519. if (Config.COORD_SYNCHRONIZE == 1)
  3520. // the only method that can modify x,y while moving (otherwise _move would/should be set null)
  3521. {
  3522. dx = m._xDestination - xPrev;
  3523. dy = m._yDestination - yPrev;
  3524. }
  3525. else // otherwise we need saved temporary values to avoid rounding errors
  3526. {
  3527. dx = m._xDestination - m._xAccurate;
  3528. dy = m._yDestination - m._yAccurate;
  3529. }
  3530. // Z coordinate will follow geodata or client values
  3531. if (Config.GEODATA > 0 && Config.COORD_SYNCHRONIZE == 2
  3532. && !isFlying()
  3533. && !isInsideZone(L2Character.ZONE_WATER)
  3534. && !m.disregardingGeodata
  3535. && GameTimeController.getGameTicks() % 10 == 0 // once a second to reduce possible cpu load
  3536. && GeoData.getInstance().hasGeo(xPrev, yPrev)
  3537. && !(this instanceof L2BoatInstance))
  3538. {
  3539. short geoHeight = GeoData.getInstance().getSpawnHeight(xPrev, yPrev, zPrev-30, zPrev+30, this.getObjectId());
  3540. dz = m._zDestination - geoHeight;
  3541. // quite a big difference, compare to validatePosition packet
  3542. if (this instanceof L2PcInstance && Math.abs(((L2PcInstance)this).getClientZ()-geoHeight) > 200 && Math.abs(((L2PcInstance)this).getClientZ()-geoHeight) < 1500)
  3543. {
  3544. dz = m._zDestination - zPrev; // allow diff
  3545. }
  3546. else if (this.isInCombat() && Math.abs(dz) > 200 && (dx*dx + dy*dy) < 40000) // allow mob to climb up to pcinstance
  3547. {
  3548. dz = m._zDestination - zPrev; // climbing
  3549. }
  3550. else
  3551. {
  3552. zPrev = geoHeight;
  3553. }
  3554. }
  3555. else
  3556. dz = m._zDestination - zPrev;
  3557. double distPassed = getStat().getMoveSpeed() * (gameTicks - m._moveTimestamp) / GameTimeController.TICKS_PER_SECOND;
  3558. if ((dx*dx + dy*dy) < 10000 && (dz*dz > 2500)) // close enough, allows error between client and server geodata if it cannot be avoided
  3559. {
  3560. distFraction = distPassed / Math.sqrt(dx*dx + dy*dy);
  3561. }
  3562. else
  3563. distFraction = distPassed / Math.sqrt(dx*dx + dy*dy + dz*dz);
  3564. // if (Config.DEVELOPER) _log.warning("Move Ticks:" + (gameTicks - m._moveTimestamp) + ", distPassed:" + distPassed + ", distFraction:" + distFraction);
  3565. if (distFraction > 1) // already there
  3566. {
  3567. // Set the position of the L2Character to the destination
  3568. if (this instanceof L2BoatInstance)
  3569. {
  3570. super.getPosition().setXYZ(m._xDestination, m._yDestination, m._zDestination);
  3571. ((L2BoatInstance)this).updatePeopleInTheBoat(m._xDestination, m._yDestination, m._zDestination);
  3572. }
  3573. else
  3574. {
  3575. super.getPosition().setXYZ(m._xDestination, m._yDestination, m._zDestination);
  3576. revalidateZone(false);
  3577. }
  3578. }
  3579. else
  3580. {
  3581. m._xAccurate += dx * distFraction;
  3582. m._yAccurate += dy * distFraction;
  3583. // Set the position of the L2Character to estimated after parcial move
  3584. if(this instanceof L2BoatInstance )
  3585. {
  3586. super.getPosition().setXYZ((int)(m._xAccurate), (int)(m._yAccurate), zPrev + (int)(dz * distFraction + 0.5));
  3587. ((L2BoatInstance)this).updatePeopleInTheBoat((int)(m._xAccurate), (int)(m._yAccurate), zPrev + (int)(dz * distFraction + 0.5));
  3588. }
  3589. else
  3590. {
  3591. super.getPosition().setXYZ((int)(m._xAccurate), (int)(m._yAccurate), zPrev + (int)(dz * distFraction + 0.5));
  3592. revalidateZone(false);
  3593. }
  3594. }
  3595. // Set the timer of last position update to now
  3596. m._moveTimestamp = gameTicks;
  3597. return (distFraction > 1);
  3598. }
  3599. public void revalidateZone(boolean force)
  3600. {
  3601. if (getWorldRegion() == null) return;
  3602. // This function is called too often from movement code
  3603. if (force) _zoneValidateCounter = 4;
  3604. else
  3605. {
  3606. _zoneValidateCounter--;
  3607. if (_zoneValidateCounter < 0)
  3608. _zoneValidateCounter = 4;
  3609. else return;
  3610. }
  3611. getWorldRegion().revalidateZones(this);
  3612. }
  3613. /**
  3614. * Stop movement of the L2Character (Called by AI Accessor only).<BR><BR>
  3615. *
  3616. * <B><U> Actions</U> :</B><BR><BR>
  3617. * <li>Delete movement data of the L2Character </li>
  3618. * <li>Set the current position (x,y,z), its current L2WorldRegion if necessary and its heading </li>
  3619. * <li>Remove the L2Object object from _gmList** of GmListTable </li>
  3620. * <li>Remove object from _knownObjects and _knownPlayer* of all surrounding L2WorldRegion L2Characters </li><BR><BR>
  3621. *
  3622. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T send Server->Client packet StopMove/StopRotation </B></FONT><BR><BR>
  3623. *
  3624. */
  3625. public void stopMove(L2CharPosition pos) { stopMove(pos, false); }
  3626. public void stopMove(L2CharPosition pos, boolean updateKnownObjects)
  3627. {
  3628. // Delete movement data of the L2Character
  3629. _move = null;
  3630. //if (getAI() != null)
  3631. // getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  3632. // Set the current position (x,y,z), its current L2WorldRegion if necessary and its heading
  3633. // All data are contained in a L2CharPosition object
  3634. if (pos != null)
  3635. {
  3636. getPosition().setXYZ(pos.x, pos.y, pos.z);
  3637. setHeading(pos.heading);
  3638. revalidateZone(true);
  3639. }
  3640. broadcastPacket(new StopMove(this));
  3641. if (Config.MOVE_BASED_KNOWNLIST && updateKnownObjects) this.getKnownList().findObjects();
  3642. }
  3643. /**
  3644. * @return Returns the showSummonAnimation.
  3645. */
  3646. public boolean isShowSummonAnimation()
  3647. {
  3648. return _showSummonAnimation;
  3649. }
  3650. /**
  3651. * @param showSummonAnimation The showSummonAnimation to set.
  3652. */
  3653. public void setShowSummonAnimation(boolean showSummonAnimation)
  3654. {
  3655. _showSummonAnimation = showSummonAnimation;
  3656. }
  3657. /**
  3658. * Target a L2Object (add the target to the L2Character _target, _knownObject and L2Character to _KnownObject of the L2Object).<BR><BR>
  3659. *
  3660. * <B><U> Concept</U> :</B><BR><BR>
  3661. * The L2Object (including L2Character) targeted is identified in <B>_target</B> of the L2Character<BR><BR>
  3662. *
  3663. * <B><U> Actions</U> :</B><BR><BR>
  3664. * <li>Set the _target of L2Character to L2Object </li>
  3665. * <li>If necessary, add L2Object to _knownObject of the L2Character </li>
  3666. * <li>If necessary, add L2Character to _KnownObject of the L2Object </li>
  3667. * <li>If object==null, cancel Attak or Cast </li><BR><BR>
  3668. *
  3669. * <B><U> Overridden in </U> :</B><BR><BR>
  3670. * <li> L2PcInstance : Remove the L2PcInstance from the old target _statusListener and add it to the new target if it was a L2Character</li><BR><BR>
  3671. *
  3672. * @param object L2object to target
  3673. *
  3674. */
  3675. public void setTarget(L2Object object)
  3676. {
  3677. if (object != null && !object.isVisible())
  3678. object = null;
  3679. if (object != null && object != _target)
  3680. {
  3681. getKnownList().addKnownObject(object);
  3682. object.getKnownList().addKnownObject(this);
  3683. }
  3684. _target = object;
  3685. }
  3686. /**
  3687. * Return the identifier of the L2Object targeted or -1.<BR><BR>
  3688. */
  3689. public final int getTargetId()
  3690. {
  3691. if (_target != null)
  3692. {
  3693. return _target.getObjectId();
  3694. }
  3695. return -1;
  3696. }
  3697. /**
  3698. * Return the L2Object targeted or null.<BR><BR>
  3699. */
  3700. public final L2Object getTarget()
  3701. {
  3702. return _target;
  3703. }
  3704. // called from AIAccessor only
  3705. /**
  3706. * Calculate movement data for a move to location action and add the L2Character to movingObjects of GameTimeController (only called by AI Accessor).<BR><BR>
  3707. *
  3708. * <B><U> Concept</U> :</B><BR><BR>
  3709. * At the beginning of the move action, all properties of the movement are stored in the MoveData object called <B>_move</B> of the L2Character.
  3710. * The position of the start point and of the destination permit to estimated in function of the movement speed the time to achieve the destination.<BR><BR>
  3711. * All L2Character in movement are identified in <B>movingObjects</B> of GameTimeController that will call the updatePosition method of those L2Character each 0.1s.<BR><BR>
  3712. *
  3713. * <B><U> Actions</U> :</B><BR><BR>
  3714. * <li>Get current position of the L2Character </li>
  3715. * <li>Calculate distance (dx,dy) between current position and destination including offset </li>
  3716. * <li>Create and Init a MoveData object </li>
  3717. * <li>Set the L2Character _move object to MoveData object </li>
  3718. * <li>Add the L2Character to movingObjects of the GameTimeController </li>
  3719. * <li>Create a task to notify the AI that L2Character arrives at a check point of the movement </li><BR><BR>
  3720. *
  3721. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T send Server->Client packet MoveToPawn/CharMoveToLocation </B></FONT><BR><BR>
  3722. *
  3723. * <B><U> Example of use </U> :</B><BR><BR>
  3724. * <li> AI : onIntentionMoveTo(L2CharPosition), onIntentionPickUp(L2Object), onIntentionInteract(L2Object) </li>
  3725. * <li> FollowTask </li><BR><BR>
  3726. *
  3727. * @param x The X position of the destination
  3728. * @param y The Y position of the destination
  3729. * @param z The Y position of the destination
  3730. * @param offset The size of the interaction area of the L2Character targeted
  3731. *
  3732. */
  3733. protected void moveToLocation(int x, int y, int z, int offset)
  3734. {
  3735. // Get the Move Speed of the L2Charcater
  3736. float speed = getStat().getMoveSpeed();
  3737. if (speed <= 0 || isMovementDisabled()) return;
  3738. // Get current position of the L2Character
  3739. final int curX = super.getX();
  3740. final int curY = super.getY();
  3741. final int curZ = super.getZ();
  3742. // Calculate distance (dx,dy) between current position and destination
  3743. // TODO: improve Z axis move/follow support when dx,dy are small compared to dz
  3744. double dx = (x - curX);
  3745. double dy = (y - curY);
  3746. double dz = (z - curZ);
  3747. double distance = Math.sqrt(dx*dx + dy*dy);
  3748. // make water move short and use no geodata checks for swimming chars
  3749. // distance in a click can easily be over 3000
  3750. if (Config.GEODATA > 0 && isInsideZone(ZONE_WATER) && distance > 700)
  3751. {
  3752. double divider = 700/distance;
  3753. x = curX + (int)(divider * dx);
  3754. y = curY + (int)(divider * dy);
  3755. z = curZ + (int)(divider * dz);
  3756. dx = (x - curX);
  3757. dy = (y - curY);
  3758. dz = (z - curZ);
  3759. distance = Math.sqrt(dx*dx + dy*dy);
  3760. }
  3761. if (Config.DEBUG) _log.fine("distance to target:" + distance);
  3762. // Define movement angles needed
  3763. // ^
  3764. // | X (x,y)
  3765. // | /
  3766. // | /distance
  3767. // | /
  3768. // |/ angle
  3769. // X ---------->
  3770. // (curx,cury)
  3771. double cos;
  3772. double sin;
  3773. // Check if a movement offset is defined or no distance to go through
  3774. if (offset > 0 || distance < 1)
  3775. {
  3776. // approximation for moving closer when z coordinates are different
  3777. // TODO: handle Z axis movement better
  3778. offset -= Math.abs(dz);
  3779. if (offset < 5) offset = 5;
  3780. // If no distance to go through, the movement is canceled
  3781. if (distance < 1 || distance - offset <= 0)
  3782. {
  3783. if (Config.DEBUG) _log.fine("already in range, no movement needed.");
  3784. // Notify the AI that the L2Character is arrived at destination
  3785. getAI().notifyEvent(CtrlEvent.EVT_ARRIVED);
  3786. return;
  3787. }
  3788. // Calculate movement angles needed
  3789. sin = dy/distance;
  3790. cos = dx/distance;
  3791. distance -= (offset-5); // due to rounding error, we have to move a bit closer to be in range
  3792. // Calculate the new destination with offset included
  3793. x = curX + (int)(distance * cos);
  3794. y = curY + (int)(distance * sin);
  3795. }
  3796. else
  3797. {
  3798. // Calculate movement angles needed
  3799. sin = dy/distance;
  3800. cos = dx/distance;
  3801. }
  3802. // Create and Init a MoveData object
  3803. MoveData m = new MoveData();
  3804. // GEODATA MOVEMENT CHECKS AND PATHFINDING
  3805. m.onGeodataPathIndex = -1; // Initialize not on geodata path
  3806. m.disregardingGeodata = false;
  3807. if (Config.GEODATA > 0
  3808. && !isFlying() // flying chars not checked - even canSeeTarget doesn't work yet
  3809. && (!isInsideZone(ZONE_WATER) || isInsideZone(ZONE_SIEGE)) // swimming also not checked unless in siege zone - but distance is limited
  3810. && !(this instanceof L2NpcWalkerInstance)) // npc walkers not checked
  3811. {
  3812. double originalDistance = distance;
  3813. int originalX = x;
  3814. int originalY = y;
  3815. int originalZ = z;
  3816. int gtx = (originalX - L2World.MAP_MIN_X) >> 4;
  3817. int gty = (originalY - L2World.MAP_MIN_Y) >> 4;
  3818. // Movement checks:
  3819. // when geodata == 2, for all characters except mobs returning home (could be changed later to teleport if pathfinding fails)
  3820. // when geodata == 1, for l2playableinstance and l2riftinstance only
  3821. if ((Config.GEODATA == 2 && !(this instanceof L2Attackable && ((L2Attackable)this).isReturningToSpawnPoint()))
  3822. || this instanceof L2PcInstance
  3823. || (this instanceof L2Summon && !(this.getAI().getIntention() == AI_INTENTION_FOLLOW)) // assuming intention_follow only when following owner
  3824. || isAfraid()
  3825. || this instanceof L2RiftInvaderInstance)
  3826. {
  3827. if (isOnGeodataPath())
  3828. {
  3829. try {
  3830. if (gtx == _move.geoPathGtx && gty == _move.geoPathGty)
  3831. return;
  3832. else
  3833. _move.onGeodataPathIndex = -1; // Set not on geodata path
  3834. } catch (NullPointerException e)
  3835. {
  3836. // nothing
  3837. }
  3838. }
  3839. if (curX < L2World.MAP_MIN_X || curX > L2World.MAP_MAX_X || curY < L2World.MAP_MIN_Y || curY > L2World.MAP_MAX_Y)
  3840. {
  3841. // Temporary fix for character outside world region errors
  3842. _log.warning("Character "+this.getName()+" outside world area, in coordinates x:"+curX+" y:"+curY);
  3843. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  3844. if (this instanceof L2PcInstance) ((L2PcInstance)this).deleteMe();
  3845. else this.onDecay();
  3846. return;
  3847. }
  3848. Location destiny = GeoData.getInstance().moveCheck(curX, curY, curZ, x, y, z, getInstanceId());
  3849. // location different if destination wasn't reached (or just z coord is different)
  3850. x = destiny.getX();
  3851. y = destiny.getY();
  3852. z = destiny.getZ();
  3853. distance = Math.sqrt((x - curX)*(x - curX) + (y - curY)*(y - curY));
  3854. }
  3855. // Pathfinding checks. Only when geodata setting is 2, the LoS check gives shorter result
  3856. // than the original movement was and the LoS gives a shorter distance than 2000
  3857. // This way of detecting need for pathfinding could be changed.
  3858. if(Config.GEODATA == 2 && originalDistance-distance > 100 && distance < 2000 && !this.isAfraid())
  3859. {
  3860. // Path calculation
  3861. // Overrides previous movement check
  3862. if(this instanceof L2PlayableInstance || this.isInCombat() || this instanceof L2MinionInstance)
  3863. {
  3864. m.geoPath = PathFinding.getInstance().findPath(curX, curY, curZ, originalX, originalY, originalZ, getInstanceId());
  3865. if (m.geoPath == null || m.geoPath.size() < 2) // No path found
  3866. {
  3867. // * Even though there's no path found (remember geonodes aren't perfect),
  3868. // the mob is attacking and right now we set it so that the mob will go
  3869. // after target anyway, is dz is small enough.
  3870. // * With cellpathfinding this approach could be changed but would require taking
  3871. // off the geonodes and some more checks.
  3872. // * Summons will follow their masters no matter what.
  3873. // * Currently minions also must move freely since L2AttackableAI commands
  3874. // them to move along with their leader
  3875. if (this instanceof L2PcInstance
  3876. || (!(this instanceof L2PlayableInstance)
  3877. && !(this instanceof L2MinionInstance)
  3878. && Math.abs(z - curZ) > 140)
  3879. || (this instanceof L2Summon && !((L2Summon)this).getFollowStatus()))
  3880. {
  3881. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  3882. return;
  3883. }
  3884. else
  3885. {
  3886. m.disregardingGeodata = true;
  3887. x = originalX;
  3888. y = originalY;
  3889. z = originalZ;
  3890. distance = originalDistance;
  3891. }
  3892. }
  3893. else
  3894. {
  3895. m.onGeodataPathIndex = 0; // on first segment
  3896. m.geoPathGtx = gtx;
  3897. m.geoPathGty = gty;
  3898. m.geoPathAccurateTx = originalX;
  3899. m.geoPathAccurateTy = originalY;
  3900. x = m.geoPath.get(m.onGeodataPathIndex).getX();
  3901. y = m.geoPath.get(m.onGeodataPathIndex).getY();
  3902. z = m.geoPath.get(m.onGeodataPathIndex).getZ();
  3903. // check for doors in the route
  3904. if (DoorTable.getInstance().checkIfDoorsBetween(curX, curY, curZ, x, y, z, getInstanceId()))
  3905. {
  3906. m.geoPath = null;
  3907. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  3908. return;
  3909. }
  3910. for (int i = 0; i < m.geoPath.size()-1; i++)
  3911. {
  3912. if (DoorTable.getInstance().checkIfDoorsBetween(m.geoPath.get(i),m.geoPath.get(i+1),getInstanceId()))
  3913. {
  3914. m.geoPath = null;
  3915. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  3916. return;
  3917. }
  3918. }
  3919. dx = (x - curX);
  3920. dy = (y - curY);
  3921. distance = Math.sqrt(dx*dx + dy*dy);
  3922. sin = dy/distance;
  3923. cos = dx/distance;
  3924. }
  3925. }
  3926. }
  3927. // If no distance to go through, the movement is canceled
  3928. if (distance < 1 && (Config.GEODATA == 2
  3929. || this instanceof L2PlayableInstance
  3930. || this.isAfraid()
  3931. || this instanceof L2RiftInvaderInstance))
  3932. {
  3933. if(this instanceof L2Summon) ((L2Summon)this).setFollowStatus(false);
  3934. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  3935. return;
  3936. }
  3937. }
  3938. // Caclulate the Nb of ticks between the current position and the destination
  3939. // One tick added for rounding reasons
  3940. int ticksToMove = 1+(int)(GameTimeController.TICKS_PER_SECOND * distance / speed);
  3941. m._xDestination = x;
  3942. m._yDestination = y;
  3943. m._zDestination = z; // this is what was requested from client
  3944. // Calculate and set the heading of the L2Character
  3945. m._heading = 0; // initial value for coordinate sync
  3946. setHeading(Util.calculateHeadingFrom(cos, sin));
  3947. if (Config.DEBUG)
  3948. _log.fine("dist:"+ distance +"speed:" + speed + " ttt:" + ticksToMove +
  3949. " heading:" + getHeading());
  3950. m._moveStartTime = GameTimeController.getGameTicks();
  3951. // Set the L2Character _move object to MoveData object
  3952. _move = m;
  3953. // Add the L2Character to movingObjects of the GameTimeController
  3954. // The GameTimeController manage objects movement
  3955. GameTimeController.getInstance().registerMovingObject(this);
  3956. // Create a task to notify the AI that L2Character arrives at a check point of the movement
  3957. if (ticksToMove*GameTimeController.MILLIS_IN_TICK > 3000)
  3958. ThreadPoolManager.getInstance().scheduleAi( new NotifyAITask(CtrlEvent.EVT_ARRIVED_REVALIDATE), 2000);
  3959. // the CtrlEvent.EVT_ARRIVED will be sent when the character will actually arrive
  3960. // to destination by GameTimeController
  3961. }
  3962. public boolean moveToNextRoutePoint()
  3963. {
  3964. if(!this.isOnGeodataPath())
  3965. {
  3966. // Cancel the move action
  3967. _move = null;
  3968. return false;
  3969. }
  3970. // Get the Move Speed of the L2Charcater
  3971. float speed = getStat().getMoveSpeed();
  3972. if (speed <= 0 || isMovementDisabled())
  3973. {
  3974. // Cancel the move action
  3975. _move = null;
  3976. return false;
  3977. }
  3978. MoveData md = _move;
  3979. if (md == null)
  3980. return false;
  3981. // Create and Init a MoveData object
  3982. MoveData m = new MoveData();
  3983. // Update MoveData object
  3984. m.onGeodataPathIndex = md.onGeodataPathIndex + 1; // next segment
  3985. m.geoPath = md.geoPath;
  3986. m.geoPathGtx = md.geoPathGtx;
  3987. m.geoPathGty = md.geoPathGty;
  3988. m.geoPathAccurateTx = md.geoPathAccurateTx;
  3989. m.geoPathAccurateTy = md.geoPathAccurateTy;
  3990. if (md.onGeodataPathIndex == md.geoPath.size()-2)
  3991. {
  3992. m._xDestination = md.geoPathAccurateTx;
  3993. m._yDestination = md.geoPathAccurateTy;
  3994. m._zDestination = md.geoPath.get(m.onGeodataPathIndex).getZ();
  3995. }
  3996. else
  3997. {
  3998. m._xDestination = md.geoPath.get(m.onGeodataPathIndex).getX();
  3999. m._yDestination = md.geoPath.get(m.onGeodataPathIndex).getY();
  4000. m._zDestination = md.geoPath.get(m.onGeodataPathIndex).getZ();
  4001. }
  4002. double dx = (m._xDestination - super.getX());
  4003. double dy = (m._yDestination - super.getY());
  4004. double distance = Math.sqrt(dx*dx + dy*dy);
  4005. double sin = dy/distance;
  4006. double cos = dx/distance;
  4007. // Caclulate the Nb of ticks between the current position and the destination
  4008. // One tick added for rounding reasons
  4009. int ticksToMove = 1+(int)(GameTimeController.TICKS_PER_SECOND * distance / speed);
  4010. // Calculate and set the heading of the L2Character
  4011. int heading = (int) (Math.atan2(-sin, -cos) * 10430.378);
  4012. heading += 32768;
  4013. setHeading(heading);
  4014. m._heading = 0; // initial value for coordinate sync
  4015. m._moveStartTime = GameTimeController.getGameTicks();
  4016. if (Config.DEBUG) _log.fine("time to target:" + ticksToMove);
  4017. // Set the L2Character _move object to MoveData object
  4018. _move = m;
  4019. // Add the L2Character to movingObjects of the GameTimeController
  4020. // The GameTimeController manage objects movement
  4021. GameTimeController.getInstance().registerMovingObject(this);
  4022. // Create a task to notify the AI that L2Character arrives at a check point of the movement
  4023. if (ticksToMove*GameTimeController.MILLIS_IN_TICK > 3000)
  4024. ThreadPoolManager.getInstance().scheduleAi( new NotifyAITask(CtrlEvent.EVT_ARRIVED_REVALIDATE), 2000);
  4025. // the CtrlEvent.EVT_ARRIVED will be sent when the character will actually arrive
  4026. // to destination by GameTimeController
  4027. // Send a Server->Client packet CharMoveToLocation to the actor and all L2PcInstance in its _knownPlayers
  4028. MoveToLocation msg = new MoveToLocation(this);
  4029. broadcastPacket(msg);
  4030. return true;
  4031. }
  4032. public boolean validateMovementHeading(int heading)
  4033. {
  4034. MoveData m = _move;
  4035. if (m == null) return true;
  4036. boolean result = true;
  4037. if (m._heading != heading)
  4038. {
  4039. result = (m._heading == 0); // initial value or false
  4040. m._heading = heading;
  4041. }
  4042. return result;
  4043. }
  4044. /**
  4045. * Return the distance between the current position of the L2Character and the target (x,y).<BR><BR>
  4046. *
  4047. * @param x X position of the target
  4048. * @param y Y position of the target
  4049. * @return the plan distance
  4050. *
  4051. * @deprecated use getPlanDistanceSq(int x, int y, int z)
  4052. */
  4053. @Deprecated
  4054. public final double getDistance(int x, int y)
  4055. {
  4056. double dx = x - getX();
  4057. double dy = y - getY();
  4058. return Math.sqrt(dx*dx + dy*dy);
  4059. }
  4060. /**
  4061. * Return the distance between the current position of the L2Character and the target (x,y).<BR><BR>
  4062. *
  4063. * @param x X position of the target
  4064. * @param y Y position of the target
  4065. * @return the plan distance
  4066. *
  4067. * @deprecated use getPlanDistanceSq(int x, int y, int z)
  4068. */
  4069. @Deprecated
  4070. public final double getDistance(int x, int y, int z)
  4071. {
  4072. double dx = x - getX();
  4073. double dy = y - getY();
  4074. double dz = z - getZ();
  4075. return Math.sqrt(dx*dx + dy*dy + dz*dz);
  4076. }
  4077. /**
  4078. * Return the squared distance between the current position of the L2Character and the given object.<BR><BR>
  4079. *
  4080. * @param object L2Object
  4081. * @return the squared distance
  4082. */
  4083. public final double getDistanceSq(L2Object object)
  4084. {
  4085. return getDistanceSq(object.getX(), object.getY(), object.getZ());
  4086. }
  4087. /**
  4088. * Return the squared distance between the current position of the L2Character and the given x, y, z.<BR><BR>
  4089. *
  4090. * @param x X position of the target
  4091. * @param y Y position of the target
  4092. * @param z Z position of the target
  4093. * @return the squared distance
  4094. */
  4095. public final double getDistanceSq(int x, int y, int z)
  4096. {
  4097. double dx = x - getX();
  4098. double dy = y - getY();
  4099. double dz = z - getZ();
  4100. return (dx*dx + dy*dy + dz*dz);
  4101. }
  4102. /**
  4103. * Return the squared plan distance between the current position of the L2Character and the given object.<BR>
  4104. * (check only x and y, not z)<BR><BR>
  4105. *
  4106. * @param object L2Object
  4107. * @return the squared plan distance
  4108. */
  4109. public final double getPlanDistanceSq(L2Object object)
  4110. {
  4111. return getPlanDistanceSq(object.getX(), object.getY());
  4112. }
  4113. /**
  4114. * Return the squared plan distance between the current position of the L2Character and the given x, y, z.<BR>
  4115. * (check only x and y, not z)<BR><BR>
  4116. *
  4117. * @param x X position of the target
  4118. * @param y Y position of the target
  4119. * @return the squared plan distance
  4120. */
  4121. public final double getPlanDistanceSq(int x, int y)
  4122. {
  4123. double dx = x - getX();
  4124. double dy = y - getY();
  4125. return (dx*dx + dy*dy);
  4126. }
  4127. /**
  4128. * Check if this object is inside the given radius around the given object. Warning: doesn't cover collision radius!<BR><BR>
  4129. *
  4130. * @param object the target
  4131. * @param radius the radius around the target
  4132. * @param checkZ should we check Z axis also
  4133. * @param strictCheck true if (distance < radius), false if (distance <= radius)
  4134. * @return true is the L2Character is inside the radius.
  4135. *
  4136. * @see net.sf.l2j.gameserver.model.L2Character.isInsideRadius(int x, int y, int z, int radius, boolean checkZ, boolean strictCheck)
  4137. */
  4138. public final boolean isInsideRadius(L2Object object, int radius, boolean checkZ, boolean strictCheck)
  4139. {
  4140. return isInsideRadius(object.getX(), object.getY(), object.getZ(), radius, checkZ, strictCheck);
  4141. }
  4142. /**
  4143. * Check if this object is inside the given plan radius around the given point. Warning: doesn't cover collision radius!<BR><BR>
  4144. *
  4145. * @param x X position of the target
  4146. * @param y Y position of the target
  4147. * @param radius the radius around the target
  4148. * @param strictCheck true if (distance < radius), false if (distance <= radius)
  4149. * @return true is the L2Character is inside the radius.
  4150. */
  4151. public final boolean isInsideRadius(int x, int y, int radius, boolean strictCheck)
  4152. {
  4153. return isInsideRadius(x, y, 0, radius, false, strictCheck);
  4154. }
  4155. /**
  4156. * Check if this object is inside the given radius around the given point.<BR><BR>
  4157. *
  4158. * @param x X position of the target
  4159. * @param y Y position of the target
  4160. * @param z Z position of the target
  4161. * @param radius the radius around the target
  4162. * @param checkZ should we check Z axis also
  4163. * @param strictCheck true if (distance < radius), false if (distance <= radius)
  4164. * @return true is the L2Character is inside the radius.
  4165. */
  4166. public final boolean isInsideRadius(int x, int y, int z, int radius, boolean checkZ, boolean strictCheck)
  4167. {
  4168. double dx = x - getX();
  4169. double dy = y - getY();
  4170. double dz = z - getZ();
  4171. if (strictCheck)
  4172. {
  4173. if (checkZ)
  4174. return (dx*dx + dy*dy + dz*dz) < radius * radius;
  4175. else
  4176. return (dx*dx + dy*dy) < radius * radius;
  4177. } else
  4178. {
  4179. if (checkZ)
  4180. return (dx*dx + dy*dy + dz*dz) <= radius * radius;
  4181. else
  4182. return (dx*dx + dy*dy) <= radius * radius;
  4183. }
  4184. }
  4185. // /**
  4186. // * event that is called when the destination coordinates are reached
  4187. // */
  4188. // public void onTargetReached()
  4189. // {
  4190. // L2Character pawn = getPawnTarget();
  4191. //
  4192. // if (pawn != null)
  4193. // {
  4194. // int x = pawn.getX(), y=pawn.getY(),z = pawn.getZ();
  4195. //
  4196. // double distance = getDistance(x,y);
  4197. // if (getCurrentState() == STATE_FOLLOW)
  4198. // {
  4199. // calculateMovement(x,y,z,distance);
  4200. // return;
  4201. // }
  4202. //
  4203. // // takes care of moving away but distance is 0 so i won't follow problem
  4204. //
  4205. //
  4206. // if (((distance > getAttackRange()) && (getCurrentState() == STATE_ATTACKING)) || (pawn.isMoving() && getCurrentState() != STATE_ATTACKING))
  4207. // {
  4208. // calculateMovement(x,y,z,distance);
  4209. // return;
  4210. // }
  4211. //
  4212. // }
  4213. // // update x,y,z with the current calculated position
  4214. // stopMove();
  4215. //
  4216. // if (Config.DEBUG)
  4217. // _log.fine(this.getName() +":: target reached at: x "+getX()+" y "+getY()+ " z:" + getZ());
  4218. //
  4219. // if (getPawnTarget() != null)
  4220. // {
  4221. //
  4222. // setPawnTarget(null);
  4223. // setMovingToPawn(false);
  4224. // }
  4225. // }
  4226. //
  4227. // public void setTo(int x, int y, int z, int heading)
  4228. // {
  4229. // setX(x);
  4230. // setY(y);
  4231. // setZ(z);
  4232. // setHeading(heading);
  4233. // updateCurrentWorldRegion(); //TODO: maybe not needed here
  4234. // if (isMoving())
  4235. // {
  4236. // setCurrentState(STATE_IDLE);
  4237. // StopMove setto = new StopMove(this);
  4238. // broadcastPacket(setto);
  4239. // }
  4240. // else
  4241. // {
  4242. // ValidateLocation setto = new ValidateLocation(this);
  4243. // broadcastPacket(setto);
  4244. // }
  4245. //
  4246. // FinishRotation fr = new FinishRotation(this);
  4247. // broadcastPacket(fr);
  4248. // }
  4249. // protected void startCombat()
  4250. // {
  4251. // if (_currentAttackTask == null )//&& !isInCombat())
  4252. // {
  4253. // _currentAttackTask = ThreadPoolManager.getInstance().scheduleMed(new AttackTask(), 0);
  4254. // }
  4255. // else
  4256. // {
  4257. // _log.info("multiple attacks want to start in parallel. prevented.");
  4258. // }
  4259. // }
  4260. //
  4261. /**
  4262. * Return the Weapon Expertise Penalty of the L2Character.<BR><BR>
  4263. */
  4264. public float getWeaponExpertisePenalty()
  4265. {
  4266. return 1.f;
  4267. }
  4268. /**
  4269. * Return the Armour Expertise Penalty of the L2Character.<BR><BR>
  4270. */
  4271. public float getArmourExpertisePenalty()
  4272. {
  4273. return 1.f;
  4274. }
  4275. /**
  4276. * Set _attacking corresponding to Attacking Body part to CHEST.<BR><BR>
  4277. */
  4278. public void setAttackingBodypart()
  4279. {
  4280. _attacking = Inventory.PAPERDOLL_CHEST;
  4281. }
  4282. /**
  4283. * Retun True if arrows are available.<BR><BR>
  4284. *
  4285. * <B><U> Overridden in </U> :</B><BR><BR>
  4286. * <li> L2PcInstance</li><BR><BR>
  4287. *
  4288. */
  4289. protected boolean checkAndEquipArrows()
  4290. {
  4291. return true;
  4292. }
  4293. /**
  4294. * Retun True if bolts are available.<BR><BR>
  4295. *
  4296. * <B><U> Overridden in </U> :</B><BR><BR>
  4297. * <li> L2PcInstance</li><BR><BR>
  4298. *
  4299. */
  4300. protected boolean checkAndEquipBolts()
  4301. {
  4302. return true;
  4303. }
  4304. /**
  4305. * Add Exp and Sp to the L2Character.<BR><BR>
  4306. *
  4307. * <B><U> Overridden in </U> :</B><BR><BR>
  4308. * <li> L2PcInstance</li>
  4309. * <li> L2PetInstance</li><BR><BR>
  4310. *
  4311. */
  4312. public void addExpAndSp(long addToExp, int addToSp)
  4313. {
  4314. // Dummy method (overridden by players and pets)
  4315. }
  4316. /**
  4317. * Return the active weapon instance (always equiped in the right hand).<BR><BR>
  4318. *
  4319. * <B><U> Overridden in </U> :</B><BR><BR>
  4320. * <li> L2PcInstance</li><BR><BR>
  4321. *
  4322. */
  4323. public abstract L2ItemInstance getActiveWeaponInstance();
  4324. /**
  4325. * Return the active weapon item (always equiped in the right hand).<BR><BR>
  4326. *
  4327. * <B><U> Overridden in </U> :</B><BR><BR>
  4328. * <li> L2PcInstance</li><BR><BR>
  4329. *
  4330. */
  4331. public abstract L2Weapon getActiveWeaponItem();
  4332. /**
  4333. * Return the secondary weapon instance (always equiped in the left hand).<BR><BR>
  4334. *
  4335. * <B><U> Overridden in </U> :</B><BR><BR>
  4336. * <li> L2PcInstance</li><BR><BR>
  4337. *
  4338. */
  4339. public abstract L2ItemInstance getSecondaryWeaponInstance();
  4340. /**
  4341. * Return the secondary weapon item (always equiped in the left hand).<BR><BR>
  4342. *
  4343. * <B><U> Overridden in </U> :</B><BR><BR>
  4344. * <li> L2PcInstance</li><BR><BR>
  4345. *
  4346. */
  4347. public abstract L2Weapon getSecondaryWeaponItem();
  4348. /**
  4349. * Manage hit process (called by Hit Task).<BR><BR>
  4350. *
  4351. * <B><U> Actions</U> :</B><BR><BR>
  4352. * <li>If the attacker/target is dead or use fake death, notify the AI with EVT_CANCEL and send a Server->Client packet ActionFailed (if attacker is a L2PcInstance)</li>
  4353. * <li>If attack isn't aborted, send a message system (critical hit, missed...) to attacker/target if they are L2PcInstance </li>
  4354. * <li>If attack isn't aborted and hit isn't missed, reduce HP of the target and calculate reflection damage to reduce HP of attacker if necessary </li>
  4355. * <li>if attack isn't aborted and hit isn't missed, manage attack or cast break of the target (calculating rate, sending message...) </li><BR><BR>
  4356. *
  4357. * @param target The L2Character targeted
  4358. * @param damage Nb of HP to reduce
  4359. * @param crit True if hit is critical
  4360. * @param miss True if hit is missed
  4361. * @param soulshot True if SoulShot are charged
  4362. * @param shld True if shield is efficient
  4363. *
  4364. */
  4365. protected void onHitTimer(L2Character target, int damage, boolean crit, boolean miss, boolean soulshot, byte shld)
  4366. {
  4367. // If the attacker/target is dead or use fake death, notify the AI with EVT_CANCEL
  4368. // and send a Server->Client packet ActionFailed (if attacker is a L2PcInstance)
  4369. if (target == null || isAlikeDead() ||(this instanceof L2NpcInstance && ((L2NpcInstance) this).isEventMob))
  4370. {
  4371. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  4372. return;
  4373. }
  4374. if ((this instanceof L2NpcInstance && target.isAlikeDead()) || target.isDead()
  4375. || (!getKnownList().knowsObject(target) && !(this instanceof L2DoorInstance)))
  4376. {
  4377. //getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE, null);
  4378. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  4379. sendPacket(ActionFailed.STATIC_PACKET);
  4380. return;
  4381. }
  4382. if (miss)
  4383. {
  4384. // ON_EVADED_HIT
  4385. if (target.getChanceSkills() != null)
  4386. target.getChanceSkills().onEvadedHit(this);
  4387. if (target instanceof L2PcInstance)
  4388. {
  4389. SystemMessage sm = new SystemMessage(SystemMessageId.AVOIDED_S1S_ATTACK);
  4390. sm.addCharName(this);
  4391. target.sendPacket(sm);
  4392. }
  4393. }
  4394. // If attack isn't aborted, send a message system (critical hit, missed...) to attacker/target if they are L2PcInstance
  4395. if (!isAttackAborted())
  4396. {
  4397. // Check Raidboss attack
  4398. // Character will be petrified if attacking a raid that's more
  4399. // than 8 levels lower
  4400. if (target.isRaid())
  4401. {
  4402. int level = 0;
  4403. if (this instanceof L2PcInstance)
  4404. level = getLevel();
  4405. else if (this instanceof L2Summon)
  4406. level = ((L2Summon)this).getOwner().getLevel();
  4407. if (level > target.getLevel() + 8)
  4408. {
  4409. L2Skill skill = SkillTable.getInstance().getInfo(4515, 1);
  4410. if (skill != null)
  4411. skill.getEffects(target, this);
  4412. else
  4413. _log.warning("Skill 4515 at level 1 is missing in DP.");
  4414. damage = 0; // prevents messing up drop calculation
  4415. }
  4416. }
  4417. sendDamageMessage(target, damage, false, crit, miss);
  4418. // If L2Character target is a L2PcInstance, send a system message
  4419. /*if (target instanceof L2PcInstance)
  4420. {
  4421. L2PcInstance enemy = (L2PcInstance)target;
  4422. enemy.getAI().clientStartAutoAttack();
  4423. if (shld && 100 - Config.ALT_PERFECT_SHLD_BLOCK < Rnd.get(100))
  4424. {
  4425. if (100 - Config.ALT_PERFECT_SHLD_BLOCK < Rnd.get(100))
  4426. {
  4427. damage = 1;
  4428. enemy.sendPacket(new SystemMessage(SystemMessageId.YOUR_EXCELLENT_SHIELD_DEFENSE_WAS_A_SUCCESS)); //SHIELD_DEFENCE faultless
  4429. }
  4430. else
  4431. enemy.sendPacket(new SystemMessage(SystemMessageId.SHIELD_DEFENCE_SUCCESSFULL));
  4432. }
  4433. }
  4434. else */if (target instanceof L2Summon)
  4435. {
  4436. L2Summon activeSummon = (L2Summon)target;
  4437. L2PcInstance owner = activeSummon.getOwner();
  4438. if (owner != null)
  4439. {
  4440. owner.getAI().clientStartAutoAttack();
  4441. SystemMessage sm = new SystemMessage(SystemMessageId.PET_RECEIVED_S2_DAMAGE_BY_S1);
  4442. sm.addString(getName());
  4443. sm.addNumber(damage);
  4444. owner.sendPacket(sm);
  4445. }
  4446. }
  4447. if (!miss && damage > 0)
  4448. {
  4449. L2Weapon weapon = getActiveWeaponItem();
  4450. boolean isBow = (weapon != null && (weapon.getItemType() == L2WeaponType.BOW || weapon.getItemType() == L2WeaponType.CROSSBOW));
  4451. int reflectedDamage = 0;
  4452. if (!isBow) // Do not reflect if weapon is of type bow
  4453. {
  4454. // Reduce HP of the target and calculate reflection damage to reduce HP of attacker if necessary
  4455. double reflectPercent = target.getStat().calcStat(Stats.REFLECT_DAMAGE_PERCENT,0,null,null);
  4456. if (reflectPercent > 0)
  4457. {
  4458. reflectedDamage = (int)(reflectPercent / 100. * damage);
  4459. damage -= reflectedDamage;
  4460. if(reflectedDamage > target.getMaxHp()) // to prevent extreme damage when hitting a low lvl char...
  4461. reflectedDamage = target.getMaxHp();
  4462. }
  4463. }
  4464. // reduce targets HP
  4465. target.reduceCurrentHp(damage, this);
  4466. if (reflectedDamage > 0)
  4467. {
  4468. reduceCurrentHp(reflectedDamage, target, true, false);
  4469. // Custom messages - nice but also more network load
  4470. /*
  4471. if (target instanceof L2PcInstance)
  4472. ((L2PcInstance)target).sendMessage("You reflected " + reflectedDamage + " damage.");
  4473. else if (target instanceof L2Summon)
  4474. ((L2Summon)target).getOwner().sendMessage("Summon reflected " + reflectedDamage + " damage.");
  4475. if (this instanceof L2PcInstance)
  4476. ((L2PcInstance)this).sendMessage("Target reflected to you " + reflectedDamage + " damage.");
  4477. else if (this instanceof L2Summon)
  4478. ((L2Summon)this).getOwner().sendMessage("Target reflected to your summon " + reflectedDamage + " damage.");
  4479. */
  4480. }
  4481. if (!isBow) // Do not absorb if weapon is of type bow
  4482. {
  4483. // Absorb HP from the damage inflicted
  4484. double absorbPercent = getStat().calcStat(Stats.ABSORB_DAMAGE_PERCENT,0, null,null);
  4485. if (absorbPercent > 0)
  4486. {
  4487. int maxCanAbsorb = (int)(getMaxHp() - getCurrentHp());
  4488. int absorbDamage = (int)(absorbPercent / 100. * damage);
  4489. if (absorbDamage > maxCanAbsorb)
  4490. absorbDamage = maxCanAbsorb; // Can't absord more than max hp
  4491. if (absorbDamage > 0)
  4492. {
  4493. setCurrentHp(getCurrentHp() + absorbDamage);
  4494. // Custom messages - nice but also more network load
  4495. /*
  4496. if (this instanceof L2PcInstance)
  4497. ((L2PcInstance)this).sendMessage("You absorbed " + absorbDamage + " damage.");
  4498. else if (this instanceof L2Summon)
  4499. ((L2Summon)this).getOwner().sendMessage("Summon absorbed " + absorbDamage + " damage.");
  4500. else if (Config.DEBUG)
  4501. _log.info(getName() + " absorbed " + absorbDamage + " damage.");
  4502. */
  4503. }
  4504. }
  4505. }
  4506. // Notify AI with EVT_ATTACKED
  4507. target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, this);
  4508. getAI().clientStartAutoAttack();
  4509. if (this instanceof L2Summon)
  4510. {
  4511. L2PcInstance owner = ((L2Summon)this).getOwner();
  4512. if (owner != null)
  4513. {
  4514. owner.getAI().clientStartAutoAttack();
  4515. }
  4516. }
  4517. // Manage attack or cast break of the target (calculating rate, sending message...)
  4518. if (!target.isRaid() && Formulas.getInstance().calcAtkBreak(target, damage))
  4519. {
  4520. target.breakAttack();
  4521. target.breakCast();
  4522. }
  4523. // Maybe launch chance skills on us
  4524. if (_chanceSkills != null)
  4525. _chanceSkills.onHit(target, false, crit);
  4526. // Maybe launch chance skills on target
  4527. if (target.getChanceSkills() != null)
  4528. target.getChanceSkills().onHit(this, true, crit);
  4529. }
  4530. // Launch weapon Special ability effect if available
  4531. L2Weapon activeWeapon = getActiveWeaponItem();
  4532. if (activeWeapon != null)
  4533. activeWeapon.getSkillEffects(this, target, crit);
  4534. /* COMMENTED OUT BY nexus - 2006-08-17
  4535. *
  4536. * We must not discharge the soulshouts at the onHitTimer method,
  4537. * as this can cause unwanted soulshout consumption if the attacker
  4538. * recharges the soulshot right after an attack request but before
  4539. * his hit actually lands on the target.
  4540. *
  4541. * The soulshot discharging has been moved to the doAttack method:
  4542. * As soon as we know that we didn't missed the hit there, then we
  4543. * must discharge any charged soulshots.
  4544. */
  4545. /*
  4546. L2ItemInstance weapon = getActiveWeaponInstance();
  4547. if (!miss)
  4548. {
  4549. if (this instanceof L2Summon && !(this instanceof L2PetInstance))
  4550. {
  4551. if (((L2Summon)this).getChargedSoulShot() != L2ItemInstance.CHARGED_NONE)
  4552. ((L2Summon)this).setChargedSoulShot(L2ItemInstance.CHARGED_NONE);
  4553. }
  4554. else
  4555. {
  4556. if (weapon != null && weapon.getChargedSoulshot() != L2ItemInstance.CHARGED_NONE)
  4557. weapon.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
  4558. }
  4559. }
  4560. */
  4561. return;
  4562. }
  4563. if (!isCastingNow() && !isCastingSimultaneouslyNow())
  4564. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  4565. }
  4566. /**
  4567. * Break an attack and send Server->Client ActionFailed packet and a System Message to the L2Character.<BR><BR>
  4568. */
  4569. public void breakAttack()
  4570. {
  4571. if (isAttackingNow())
  4572. {
  4573. // Abort the attack of the L2Character and send Server->Client ActionFailed packet
  4574. abortAttack();
  4575. if (this instanceof L2PcInstance)
  4576. {
  4577. //TODO Remove sendPacket because it's always done in abortAttack
  4578. sendPacket(ActionFailed.STATIC_PACKET);
  4579. // Send a system message
  4580. sendPacket(new SystemMessage(SystemMessageId.ATTACK_FAILED));
  4581. }
  4582. }
  4583. }
  4584. /**
  4585. * Break a cast and send Server->Client ActionFailed packet and a System Message to the L2Character.<BR><BR>
  4586. */
  4587. public void breakCast()
  4588. {
  4589. // damage can only cancel magical skills
  4590. if (isCastingNow() && canAbortCast() && getLastSkillCast() != null && getLastSkillCast().isMagic())
  4591. {
  4592. // Abort the cast of the L2Character and send Server->Client MagicSkillCanceld/ActionFailed packet.
  4593. abortCast();
  4594. if (this instanceof L2PcInstance)
  4595. {
  4596. // Send a system message
  4597. sendPacket(new SystemMessage(SystemMessageId.CASTING_INTERRUPTED));
  4598. }
  4599. }
  4600. }
  4601. /**
  4602. * Reduce the arrow number of the L2Character.<BR><BR>
  4603. *
  4604. * <B><U> Overridden in </U> :</B><BR><BR>
  4605. * <li> L2PcInstance</li><BR><BR>
  4606. *
  4607. */
  4608. protected void reduceArrowCount(boolean bolts)
  4609. {
  4610. // default is to do nothing
  4611. }
  4612. /**
  4613. * Manage Forced attack (shift + select target).<BR><BR>
  4614. *
  4615. * <B><U> Actions</U> :</B><BR><BR>
  4616. * <li>If L2Character or target is in a town area, send a system message TARGET_IN_PEACEZONE a Server->Client packet ActionFailed </li>
  4617. * <li>If target is confused, send a Server->Client packet ActionFailed </li>
  4618. * <li>If L2Character is a L2ArtefactInstance, send a Server->Client packet ActionFailed </li>
  4619. * <li>Send a Server->Client packet MyTargetSelected to start attack and Notify AI with AI_INTENTION_ATTACK </li><BR><BR>
  4620. *
  4621. * @param player The L2PcInstance to attack
  4622. *
  4623. */
  4624. @Override
  4625. public void onForcedAttack(L2PcInstance player)
  4626. {
  4627. if (isInsidePeaceZone(player))
  4628. {
  4629. // If L2Character or target is in a peace zone, send a system message TARGET_IN_PEACEZONE a Server->Client packet ActionFailed
  4630. player.sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
  4631. player.sendPacket(ActionFailed.STATIC_PACKET);
  4632. }
  4633. else if (player.isInOlympiadMode() && player.getTarget() != null && player.getTarget() instanceof L2PlayableInstance)
  4634. {
  4635. L2PcInstance target;
  4636. if (player.getTarget() instanceof L2Summon)
  4637. target=((L2Summon)player.getTarget()).getOwner();
  4638. else
  4639. target=(L2PcInstance)player.getTarget();
  4640. if (target.isInOlympiadMode() && !player.isOlympiadStart() && player.getOlympiadGameId()!=target.getOlympiadGameId())
  4641. {
  4642. // if L2PcInstance is in Olympia and the match isn't already start, send a Server->Client packet ActionFailed
  4643. player.sendPacket(ActionFailed.STATIC_PACKET);
  4644. }
  4645. }
  4646. else if (player.getTarget() != null && !player.getTarget().isAttackable() && !player.getAccessLevel().allowPeaceAttack())
  4647. {
  4648. // If target is not attackable, send a Server->Client packet ActionFailed
  4649. player.sendPacket(ActionFailed.STATIC_PACKET);
  4650. }
  4651. else if (player.isConfused())
  4652. {
  4653. // If target is confused, send a Server->Client packet ActionFailed
  4654. player.sendPacket(ActionFailed.STATIC_PACKET);
  4655. }
  4656. else if (this instanceof L2ArtefactInstance)
  4657. {
  4658. // If L2Character is a L2ArtefactInstance, send a Server->Client packet ActionFailed
  4659. player.sendPacket(ActionFailed.STATIC_PACKET);
  4660. }
  4661. else
  4662. {
  4663. // GeoData Los Check or dz > 1000
  4664. if (!GeoData.getInstance().canSeeTarget(player, this))
  4665. {
  4666. player.sendPacket(new SystemMessage(SystemMessageId.CANT_SEE_TARGET));
  4667. player.sendPacket(ActionFailed.STATIC_PACKET);
  4668. return;
  4669. }
  4670. // Notify AI with AI_INTENTION_ATTACK
  4671. player.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, this);
  4672. }
  4673. }
  4674. /**
  4675. * Return True if inside peace zone.<BR><BR>
  4676. */
  4677. public boolean isInsidePeaceZone(L2PcInstance attacker)
  4678. {
  4679. return isInsidePeaceZone(attacker, this);
  4680. }
  4681. public boolean isInsidePeaceZone(L2PcInstance attacker, L2Object target)
  4682. {
  4683. return (
  4684. !attacker.getAccessLevel().allowPeaceAttack() &&
  4685. isInsidePeaceZone((L2Object)attacker, target)
  4686. );
  4687. }
  4688. public boolean isInsidePeaceZone(L2Object attacker, L2Object target)
  4689. {
  4690. if (target == null)
  4691. return false;
  4692. if (!(target instanceof L2PlayableInstance && attacker instanceof L2PlayableInstance))
  4693. return false;
  4694. if (Config.ALT_GAME_KARMA_PLAYER_CAN_BE_KILLED_IN_PEACEZONE)
  4695. {
  4696. // allows red to be attacked and red to attack flagged players
  4697. if (target.getActingPlayer() != null && target.getActingPlayer().getKarma() > 0)
  4698. return false;
  4699. if (attacker.getActingPlayer() != null && attacker.getActingPlayer().getKarma() > 0
  4700. && target.getActingPlayer() != null && target.getActingPlayer().getPvpFlag() > 0)
  4701. return false;
  4702. if (attacker instanceof L2Character && target instanceof L2Character)
  4703. {
  4704. return (((L2Character)target).isInsideZone(ZONE_PEACE) || ((L2Character)attacker).isInsideZone(ZONE_PEACE));
  4705. }
  4706. if (attacker instanceof L2Character)
  4707. {
  4708. return (TownManager.getInstance().getTown(target.getX(), target.getY(), target.getZ()) != null || ((L2Character)attacker).isInsideZone(ZONE_PEACE));
  4709. }
  4710. }
  4711. if (attacker instanceof L2Character && target instanceof L2Character)
  4712. {
  4713. return (((L2Character)target).isInsideZone(ZONE_PEACE) || ((L2Character)attacker).isInsideZone(ZONE_PEACE));
  4714. }
  4715. if (attacker instanceof L2Character)
  4716. {
  4717. return (TownManager.getInstance().getTown(target.getX(), target.getY(), target.getZ()) != null || ((L2Character)attacker).isInsideZone(ZONE_PEACE));
  4718. }
  4719. return (TownManager.getInstance().getTown(target.getX(), target.getY(), target.getZ()) != null ||
  4720. TownManager.getInstance().getTown(attacker.getX(), attacker.getY(), attacker.getZ()) != null);
  4721. }
  4722. /**
  4723. * return true if this character is inside an active grid.
  4724. */
  4725. public Boolean isInActiveRegion()
  4726. {
  4727. L2WorldRegion region = getWorldRegion();
  4728. return ((region !=null) && (region.isActive()));
  4729. }
  4730. /**
  4731. * Return True if the L2Character has a Party in progress.<BR><BR>
  4732. */
  4733. public boolean isInParty()
  4734. {
  4735. return false;
  4736. }
  4737. /**
  4738. * Return the L2Party object of the L2Character.<BR><BR>
  4739. */
  4740. public L2Party getParty()
  4741. {
  4742. return null;
  4743. }
  4744. /**
  4745. * Return the Attack Speed of the L2Character (delay (in milliseconds) before next attack).<BR><BR>
  4746. */
  4747. public int calculateTimeBetweenAttacks(L2Character target, L2Weapon weapon)
  4748. {
  4749. double atkSpd = 0;
  4750. if (weapon !=null && !isTransformed())
  4751. {
  4752. switch (weapon.getItemType())
  4753. {
  4754. case BOW:
  4755. atkSpd = getStat().getPAtkSpd();
  4756. return (int)(1500*345/atkSpd);
  4757. case CROSSBOW:
  4758. atkSpd = getStat().getPAtkSpd();
  4759. return (int)(1200*345/atkSpd);
  4760. case DAGGER:
  4761. atkSpd = getStat().getPAtkSpd();
  4762. //atkSpd /= 1.15;
  4763. break;
  4764. default:
  4765. atkSpd = getStat().getPAtkSpd();
  4766. }
  4767. }
  4768. else
  4769. atkSpd = getPAtkSpd();
  4770. return Formulas.getInstance().calcPAtkSpd(this, target, atkSpd);
  4771. }
  4772. public int calculateReuseTime(L2Character target, L2Weapon weapon)
  4773. {
  4774. if (weapon == null || isTransformed()) return 0;
  4775. int reuse = weapon.getAttackReuseDelay();
  4776. // only bows should continue for now
  4777. if (reuse == 0) return 0;
  4778. // else if (reuse < 10) reuse = 1500;
  4779. reuse *= getStat().getWeaponReuseModifier(target);
  4780. double atkSpd = getStat().getPAtkSpd();
  4781. switch (weapon.getItemType())
  4782. {
  4783. case BOW:
  4784. case CROSSBOW:
  4785. return (int)(reuse*345/atkSpd);
  4786. default:
  4787. return (int)(reuse*312/atkSpd);
  4788. }
  4789. }
  4790. /**
  4791. * Return True if the L2Character use a dual weapon.<BR><BR>
  4792. */
  4793. public boolean isUsingDualWeapon()
  4794. {
  4795. return false;
  4796. }
  4797. /**
  4798. * Add a skill to the L2Character _skills and its Func objects to the calculator set of the L2Character.<BR><BR>
  4799. *
  4800. * <B><U> Concept</U> :</B><BR><BR>
  4801. * All skills own by a L2Character are identified in <B>_skills</B><BR><BR>
  4802. *
  4803. * <B><U> Actions</U> :</B><BR><BR>
  4804. * <li>Replace oldSkill by newSkill or Add the newSkill </li>
  4805. * <li>If an old skill has been replaced, remove all its Func objects of L2Character calculator set</li>
  4806. * <li>Add Func objects of newSkill to the calculator set of the L2Character </li><BR><BR>
  4807. *
  4808. * <B><U> Overridden in </U> :</B><BR><BR>
  4809. * <li> L2PcInstance : Save update in the character_skills table of the database</li><BR><BR>
  4810. *
  4811. * @param newSkill The L2Skill to add to the L2Character
  4812. *
  4813. * @return The L2Skill replaced or null if just added a new L2Skill
  4814. *
  4815. */
  4816. public L2Skill addSkill(L2Skill newSkill)
  4817. {
  4818. L2Skill oldSkill = null;
  4819. if (newSkill != null)
  4820. {
  4821. // Replace oldSkill by newSkill or Add the newSkill
  4822. oldSkill = _skills.put(newSkill.getId(), newSkill);
  4823. // If an old skill has been replaced, remove all its Func objects
  4824. if (oldSkill != null)
  4825. {
  4826. // if skill came with another one, we should delete the other one too.
  4827. if((oldSkill.bestowTriggered() || oldSkill.triggerAnotherSkill()) && oldSkill.getTriggeredId() > 0 )
  4828. {
  4829. removeSkill(oldSkill.getTriggeredId(),true);
  4830. }
  4831. removeStatsOwner(oldSkill);
  4832. }
  4833. // Add Func objects of newSkill to the calculator set of the L2Character
  4834. addStatFuncs(newSkill.getStatFuncs(null, this));
  4835. if (oldSkill != null && _chanceSkills != null)
  4836. {
  4837. removeChanceSkill(oldSkill.getId());
  4838. }
  4839. if (newSkill.isChance())
  4840. {
  4841. addChanceSkill(newSkill);
  4842. }
  4843. if (!newSkill.isChance() && newSkill.getTriggeredId() > 0 && newSkill.bestowTriggered())
  4844. {
  4845. L2Skill bestowed = SkillTable.getInstance().getInfo(newSkill.getTriggeredId(), newSkill.getTriggeredLevel());
  4846. addSkill(bestowed);
  4847. //bestowed skills are invisible for player. Visible for gm's looking thru gm window.
  4848. //those skills should always be chance or passive, to prevent hlapex.
  4849. }
  4850. if(newSkill.isChance() && newSkill.getTriggeredId() > 0 && !newSkill.bestowTriggered() && newSkill.triggerAnotherSkill())
  4851. {
  4852. L2Skill triggeredSkill = SkillTable.getInstance().getInfo(newSkill.getTriggeredId(),newSkill.getTriggeredLevel());
  4853. addSkill(triggeredSkill);
  4854. }
  4855. }
  4856. return oldSkill;
  4857. }
  4858. /**
  4859. * Remove a skill from the L2Character and its Func objects from calculator set of the L2Character.<BR><BR>
  4860. *
  4861. * <B><U> Concept</U> :</B><BR><BR>
  4862. * All skills own by a L2Character are identified in <B>_skills</B><BR><BR>
  4863. *
  4864. * <B><U> Actions</U> :</B><BR><BR>
  4865. * <li>Remove the skill from the L2Character _skills </li>
  4866. * <li>Remove all its Func objects from the L2Character calculator set</li><BR><BR>
  4867. *
  4868. * <B><U> Overridden in </U> :</B><BR><BR>
  4869. * <li> L2PcInstance : Save update in the character_skills table of the database</li><BR><BR>
  4870. *
  4871. * @param skill The L2Skill to remove from the L2Character
  4872. *
  4873. * @return The L2Skill removed
  4874. *
  4875. */
  4876. public L2Skill removeSkill(L2Skill skill)
  4877. {
  4878. if (skill == null) return null;
  4879. return removeSkill(skill.getId(), true);
  4880. }
  4881. public L2Skill removeSkill(L2Skill skill, boolean cancelEffect)
  4882. {
  4883. if (skill == null) return null;
  4884. // Remove the skill from the L2Character _skills
  4885. return removeSkill(skill.getId(), cancelEffect);
  4886. }
  4887. public L2Skill removeSkill(int skillId)
  4888. {
  4889. return removeSkill(skillId, true);
  4890. }
  4891. public L2Skill removeSkill(int skillId, boolean cancelEffect)
  4892. {
  4893. // Remove the skill from the L2Character _skills
  4894. L2Skill oldSkill = _skills.remove(skillId);
  4895. // Remove all its Func objects from the L2Character calculator set
  4896. if (oldSkill != null)
  4897. {
  4898. //this is just a fail-safe againts buggers and gm dummies...
  4899. if((oldSkill.bestowTriggered() || oldSkill.triggerAnotherSkill()) && oldSkill.getTriggeredId()>0)
  4900. {
  4901. removeSkill(oldSkill.getTriggeredId(),true);
  4902. }
  4903. // Stop casting if this skill is used right now
  4904. if (getLastSkillCast() != null && isCastingNow())
  4905. {
  4906. if (oldSkill.getId() == getLastSkillCast().getId())
  4907. abortCast();
  4908. }
  4909. if (getLastSimultaneousSkillCast() != null && isCastingSimultaneouslyNow())
  4910. {
  4911. if (oldSkill.getId() == getLastSimultaneousSkillCast().getId())
  4912. abortCast();
  4913. }
  4914. if (cancelEffect || oldSkill.isToggle())
  4915. {
  4916. // for now, to support transformations, we have to let their
  4917. // effects stay when skill is removed
  4918. L2Effect e = getFirstEffect(oldSkill);
  4919. if (e == null || e.getEffectType() != L2EffectType.TRANSFORMATION)
  4920. {
  4921. removeStatsOwner(oldSkill);
  4922. stopSkillEffects(oldSkill.getId());
  4923. }
  4924. }
  4925. if (oldSkill instanceof L2SkillAgathion && this instanceof L2PcInstance && ((L2PcInstance)this).getAgathionId() > 0)
  4926. {
  4927. ((L2PcInstance)this).setAgathionId(0);
  4928. ((L2PcInstance)this).broadcastUserInfo();
  4929. }
  4930. if (oldSkill.isChance() && _chanceSkills != null)
  4931. {
  4932. removeChanceSkill(oldSkill.getId());
  4933. }
  4934. }
  4935. return oldSkill;
  4936. }
  4937. public void addChanceSkill(L2Skill skill)
  4938. {
  4939. synchronized(this)
  4940. {
  4941. if (_chanceSkills == null)
  4942. _chanceSkills = new ChanceSkillList(this);
  4943. _chanceSkills.put(skill, skill.getChanceCondition());
  4944. }
  4945. }
  4946. public void removeChanceSkill(int id)
  4947. {
  4948. synchronized(this)
  4949. {
  4950. for (L2Skill skill : _chanceSkills.keySet())
  4951. {
  4952. if (skill.getId() == id)
  4953. _chanceSkills.remove(skill);
  4954. }
  4955. if (_chanceSkills.size() == 0)
  4956. _chanceSkills = null;
  4957. }
  4958. }
  4959. /**
  4960. * Return all skills own by the L2Character in a table of L2Skill.<BR><BR>
  4961. *
  4962. * <B><U> Concept</U> :</B><BR><BR>
  4963. * All skills own by a L2Character are identified in <B>_skills</B> the L2Character <BR><BR>
  4964. *
  4965. */
  4966. public final L2Skill[] getAllSkills()
  4967. {
  4968. if (_skills == null)
  4969. return new L2Skill[0];
  4970. return _skills.values().toArray(new L2Skill[_skills.values().size()]);
  4971. }
  4972. public ChanceSkillList getChanceSkills()
  4973. {
  4974. return _chanceSkills;
  4975. }
  4976. /**
  4977. * Return the level of a skill owned by the L2Character.<BR><BR>
  4978. *
  4979. * @param skillId The identifier of the L2Skill whose level must be returned
  4980. *
  4981. * @return The level of the L2Skill identified by skillId
  4982. *
  4983. */
  4984. public int getSkillLevel(int skillId)
  4985. {
  4986. if (_skills == null)
  4987. return -1;
  4988. L2Skill skill = _skills.get(skillId);
  4989. if (skill == null)
  4990. return -1;
  4991. return skill.getLevel();
  4992. }
  4993. /**
  4994. * Return True if the skill is known by the L2Character.<BR><BR>
  4995. *
  4996. * @param skillId The identifier of the L2Skill to check the knowledge
  4997. *
  4998. */
  4999. public final L2Skill getKnownSkill(int skillId)
  5000. {
  5001. if (_skills == null)
  5002. return null;
  5003. return _skills.get(skillId);
  5004. }
  5005. /**
  5006. * Return the number of buffs affecting this L2Character.<BR><BR>
  5007. *
  5008. * @return The number of Buffs affecting this L2Character
  5009. */
  5010. public int getBuffCount()
  5011. {
  5012. return _effects.getBuffCount();
  5013. }
  5014. public int getDanceCount()
  5015. {
  5016. return _effects.getDanceCount();
  5017. }
  5018. /**
  5019. * Manage the magic skill launching task (MP, HP, Item consummation...) and display the magic skill animation on client.<BR><BR>
  5020. *
  5021. * <B><U> Actions</U> :</B><BR><BR>
  5022. * <li>Send a Server->Client packet MagicSkillLaunched (to display magic skill animation) to all L2PcInstance of L2Charcater _knownPlayers</li>
  5023. * <li>Consumme MP, HP and Item if necessary</li>
  5024. * <li>Send a Server->Client packet StatusUpdate with MP modification to the L2PcInstance</li>
  5025. * <li>Launch the magic skill in order to calculate its effects</li>
  5026. * <li>If the skill type is PDAM, notify the AI of the target with AI_INTENTION_ATTACK</li>
  5027. * <li>Notify the AI of the L2Character with EVT_FINISH_CASTING</li><BR><BR>
  5028. *
  5029. * <FONT COLOR=#FF0000><B> <U>Caution</U> : A magic skill casting MUST BE in progress</B></FONT><BR><BR>
  5030. *
  5031. * @param skill The L2Skill to use
  5032. *
  5033. */
  5034. public void onMagicLaunchedTimer(L2Object[] targets, L2Skill skill, int coolTime, boolean instant, boolean simultaneously)
  5035. {
  5036. if (skill == null || targets == null || targets.length <= 0)
  5037. {
  5038. abortCast();
  5039. return;
  5040. }
  5041. // Escaping from under skill's radius and peace zone check. First version, not perfect in AoE skills.
  5042. int escapeRange = 0;
  5043. if(skill.getEffectRange() > escapeRange) escapeRange = skill.getEffectRange();
  5044. else if(skill.getCastRange() < 0 && skill.getSkillRadius() > 80) escapeRange = skill.getSkillRadius();
  5045. if (escapeRange > 0)
  5046. {
  5047. List<L2Character> targetList = new FastList<L2Character>();
  5048. for (L2Object target: targets)
  5049. {
  5050. if (target instanceof L2Character)
  5051. {
  5052. if (!Util.checkIfInRange(escapeRange, this, target, true))
  5053. continue;
  5054. if(skill.isOffensive())
  5055. {
  5056. if(this instanceof L2PcInstance)
  5057. {
  5058. if(((L2Character)target).isInsidePeaceZone((L2PcInstance)this))
  5059. continue;
  5060. }
  5061. else
  5062. {
  5063. if(((L2Character)target).isInsidePeaceZone(this, target))
  5064. continue;
  5065. }
  5066. }
  5067. targetList.add((L2Character)target);
  5068. }
  5069. //else
  5070. //{
  5071. // if (Config.DEBUG)
  5072. // _log.warning("Class cast bad: "+targets[i].getClass().toString());
  5073. //}
  5074. }
  5075. if(targetList.isEmpty())
  5076. {
  5077. abortCast();
  5078. return;
  5079. }
  5080. else targets = targetList.toArray(new L2Character[targetList.size()]);
  5081. }
  5082. // Ensure that a cast is in progress
  5083. // Check if player is using fake death.
  5084. // Potions can be used while faking death.
  5085. if ((simultaneously && !isCastingSimultaneouslyNow())
  5086. || (!simultaneously && !isCastingNow())
  5087. || (isAlikeDead() && !skill.isPotion()))
  5088. {
  5089. // now cancels both, simultaneous and normal
  5090. getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
  5091. return;
  5092. }
  5093. // Get the display identifier of the skill
  5094. int magicId = skill.getDisplayId();
  5095. // Get the level of the skill
  5096. int level = getSkillLevel(skill.getId());
  5097. if (level < 1)
  5098. level = 1;
  5099. // Send a Server->Client packet MagicSkillLaunched to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
  5100. if (!skill.isPotion()) broadcastPacket(new MagicSkillLaunched(this, magicId, level, targets));
  5101. if (instant)
  5102. onMagicHitTimer(targets, skill, coolTime, true, simultaneously);
  5103. else
  5104. _skillCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 2, simultaneously), 200);
  5105. }
  5106. /*
  5107. * Runs in the end of skill casting
  5108. */
  5109. public void onMagicHitTimer(L2Object[] targets, L2Skill skill, int coolTime, boolean instant, boolean simultaneously)
  5110. {
  5111. if (skill == null || targets == null || targets.length <= 0)
  5112. {
  5113. abortCast();
  5114. return;
  5115. }
  5116. if(getForceBuff() != null)
  5117. {
  5118. if (simultaneously)
  5119. {
  5120. _skillCast2 = null;
  5121. setIsCastingSimultaneouslyNow(false);
  5122. }
  5123. else
  5124. {
  5125. _skillCast = null;
  5126. setIsCastingNow(false);
  5127. }
  5128. getForceBuff().onCastAbort();
  5129. notifyQuestEventSkillFinished(skill, targets[0]);
  5130. return;
  5131. }
  5132. L2Effect mog = getFirstEffect(L2EffectType.SIGNET_GROUND);
  5133. if (mog != null)
  5134. {
  5135. if (simultaneously)
  5136. {
  5137. _skillCast2 = null;
  5138. setIsCastingSimultaneouslyNow(false);
  5139. }
  5140. else
  5141. {
  5142. _skillCast = null;
  5143. setIsCastingNow(false);
  5144. }
  5145. mog.exit();
  5146. notifyQuestEventSkillFinished(skill, targets[0]);
  5147. return;
  5148. }
  5149. try
  5150. {
  5151. // Go through targets table
  5152. for (L2Object tgt: targets)
  5153. {
  5154. if (tgt instanceof L2PlayableInstance)
  5155. {
  5156. L2Character target = (L2Character) tgt;
  5157. if (skill.getSkillType() == L2SkillType.BUFF)
  5158. {
  5159. SystemMessage smsg = new SystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  5160. smsg.addSkillName(skill);
  5161. target.sendPacket(smsg);
  5162. }
  5163. if (this instanceof L2PcInstance
  5164. && target instanceof L2Summon)
  5165. {
  5166. target.getActingPlayer().sendPacket(new PetInfo((L2Summon) target));
  5167. sendPacket(new NpcInfo((L2Summon) target, this));
  5168. // The PetInfo packet wipes the PartySpelled (list of
  5169. // active spells' icons). Re-add them
  5170. ((L2Summon) target).updateEffectIcons(true);
  5171. }
  5172. }
  5173. }
  5174. StatusUpdate su = new StatusUpdate(getObjectId());
  5175. boolean isSendStatus = false;
  5176. // Consume MP of the L2Character and Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
  5177. double mpConsume = getStat().getMpConsume(skill);
  5178. if (mpConsume > 0)
  5179. {
  5180. if (skill.isDance())
  5181. {
  5182. getStatus().reduceMp(calcStat(Stats.DANCE_MP_CONSUME_RATE, mpConsume, null, null));
  5183. }
  5184. else if (skill.isMagic())
  5185. {
  5186. getStatus().reduceMp(calcStat(Stats.MAGICAL_MP_CONSUME_RATE, mpConsume, null, null));
  5187. }
  5188. else
  5189. {
  5190. getStatus().reduceMp(calcStat(Stats.PHYSICAL_MP_CONSUME_RATE, mpConsume, null, null));
  5191. }
  5192. su.addAttribute(StatusUpdate.CUR_MP, (int) getCurrentMp());
  5193. isSendStatus = true;
  5194. }
  5195. // Consume HP if necessary and Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
  5196. if (skill.getHpConsume() > 0)
  5197. {
  5198. double consumeHp;
  5199. consumeHp = calcStat(Stats.HP_CONSUME_RATE, skill.getHpConsume(), null, null);
  5200. if (consumeHp + 1 >= getCurrentHp())
  5201. consumeHp = getCurrentHp() - 1.0;
  5202. getStatus().reduceHp(consumeHp, this);
  5203. su.addAttribute(StatusUpdate.CUR_HP, (int) getCurrentHp());
  5204. isSendStatus = true;
  5205. }
  5206. // Consume CP if necessary and Send the Server->Client packet StatusUpdate with current CP/HP and MP to all other L2PcInstance to inform
  5207. if (skill.getCpConsume() > 0)
  5208. {
  5209. double consumeCp;
  5210. consumeCp = skill.getCpConsume();
  5211. if (consumeCp + 1 >= getCurrentHp())
  5212. consumeCp = getCurrentHp() - 1.0;
  5213. getStatus().reduceCp((int)consumeCp);
  5214. su.addAttribute(StatusUpdate.CUR_CP, (int) getCurrentCp());
  5215. isSendStatus = true;
  5216. }
  5217. // Send a Server->Client packet StatusUpdate with MP modification to the L2PcInstance
  5218. if (isSendStatus) sendPacket(su);
  5219. // Consume Items if necessary and Send the Server->Client packet InventoryUpdate with Item modification to all the L2Character
  5220. if (skill.getItemConsume() > 0)
  5221. {
  5222. if (!destroyItemByItemId("Consume", skill.getItemConsumeId(), skill.getItemConsume(), null, false))
  5223. {
  5224. sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_ITEMS));
  5225. abortCast();
  5226. return;
  5227. }
  5228. }
  5229. // Consume Souls if necessary
  5230. if (skill.getSoulConsumeCount() > 0 || skill.getMaxSoulConsumeCount() > 0)
  5231. {
  5232. if (this instanceof L2PcInstance)
  5233. {
  5234. ((L2PcInstance)this).decreaseSouls(skill.getSoulConsumeCount(),skill);
  5235. sendPacket(new EtcStatusUpdate((L2PcInstance)this));
  5236. }
  5237. }
  5238. // Launch the magic skill in order to calculate its effects
  5239. callSkill(skill, targets);
  5240. }
  5241. catch (NullPointerException e) {}
  5242. if (instant || coolTime == 0)
  5243. onMagicFinalizer(skill, targets[0], simultaneously);
  5244. else
  5245. {
  5246. if (simultaneously)
  5247. _skillCast2 = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 3, simultaneously), coolTime);
  5248. else
  5249. _skillCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 3, simultaneously), coolTime);
  5250. }
  5251. }
  5252. /*
  5253. * Runs after skill hitTime+coolTime
  5254. */
  5255. public void onMagicFinalizer(L2Skill skill, L2Object target, boolean simultaneously)
  5256. {
  5257. if (simultaneously)
  5258. {
  5259. _skillCast2 = null;
  5260. setIsCastingSimultaneouslyNow(false);
  5261. return;
  5262. }
  5263. else
  5264. {
  5265. _skillCast = null;
  5266. setIsCastingNow(false);
  5267. _castInterruptTime = 0;
  5268. }
  5269. // If the skill type is listed here, notify the AI of the target with AI_INTENTION_ATTACK
  5270. // for offensive skills the nextintention is always null unless player wants action after skill
  5271. // Note: this might also work
  5272. // if (skill.isOffensive() && getAI().getNextIntention() == null
  5273. // && !(skill.getSkillType() == SkillType.UNLOCK) && !(skill.getSkillType() == SkillType.DELUXE_KEY_UNLOCK) && !(skill.getSkillType() == SkillType.MDAM))
  5274. if (getAI().getNextIntention() == null && skill.getSkillType() == L2SkillType.PDAM || skill.getSkillType() == L2SkillType.BLOW
  5275. || skill.getSkillType() == L2SkillType.DRAIN_SOUL || skill.getSkillType() == L2SkillType.SOW || skill.getSkillType() == L2SkillType.CHARGEDAM
  5276. || skill.getSkillType() == L2SkillType.SPOIL)
  5277. {
  5278. if (getTarget() instanceof L2Character && getTarget() != this && target == getTarget())
  5279. getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, getTarget());
  5280. }
  5281. if (skill.isOffensive() && !(skill.getSkillType() == L2SkillType.UNLOCK) && !(skill.getSkillType() == L2SkillType.DELUXE_KEY_UNLOCK))
  5282. getAI().clientStartAutoAttack();
  5283. // Notify the AI of the L2Character with EVT_FINISH_CASTING
  5284. getAI().notifyEvent(CtrlEvent.EVT_FINISH_CASTING);
  5285. notifyQuestEventSkillFinished(skill, target);
  5286. /*
  5287. * If character is a player, then wipe their current cast state and
  5288. * check if a skill is queued.
  5289. *
  5290. * If there is a queued skill, launch it and wipe the queue.
  5291. */
  5292. if (this instanceof L2PcInstance)
  5293. {
  5294. L2PcInstance currPlayer = (L2PcInstance)this;
  5295. SkillDat queuedSkill = currPlayer.getQueuedSkill();
  5296. currPlayer.setCurrentSkill(null, false, false);
  5297. if (queuedSkill != null)
  5298. {
  5299. currPlayer.setQueuedSkill(null, false, false);
  5300. // DON'T USE : Recursive call to useMagic() method
  5301. // currPlayer.useMagic(queuedSkill.getSkill(), queuedSkill.isCtrlPressed(), queuedSkill.isShiftPressed());
  5302. ThreadPoolManager.getInstance().executeTask(new QueuedMagicUseTask(currPlayer, queuedSkill.getSkill(), queuedSkill.isCtrlPressed(), queuedSkill.isShiftPressed()) );
  5303. }
  5304. }
  5305. }
  5306. // Quest event ON_SPELL_FNISHED
  5307. private void notifyQuestEventSkillFinished(L2Skill skill, L2Object target)
  5308. {
  5309. if (this instanceof L2NpcInstance)
  5310. {
  5311. try
  5312. {
  5313. if (((L2NpcTemplate) getTemplate()).getEventQuests(Quest.QuestEventType.ON_SPELL_FINISHED) != null)
  5314. {
  5315. L2PcInstance player = target.getActingPlayer();
  5316. for (Quest quest : ((L2NpcTemplate) getTemplate()).getEventQuests(Quest.QuestEventType.ON_SPELL_FINISHED))
  5317. {
  5318. quest.notifySpellFinished(((L2NpcInstance) this), player, skill);
  5319. }
  5320. }
  5321. }
  5322. catch (Exception e)
  5323. {
  5324. _log.log(Level.SEVERE, "", e);
  5325. }
  5326. }
  5327. }
  5328. /**
  5329. * Enable a skill (remove it from _disabledSkills of the L2Character).<BR><BR>
  5330. *
  5331. * <B><U> Concept</U> :</B><BR><BR>
  5332. * All skills disabled are identified by their skillId in <B>_disabledSkills</B> of the L2Character <BR><BR>
  5333. *
  5334. * @param skillId The identifier of the L2Skill to enable
  5335. *
  5336. */
  5337. public void enableSkill(int skillId)
  5338. {
  5339. if (_disabledSkills == null) return;
  5340. _disabledSkills.remove(new Integer(skillId));
  5341. if (this instanceof L2PcInstance)
  5342. removeTimeStamp(skillId);
  5343. }
  5344. /**
  5345. * Disable a skill (add it to _disabledSkills of the L2Character).<BR><BR>
  5346. *
  5347. * <B><U> Concept</U> :</B><BR><BR>
  5348. * All skills disabled are identified by their skillId in <B>_disabledSkills</B> of the L2Character <BR><BR>
  5349. *
  5350. * @param skillId The identifier of the L2Skill to disable
  5351. *
  5352. */
  5353. public void disableSkill(int skillId)
  5354. {
  5355. if (_disabledSkills == null) _disabledSkills = Collections.synchronizedList(new FastList<Integer>());
  5356. _disabledSkills.add(skillId);
  5357. }
  5358. /**
  5359. * Disable this skill id for the duration of the delay in milliseconds.
  5360. * @param skillId
  5361. * @param delay (seconds * 1000)
  5362. */
  5363. public void disableSkill(int skillId, long delay)
  5364. {
  5365. disableSkill(skillId);
  5366. if (delay > 10) ThreadPoolManager.getInstance().scheduleAi(new EnableSkill(skillId), delay);
  5367. }
  5368. /**
  5369. * Check if a skill is disabled.<BR><BR>
  5370. *
  5371. * <B><U> Concept</U> :</B><BR><BR>
  5372. * All skills disabled are identified by their skillId in <B>_disabledSkills</B> of the L2Character <BR><BR>
  5373. *
  5374. * @param skillId The identifier of the L2Skill to disable
  5375. *
  5376. */
  5377. public boolean isSkillDisabled(int skillId)
  5378. {
  5379. if (isAllSkillsDisabled()) return true;
  5380. if (_disabledSkills == null) return false;
  5381. return _disabledSkills.contains(skillId);
  5382. }
  5383. /**
  5384. * Disable all skills (set _allSkillsDisabled to True).<BR><BR>
  5385. */
  5386. public void disableAllSkills()
  5387. {
  5388. if (Config.DEBUG) _log.fine("all skills disabled");
  5389. _allSkillsDisabled = true;
  5390. }
  5391. /**
  5392. * Enable all skills (set _allSkillsDisabled to False).<BR><BR>
  5393. */
  5394. public void enableAllSkills()
  5395. {
  5396. if (Config.DEBUG) _log.fine("all skills enabled");
  5397. _allSkillsDisabled = false;
  5398. }
  5399. /**
  5400. * Launch the magic skill and calculate its effects on each target contained in the targets table.<BR><BR>
  5401. *
  5402. * @param skill The L2Skill to use
  5403. * @param targets The table of L2Object targets
  5404. *
  5405. */
  5406. public void callSkill(L2Skill skill, L2Object[] targets)
  5407. {
  5408. try
  5409. {
  5410. // Get the skill handler corresponding to the skill type (PDAM, MDAM, SWEEP...) started in gameserver
  5411. ISkillHandler handler = SkillHandler.getInstance().getSkillHandler(skill.getSkillType());
  5412. L2Weapon activeWeapon = getActiveWeaponItem();
  5413. // Check if the toggle skill effects are already in progress on the L2Character
  5414. if(skill.isToggle() && getFirstEffect(skill.getId()) != null)
  5415. return;
  5416. // Initial checks
  5417. for (L2Object trg : targets)
  5418. {
  5419. if (trg instanceof L2Character)
  5420. {
  5421. // Set some values inside target's instance for later use
  5422. L2Character target = (L2Character) trg;
  5423. // Check Raidboss attack and
  5424. // check buffing chars who attack raidboss. Results in mute.
  5425. L2Character targetsAttackTarget = target.getAI().getAttackTarget();
  5426. L2Character targetsCastTarget = target.getAI().getCastTarget();
  5427. if (
  5428. (target.isRaid() && getLevel() > target.getLevel() + 8)
  5429. ||
  5430. (!skill.isOffensive() && targetsAttackTarget != null && targetsAttackTarget.isRaid()
  5431. && targetsAttackTarget.getAttackByList().contains(target) // has attacked raid
  5432. && getLevel() > targetsAttackTarget.getLevel() + 8)
  5433. ||
  5434. (!skill.isOffensive() && targetsCastTarget != null && targetsCastTarget.isRaid()
  5435. && targetsCastTarget.getAttackByList().contains(target) // has attacked raid
  5436. && getLevel() > targetsCastTarget.getLevel() + 8)
  5437. )
  5438. {
  5439. if (skill.isMagic())
  5440. {
  5441. L2Skill tempSkill = SkillTable.getInstance().getInfo(4215, 1);
  5442. if(tempSkill != null)
  5443. tempSkill.getEffects(target, this);
  5444. else
  5445. _log.warning("Skill 4215 at level 1 is missing in DP.");
  5446. }
  5447. else
  5448. {
  5449. L2Skill tempSkill = SkillTable.getInstance().getInfo(4515, 1);
  5450. if(tempSkill != null)
  5451. tempSkill.getEffects(target, this);
  5452. else
  5453. _log.warning("Skill 4515 at level 1 is missing in DP.");
  5454. }
  5455. return;
  5456. }
  5457. // Check if over-hit is possible
  5458. if(skill.isOverhit())
  5459. {
  5460. if(target instanceof L2Attackable)
  5461. ((L2Attackable)target).overhitEnabled(true);
  5462. }
  5463. // Launch weapon Special ability skill effect if available
  5464. if (activeWeapon != null && !target.isDead())
  5465. {
  5466. if (activeWeapon.getSkillEffects(this, target, skill).length > 0 && this instanceof L2PcInstance)
  5467. {
  5468. sendMessage("Target affected by weapon special ability!");
  5469. }
  5470. }
  5471. // Maybe launch chance skills on us
  5472. if (_chanceSkills != null)
  5473. _chanceSkills.onSkillHit(target, false, skill.isMagic(), skill.isOffensive());
  5474. // Maybe launch chance skills on target
  5475. if (target.getChanceSkills() != null)
  5476. target.getChanceSkills().onSkillHit(this, true, skill.isMagic(), skill.isOffensive());
  5477. }
  5478. }
  5479. // Launch the magic skill and calculate its effects
  5480. if (handler != null)
  5481. handler.useSkill(this, skill, targets);
  5482. else
  5483. skill.useSkill(this, targets);
  5484. L2PcInstance player = getActingPlayer();
  5485. if (player != null)
  5486. {
  5487. for (L2Object target : targets)
  5488. {
  5489. // EVT_ATTACKED and PvPStatus
  5490. if (target instanceof L2Character)
  5491. {
  5492. if (skill.isOffensive())
  5493. {
  5494. if (target instanceof L2PcInstance || target instanceof L2Summon || target instanceof L2Trap)
  5495. {
  5496. // Signets are a special case, casted on target_self but don't harm self
  5497. if (skill.getSkillType() != L2SkillType.SIGNET && skill.getSkillType() != L2SkillType.SIGNET_CASTTIME)
  5498. {
  5499. if (skill.getSkillType() != L2SkillType.AGGREDUCE
  5500. && skill.getSkillType() != L2SkillType.AGGREDUCE_CHAR
  5501. && skill.getSkillType() != L2SkillType.AGGREMOVE)
  5502. {
  5503. // notify target AI about the attack
  5504. ((L2Character)target).getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, player);
  5505. }
  5506. if (target instanceof L2PcInstance)
  5507. {
  5508. ((L2PcInstance)target).getAI().clientStartAutoAttack();
  5509. }
  5510. else if (target instanceof L2Summon)
  5511. {
  5512. L2PcInstance owner =((L2Summon)target).getOwner();
  5513. if (owner != null)
  5514. {
  5515. owner.getAI().clientStartAutoAttack();
  5516. }
  5517. }
  5518. player.updatePvPStatus((L2Character)target);
  5519. }
  5520. }
  5521. else if (target instanceof L2Attackable)
  5522. {
  5523. if (skill.getSkillType() != L2SkillType.AGGREDUCE
  5524. && skill.getSkillType() != L2SkillType.AGGREDUCE_CHAR
  5525. && skill.getSkillType() != L2SkillType.AGGREMOVE)
  5526. {
  5527. // notify target AI about the attack
  5528. ((L2Character)target).getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, player);
  5529. }
  5530. }
  5531. }
  5532. else
  5533. {
  5534. if (target instanceof L2PcInstance)
  5535. {
  5536. // Casting non offensive skill on player with pvp flag set or with karma
  5537. if (!target.equals(this) &&
  5538. (((L2PcInstance)target).getPvpFlag() > 0 ||
  5539. ((L2PcInstance)target).getKarma() > 0)) player.updatePvPStatus();
  5540. }
  5541. else if (target instanceof L2Attackable
  5542. && !(skill.getSkillType() == L2SkillType.SUMMON)
  5543. && !(skill.getSkillType() == L2SkillType.BEAST_FEED)
  5544. && !(skill.getSkillType() == L2SkillType.UNLOCK)
  5545. && !(skill.getSkillType() == L2SkillType.DELUXE_KEY_UNLOCK))
  5546. player.updatePvPStatus();
  5547. }
  5548. }
  5549. }
  5550. // Mobs in range 1000 see spell
  5551. Collection<L2Object> objs = player.getKnownList().getKnownObjects().values();
  5552. //synchronized (player.getKnownList().getKnownObjects())
  5553. {
  5554. for (L2Object spMob : objs)
  5555. {
  5556. if (spMob instanceof L2NpcInstance)
  5557. {
  5558. L2NpcInstance npcMob = (L2NpcInstance) spMob;
  5559. if ((npcMob.isInsideRadius(player, 1000, true, true))
  5560. && (npcMob.getTemplate().getEventQuests(Quest.QuestEventType.ON_SKILL_SEE) != null))
  5561. for (Quest quest : npcMob.getTemplate().getEventQuests(Quest.QuestEventType.ON_SKILL_SEE))
  5562. quest.notifySkillSee(npcMob, player, skill, targets, this instanceof L2Summon);
  5563. }
  5564. }
  5565. }
  5566. }
  5567. }
  5568. catch (Exception e)
  5569. {
  5570. _log.log(Level.WARNING, "", e);
  5571. }
  5572. }
  5573. /**
  5574. * Return True if the L2Character is behind the target and can't be seen.<BR><BR>
  5575. */
  5576. public boolean isBehind(L2Object target)
  5577. {
  5578. double angleChar, angleTarget, angleDiff, maxAngleDiff = 45;
  5579. if(target == null)
  5580. return false;
  5581. if (target instanceof L2Character)
  5582. {
  5583. L2Character target1 = (L2Character) target;
  5584. angleChar = Util.calculateAngleFrom(this, target1);
  5585. angleTarget = Util.convertHeadingToDegree(target1.getHeading());
  5586. angleDiff = angleChar - angleTarget;
  5587. if (angleDiff <= -360 + maxAngleDiff) angleDiff += 360;
  5588. if (angleDiff >= 360 - maxAngleDiff) angleDiff -= 360;
  5589. if (Math.abs(angleDiff) <= maxAngleDiff)
  5590. {
  5591. if (Config.DEBUG)
  5592. _log.info("Char " + getName() + " is behind " + target.getName());
  5593. return true;
  5594. }
  5595. }
  5596. else
  5597. {
  5598. _log.fine("isBehindTarget's target not an L2 Character.");
  5599. }
  5600. return false;
  5601. }
  5602. public boolean isBehindTarget()
  5603. {
  5604. return isBehind(getTarget());
  5605. }
  5606. /**
  5607. * Return True if the target is facing the L2Character.<BR><BR>
  5608. */
  5609. public boolean isInFrontOf(L2Character target)
  5610. {
  5611. double angleChar, angleTarget, angleDiff, maxAngleDiff = 45;
  5612. if(target == null)
  5613. return false;
  5614. angleTarget = Util.calculateAngleFrom(target, this);
  5615. angleChar = Util.convertHeadingToDegree(target.getHeading());
  5616. angleDiff = angleChar - angleTarget;
  5617. if (angleDiff <= -360 + maxAngleDiff) angleDiff += 360;
  5618. if (angleDiff >= 360 - maxAngleDiff) angleDiff -= 360;
  5619. if (Math.abs(angleDiff) <= maxAngleDiff)
  5620. return true;
  5621. return false;
  5622. }
  5623. /** Returns true if target is in front of L2Character (shield def etc) */
  5624. public boolean isFacing(L2Object target, int maxAngle)
  5625. {
  5626. double angleChar, angleTarget, angleDiff, maxAngleDiff;
  5627. if(target == null)
  5628. return false;
  5629. maxAngleDiff = maxAngle / 2;
  5630. angleTarget = Util.calculateAngleFrom(this, target);
  5631. angleChar = Util.convertHeadingToDegree(this.getHeading());
  5632. angleDiff = angleChar - angleTarget;
  5633. if (angleDiff <= -360 + maxAngleDiff) angleDiff += 360;
  5634. if (angleDiff >= 360 - maxAngleDiff) angleDiff -= 360;
  5635. if (Math.abs(angleDiff) <= maxAngleDiff)
  5636. return true;
  5637. return false;
  5638. }
  5639. public boolean isInFrontOfTarget()
  5640. {
  5641. L2Object target = getTarget();
  5642. if (target instanceof L2Character)
  5643. return isInFrontOf((L2Character)target);
  5644. else
  5645. return false;
  5646. }
  5647. /**
  5648. * Return 1.<BR><BR>
  5649. */
  5650. public double getLevelMod()
  5651. {
  5652. return 1;
  5653. }
  5654. public final void setSkillCast(Future<?> newSkillCast)
  5655. {
  5656. _skillCast = newSkillCast;
  5657. }
  5658. /** Sets _isCastingNow to true and _castInterruptTime is calculated from end time (ticks) */
  5659. public final void forceIsCasting(int newSkillCastEndTick)
  5660. {
  5661. setIsCastingNow(true);
  5662. // for interrupt -200 ms
  5663. _castInterruptTime = newSkillCastEndTick-2;
  5664. }
  5665. private Future<?> _PvPRegTask;
  5666. private long _pvpFlagLasts;
  5667. private boolean _AIdisabled = false;
  5668. private boolean _isMinion = false;
  5669. public void setPvpFlagLasts(long time)
  5670. {
  5671. _pvpFlagLasts = time;
  5672. }
  5673. public long getPvpFlagLasts()
  5674. {
  5675. return _pvpFlagLasts;
  5676. }
  5677. public void startPvPFlag()
  5678. {
  5679. updatePvPFlag(1);
  5680. _PvPRegTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new PvPFlag(), 1000, 1000);
  5681. }
  5682. public void stopPvpRegTask()
  5683. {
  5684. if (_PvPRegTask != null)
  5685. _PvPRegTask.cancel(true);
  5686. }
  5687. public void stopPvPFlag()
  5688. {
  5689. stopPvpRegTask();
  5690. updatePvPFlag(0);
  5691. _PvPRegTask = null;
  5692. }
  5693. public void updatePvPFlag(int value)
  5694. {
  5695. // Overridden in L2PcInstance
  5696. }
  5697. /**
  5698. * Return a Random Damage in function of the weapon.<BR><BR>
  5699. */
  5700. public final int getRandomDamage(L2Character target)
  5701. {
  5702. L2Weapon weaponItem = getActiveWeaponItem();
  5703. if (weaponItem == null)
  5704. return 5+(int)Math.sqrt(getLevel());
  5705. return weaponItem.getRandomDamage();
  5706. }
  5707. @Override
  5708. public String toString()
  5709. {
  5710. return "mob "+getObjectId();
  5711. }
  5712. public int getAttackEndTime()
  5713. {
  5714. return _attackEndTime;
  5715. }
  5716. /**
  5717. * Not Implemented.<BR><BR>
  5718. */
  5719. public abstract int getLevel();
  5720. // =========================================================
  5721. // =========================================================
  5722. // Stat - NEED TO REMOVE ONCE L2CHARSTAT IS COMPLETE
  5723. // Property - Public
  5724. public final double calcStat(Stats stat, double init, L2Character target, L2Skill skill) { return getStat().calcStat(stat, init, target, skill); }
  5725. // Property - Public
  5726. public int getAccuracy() { return getStat().getAccuracy(); }
  5727. public final float getAttackSpeedMultiplier() { return getStat().getAttackSpeedMultiplier(); }
  5728. public int getCON() { return getStat().getCON(); }
  5729. public int getDEX() { return getStat().getDEX(); }
  5730. public final double getCriticalDmg(L2Character target, double init) { return getStat().getCriticalDmg(target, init); }
  5731. public int getCriticalHit(L2Character target, L2Skill skill) { return getStat().getCriticalHit(target, skill); }
  5732. public int getEvasionRate(L2Character target) { return getStat().getEvasionRate(target); }
  5733. public int getINT() { return getStat().getINT(); }
  5734. public final int getMagicalAttackRange(L2Skill skill) { return getStat().getMagicalAttackRange(skill); }
  5735. public final int getMaxCp() { return getStat().getMaxCp(); }
  5736. public int getMAtk(L2Character target, L2Skill skill) { return getStat().getMAtk(target, skill); }
  5737. public int getMAtkSpd() { return getStat().getMAtkSpd(); }
  5738. public int getMaxMp() { return getStat().getMaxMp(); }
  5739. public int getMaxHp() { return getStat().getMaxHp(); }
  5740. public final int getMCriticalHit(L2Character target, L2Skill skill) { return getStat().getMCriticalHit(target, skill); }
  5741. public int getMDef(L2Character target, L2Skill skill) { return getStat().getMDef(target, skill); }
  5742. public int getMEN() { return getStat().getMEN(); }
  5743. public double getMReuseRate(L2Skill skill) { return getStat().getMReuseRate(skill); }
  5744. public float getMovementSpeedMultiplier() { return getStat().getMovementSpeedMultiplier(); }
  5745. public int getPAtk(L2Character target) { return getStat().getPAtk(target); }
  5746. public double getPAtkAnimals(L2Character target) { return getStat().getPAtkAnimals(target); }
  5747. public double getPAtkDragons(L2Character target) { return getStat().getPAtkDragons(target); }
  5748. public double getPAtkInsects(L2Character target) { return getStat().getPAtkInsects(target); }
  5749. public double getPAtkMonsters(L2Character target) { return getStat().getPAtkMonsters(target); }
  5750. public double getPAtkPlants(L2Character target) { return getStat().getPAtkPlants(target); }
  5751. public double getPAtkGiants(L2Character target) { return getStat().getPAtkGiants(target); }
  5752. public double getPDefAnimals(L2Character target) { return getStat().getPDefAnimals(target); }
  5753. public double getPDefDragons(L2Character target) { return getStat().getPDefDragons(target); }
  5754. public double getPDefInsects(L2Character target) { return getStat().getPDefInsects(target); }
  5755. public double getPDefMonsters(L2Character target) { return getStat().getPDefMonsters(target); }
  5756. public double getPDefPlants(L2Character target) { return getStat().getPDefPlants(target); }
  5757. public double getPDefGiants(L2Character target) { return getStat().getPDefGiants(target); }
  5758. public int getPAtkSpd() { return getStat().getPAtkSpd(); }
  5759. public double getPAtkUndead(L2Character target) { return getStat().getPAtkUndead(target); }
  5760. public double getPDefUndead(L2Character target) { return getStat().getPDefUndead(target); }
  5761. public int getPDef(L2Character target) { return getStat().getPDef(target); }
  5762. public final int getPhysicalAttackRange() { return getStat().getPhysicalAttackRange(); }
  5763. public int getRunSpeed() { return getStat().getRunSpeed(); }
  5764. public final int getShldDef() { return getStat().getShldDef(); }
  5765. public int getSTR() { return getStat().getSTR(); }
  5766. public final int getWalkSpeed() { return getStat().getWalkSpeed(); }
  5767. public int getWIT() { return getStat().getWIT(); }
  5768. // =========================================================
  5769. // =========================================================
  5770. // Status - NEED TO REMOVE ONCE L2CHARTATUS IS COMPLETE
  5771. // Method - Public
  5772. public void addStatusListener(L2Character object) { getStatus().addStatusListener(object); }
  5773. public void reduceCurrentHp(double i, L2Character attacker) { reduceCurrentHp(i, attacker, true, false); }
  5774. public void reduceCurrentHpByDOT(double i, L2Character attacker) { reduceCurrentHp(i, attacker, true, true); }
  5775. public void reduceCurrentHp(double i, L2Character attacker, boolean awake, boolean isDOT)
  5776. {
  5777. if (Config.L2JMOD_CHAMPION_ENABLE && isChampion() && Config.L2JMOD_CHAMPION_HP != 0)
  5778. getStatus().reduceHp(i/Config.L2JMOD_CHAMPION_HP, attacker, awake, isDOT);
  5779. else
  5780. getStatus().reduceHp(i, attacker, awake, isDOT);
  5781. }
  5782. public void reduceCurrentMp(double i) { getStatus().reduceMp(i); }
  5783. public void removeStatusListener(L2Character object) { getStatus().removeStatusListener(object); }
  5784. protected void stopHpMpRegeneration() { getStatus().stopHpMpRegeneration(); }
  5785. // Property - Public
  5786. public final double getCurrentCp() { return getStatus().getCurrentCp(); }
  5787. public final void setCurrentCp(Double newCp) { setCurrentCp((double) newCp); }
  5788. public final void setCurrentCp(double newCp) { getStatus().setCurrentCp(newCp); }
  5789. public final double getCurrentHp() { return getStatus().getCurrentHp(); }
  5790. public final void setCurrentHp(double newHp) { getStatus().setCurrentHp(newHp); }
  5791. public final void setCurrentHpMp(double newHp, double newMp){ getStatus().setCurrentHpMp(newHp, newMp); }
  5792. public final double getCurrentMp() { return getStatus().getCurrentMp(); }
  5793. public final void setCurrentMp(Double newMp) { setCurrentMp((double)newMp); }
  5794. public final void setCurrentMp(double newMp) { getStatus().setCurrentMp(newMp); }
  5795. // =========================================================
  5796. public void setAiClass(String aiClass)
  5797. {
  5798. _aiClass = aiClass;
  5799. }
  5800. public String getAiClass()
  5801. {
  5802. return _aiClass;
  5803. }
  5804. public L2Character getLastBuffer()
  5805. {
  5806. return _lastBuffer;
  5807. }
  5808. public void setChampion(boolean champ)
  5809. {
  5810. _champion = champ;
  5811. }
  5812. public boolean isChampion()
  5813. {
  5814. return _champion;
  5815. }
  5816. public int getLastHealAmount()
  5817. {
  5818. return _lastHealAmount;
  5819. }
  5820. public void setLastBuffer(L2Character buffer)
  5821. {
  5822. _lastBuffer = buffer;
  5823. }
  5824. public void setLastHealAmount(int hp)
  5825. {
  5826. _lastHealAmount = hp;
  5827. }
  5828. /**
  5829. * Check if character reflected skill
  5830. * @param skill
  5831. * @return
  5832. */
  5833. public boolean reflectSkill(L2Skill skill)
  5834. {
  5835. double reflect = calcStat(skill.isMagic() ? Stats.REFLECT_SKILL_MAGIC : Stats.REFLECT_SKILL_PHYSIC, 0, null, null);
  5836. if( Rnd.get(100) < reflect)
  5837. return true;
  5838. return false;
  5839. }
  5840. /**
  5841. * Check player max buff count
  5842. * @return max buff count
  5843. */
  5844. public int getMaxBuffCount()
  5845. {
  5846. return Config.BUFFS_MAX_AMOUNT + Math.max(0, getSkillLevel(L2Skill.SKILL_DIVINE_INSPIRATION));
  5847. }
  5848. /**
  5849. * Send system message about damage.<BR><BR>
  5850. *
  5851. * <B><U> Overridden in </U> :</B><BR><BR>
  5852. * <li> L2PcInstance
  5853. * <li> L2SummonInstance
  5854. * <li> L2PetInstance</li><BR><BR>
  5855. *
  5856. */
  5857. public void sendDamageMessage(L2Character target, int damage, boolean mcrit, boolean pcrit, boolean miss)
  5858. {
  5859. }
  5860. public ForceBuff getForceBuff()
  5861. {
  5862. return _forceBuff;
  5863. }
  5864. public void setForceBuff(ForceBuff fb)
  5865. {
  5866. _forceBuff = fb;
  5867. }
  5868. public int getAttackElement()
  5869. {
  5870. return getStat().getAttackElement();
  5871. }
  5872. public int getAttackElementValue()
  5873. {
  5874. return (int)getStat().getAttackElementValue();
  5875. }
  5876. public int getDefAttrFire()
  5877. {
  5878. return (int)getStat().getElementAttributeFire();
  5879. }
  5880. public int getDefAttrWater()
  5881. {
  5882. return (int)getStat().getElementAttributeWater();
  5883. }
  5884. public int getDefAttrEarth()
  5885. {
  5886. return (int)getStat().getElementAttributeEarth();
  5887. }
  5888. public int getDefAttrWind()
  5889. {
  5890. return (int)getStat().getElementAttributeWind();
  5891. }
  5892. public int getDefAttrHoly()
  5893. {
  5894. return (int)getStat().getElementAttributeHoly();
  5895. }
  5896. public int getDefAttrUnholy()
  5897. {
  5898. return (int)getStat().getElementAttributeUnholy();
  5899. }
  5900. public final void startPhysicalAttackMuted()
  5901. {
  5902. setIsPhysicalAttackMuted(true);
  5903. abortAttack();
  5904. }
  5905. public final void stopPhysicalAttackMuted(L2Effect effect)
  5906. {
  5907. if (effect == null)
  5908. stopEffects(L2EffectType.PHYSICAL_ATTACK_MUTE);
  5909. else
  5910. removeEffect(effect);
  5911. setIsPhysicalAttackMuted(false);
  5912. }
  5913. public void disableCoreAI(boolean val)
  5914. {
  5915. _AIdisabled = val;
  5916. }
  5917. public boolean isCoreAIDisabled()
  5918. {
  5919. return _AIdisabled;
  5920. }
  5921. /** Task for potion and herb queue */
  5922. private class UsePotionTask implements Runnable
  5923. {
  5924. private L2Character _activeChar;
  5925. private L2Skill _skill;
  5926. UsePotionTask(L2Character activeChar, L2Skill skill)
  5927. {
  5928. _activeChar = activeChar;
  5929. _skill = skill;
  5930. }
  5931. public void run()
  5932. {
  5933. try
  5934. {
  5935. _activeChar.doSimultaneousCast(_skill);
  5936. }
  5937. catch (Exception e)
  5938. {
  5939. _log.log(Level.WARNING, "", e);
  5940. }
  5941. }
  5942. }
  5943. public boolean isRaidMinion()
  5944. {
  5945. return _isMinion ;
  5946. }
  5947. /**
  5948. * Set this Npc as a Minion instance.<BR><BR>
  5949. * @param val
  5950. */
  5951. public void setIsRaidMinion(boolean val)
  5952. {
  5953. _isRaid = val;
  5954. _isMinion = val;
  5955. }
  5956. }