L2Character.java 225 KB

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