L2Character.java 228 KB

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