L2Character.java 224 KB

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