L2Character.java 224 KB

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