L2Character.java 215 KB

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