L2Character.java 216 KB

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