L2Character.java 216 KB

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