L2Character.java 195 KB

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