L2Character.java 217 KB

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