L2Character.java 224 KB

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