2
0

L2Character.java 220 KB

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