L2Character.java 229 KB

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