L2Character.java 217 KB

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