L2Character.java 208 KB

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