L2Character.java 196 KB

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