L2Character.java 229 KB

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