L2Character.java 229 KB

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