L2Character.java 229 KB

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