L2Character.java 229 KB

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