L2Character.java 225 KB

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