L2Character.java 225 KB

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