L2Character.java 225 KB

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