L2Character.java 208 KB

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