L2Character.java 216 KB

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