L2Character.java 225 KB

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