L2Character.java 230 KB

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