L2Character.java 229 KB

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