L2Character.java 229 KB

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