L2Character.java 196 KB

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