L2Character.java 229 KB

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