L2Character.java 216 KB

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