1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649 |
- /*
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package net.sf.l2j.gameserver.model;
- import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
- import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_FOLLOW;
- import java.util.Collections;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import java.util.concurrent.Future;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javolution.util.FastList;
- import javolution.util.FastMap;
- import javolution.util.FastTable;
- import net.sf.l2j.Config;
- import net.sf.l2j.gameserver.GameTimeController;
- import net.sf.l2j.gameserver.GeoData;
- import net.sf.l2j.gameserver.ThreadPoolManager;
- import net.sf.l2j.gameserver.ai.CtrlEvent;
- import net.sf.l2j.gameserver.ai.CtrlIntention;
- import net.sf.l2j.gameserver.ai.L2AttackableAI;
- import net.sf.l2j.gameserver.ai.L2CharacterAI;
- import net.sf.l2j.gameserver.datatables.DoorTable;
- import net.sf.l2j.gameserver.datatables.MapRegionTable;
- import net.sf.l2j.gameserver.datatables.SkillTable;
- import net.sf.l2j.gameserver.datatables.MapRegionTable.TeleportWhereType;
- import net.sf.l2j.gameserver.handler.ISkillHandler;
- import net.sf.l2j.gameserver.handler.SkillHandler;
- import net.sf.l2j.gameserver.instancemanager.DimensionalRiftManager;
- import net.sf.l2j.gameserver.instancemanager.TownManager;
- import net.sf.l2j.gameserver.model.L2Effect.EffectType;
- import net.sf.l2j.gameserver.model.L2Skill.SkillTargetType;
- import net.sf.l2j.gameserver.model.L2Skill.SkillType;
- import net.sf.l2j.gameserver.model.actor.instance.L2ArtefactInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2BoatInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2CommanderInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2ControlTowerInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2DecoyInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2DoorInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2EffectPointInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2FriendlyMobInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2GuardInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2MonsterInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2NpcWalkerInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2RiftInvaderInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2SiegeFlagInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2SiegeGuardInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2SiegeSummonInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2SummonInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2TrapInstance;
- import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance.SkillDat;
- import net.sf.l2j.gameserver.model.actor.knownlist.CharKnownList;
- import net.sf.l2j.gameserver.model.actor.stat.CharStat;
- import net.sf.l2j.gameserver.model.actor.status.CharStatus;
- import net.sf.l2j.gameserver.model.entity.Duel;
- import net.sf.l2j.gameserver.model.quest.Quest;
- import net.sf.l2j.gameserver.model.quest.QuestState;
- import net.sf.l2j.gameserver.network.SystemMessageId;
- import net.sf.l2j.gameserver.pathfinding.AbstractNodeLoc;
- import net.sf.l2j.gameserver.pathfinding.geonodes.GeoPathFinding;
- import net.sf.l2j.gameserver.serverpackets.ActionFailed;
- import net.sf.l2j.gameserver.serverpackets.Attack;
- import net.sf.l2j.gameserver.serverpackets.ChangeMoveType;
- import net.sf.l2j.gameserver.serverpackets.ChangeWaitType;
- import net.sf.l2j.gameserver.serverpackets.CharInfo;
- import net.sf.l2j.gameserver.serverpackets.EtcStatusUpdate;
- import net.sf.l2j.gameserver.serverpackets.FlyToLocation;
- import net.sf.l2j.gameserver.serverpackets.L2GameServerPacket;
- import net.sf.l2j.gameserver.serverpackets.MagicSkillCanceld;
- import net.sf.l2j.gameserver.serverpackets.MagicSkillLaunched;
- import net.sf.l2j.gameserver.serverpackets.MagicSkillUse;
- import net.sf.l2j.gameserver.serverpackets.MoveToLocation;
- import net.sf.l2j.gameserver.serverpackets.NpcInfo;
- import net.sf.l2j.gameserver.serverpackets.PetInfo;
- import net.sf.l2j.gameserver.serverpackets.RelationChanged;
- import net.sf.l2j.gameserver.serverpackets.Revive;
- import net.sf.l2j.gameserver.serverpackets.SetupGauge;
- import net.sf.l2j.gameserver.serverpackets.StatusUpdate;
- import net.sf.l2j.gameserver.serverpackets.StopMove;
- import net.sf.l2j.gameserver.serverpackets.SystemMessage;
- import net.sf.l2j.gameserver.serverpackets.TeleportToLocation;
- import net.sf.l2j.gameserver.serverpackets.UserInfo;
- import net.sf.l2j.gameserver.serverpackets.FlyToLocation.FlyType;
- import net.sf.l2j.gameserver.skills.Calculator;
- import net.sf.l2j.gameserver.skills.Formulas;
- import net.sf.l2j.gameserver.skills.Stats;
- import net.sf.l2j.gameserver.skills.effects.EffectCharge;
- import net.sf.l2j.gameserver.skills.funcs.Func;
- import net.sf.l2j.gameserver.templates.L2CharTemplate;
- import net.sf.l2j.gameserver.templates.L2NpcTemplate;
- import net.sf.l2j.gameserver.templates.L2Weapon;
- import net.sf.l2j.gameserver.templates.L2WeaponType;
- import net.sf.l2j.gameserver.util.Util;
- import net.sf.l2j.util.Point3D;
- import net.sf.l2j.util.Rnd;
- /**
- * Mother class of all character objects of the world (PC, NPC...)<BR><BR>
- *
- * L2Character :<BR><BR>
- * <li>L2CastleGuardInstance</li>
- * <li>L2DoorInstance</li>
- * <li>L2NpcInstance</li>
- * <li>L2PlayableInstance </li><BR><BR>
- *
- *
- * <B><U> Concept of L2CharTemplate</U> :</B><BR><BR>
- * Each L2Character owns generic and static properties (ex : all Keltir have the same number of HP...).
- * All of those properties are stored in a different template for each type of L2Character.
- * Each template is loaded once in the server cache memory (reduce memory use).
- * When a new instance of L2Character is spawned, server just create a link between the instance and the template.
- * This link is stored in <B>_template</B><BR><BR>
- *
- *
- * @version $Revision: 1.53.2.45.2.34 $ $Date: 2005/04/11 10:06:08 $
- */
- public abstract class L2Character extends L2Object
- {
- protected static final Logger _log = Logger.getLogger(L2Character.class.getName());
- // =========================================================
- // Data Field
- private List<L2Character> _attackByList;
- // private L2Character _attackingChar;
- private L2Skill _lastSkillCast;
- private boolean _isAfraid = false; // Flee in a random direction
- private boolean _isConfused = false; // Attack anyone randomly
- private boolean _isFakeDeath = false; // Fake death
- private boolean _isFlying = false; //Is flying Wyvern?
- private boolean _isMuted = false; // Cannot use magic
- private boolean _isPhysicalMuted = false; // Cannot use physical skills
- private boolean _isPhysicalAttackMuted = false; // Cannot use attack
- private boolean _isDead = false;
- private boolean _isImmobilized = false;
- private boolean _isOverloaded = false; // the char is carrying too much
- private boolean _isParalyzed = false;
- private boolean _isDisarmed = false;
- private boolean _isRidingGreatWolf = false;
- private boolean _isRidingStrider = false;
- private boolean _isPendingRevive = false;
- private boolean _isRooted = false; // Cannot move until root timed out
- private boolean _isRunning = false;
- private boolean _isImmobileUntilAttacked = false; // Is in immobile until attacked.
- private boolean _isSleeping = false; // Cannot move/attack until sleep timed out or monster is attacked
- private boolean _isStunned = false; // Cannot move/attack until stun timed out
- private boolean _isBetrayed = false; // Betrayed by own summon
- protected boolean _isTeleporting = false;
- private L2Character _lastBuffer = null;
- protected boolean _isInvul = false;
- private int _lastHealAmount = 0;
- private CharStat _stat;
- private CharStatus _status;
- private L2CharTemplate _template; // The link on the L2CharTemplate object containing generic and static properties of this L2Character type (ex : Max HP, Speed...)
- private String _title;
- private String _aiClass = "default";
- private double _hpUpdateIncCheck = .0;
- private double _hpUpdateDecCheck = .0;
- private double _hpUpdateInterval = .0;
- private boolean _champion = false;
- /** Table of Calculators containing all used calculator */
- private Calculator[] _calculators;
- /** FastMap(Integer, L2Skill) containing all skills of the L2Character */
- protected final Map<Integer, L2Skill> _skills;
- /** Zone system */
- public static final int ZONE_PVP = 1;
- public static final int ZONE_PEACE = 2;
- public static final int ZONE_SIEGE = 4;
- public static final int ZONE_MOTHERTREE = 8;
- public static final int ZONE_CLANHALL = 16;
- public static final int ZONE_UNUSED = 32;
- public static final int ZONE_NOLANDING = 64;
- public static final int ZONE_WATER = 128;
- public static final int ZONE_JAIL = 256;
- public static final int ZONE_MONSTERTRACK = 512;
- private int _currentZones = 0;
- public boolean isInsideZone(int zone)
- {
- return ((_currentZones & zone) != 0);
- }
- public void setInsideZone(int zone, boolean state)
- {
- if (state)
- _currentZones |= zone;
- else if (isInsideZone(zone)) // zone overlap possible
- _currentZones ^= zone;
- }
-
- /**
- * This will return true if the player is transformed,<br>
- * but if the player is not transformed it will return false.
- * @return transformation status
- */
- public boolean charIsTransformed()
- {
- if (this instanceof L2PcInstance)
- {
- if (((L2PcInstance)this).isTransformed())
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * This will return true if the player is GM,<br>
- * but if the player is not GM it will return false.
- * @return GM status
- */
- public boolean charIsGM()
- {
- if (this instanceof L2PcInstance)
- {
- if (((L2PcInstance)this).isGM())
- {
- return true;
- }
- }
- return false;
- }
- // =========================================================
- // Constructor
- /**
- * Constructor of L2Character.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * Each L2Character owns generic and static properties (ex : all Keltir have the same number of HP...).
- * All of those properties are stored in a different template for each type of L2Character.
- * Each template is loaded once in the server cache memory (reduce memory use).
- * When a new instance of L2Character is spawned, server just create a link between the instance and the template
- * This link is stored in <B>_template</B><BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Set the _template of the L2Character </li>
- * <li>Set _overloaded to false (the charcater can take more items)</li><BR><BR>
- *
- * <li>If L2Character is a L2NPCInstance, copy skills from template to object</li>
- * <li>If L2Character is a L2NPCInstance, link _calculators to NPC_STD_CALCULATOR</li><BR><BR>
- *
- * <li>If L2Character is NOT a L2NPCInstance, create an empty _skills slot</li>
- * <li>If L2Character is a L2PcInstance or L2Summon, copy basic Calculator set to object</li><BR><BR>
- *
- * @param objectId Identifier of the object to initialized
- * @param template The L2CharTemplate to apply to the object
- */
- public L2Character(int objectId, L2CharTemplate template)
- {
- super(objectId);
- getKnownList();
- // Set its template to the new L2Character
- _template = template;
- if (template != null && this instanceof L2NpcInstance)
- {
- // Copy the Standard Calcultors of the L2NPCInstance in _calculators
- _calculators = NPC_STD_CALCULATOR;
- // Copy the skills of the L2NPCInstance from its template to the L2Character Instance
- // The skills list can be affected by spell effects so it's necessary to make a copy
- // to avoid that a spell affecting a L2NPCInstance, affects others L2NPCInstance of the same type too.
- _skills = ((L2NpcTemplate)template).getSkills();
- if (_skills != null)
- {
- for(Map.Entry<Integer, L2Skill> skill : _skills.entrySet())
- addStatFuncs(skill.getValue().getStatFuncs(null, this));
- }
- }
- else
- {
- // Initialize the FastMap _skills to null
- _skills = new FastMap<Integer,L2Skill>().setShared(true);
- // If L2Character is a L2PcInstance or a L2Summon, create the basic calculator set
- _calculators = new Calculator[Stats.NUM_STATS];
- Formulas.getInstance().addFuncsToNewCharacter(this);
- }
- if (!(this instanceof L2PcInstance) && !(this instanceof L2MonsterInstance) &&
- !(this instanceof L2GuardInstance) && !(this instanceof L2SiegeGuardInstance) &&
- !(this instanceof L2ControlTowerInstance) && !(this instanceof L2DoorInstance) &&
- !(this instanceof L2TrapInstance) && !(this instanceof L2FriendlyMobInstance) &&
- !(this instanceof L2DecoyInstance) && !(this instanceof L2SiegeSummonInstance) &&
- !(this instanceof L2PetInstance) && !(this instanceof L2SummonInstance) &&
- !(this instanceof L2SiegeFlagInstance) && !(this instanceof L2EffectPointInstance) &&
- !(this instanceof L2CommanderInstance))
- setIsInvul(true);
- }
- protected void initCharStatusUpdateValues()
- {
- _hpUpdateInterval = getMaxHp()/352.0; // MAX_HP div MAX_HP_BAR_PX
- _hpUpdateIncCheck = getMaxHp();
- _hpUpdateDecCheck = getMaxHp()-_hpUpdateInterval;
- }
- // =========================================================
- // Event - Public
- /**
- * Remove the L2Character from the world when the decay task is launched.<BR><BR>
- *
- * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T REMOVE the object from _allObjects of L2World </B></FONT><BR>
- * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T SEND Server->Client packets to players</B></FONT><BR><BR>
- *
- */
- public void onDecay()
- {
- L2WorldRegion reg = getWorldRegion();
- decayMe();
- if(reg != null) reg.removeFromZones(this);
-
- }
- @Override
- public void onSpawn()
- {
- super.onSpawn();
- this.revalidateZone();
- }
- public void onTeleported()
- {
- if (!isTeleporting())
- return;
-
- spawnMe(getPosition().getX(), getPosition().getY(), getPosition().getZ());
- setIsTeleporting(false);
-
- if (_isPendingRevive) doRevive();
- // Modify the position of the pet if necessary
- if(getPet() != null)
- {
- getPet().setFollowStatus(false);
- getPet().teleToLocation(getPosition().getX() + Rnd.get(-100,100), getPosition().getY() + Rnd.get(-100,100), getPosition().getZ(), false);
- getPet().setFollowStatus(true);
- getPet().broadcastPacket(new PetInfo(getPet()));
- getPet().updateEffectIcons(true);
- }
- }
- // =========================================================
- // Method - Public
- /**
- * Add L2Character instance that is attacking to the attacker list.<BR><BR>
- * @param player The L2Character that attcks this one
- */
- public void addAttackerToAttackByList (L2Character player)
- {
- if (player == null || player == this || getAttackByList() == null || getAttackByList().contains(player)) return;
- getAttackByList().add(player);
- }
- /**
- * Send a packet to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * L2PcInstance in the detection area of the L2Character are identified in <B>_knownPlayers</B>.
- * 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>
- *
- */
- public final void broadcastPacket(L2GameServerPacket mov)
- {
- if (!(mov instanceof CharInfo))
- sendPacket(mov);
- //if (Config.DEBUG) _log.fine("players to notify:" + knownPlayers.size() + " packet:"+mov.getType());
- for (L2PcInstance player : getKnownList().getKnownPlayers().values())
- {
- try
- {
- player.sendPacket(mov);
- if (mov instanceof CharInfo && this instanceof L2PcInstance) {
- int relation = ((L2PcInstance)this).getRelation(player);
- if (getKnownList().getKnownRelations().get(player.getObjectId()) != null && getKnownList().getKnownRelations().get(player.getObjectId()) != relation)
- player.sendPacket(new RelationChanged((L2PcInstance)this, relation, player.isAutoAttackable(this)));
- }
- //if(Config.DEVELOPER && !isInsideRadius(player, 3500, false, false)) _log.warning("broadcastPacket: Too far player see event!");
- } catch (NullPointerException e) { }
- }
- }
- /**
- * Send a packet to the L2Character AND to all L2PcInstance in the radius (max knownlist radius) from the L2Character.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * L2PcInstance in the detection area of the L2Character are identified in <B>_knownPlayers</B>.
- * 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>
- *
- */
- public final void broadcastPacket(L2GameServerPacket mov, int radiusInKnownlist)
- {
- if (!(mov instanceof CharInfo))
- sendPacket(mov);
- //if (Config.DEBUG) _log.fine("players to notify:" + knownPlayers.size() + " packet:"+mov.getType());
- for (L2PcInstance player : getKnownList().getKnownPlayers().values())
- {
- try
- {
- if (!isInsideRadius(player, radiusInKnownlist, false, false)) continue;
- player.sendPacket(mov);
- if (mov instanceof CharInfo && this instanceof L2PcInstance) {
- int relation = ((L2PcInstance)this).getRelation(player);
- if (getKnownList().getKnownRelations().get(player.getObjectId()) != null && getKnownList().getKnownRelations().get(player.getObjectId()) != relation)
- player.sendPacket(new RelationChanged((L2PcInstance)this, relation, player.isAutoAttackable(this)));
- }
- } catch (NullPointerException e) {}
- }
- }
- /**
- * Returns true if hp update should be done, false if not
- * @return boolean
- */
- protected boolean needHpUpdate(int barPixels)
- {
- double currentHp = getCurrentHp();
- if (currentHp <= 1.0 || getMaxHp() < barPixels)
- return true;
- if (currentHp <= _hpUpdateDecCheck || currentHp >= _hpUpdateIncCheck)
- {
- if (currentHp == getMaxHp())
- {
- _hpUpdateIncCheck = currentHp + 1;
- _hpUpdateDecCheck = currentHp - _hpUpdateInterval;
- }
- else
- {
- double doubleMulti = currentHp / _hpUpdateInterval;
- int intMulti = (int)doubleMulti;
- _hpUpdateDecCheck = _hpUpdateInterval * (doubleMulti < intMulti ? intMulti-- : intMulti);
- _hpUpdateIncCheck = _hpUpdateDecCheck + _hpUpdateInterval;
- }
- return true;
- }
- return false;
- }
- /**
- * Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Create the Server->Client packet StatusUpdate with current HP and MP </li>
- * <li>Send the Server->Client packet StatusUpdate with current HP and MP to all
- * L2Character called _statusListener that must be informed of HP/MP updates of this L2Character </li><BR><BR>
- *
- * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T SEND CP information</B></FONT><BR><BR>
- *
- * <B><U> Overriden in </U> :</B><BR><BR>
- * <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>
- *
- */
- public void broadcastStatusUpdate()
- {
- if (getStatus().getStatusListener().isEmpty()) return;
- if (!needHpUpdate(352))
- return;
- if (Config.DEBUG)
- _log.fine("Broadcast Status Update for " + getObjectId() + "(" + getName() + "). HP: " + getCurrentHp());
- // Create the Server->Client packet StatusUpdate with current HP and MP
- StatusUpdate su = new StatusUpdate(getObjectId());
- su.addAttribute(StatusUpdate.CUR_HP, (int)getCurrentHp());
- su.addAttribute(StatusUpdate.CUR_MP, (int)getCurrentMp());
- // Go through the StatusListener
- // Send the Server->Client packet StatusUpdate with current HP and MP
- synchronized (getStatus().getStatusListener())
- {
- for (L2Character temp : getStatus().getStatusListener())
- {
- try { temp.sendPacket(su); } catch (NullPointerException e) {}
- }
- }
- }
- /**
- * Not Implemented.<BR><BR>
- *
- * <B><U> Overriden in </U> :</B><BR><BR>
- * <li> L2PcInstance</li><BR><BR>
- */
- public void sendPacket(@SuppressWarnings("unused") L2GameServerPacket mov)
- {
- // default implementation
- }
- /**
- * Teleport a L2Character and its pet if necessary.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Stop the movement of the L2Character</li>
- * <li>Set the x,y,z position of the L2Object and if necessary modify its _worldRegion</li>
- * <li>Send a Server->Client packet TeleportToLocationt to the L2Character AND to all L2PcInstance in its _KnownPlayers</li>
- * <li>Modify the position of the pet if necessary</li><BR><BR>
- *
- */
- public void teleToLocation(int x, int y, int z, boolean allowRandomOffset)
- {
- // Stop movement
- stopMove(null, false);
- abortAttack();
- abortCast();
- setIsTeleporting(true);
- setTarget(null);
- getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
- if (Config.RESPAWN_RANDOM_ENABLED && allowRandomOffset)
- {
- x += Rnd.get(-Config.RESPAWN_RANDOM_MAX_OFFSET, Config.RESPAWN_RANDOM_MAX_OFFSET);
- y += Rnd.get(-Config.RESPAWN_RANDOM_MAX_OFFSET, Config.RESPAWN_RANDOM_MAX_OFFSET);
- }
- z += 5;
- if (Config.DEBUG)
- _log.fine("Teleporting to: " + x + ", " + y + ", " + z);
- // remove the object from its old location
- decayMe();
-
- // Send a Server->Client packet TeleportToLocationt to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
- broadcastPacket(new TeleportToLocation(this, x, y, z));
- // Set the x,y,z position of the L2Object and if necessary modify its _worldRegion
- getPosition().setXYZ(x, y, z);
- if (!(this instanceof L2PcInstance))
- onTeleported();
- }
- public void teleToLocation(int x, int y, int z) { teleToLocation(x, y, z, false); }
- public void teleToLocation(Location loc, boolean allowRandomOffset)
- {
- int x = loc.getX();
- int y = loc.getY();
- int z = loc.getZ();
- if (this instanceof L2PcInstance && DimensionalRiftManager.getInstance().checkIfInRiftZone(getX(), getY(), getZ(), true)) // true -> ignore waiting room :)
- {
- L2PcInstance player = (L2PcInstance)this;
- player.sendMessage("You have been sent to the waiting room.");
- if(player.isInParty() && player.getParty().isInDimensionalRift())
- {
- player.getParty().getDimensionalRift().usedTeleport(player);
- }
- int[] newCoords = DimensionalRiftManager.getInstance().getRoom((byte) 0, (byte) 0).getTeleportCoords();
- x = newCoords[0];
- y = newCoords[1];
- z = newCoords[2];
- }
- teleToLocation(x, y, z, allowRandomOffset);
- }
- public void teleToLocation(TeleportWhereType teleportWhere) { teleToLocation(MapRegionTable.getInstance().getTeleToLocation(this, teleportWhere), true); }
- // =========================================================
- // Method - Private
- /**
- * Launch a physical attack against a target (Simple, Bow, Pole or Dual).<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Get the active weapon (always equiped in the right hand) </li><BR><BR>
- * <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>
- * <li>If weapon is a bow, consume MP and set the new period of bow non re-use </li><BR><BR>
- * <li>Get the Attack Speed of the L2Character (delay (in milliseconds) before next attack) </li>
- * <li>Select the type of attack to start (Simple, Bow, Pole or Dual) and verify if SoulShot are charged then start calculation</li>
- * <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>
- * <li>Notify AI with EVT_READY_TO_ACT</li><BR><BR>
- *
- * @param target The L2Character targeted
- *
- */
- protected void doAttack(L2Character target)
- {
- if (Config.DEBUG)
- _log.fine(getName()+" doAttack: target="+target);
- if (isAlikeDead() || target == null || (this instanceof L2NpcInstance && target.isAlikeDead())
- || (this instanceof L2PcInstance && target.isDead() && !target.isFakeDeath())
- || !getKnownList().knowsObject(target)
- || (this instanceof L2PcInstance && isDead())
- || (target instanceof L2PcInstance && ((L2PcInstance)target).getDuelState() == Duel.DUELSTATE_DEAD))
- {
- // If L2PcInstance is dead or the target is dead, the action is stoped
- getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- if (isAttackingDisabled())
- return;
- if (this instanceof L2PcInstance)
- {
- if (((L2PcInstance)this).inObserverMode())
- {
- sendPacket(new SystemMessage(SystemMessageId.OBSERVERS_CANNOT_PARTICIPATE));
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- if (target instanceof L2PcInstance)
- {
- if (((L2PcInstance)target).isCursedWeaponEquipped() && ((L2PcInstance)this).getLevel()<=20){
- ((L2PcInstance)this).sendMessage("Can't attack a cursed player when under level 21.");
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- if (((L2PcInstance)this).isCursedWeaponEquipped() && ((L2PcInstance)target).getLevel()<=20){
- ((L2PcInstance)this).sendMessage("Can't attack a newbie player using a cursed weapon.");
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- }
- // Checking if target has moved to peace zone
- if (target.isInsidePeaceZone((L2PcInstance)this))
- {
- getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- }
- else if (isInsidePeaceZone(this, target))
- {
- getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- // Get the active weapon instance (always equiped in the right hand)
- L2ItemInstance weaponInst = getActiveWeaponInstance();
- // Get the active weapon item corresponding to the active weapon instance (always equiped in the right hand)
- L2Weapon weaponItem = getActiveWeaponItem();
- if (weaponItem != null && weaponItem.getItemType() == L2WeaponType.ROD)
- {
- // You can't make an attack with a fishing pole.
- ((L2PcInstance)this).sendPacket(new SystemMessage(SystemMessageId.CANNOT_ATTACK_WITH_FISHING_POLE));
- getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
- ActionFailed af = ActionFailed.STATIC_PACKET;
- sendPacket(af);
- return;
- }
- // GeoData Los Check here (or dz > 1000)
- if (!GeoData.getInstance().canSeeTarget(this, target))
- {
- sendPacket(new SystemMessage(SystemMessageId.CANT_SEE_TARGET));
- getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- // Check for a bow
- if ((weaponItem != null && weaponItem.getItemType() == L2WeaponType.BOW && !charIsTransformed()))
- {
- //Check for arrows and MP
- if (this instanceof L2PcInstance)
- {
- // Verify if the bow can be use
- if (_disableBowAttackEndTime <= GameTimeController.getGameTicks())
- {
- // Verify if L2PcInstance owns enough MP
- int saMpConsume = (int)getStat().calcStat(Stats.MP_CONSUME, 0, null, null);
- int mpConsume = saMpConsume == 0 ? weaponItem.getMpConsume() : saMpConsume;
- if (getCurrentMp() < mpConsume)
- {
- // If L2PcInstance doesn't have enough MP, stop the attack
- ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_READY_TO_ACT), 1000);
- sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_MP));
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- // If L2PcInstance have enough MP, the bow consummes it
- getStatus().reduceMp(mpConsume);
- // Set the period of bow non re-use
- _disableBowAttackEndTime = 5 * GameTimeController.TICKS_PER_SECOND + GameTimeController.getGameTicks();
- }
- else
- {
- // Cancel the action because the bow can't be re-use at this moment
- ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_READY_TO_ACT), 1000);
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- // Equip arrows needed in left hand and send a Server->Client packet ItemList to the L2PcINstance then return True
- if (!checkAndEquipArrows())
- {
- // Cancel the action because the L2PcInstance have no arrow
- getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
- sendPacket(ActionFailed.STATIC_PACKET);
- sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_ARROWS));
- return;
- }
- }
- }
- // Check for a crossbow
- if ((weaponItem != null && weaponItem.getItemType() == L2WeaponType.CROSSBOW && !charIsTransformed()))
- {
- //Check for bolts
- if (this instanceof L2PcInstance)
- {
- // Checking if target has moved to peace zone - only for player-crossbow attacks at the moment
- // Other melee is checked in movement code and for offensive spells a check is done every time
- if (target.isInsidePeaceZone((L2PcInstance)this))
- {
- getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- // Verify if the crossbow can be use
- if (_disableCrossBowAttackEndTime <= GameTimeController.getGameTicks())
- {
- // Set the period of bow non re-use
- _disableCrossBowAttackEndTime = 5 * GameTimeController.TICKS_PER_SECOND + GameTimeController.getGameTicks();
- }
- else
- {
- // Cancel the action because the crossbow can't be re-use at this moment
- ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_READY_TO_ACT), 1000);
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- // Equip bolts needed in left hand and send a Server->Client packet ItemList to the L2PcINstance then return True
- if (!checkAndEquipBolts())
- {
- // Cancel the action because the L2PcInstance have no arrow
- getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
- sendPacket(ActionFailed.STATIC_PACKET);
- sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_BOLTS));
- return;
- }
- }
- else if (this instanceof L2NpcInstance)
- {
- if (_disableCrossBowAttackEndTime > GameTimeController.getGameTicks())
- return;
- }
- }
- // Add the L2PcInstance to _knownObjects and _knownPlayer of the target
- target.getKnownList().addKnownObject(this);
- // Reduce the current CP if TIREDNESS configuration is activated
- if (Config.ALT_GAME_TIREDNESS)
- setCurrentCp(getCurrentCp() - 10);
- // Recharge any active auto soulshot tasks for player (or player's summon if one exists).
- if (this instanceof L2PcInstance)
- ((L2PcInstance)this).rechargeAutoSoulShot(true, false, false);
- else if (this instanceof L2Summon)
- ((L2Summon)this).getOwner().rechargeAutoSoulShot(true, false, true);
- // Verify if soulshots are charged.
- boolean wasSSCharged;
- if (this instanceof L2NpcInstance)
- wasSSCharged = ((L2NpcInstance)this).rechargeAutoSoulShot(true, false);
- else if (this instanceof L2Summon && !(this instanceof L2PetInstance))
- wasSSCharged = (((L2Summon)this).getChargedSoulShot() != L2ItemInstance.CHARGED_NONE);
- else
- wasSSCharged = (weaponInst != null && weaponInst.getChargedSoulshot() != L2ItemInstance.CHARGED_NONE);
- // Get the Attack Speed of the L2Character (delay (in milliseconds) before next attack)
- int timeAtk = calculateTimeBetweenAttacks(target, weaponItem);
- // the hit is calculated to happen halfway to the animation - might need further tuning e.g. in bow case
- int timeToHit = timeAtk/2;
- _attackEndTime = GameTimeController.getGameTicks();
- _attackEndTime += (timeAtk / GameTimeController.MILLIS_IN_TICK);
- _attackEndTime -= 1;
- int ssGrade = 0;
- if (weaponItem != null)
- {
- ssGrade = weaponItem.getCrystalType();
- if (ssGrade == 6)
- ssGrade = 5;
- }
-
- // Create a Server->Client packet Attack
- Attack attack = new Attack(this, wasSSCharged, ssGrade);
- boolean hitted;
- // Set the Attacking Body part to CHEST
- setAttackingBodypart();
- // Make sure that char is facing selected target
- // also works: setHeading(Util.convertDegreeToClientHeading(Util.calculateAngleFrom(this, target)));
- setHeading(Util.calculateHeadingFrom(this, target));
-
- // Get the Attack Reuse Delay of the L2Weapon
- int reuse = calculateReuseTime(target, weaponItem);
- // Select the type of attack to start
- if (weaponItem == null || charIsTransformed())
- hitted = doAttackHitSimple(attack, target, timeToHit);
- else if (weaponItem.getItemType() == L2WeaponType.BOW)
- hitted = doAttackHitByBow(attack, target, timeAtk, reuse);
- else if (weaponItem.getItemType() == L2WeaponType.CROSSBOW)
- hitted = doAttackHitByCrossBow(attack, target, timeAtk, reuse);
- else if (weaponItem.getItemType() == L2WeaponType.POLE)
- hitted = doAttackHitByPole(attack, target, timeToHit);
- else if (isUsingDualWeapon())
- hitted = doAttackHitByDual(attack, target, timeToHit);
- else
- hitted = doAttackHitSimple(attack, target, timeToHit);
- // Flag the attacker if it's a L2PcInstance outside a PvP area
- L2PcInstance player = null;
- if (this instanceof L2PcInstance)
- player = (L2PcInstance)this;
- else if (this instanceof L2Summon)
- player = ((L2Summon)this).getOwner();
- else if (this instanceof L2Trap)
- player = ((L2Trap)this).getOwner();
- if (player != null)
- player.updatePvPStatus(target);
- // Check if hit isn't missed
- if (!hitted)
- // Abort the attack of the L2Character and send Server->Client ActionFailed packet
- abortAttack();
- else
- {
- /* ADDED BY nexus - 2006-08-17
- *
- * As soon as we know that our hit landed, we must discharge any active soulshots.
- * This must be done so to avoid unwanted soulshot consumption.
- */
- // If we didn't miss the hit, discharge the shoulshots, if any
- if (this instanceof L2Summon && !(this instanceof L2PetInstance))
- ((L2Summon)this).setChargedSoulShot(L2ItemInstance.CHARGED_NONE);
- else
- if (weaponInst != null)
- weaponInst.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
- if (player != null)
- {
- if (player.isCursedWeaponEquipped())
- {
- // If hitted by a cursed weapon, Cp is reduced to 0
- if (!target.isInvul())
- target.setCurrentCp(0);
- } else if (player.isHero())
- {
- if (target instanceof L2PcInstance && ((L2PcInstance)target).isCursedWeaponEquipped())
- // If a cursed weapon is hitted by a Hero, Cp is reduced to 0
- target.setCurrentCp(0);
- }
- }
- }
- // 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
- if (attack.hasHits())
- broadcastPacket(attack);
- // Notify AI with EVT_READY_TO_ACT
- ThreadPoolManager.getInstance().scheduleAi(new NotifyAITask(CtrlEvent.EVT_READY_TO_ACT), timeAtk+reuse);
- }
- /**
- * Launch a Bow attack.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Calculate if hit is missed or not </li>
- * <li>Consumme arrows </li>
- * <li>If hit isn't missed, calculate if shield defense is efficient </li>
- * <li>If hit isn't missed, calculate if hit is critical </li>
- * <li>If hit isn't missed, calculate physical damages </li>
- * <li>If the L2Character is a L2PcInstance, Send a Server->Client packet SetupGauge </li>
- * <li>Create a new hit task with Medium priority</li>
- * <li>Calculate and set the disable delay of the bow in function of the Attack Speed</li>
- * <li>Add this hit to the Server-Client packet Attack </li><BR><BR>
- *
- * @param attack Server->Client packet Attack in which the hit will be added
- * @param target The L2Character targeted
- * @param sAtk The Attack Speed of the attacker
- *
- * @return True if the hit isn't missed
- *
- */
- private boolean doAttackHitByBow(Attack attack, L2Character target, int sAtk, int reuse)
- {
- int damage1 = 0;
- boolean shld1 = false;
- boolean crit1 = false;
- // Calculate if hit is missed or not
- boolean miss1 = Formulas.getInstance().calcHitMiss(this, target);
- // Consumme arrows
- reduceArrowCount(false);
- _move = null;
- // Check if hit isn't missed
- if (!miss1)
- {
- // Calculate if shield defense is efficient
- shld1 = Formulas.getInstance().calcShldUse(this, target);
- // Calculate if hit is critical
- crit1 = Formulas.getInstance().calcCrit(getStat().getCriticalHit(target, null));
- // Calculate physical damages
- damage1 = (int)Formulas.getInstance().calcPhysDam(this, target, null, shld1, crit1, false, attack.soulshot);
- }
- // Check if the L2Character is a L2PcInstance
- if (this instanceof L2PcInstance)
- {
- // Send a system message
- sendPacket(new SystemMessage(SystemMessageId.GETTING_READY_TO_SHOOT_AN_ARROW));
- // Send a Server->Client packet SetupGauge
- SetupGauge sg = new SetupGauge(SetupGauge.RED, sAtk+reuse);
- sendPacket(sg);
- }
- // Create a new hit task with Medium priority
- ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk);
- // Calculate and set the disable delay of the bow in function of the Attack Speed
- _disableBowAttackEndTime = (sAtk+reuse)/GameTimeController.MILLIS_IN_TICK + GameTimeController.getGameTicks();
- // Add this hit to the Server-Client packet Attack
- attack.addHit(target, damage1, miss1, crit1, shld1);
- // Return true if hit isn't missed
- return !miss1;
- }
- /**
- * Launch a CrossBow attack.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Calculate if hit is missed or not </li>
- * <li>Consumme bolts </li>
- * <li>If hit isn't missed, calculate if shield defense is efficient </li>
- * <li>If hit isn't missed, calculate if hit is critical </li>
- * <li>If hit isn't missed, calculate physical damages </li>
- * <li>If the L2Character is a L2PcInstance, Send a Server->Client packet SetupGauge </li>
- * <li>Create a new hit task with Medium priority</li>
- * <li>Calculate and set the disable delay of the crossbow in function of the Attack Speed</li>
- * <li>Add this hit to the Server-Client packet Attack </li><BR><BR>
- *
- * @param attack Server->Client packet Attack in which the hit will be added
- * @param target The L2Character targeted
- * @param sAtk The Attack Speed of the attacker
- *
- * @return True if the hit isn't missed
- *
- */
- private boolean doAttackHitByCrossBow(Attack attack, L2Character target, int sAtk, int reuse)
- {
- int damage1 = 0;
- boolean shld1 = false;
- boolean crit1 = false;
- // Calculate if hit is missed or not
- boolean miss1 = Formulas.getInstance().calcHitMiss(this, target);
- // Consume bolts
- reduceArrowCount(true);
- _move = null;
- // Check if hit isn't missed
- if (!miss1)
- {
- // Calculate if shield defense is efficient
- shld1 = Formulas.getInstance().calcShldUse(this, target);
- // Calculate if hit is critical
- crit1 = Formulas.getInstance().calcCrit(getStat().getCriticalHit(target, null));
- // Calculate physical damages
- damage1 = (int)Formulas.getInstance().calcPhysDam(this, target, null, shld1, crit1, false, attack.soulshot);
- }
- // Check if the L2Character is a L2PcInstance
- if (this instanceof L2PcInstance)
- {
- // Send a system message
- sendPacket(new SystemMessage(SystemMessageId.CROSSBOW_PREPARING_TO_FIRE));
- // Send a Server->Client packet SetupGauge
- SetupGauge sg = new SetupGauge(SetupGauge.RED, sAtk+reuse);
- sendPacket(sg);
- }
- // Create a new hit task with Medium priority
- ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk);
- // Calculate and set the disable delay of the bow in function of the Attack Speed
- _disableCrossBowAttackEndTime = (sAtk+reuse)/GameTimeController.MILLIS_IN_TICK + GameTimeController.getGameTicks();
- // Add this hit to the Server-Client packet Attack
- attack.addHit(target, damage1, miss1, crit1, shld1);
- // Return true if hit isn't missed
- return !miss1;
- }
- /**
- * Launch a Dual attack.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Calculate if hits are missed or not </li>
- * <li>If hits aren't missed, calculate if shield defense is efficient </li>
- * <li>If hits aren't missed, calculate if hit is critical </li>
- * <li>If hits aren't missed, calculate physical damages </li>
- * <li>Create 2 new hit tasks with Medium priority</li>
- * <li>Add those hits to the Server-Client packet Attack </li><BR><BR>
- *
- * @param attack Server->Client packet Attack in which the hit will be added
- * @param target The L2Character targeted
- *
- * @return True if hit 1 or hit 2 isn't missed
- *
- */
- private boolean doAttackHitByDual(Attack attack, L2Character target, int sAtk)
- {
- int damage1 = 0;
- int damage2 = 0;
- boolean shld1 = false;
- boolean shld2 = false;
- boolean crit1 = false;
- boolean crit2 = false;
- // Calculate if hits are missed or not
- boolean miss1 = Formulas.getInstance().calcHitMiss(this, target);
- boolean miss2 = Formulas.getInstance().calcHitMiss(this, target);
- // Check if hit 1 isn't missed
- if (!miss1)
- {
- // Calculate if shield defense is efficient against hit 1
- shld1 = Formulas.getInstance().calcShldUse(this, target);
- // Calculate if hit 1 is critical
- crit1 = Formulas.getInstance().calcCrit(getStat().getCriticalHit(target, null));
- // Calculate physical damages of hit 1
- damage1 = (int)Formulas.getInstance().calcPhysDam(this, target, null, shld1, crit1, true, attack.soulshot);
- damage1 /= 2;
- }
- // Check if hit 2 isn't missed
- if (!miss2)
- {
- // Calculate if shield defense is efficient against hit 2
- shld2 = Formulas.getInstance().calcShldUse(this, target);
- // Calculate if hit 2 is critical
- crit2 = Formulas.getInstance().calcCrit(getStat().getCriticalHit(target, null));
- // Calculate physical damages of hit 2
- damage2 = (int)Formulas.getInstance().calcPhysDam(this, target, null, shld2, crit2, true, attack.soulshot);
- damage2 /= 2;
- }
- // Create a new hit task with Medium priority for hit 1
- ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk/2);
- // Create a new hit task with Medium priority for hit 2 with a higher delay
- ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage2, crit2, miss2, attack.soulshot, shld2), sAtk);
- // Add those hits to the Server-Client packet Attack
- attack.addHit(target, damage1, miss1, crit1, shld1);
- attack.addHit(target, damage2, miss2, crit2, shld2);
- // Return true if hit 1 or hit 2 isn't missed
- return (!miss1 || !miss2);
- }
- /**
- * Launch a Pole attack.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Get all visible objects in a spheric area near the L2Character to obtain possible targets </li>
- * <li>If possible target is the L2Character targeted, launch a simple attack against it </li>
- * <li>If possible target isn't the L2Character targeted but is attakable, launch a simple attack against it </li><BR><BR>
- *
- * @param attack Server->Client packet Attack in which the hit will be added
- *
- * @return True if one hit isn't missed
- *
- */
- private boolean doAttackHitByPole(Attack attack, L2Character target, int sAtk)
- {
- double angleChar;
- int maxRadius = getPhysicalAttackRange();
- int maxAngleDiff = (int)getStat().calcStat(Stats.POWER_ATTACK_ANGLE, 120, null, null);
- if (Config.DEBUG)
- {
- _log.info("doAttackHitByPole: Max radius = " + maxRadius);
- _log.info("doAttackHitByPole: Max angle = " + maxAngleDiff);
- }
- // o1 x: 83420 y: 148158 (Giran)
- // o2 x: 83379 y: 148081 (Giran)
- // dx = -41
- // dy = -77
- // distance between o1 and o2 = 87.24
- // arctan2 = -120 (240) degree (excel arctan2(dx, dy); java arctan2(dy, dx))
- //
- // o2
- //
- // o1 ----- (heading)
- // In the diagram above:
- // o1 has a heading of 0/360 degree from horizontal (facing East)
- // Degree of o2 in respect to o1 = -120 (240) degree
- //
- // o2 / (heading)
- // /
- // o1
- // In the diagram above
- // o1 has a heading of -80 (280) degree from horizontal (facing north east)
- // Degree of o2 in respect to 01 = -40 (320) degree
- // Get char's heading degree
- angleChar = Util.convertHeadingToDegree(getHeading());
- int attackRandomCountMax = (int)getStat().calcStat(Stats.ATTACK_COUNT_MAX, 3, null, null) - 1;
- int attackcount = 0;
- if (angleChar <= 0)
- angleChar += 360;
- // ===========================================================
- boolean hitted = doAttackHitSimple(attack, target, 100, sAtk);
- double attackpercent = 85;
- L2Character temp;
- for (L2Object obj : getKnownList().getKnownObjects().values())
- {
- if (obj == target) continue; // do not hit twice
- //Check if the L2Object is a L2Character
- if(obj instanceof L2Character)
- {
- if (obj instanceof L2PetInstance &&
- this instanceof L2PcInstance &&
- ((L2PetInstance)obj).getOwner() == ((L2PcInstance)this)) continue;
- if (!Util.checkIfInRange(maxRadius, this, obj, false)) continue;
- //otherwise hit too high/low. 650 because mob z coord sometimes wrong on hills
- if(Math.abs(obj.getZ() - getZ()) > 650) continue;
- if (!isFacing(obj, maxAngleDiff)) continue;
- temp = (L2Character) obj;
- // Launch a simple attack against the L2Character targeted
- if(!temp.isAlikeDead())
- {
- attackcount += 1;
- if (attackcount <= attackRandomCountMax)
- {
- if (temp == getAI().getAttackTarget() || temp.isAutoAttackable(this))
- {
- hitted |= doAttackHitSimple(attack, temp, attackpercent, sAtk);
- attackpercent /= 1.15;
- }
- }
- }
- }
- }
- // Return true if one hit isn't missed
- return hitted;
- }
- /**
- * Launch a simple attack.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Calculate if hit is missed or not </li>
- * <li>If hit isn't missed, calculate if shield defense is efficient </li>
- * <li>If hit isn't missed, calculate if hit is critical </li>
- * <li>If hit isn't missed, calculate physical damages </li>
- * <li>Create a new hit task with Medium priority</li>
- * <li>Add this hit to the Server-Client packet Attack </li><BR><BR>
- *
- * @param attack Server->Client packet Attack in which the hit will be added
- * @param target The L2Character targeted
- *
- * @return True if the hit isn't missed
- *
- */
- private boolean doAttackHitSimple(Attack attack, L2Character target, int sAtk)
- {
- return doAttackHitSimple(attack, target, 100, sAtk);
- }
- private boolean doAttackHitSimple(Attack attack, L2Character target, double attackpercent, int sAtk)
- {
- int damage1 = 0;
- boolean shld1 = false;
- boolean crit1 = false;
- // Calculate if hit is missed or not
- boolean miss1 = Formulas.getInstance().calcHitMiss(this, target);
- // Check if hit isn't missed
- if (!miss1)
- {
- // Calculate if shield defense is efficient
- shld1 = Formulas.getInstance().calcShldUse(this, target);
- // Calculate if hit is critical
- crit1 = Formulas.getInstance().calcCrit(getStat().getCriticalHit(target, null));
- // Calculate physical damages
- damage1 = (int)Formulas.getInstance().calcPhysDam(this, target, null, shld1, crit1, false, attack.soulshot);
- if (attackpercent != 100)
- damage1 = (int)(damage1*attackpercent/100);
- }
- // Create a new hit task with Medium priority
- ThreadPoolManager.getInstance().scheduleAi(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk);
- // Add this hit to the Server-Client packet Attack
- attack.addHit(target, damage1, miss1, crit1, shld1);
- // Return true if hit isn't missed
- return !miss1;
- }
- /**
- * Manage the casting task (casting and interrupt time, re-use delay...) and display the casting bar and animation on client.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Verify the possibilty of the the cast : skill is a spell, caster isn't muted... </li>
- * <li>Get the list of all targets (ex : area effects) and define the L2Charcater targeted (its stats will be used in calculation)</li>
- * <li>Calculate the casting time (base + modifier of MAtkSpd), interrupt time and re-use delay</li>
- * <li>Send a Server->Client packet MagicSkillUser (to diplay casting animation), a packet SetupGauge (to display casting bar) and a system message </li>
- * <li>Disable all skills during the casting time (create a task EnableAllSkills)</li>
- * <li>Disable the skill during the re-use delay (create a task EnableSkill)</li>
- * <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>
- *
- * @param skill The L2Skill to use
- *
- */
- public void doCast(L2Skill skill)
- {
- if (skill == null)
- {
- getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
- return;
- }
- if (isSkillDisabled(skill.getId()))
- {
- if (this instanceof L2PcInstance)
- {
- SystemMessage sm = new SystemMessage(SystemMessageId.S1_PREPARED_FOR_REUSE);
- sm.addSkillName(skill.getId(),skill.getLevel());
- sendPacket(sm);
- }
- return;
- }
-
- switch (skill.getSkillType())
- {
- case SUMMON_TRAP:
- {
- if (isInsideZone(ZONE_PEACE))
- {
- if (this instanceof L2PcInstance)
- ((L2PcInstance)this).sendPacket(new SystemMessage(SystemMessageId.A_MALICIOUS_SKILL_CANNOT_BE_USED_IN_PEACE_ZONE));
- return;
- }
- if (this instanceof L2PcInstance && ((L2PcInstance)this).getTrap() != null)
- return;
- break;
- }
- }
- // Check if the skill is a magic spell and if the L2Character is not muted
- if (skill.isMagic() && isMuted() && !skill.isPotion())
- {
- getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
- return;
- }
- // Check if the skill is physical and if the L2Character is not physical_muted
- if (!skill.isMagic() && isPhysicalMuted() && !skill.isPotion())
- {
- getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
- return;
- }
-
- // Prevent use attack
- if (isPhysicalAttackMuted() && !skill.isMagic() && !skill.isPotion())
- {
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- // Can't use Hero and resurrect skills during Olympiad
- if (this instanceof L2PcInstance && ((L2PcInstance)this).isInOlympiadMode() &&
- (skill.isHeroSkill() || skill.getSkillType() == SkillType.RESURRECT))
- {
- SystemMessage sm = new SystemMessage(SystemMessageId.THIS_SKILL_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
- sendPacket(sm);
- return;
- }
-
- // prevent casting signets to peace zone
- if (skill.getSkillType() == SkillType.SIGNET || skill.getSkillType() == SkillType.SIGNET_CASTTIME)
- {
- /*for (L2Effect effect : getAllEffects())
- {
- if (effect.getEffectType() == L2Effect.EffectType.SIGNET_EFFECT
- || effect.getEffectType() == L2Effect.EffectType.SIGNET_GROUND)
- {
- SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
- sm.addSkillName(skill.getId());
- sendPacket(sm);
- return;
- }
- }*/
-
- L2WorldRegion region = getWorldRegion();
- if (region == null) return;
- boolean canCast = true;
- if (skill.getTargetType() == SkillTargetType.TARGET_GROUND && this instanceof L2PcInstance)
- {
- Point3D wp = ((L2PcInstance) this).getCurrentSkillWorldPosition();
- if (!region.checkEffectRangeInsidePeaceZone(skill, wp.getX(), wp.getY(), wp.getZ()))
- canCast = false;
- }
- else if (!region.checkEffectRangeInsidePeaceZone(skill, getX(), getY(), getZ()))
- canCast = false;
- if (!canCast)
- {
- SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
- sm.addSkillName(skill.getId());
- sendPacket(sm);
- return;
- }
- }
- //Recharge AutoSoulShot
- if (skill.useSoulShot())
- {
- if (this instanceof L2NpcInstance)
- ((L2NpcInstance)this).rechargeAutoSoulShot(true, false);
- else if (this instanceof L2PcInstance)
- ((L2PcInstance)this).rechargeAutoSoulShot(true, false, false);
- else if (this instanceof L2Summon)
- ((L2Summon)this).getOwner().rechargeAutoSoulShot(true, false, true);
- }
- else if (skill.useSpiritShot())
- {
- if (this instanceof L2PcInstance)
- ((L2PcInstance)this).rechargeAutoSoulShot(false, true, false);
- else if (this instanceof L2Summon)
- ((L2Summon)this).getOwner().rechargeAutoSoulShot(false, true, true);
- }
- // Set the target of the skill in function of Skill Type and Target Type
- L2Character target = null;
- // Get all possible targets of the skill in a table in function of the skill target type
- L2Object[] targets = skill.getTargetList(this);
- // AURA skills should always be using caster as target
- if (skill.getTargetType() == SkillTargetType.TARGET_AURA
- || skill.getTargetType() == SkillTargetType.TARGET_FRONT_AURA
- || skill.getTargetType() == SkillTargetType.TARGET_BEHIND_AURA
- || skill.getTargetType() == SkillTargetType.TARGET_GROUND)
- {
- target = this;
- }
- else
- {
- if (targets == null || targets.length == 0)
- {
- getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
- return;
- }
-
- if( skill.getSkillType() == SkillType.BUFF ||
- skill.getSkillType() == SkillType.HEAL ||
- skill.getSkillType() == SkillType.COMBATPOINTHEAL ||
- skill.getSkillType() == SkillType.MANAHEAL ||
- skill.getSkillType() == SkillType.REFLECT ||
- skill.getTargetType() == L2Skill.SkillTargetType.TARGET_SELF ||
- skill.getTargetType() == L2Skill.SkillTargetType.TARGET_PET ||
- skill.getTargetType() == L2Skill.SkillTargetType.TARGET_PARTY ||
- skill.getTargetType() == L2Skill.SkillTargetType.TARGET_CLAN ||
- skill.getTargetType() == L2Skill.SkillTargetType.TARGET_ALLY)
- {
- target = (L2Character) targets[0];
- if (this instanceof L2PcInstance && target instanceof L2PcInstance && target.getAI().getIntention() == CtrlIntention.AI_INTENTION_ATTACK)
- {
- if(skill.getSkillType() == SkillType.BUFF || skill.getSkillType() == SkillType.HOT || skill.getSkillType() == SkillType.HEAL || skill.getSkillType() == SkillType.HEAL_PERCENT || skill.getSkillType() == SkillType.MANAHEAL || skill.getSkillType() == SkillType.MANAHEAL_PERCENT || skill.getSkillType() == SkillType.BALANCE_LIFE)
- target.setLastBuffer(this);
- if (((L2PcInstance)this).isInParty() && skill.getTargetType() == L2Skill.SkillTargetType.TARGET_PARTY)
- {
- for (L2PcInstance member : ((L2PcInstance)this).getParty().getPartyMembers())
- member.setLastBuffer(this);
- }
- }
- }
- else target = (L2Character) getTarget();
- }
- if (target == null)
- {
- getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
- return;
- }
- setLastSkillCast(skill);
- // Get the Identifier of the skill
- int magicId = skill.getId();
- // Get the Display Identifier for a skill that client can't display
- int displayId = skill.getDisplayId();
- // Get the level of the skill
- int level = skill.getLevel();
- if (level < 1)
- level = 1;
- // Get the casting time of the skill (base)
- int hitTime = skill.getHitTime();
- int coolTime = skill.getCoolTime();
- boolean effectWhileCasting = skill.getSkillType() == SkillType.FORCE_BUFF
- || skill.getSkillType() == SkillType.SIGNET_CASTTIME;
- // Calculate the casting time of the skill (base + modifier of MAtkSpd)
- // Don't modify the skill time for FORCE_BUFF skills. The skill time for those skills represent the buff time.
- if(!effectWhileCasting)
- {
- hitTime = Formulas.getInstance().calcMAtkSpd(this, skill, hitTime);
- if (coolTime > 0)
- coolTime = Formulas.getInstance().calcMAtkSpd(this, skill, coolTime);
- }
-
- // Calculate altered Cast Speed due to BSpS/SpS
- L2ItemInstance weaponInst = getActiveWeaponInstance();
- if (weaponInst != null && skill.isMagic() && !effectWhileCasting && skill.getTargetType() != SkillTargetType.TARGET_SELF)
- {
- if ((weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
- || (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT))
- {
- //Only takes 70% of the time to cast a BSpS/SpS cast
- hitTime = (int)(0.70 * hitTime);
- coolTime = (int)(0.70 * coolTime);
- //Because the following are magic skills that do not actively 'eat' BSpS/SpS,
- //I must 'eat' them here so players don't take advantage of infinite speed increase
- switch (skill.getSkillType())
- {
- case BUFF:
- case MANAHEAL:
- case RESURRECT:
- case RECALL:
- case DOT:
- weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
- break;
- }
- }
- }
- else if (this instanceof L2NpcInstance && skill.useSpiritShot() && !effectWhileCasting)
- {
- if(((L2NpcInstance)this).rechargeAutoSoulShot(false, true))
- {
- hitTime = (int)(0.70 * hitTime);
- coolTime = (int)(0.70 * coolTime);
- }
- }
- // Set the _castEndTime and _castInterruptTim. +10 ticks for lag situations, will be reseted in onMagicFinalizer
- _castEndTime = 10 + GameTimeController.getGameTicks() + (coolTime + hitTime) / GameTimeController.MILLIS_IN_TICK;
- _castInterruptTime = -2 + GameTimeController.getGameTicks() + hitTime / GameTimeController.MILLIS_IN_TICK;
-
- // Init the reuse time of the skill
- int reuseDelay;
-
- if(skill.isMagic())
- {
- reuseDelay = (int)(skill.getReuseDelay() * getStat().getMReuseRate(skill));
- }
- else
- {
- reuseDelay = (int)(skill.getReuseDelay() * getStat().getPReuseRate(skill));
- }
- reuseDelay *= 333.0 / (skill.isMagic() ? getMAtkSpd() : getPAtkSpd());
- // Skill reuse check
- if (reuseDelay > 30000) addTimeStamp(skill.getId(),reuseDelay);
- // Check if this skill consume mp on start casting
- int initmpcons = getStat().getMpInitialConsume(skill);
- if (initmpcons > 0)
- {
- StatusUpdate su = new StatusUpdate(getObjectId());
- getStatus().reduceMp(calcStat(Stats.MP_CONSUME_RATE,initmpcons,null,null));
- su.addAttribute(StatusUpdate.CUR_MP, (int) getCurrentMp());
- sendPacket(su);
- }
- // 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
- if (reuseDelay > 10)
- {
- disableSkill(skill.getId(), reuseDelay);
- }
- // Make sure that char is facing selected target
- setHeading(Util.calculateHeadingFrom(this, target));
-
- // For force buff skills, start the effect as long as the player is casting.
- if(effectWhileCasting)
- {
- // Consume Items if necessary and Send the Server->Client packet InventoryUpdate with Item modification to all the L2Character
- if (skill.getItemConsume() > 0)
- consumeItem(skill.getItemConsumeId(), skill.getItemConsume());
- // Consume Souls if necessary
- if (skill.getSoulConsumeCount() > 0)
- {
- if (this instanceof L2PcInstance)
- {
- ((L2PcInstance)this).decreaseSouls(skill.getSoulConsumeCount());
- sendPacket(new EtcStatusUpdate((L2PcInstance)this));
- }
- }
-
- if (skill.getSkillType() == SkillType.FORCE_BUFF)
- startForceBuff(target, skill);
- else
- callSkill(skill, targets);
- }
-
- // Send a Server->Client packet MagicSkillUser with target, displayId, level, skillTime, reuseDelay
- // to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
- broadcastPacket(new MagicSkillUse(this, target, displayId, level, hitTime, reuseDelay));
- // Send a system message USE_S1 to the L2Character
- if (this instanceof L2PcInstance && magicId != 1312)
- {
- SystemMessage sm = new SystemMessage(SystemMessageId.USE_S1);
- sm.addSkillName(magicId,skill.getLevel());
- sendPacket(sm);
- }
-
- // Before start AI Cast Broadcast Fly Effect is Need
- if (skill.getFlyType() != null && (this instanceof L2PcInstance))
- {
- ThreadPoolManager.getInstance().scheduleEffect(new FlyToLocationTask(this, target, skill), 50);
- }
- // launch the magic in hitTime milliseconds
- if (hitTime > 210)
- {
- // Send a Server->Client packet SetupGauge with the color of the gauge and the casting time
- if (this instanceof L2PcInstance && !effectWhileCasting)
- {
- SetupGauge sg = new SetupGauge(SetupGauge.BLUE, hitTime);
- sendPacket(sg);
- }
- // Disable all skills during the casting
- disableAllSkills();
- if (_skillCast != null)
- {
- _skillCast.cancel(true);
- _skillCast = null;
- }
- // Create a task MagicUseTask to launch the MagicSkill at the end of the casting time (hitTime)
- // For client animation reasons (party buffs especially) 200 ms before!
- if (effectWhileCasting)
- _skillCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 2), hitTime);
- else
- _skillCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 1), hitTime-200);
- }
- else
- onMagicLaunchedTimer(targets, skill, coolTime, true);
- }
- /**
- * Index according to skill id the current timestamp of use.<br><br>
- *
- * @param skill id
- * @param reuse delay
- * <BR><B>Overriden in :</B> (L2PcInstance)
- */
- public void addTimeStamp(int s, int r) {/***/}
- /**
- * Index according to skill id the current timestamp of use.<br><br>
- *
- * @param skill id
- * <BR><B>Overriden in :</B> (L2PcInstance)
- */
- public void removeTimeStamp(int s) {/***/}
- /**
- * Starts a force buff on target.<br><br>
- *
- * @param caster
- * @param force type
- * <BR><B>Overriden in :</B> (L2PcInstance)
- */
- public void startForceBuff(L2Character caster, L2Skill skill) {/***/}
- /**
- * Kill the L2Character.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Set target to null and cancel Attack or Cast </li>
- * <li>Stop movement </li>
- * <li>Stop HP/MP/CP Regeneration task </li>
- * <li>Stop all active skills effects in progress on the L2Character </li>
- * <li>Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform </li>
- * <li>Notify L2Character AI </li><BR><BR>
- *
- * <B><U> Overriden in </U> :</B><BR><BR>
- * <li> L2NpcInstance : Create a DecayTask to remove the corpse of the L2NpcInstance after 7 seconds </li>
- * <li> L2Attackable : Distribute rewards (EXP, SP, Drops...) and notify Quest Engine </li>
- * <li> L2PcInstance : Apply Death Penalty, Manage gain/loss Karma and Item Drop </li><BR><BR>
- *
- * @param killer The L2Character who killed it
- *
- */
- public boolean doDie(L2Character killer)
- {
- // killing is only possible one time
- synchronized (this)
- {
- if (isDead()) return false;
- // now reset currentHp to zero
- setCurrentHp(0);
- if (isFakeDeath()) stopFakeDeath(null);
- setIsDead(true);
- }
- // Set target to null and cancel Attack or Cast
- setTarget(null);
- // Stop movement
- stopMove(null);
- // Stop HP/MP/CP Regeneration task
- getStatus().stopHpMpRegeneration();
- // Stop all active skills effects in progress on the L2Character,
- // if the Character isn't affected by Soul of The Phoenix or Salvation
- if (this instanceof L2PlayableInstance && ((L2PlayableInstance)this).isPhoenixBlessed())
- {
- if (((L2PlayableInstance)this).getCharmOfLuck()) //remove Lucky Charm if player has SoulOfThePhoenix/Salvation buff
- ((L2PlayableInstance)this).stopCharmOfLuck(null);
- if (((L2PlayableInstance)this).isNoblesseBlessed())
- ((L2PlayableInstance)this).stopNoblesseBlessing(null);
- }
- // Same thing if the Character isn't a Noblesse Blessed L2PlayableInstance
- else if (this instanceof L2PlayableInstance && ((L2PlayableInstance)this).isNoblesseBlessed())
- {
- ((L2PlayableInstance)this).stopNoblesseBlessing(null);
- if (((L2PlayableInstance)this).getCharmOfLuck()) //remove Lucky Charm if player have Nobless blessing buff
- ((L2PlayableInstance)this).stopCharmOfLuck(null);
- }
- else
- stopAllEffects();
- if (this instanceof L2PcInstance && ((L2PcInstance)this).getAgathionId() != 0)
- ((L2PcInstance)this).setAgathionId(0);
- calculateRewards(killer);
- // Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
- broadcastStatusUpdate();
- // Notify L2Character AI
- getAI().notifyEvent(CtrlEvent.EVT_DEAD, null);
-
- if (getWorldRegion() != null)
- getWorldRegion().onDeath(this);
- // Notify Quest of character's death
- for (QuestState qs: getNotifyQuestOfDeath())
- {
- qs.getQuest().notifyDeath( (killer==null?this:killer) , this, qs);
- }
- getNotifyQuestOfDeath().clear();
- getAttackByList().clear();
- //If character is PhoenixBlessed a resurrection popup will show up
- if (this instanceof L2PlayableInstance && ((L2PlayableInstance)this).isPhoenixBlessed())
- {
- if (this instanceof L2Summon) {
- ((L2Summon)this).getOwner().reviveRequest(((L2Summon)this).getOwner(), null, true);
- }
- else ((L2PcInstance)this).reviveRequest(((L2PcInstance)this),null,false);
- }
- return true;
- }
- protected void calculateRewards(L2Character killer)
- {
- }
-
- /** Sets HP, MP and CP and revives the L2Character. */
- public void doRevive()
- {
- if (!isDead()) return;
- if (!isTeleporting())
- {
- setIsPendingRevive(false);
- setIsDead(false);
- if (this instanceof L2PlayableInstance && ((L2PlayableInstance)this).isPhoenixBlessed())
- {
- ((L2PlayableInstance)this).stopPhoenixBlessing(null);
- }
- //_status.setCurrentCp(getMaxCp() * Config.RESPAWN_RESTORE_CP);
- _status.setCurrentHp(getMaxHp() * Config.RESPAWN_RESTORE_HP);
- //_Status.setCurrentMp(getMaxMp() * Config.RESPAWN_RESTORE_MP);
-
- // Start broadcast status
- broadcastPacket(new Revive(this));
- if (getWorldRegion() != null)
- getWorldRegion().onRevive(this);
- }
- else
- setIsPendingRevive(true);
- }
- /** Revives the L2Character using skill. */
- public void doRevive(double revivePower) { doRevive(); }
- /**
- * Check if the active L2Skill can be casted.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Check if the L2Character can cast (ex : not sleeping...) </li>
- * <li>Check if the target is correct </li>
- * <li>Notify the AI with AI_INTENTION_CAST and target</li><BR><BR>
- *
- * @param skill The L2Skill to use
- *
- */
- protected void useMagic(L2Skill skill)
- {
- if (skill == null || isDead())
- return;
- // Check if the L2Character can cast
- if (isAllSkillsDisabled())
- {
- // must be checked by caller
- return;
- }
- // Ignore the passive skill request. why does the client send it anyway ??
- if (skill.isPassive())
- return;
- // Get the target for the skill
- L2Object target = null;
- switch (skill.getTargetType())
- {
- case TARGET_AURA: // AURA, SELF should be cast even if no target has been found
- case TARGET_FRONT_AURA:
- case TARGET_BEHIND_AURA:
- case TARGET_GROUND:
- case TARGET_SELF:
- target = this;
- break;
- default:
- // Get the first target of the list
- target = skill.getFirstOfTargetList(this);
- break;
- }
- // Notify the AI with AI_INTENTION_CAST and target
- getAI().setIntention(CtrlIntention.AI_INTENTION_CAST, skill, target);
- }
- // =========================================================
- // Property - Public
- /**
- * Return the L2CharacterAI of the L2Character and if its null create a new one.
- */
- public L2CharacterAI getAI()
- {
- if (_ai == null)
- {
- synchronized(this)
- {
- if (_ai == null) _ai = new L2CharacterAI(new AIAccessor());
- }
- }
- return _ai;
- }
- public void setAI(L2CharacterAI newAI)
- {
- L2CharacterAI oldAI = getAI();
- if(oldAI != null && oldAI != newAI && oldAI instanceof L2AttackableAI)
- ((L2AttackableAI)oldAI).stopAITask();
- _ai = newAI;
- }
- /** Return True if the L2Character has a L2CharacterAI. */
- public boolean hasAI() { return _ai != null; }
- /** Return True if the L2Character is RaidBoss or his minion. */
- public boolean isRaid()
- {
- return false;
- }
- /** Return a list of L2Character that attacked. */
- public final List<L2Character> getAttackByList ()
- {
- if (_attackByList == null) _attackByList = new FastList<L2Character>();
- return _attackByList;
- }
- public final L2Skill getLastSkillCast() { return _lastSkillCast; }
- public void setLastSkillCast (L2Skill skill) { _lastSkillCast = skill; }
- public final boolean isAfraid() { return _isAfraid; }
- public final void setIsAfraid(boolean value) { _isAfraid = value; }
- /** Return True if the L2Character can't use its skills (ex : stun, sleep...). */
- public final boolean isAllSkillsDisabled() { return _allSkillsDisabled || isImmobileUntilAttacked() || isStunned() || isSleeping() || isParalyzed(); }
- /** Return True if the L2Character can't attack (stun, sleep, attackEndTime, fakeDeath, paralyse, attackMute). */
- public boolean isAttackingDisabled() { return isStunned() || isImmobileUntilAttacked() || isSleeping() || _attackEndTime > GameTimeController.getGameTicks() || isFakeDeath() || isParalyzed() || isPhysicalAttackMuted(); }
- public final Calculator[] getCalculators() { return _calculators; }
- public final boolean isConfused() { return _isConfused; }
- public final void setIsConfused(boolean value) { _isConfused = value; }
- /** Return True if the L2Character is dead or use fake death. */
- public final boolean isAlikeDead() { return isFakeDeath() || _isDead; }
- /** Return True if the L2Character is dead. */
- public final boolean isDead() { return _isDead; }
- public final void setIsDead(boolean value) { _isDead = value; }
-
- public final boolean isFakeDeath() { return _isFakeDeath; }
- public final void setIsFakeDeath(boolean value) { _isFakeDeath = value; }
- /** Return True if the L2Character is flying. */
- public final boolean isFlying() { return _isFlying; }
- /** Set the L2Character flying mode to True. */
- public final void setIsFlying(boolean mode) { _isFlying = mode; }
- public boolean isImmobilized() { return _isImmobilized; }
- public void setIsImmobilized(boolean value){ _isImmobilized = value; }
- public final boolean isMuted() { return _isMuted; }
- public final void setIsMuted(boolean value) { _isMuted = value; }
- public final boolean isPhysicalMuted() { return _isPhysicalMuted; }
- public final void setIsPhysicalMuted(boolean value) { _isPhysicalMuted = value; }
-
- public final boolean isPhysicalAttackMuted() { return _isPhysicalAttackMuted; }
- public final void setIsPhysicalAttackMuted(boolean value) { _isPhysicalAttackMuted = value; }
- /** Return True if the L2Character can't move (stun, root, sleep, overload, paralyzed). */
- public boolean isMovementDisabled()
- {
- // check for isTeleporting to prevent teleport cheating (if appear packet not received)
- return isStunned() || isRooted() || isSleeping() || isOverloaded() || isParalyzed()
- || isImmobilized() || isFakeDeath() || isTeleporting();
- }
- /** Return True if the L2Character can be controlled by the player (confused, afraid). */
- public final boolean isOutOfControl() { return isConfused() || isAfraid(); }
- public final boolean isOverloaded() { return _isOverloaded; }
- /** Set the overloaded status of the L2Character is overloaded (if True, the L2PcInstance can't take more item). */
- public final void setIsOverloaded(boolean value) { _isOverloaded = value; }
- public final boolean isParalyzed() { return _isParalyzed; }
- public final void setIsParalyzed(boolean value) { _isParalyzed = value; }
- public final boolean isPendingRevive() { return isDead() && _isPendingRevive; }
- public final void setIsPendingRevive(boolean value) { _isPendingRevive = value; }
-
- public final boolean isDisarmed() { return _isDisarmed; }
- public final void setIsDisarmed(boolean value) { _isDisarmed = value; }
- /**
- * Return the L2Summon of the L2Character.<BR><BR>
- * <B><U> Overriden in </U> :</B><BR><BR>
- * <li> L2PcInstance</li><BR><BR>
- */
- public L2Summon getPet() { return null; }
- /** Return True if the L2Character is riding. */
- public final boolean isRidingGreatWolf()
- {
- return _isRidingGreatWolf;
- }
- public final boolean isRidingStrider()
- {
- return _isRidingStrider;
- }
- /** Set the L2Character riding mode to True. */
- public final void setIsRidingGreatWolf(boolean mode) { _isRidingGreatWolf = mode; }
- public final void setIsRidingStrider(boolean mode) { _isRidingStrider = mode; }
- public final boolean isRooted() { return _isRooted; }
- public final void setIsRooted(boolean value) { _isRooted = value; }
- /** Return True if the L2Character is running. */
- public final boolean isRunning() { return _isRunning; }
- public final void setIsRunning(boolean value)
- {
- _isRunning = value;
- broadcastPacket(new ChangeMoveType(this));
- }
- /** Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance. */
- public final void setRunning() { if (!isRunning()) setIsRunning(true); }
-
- public final boolean isImmobileUntilAttacked() {return _isImmobileUntilAttacked; }
- public final void setIsImmobileUntilAttacked(boolean value) { _isImmobileUntilAttacked = value; }
- public final boolean isSleeping() { return _isSleeping; }
- public final void setIsSleeping(boolean value) { _isSleeping = value; }
- public final boolean isStunned() { return _isStunned; }
- public final void setIsStunned(boolean value) { _isStunned = value; }
- public final boolean isBetrayed() { return _isBetrayed; }
- public final void setIsBetrayed(boolean value) { _isBetrayed = value; }
- public final boolean isTeleporting() { return _isTeleporting; }
- public final void setIsTeleporting(boolean value) { _isTeleporting = value; }
- public void setIsInvul(boolean b){_isInvul = b;}
- public boolean isInvul(){return _isInvul || _isTeleporting;}
- public boolean isUndead() { return _template.isUndead; }
- @Override
- public CharKnownList getKnownList()
- {
- if(super.getKnownList() == null || !(super.getKnownList() instanceof CharKnownList))
- setKnownList(new CharKnownList(this));
- return ((CharKnownList)super.getKnownList());
- }
- public CharStat getStat()
- {
- if (_stat == null) _stat = new CharStat(this);
- return _stat;
- }
- public final void setStat(CharStat value) { _stat = value; }
- public CharStatus getStatus()
- {
- if (_status == null) _status = new CharStatus(this);
- return _status;
- }
- public final void setStatus(CharStatus value) { _status = value; }
- public L2CharTemplate getTemplate() { return _template; }
- /**
- * Set the template of the L2Character.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * Each L2Character owns generic and static properties (ex : all Keltir have the same number of HP...).
- * All of those properties are stored in a different template for each type of L2Character.
- * Each template is loaded once in the server cache memory (reduce memory use).
- * When a new instance of L2Character is spawned, server just create a link between the instance and the template
- * This link is stored in <B>_template</B><BR><BR>
- *
- * <B><U> Assert </U> :</B><BR><BR>
- * <li> this instanceof L2Character</li><BR><BR
- */
- protected final void setTemplate(L2CharTemplate template) { _template = template; }
- /** Return the Title of the L2Character. */
- public final String getTitle() { return _title; }
- /** Set the Title of the L2Character. */
- public final void setTitle(String value) { _title = value.length()>16? value.substring(0,15):value; }
- /** Set the L2Character movement type to walk and send Server->Client packet ChangeMoveType to all others L2PcInstance. */
- public final void setWalking() { if (isRunning()) setIsRunning(false); }
- /** Task lauching the function enableSkill() */
- class EnableSkill implements Runnable
- {
- int _skillId;
- public EnableSkill(int skillId)
- {
- _skillId = skillId;
- }
- public void run()
- {
- try
- {
- enableSkill(_skillId);
- }
- catch (Throwable e)
- {
- _log.log(Level.SEVERE, "", e);
- }
- }
- }
- /**
- * Task lauching the function onHitTimer().<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <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>
- * <li>If attack isn't aborted, send a message system (critical hit, missed...) to attacker/target if they are L2PcInstance </li>
- * <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>
- * <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>
- *
- */
- class HitTask implements Runnable
- {
- L2Character _hitTarget;
- int _damage;
- boolean _crit;
- boolean _miss;
- boolean _shld;
- boolean _soulshot;
- public HitTask(L2Character target, int damage, boolean crit, boolean miss, boolean soulshot, boolean shld)
- {
- _hitTarget = target;
- _damage = damage;
- _crit = crit;
- _shld = shld;
- _miss = miss;
- _soulshot = soulshot;
- }
- public void run()
- {
- try
- {
- onHitTimer(_hitTarget, _damage, _crit, _miss, _soulshot, _shld);
- }
- catch (Throwable e)
- {
- _log.severe(e.toString());
- }
- }
- }
- /** Task lauching the magic skill phases */
- class MagicUseTask implements Runnable
- {
- L2Object[] _targets;
- L2Skill _skill;
- int _coolTime;
- int _phase;
- public MagicUseTask(L2Object[] targets, L2Skill skill, int coolTime, int phase)
- {
- _targets = targets;
- _skill = skill;
- _coolTime = coolTime;
- _phase = phase;
- }
- public void run()
- {
- try
- {
- switch (_phase)
- {
- case 1:
- onMagicLaunchedTimer(_targets, _skill, _coolTime, false);
- break;
- case 2:
- onMagicHitTimer(_targets, _skill, _coolTime, false);
- break;
- case 3:
- onMagicFinalizer(_skill);
- break;
- default:
- break;
- }
- }
- catch (Throwable e)
- {
- _log.log(Level.SEVERE, "", e);
- enableAllSkills();
- }
- }
- }
- /** Task lauching the function useMagic() */
- class QueuedMagicUseTask implements Runnable
- {
- L2PcInstance _currPlayer;
- L2Skill _queuedSkill;
- boolean _isCtrlPressed;
- boolean _isShiftPressed;
- public QueuedMagicUseTask(L2PcInstance currPlayer, L2Skill queuedSkill, boolean isCtrlPressed, boolean isShiftPressed)
- {
- _currPlayer = currPlayer;
- _queuedSkill = queuedSkill;
- _isCtrlPressed = isCtrlPressed;
- _isShiftPressed = isShiftPressed;
- }
- public void run()
- {
- try
- {
- _currPlayer.useMagic(_queuedSkill, _isCtrlPressed, _isShiftPressed);
- }
- catch (Throwable e)
- {
- _log.log(Level.SEVERE, "", e);
- }
- }
- }
- /** Task of AI notification */
- public class NotifyAITask implements Runnable
- {
- private final CtrlEvent _evt;
- NotifyAITask(CtrlEvent evt)
- {
- _evt = evt;
- }
- public void run()
- {
- try
- {
- getAI().notifyEvent(_evt, null);
- }
- catch (Throwable t)
- {
- _log.log(Level.WARNING, "", t);
- }
- }
- }
- /** Task lauching the function stopPvPFlag() */
- class PvPFlag implements Runnable
- {
- public PvPFlag()
- {
- }
- public void run()
- {
- try
- {
- // _log.fine("Checking pvp time: " + getlastPvpAttack());
- // "lastattack: " _lastAttackTime "currenttime: "
- // System.currentTimeMillis());
- if (System.currentTimeMillis() > getPvpFlagLasts())
- {
- // _log.fine("Stopping PvP");
- stopPvPFlag();
- }
- else if (System.currentTimeMillis() > (getPvpFlagLasts() - 5000))
- {
- updatePvPFlag(2);
- }
- else
- {
- updatePvPFlag(1);
- // Start a new PvP timer check
- //checkPvPFlag();
- }
- }
- catch (Exception e)
- {
- _log.log(Level.WARNING, "error in pvp flag task:", e);
- }
- }
- }
- // =========================================================
- /** Task lauching the magic skill phases */
- class FlyToLocationTask implements Runnable
- {
- @SuppressWarnings("hiding")
- L2Object _target;
- L2Character _actor;
- L2Skill _skill;
- public FlyToLocationTask(L2Character actor, L2Object target, L2Skill skill)
- {
- _actor = actor;
- _target = target;
- _skill = skill;
- }
- public void run()
- {
- try
- {
- FlyType _flyType;
-
- _flyType = FlyType.valueOf(_skill.getFlyType());
- broadcastPacket(new FlyToLocation(_actor,_target,_flyType));
- }
- catch (Throwable e)
- {
- _log.log(Level.SEVERE, "", e);
- }
- }
- }
- // =========================================================
- // Abnormal Effect - NEED TO REMOVE ONCE L2CHARABNORMALEFFECT IS COMPLETE
- // Data Field
- /** Map 32 bits (0x0000) containing all abnormal effect in progress */
- private int _AbnormalEffects;
- /**
- * FastTable containing all active skills effects in progress of a L2Character.
- */
- private FastTable<L2Effect> _effects;
- /** The table containing the List of all stacked effect in progress for each Stack group Identifier */
- protected Map<String, List<L2Effect>> _stackedEffects;
- /** Table EMPTY_EFFECTS shared by all L2Character without effects in progress */
- private static final L2Effect[] EMPTY_EFFECTS = new L2Effect[0];
- public static final int ABNORMAL_EFFECT_BLEEDING = 0x000001;
- public static final int ABNORMAL_EFFECT_POISON = 0x000002;
- public static final int ABNORMAL_EFFECT_UNKNOWN_3 = 0x000004;
- public static final int ABNORMAL_EFFECT_UNKNOWN_4 = 0x000008;
- public static final int ABNORMAL_EFFECT_UNKNOWN_5 = 0x000010;
- public static final int ABNORMAL_EFFECT_UNKNOWN_6 = 0x000020;
- public static final int ABNORMAL_EFFECT_STUN = 0x000040;
- public static final int ABNORMAL_EFFECT_SLEEP = 0x000080;
- public static final int ABNORMAL_EFFECT_MUTED = 0x000100;
- public static final int ABNORMAL_EFFECT_ROOT = 0x000200;
- public static final int ABNORMAL_EFFECT_HOLD_1 = 0x000400;
- public static final int ABNORMAL_EFFECT_HOLD_2 = 0x000800;
- public static final int ABNORMAL_EFFECT_UNKNOWN_13 = 0x001000;
- public static final int ABNORMAL_EFFECT_BIG_HEAD = 0x002000;
- public static final int ABNORMAL_EFFECT_FLAME = 0x004000;
- public static final int ABNORMAL_EFFECT_UNKNOWN_16 = 0x008000;
- public static final int ABNORMAL_EFFECT_GROW = 0x010000;
- public static final int ABNORMAL_EFFECT_FLOATING_ROOT = 0x020000;
- public static final int ABNORMAL_EFFECT_DANCE_STUNNED = 0x040000;
- public static final int ABNORMAL_EFFECT_FIREROOT_STUN = 0x080000;
- public static final int ABNORMAL_EFFECT_STEALTH = 0x100000;
- public static final int ABNORMAL_EFFECT_IMPRISIONING_1 = 0x200000;
- public static final int ABNORMAL_EFFECT_IMPRISIONING_2 = 0x400000;
- public static final int ABNORMAL_EFFECT_MAGIC_CIRCLE = 0x800000;
- // XXX TEMP HACKS (get the proper mask for these effects)
- public static final int ABNORMAL_EFFECT_CONFUSED = 0x0020;
- public static final int ABNORMAL_EFFECT_AFRAID = 0x0010;
- // Method - Public
- /**
- * Launch and add L2Effect (including Stack Group management) to L2Character and update client magic icon.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>.
- * The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR><BR>
- *
- * Several same effect can't be used on a L2Character at the same time.
- * Indeed, effects are not stackable and the last cast will replace the previous in progress.
- * More, some effects belong to the same Stack Group (ex WindWald and Haste Potion).
- * 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>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Add the L2Effect to the L2Character _effects</li>
- * <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>
- * <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>
- * <li>If this effect has NOT higher priority in its Stack Group, set the effect to Not In Use</li>
- * <li>Update active skills in progress icons on player client</li><BR>
- *
- */
- public final void addEffect(L2Effect newEffect)
- {
- if(newEffect == null) return;
- synchronized (this)
- {
- if (_effects == null)
- _effects = new FastTable<L2Effect>();
- if (_stackedEffects == null)
- _stackedEffects = new FastMap<String, List<L2Effect>>();
- }
- synchronized(_effects)
- {
- L2Effect tempEffect, tempEffect2;
- // Check for same effects
- for (int i=0; i<_effects.size(); i++)
- {
- if (_effects.get(i).getSkill().getId() == newEffect.getSkill().getId()
- && _effects.get(i).getEffectType() == newEffect.getEffectType()
- && _effects.get(i).getStackOrder() == newEffect.getStackOrder())
- {
- if (newEffect.getSkill().getSkillType() == L2Skill.SkillType.BUFF
- || newEffect.getEffectType() == L2Effect.EffectType.BUFF)
- {
- // renew buffs, exit old (could consider only reschedule and stop new but then effector would be wrong)
- _effects.get(i).exit();
- }
- else
- {
- // Started scheduled timer needs to be canceled.
- newEffect.stopEffectTask();
- return;
- }
- }
- }
- // Remove first Buff if number of buffs > getMaxBuffCount()
- L2Skill tempskill = newEffect.getSkill();
- if (getBuffCount() > getMaxBuffCount() && !doesStack(tempskill) && ((
- tempskill.getSkillType() == L2Skill.SkillType.BUFF ||
- tempskill.getSkillType() == L2Skill.SkillType.DEBUFF ||
- tempskill.getSkillType() == L2Skill.SkillType.REFLECT ||
- tempskill.getSkillType() == L2Skill.SkillType.HEAL_PERCENT ||
- tempskill.getSkillType() == L2Skill.SkillType.MANAHEAL_PERCENT)&&
- !(tempskill.getId() > 4360 && tempskill.getId() < 4367))
- )
- {
- // if max buffs, no herb effects are used, even if they would replace one old
- if (newEffect.isHerbEffect())
- {
- newEffect.stopEffectTask();
- return;
- }
- removeFirstBuff(tempskill.getId());
- }
- // Add the L2Effect to all effect in progress on the L2Character
- if (!newEffect.getSkill().isToggle())
- {
- int pos=0;
- for (int i=0; i<_effects.size(); i++)
- {
- if (_effects.get(i) != null)
- {
- int skillid = _effects.get(i).getSkill().getId();
- if (!_effects.get(i).getSkill().isToggle() &&
- (!(skillid > 4360 && skillid < 4367))
- ) pos++;
- }
- else break;
- }
- _effects.add(pos, newEffect);
- }
- else _effects.addLast(newEffect);
- // Check if a stack group is defined for this effect
- if (newEffect.getStackType().equals("none"))
- {
- // Set this L2Effect to In Use
- newEffect.setInUse(true);
- // Add Funcs of this effect to the Calculator set of the L2Character
- addStatFuncs(newEffect.getStatFuncs());
- // Update active skills in progress icons on player client
- updateEffectIcons();
- return;
- }
- // Get the list of all stacked effects corresponding to the stack type of the L2Effect to add
- List<L2Effect> stackQueue = _stackedEffects.get(newEffect.getStackType());
- if (stackQueue == null)
- stackQueue = new FastList<L2Effect>();
- tempEffect = null;
- if (stackQueue.size() > 0)
- {
- // Get the first stacked effect of the Stack group selected
- for (int i=0; i<_effects.size(); i++)
- {
- if (_effects.get(i) == stackQueue.get(0))
- {
- tempEffect = _effects.get(i);
- break;
- }
- }
- }
- // Add the new effect to the stack group selected at its position
- stackQueue = effectQueueInsert(newEffect, stackQueue);
- if (stackQueue == null) return;
- // Update the Stack Group table _stackedEffects of the L2Character
- _stackedEffects.put(newEffect.getStackType(), stackQueue);
- // Get the first stacked effect of the Stack group selected
- tempEffect2 = null;
- for (int i=0; i<_effects.size(); i++)
- {
- if (_effects.get(i) == stackQueue.get(0))
- {
- tempEffect2 = _effects.get(i);
- break;
- }
- }
- if (tempEffect != tempEffect2)
- {
- if (tempEffect != null)
- {
- // Remove all Func objects corresponding to this stacked effect from the Calculator set of the L2Character
- removeStatsOwner(tempEffect);
- // Set the L2Effect to Not In Use
- tempEffect.setInUse(false);
- }
- if (tempEffect2 != null)
- {
- // Set this L2Effect to In Use
- tempEffect2.setInUse(true);
- // Add all Func objects corresponding to this stacked effect to the Calculator set of the L2Character
- addStatFuncs(tempEffect2.getStatFuncs());
- }
- }
- }
- // Update active skills in progress (In Use and Not In Use because stacked) icons on client
- updateEffectIcons();
- }
- /**
- * Insert an effect at the specified position in a Stack Group.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * Several same effect can't be used on a L2Character at the same time.
- * Indeed, effects are not stackable and the last cast will replace the previous in progress.
- * More, some effects belong to the same Stack Group (ex WindWald and Haste Potion).
- * 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>
- *
- * @param id The identifier of the stacked effect to add to the Stack Group
- * @param stackOrder The position of the effect in the Stack Group
- * @param stackQueue The Stack Group in wich the effect must be added
- *
- */
- private List<L2Effect> effectQueueInsert(L2Effect newStackedEffect, List<L2Effect> stackQueue)
- {
- // Get the L2Effect corresponding to the Effect Identifier from the L2Character _effects
- if(_effects == null)
- return null;
- // Create an Iterator to go through the list of stacked effects in progress on the L2Character
- Iterator<L2Effect> queueIterator = stackQueue.iterator();
- int i = 0;
- while (queueIterator.hasNext()) {
- L2Effect cur = queueIterator.next();
- if (newStackedEffect.getStackOrder() < cur.getStackOrder())
- i++;
- else break;
- }
- // Add the new effect to the Stack list in function of its position in the Stack group
- stackQueue.add(i, newStackedEffect);
- // skill.exit() could be used, if the users don't wish to see "effect
- // removed" always when a timer goes off, even if the buff isn't active
- // any more (has been replaced). but then check e.g. npc hold and raid petrify.
- if (Config.EFFECT_CANCELING && !newStackedEffect.isHerbEffect() && stackQueue.size() > 1)
- {
- // only keep the current effect, cancel other effects
- for (int n=0; n<_effects.size(); n++)
- {
- if (_effects.get(n) == stackQueue.get(1))
- {
- _effects.remove(n);
- break;
- }
- }
- stackQueue.remove(1);
- }
- return stackQueue;
- }
- /**
- * Stop and remove L2Effect (including Stack Group management) from L2Character and update client magic icon.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>.
- * The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR><BR>
- *
- * Several same effect can't be used on a L2Character at the same time.
- * Indeed, effects are not stackable and the last cast will replace the previous in progress.
- * More, some effects belong to the same Stack Group (ex WindWald and Haste Potion).
- * 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>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Remove Func added by this effect from the L2Character Calculator (Stop L2Effect)</li>
- * <li>If the L2Effect belongs to a not empty Stack Group, replace theses Funcs by next stacked effect Funcs</li>
- * <li>Remove the L2Effect from _effects of the L2Character</li>
- * <li>Update active skills in progress icons on player client</li><BR>
- *
- */
- public final void removeEffect(L2Effect effect)
- {
- if(effect == null || _effects == null)
- return;
- synchronized(_effects)
- {
- if (effect.getStackType() == "none")
- {
- // Remove Func added by this effect from the L2Character Calculator
- removeStatsOwner(effect);
- }
- else
- {
- if(_stackedEffects == null)
- return;
- // Get the list of all stacked effects corresponding to the stack type of the L2Effect to add
- List<L2Effect> stackQueue = _stackedEffects.get(effect.getStackType());
- if (stackQueue == null || stackQueue.size() < 1)
- return;
- // Get the Identifier of the first stacked effect of the Stack group selected
- L2Effect frontEffect = stackQueue.get(0);
- // Remove the effect from the Stack Group
- boolean removed = stackQueue.remove(effect);
- if (removed)
- {
- // Check if the first stacked effect was the effect to remove
- if (frontEffect == effect)
- {
- // Remove all its Func objects from the L2Character calculator set
- removeStatsOwner(effect);
- // Check if there's another effect in the Stack Group
- if (stackQueue.size() > 0)
- {
- // Add its list of Funcs to the Calculator set of the L2Character
- for (int i=0; i<_effects.size(); i++)
- {
- if (_effects.get(i) == stackQueue.get(0))
- {
- // Add its list of Funcs to the Calculator set of the L2Character
- addStatFuncs(_effects.get(i).getStatFuncs());
- // Set the effect to In Use
- _effects.get(i).setInUse(true);
- break;
- }
- }
- }
- }
- if (stackQueue.isEmpty())
- _stackedEffects.remove(effect.getStackType());
- else
- // Update the Stack Group table _stackedEffects of the L2Character
- _stackedEffects.put(effect.getStackType(), stackQueue);
- }
- }
- // Remove the active skill L2effect from _effects of the L2Character
- // The Integer key of _effects is the L2Skill Identifier that has created the effect
- for (int i=0; i<_effects.size(); i++)
- {
- if (_effects.get(i) == effect)
- {
- _effects.remove(i);
- if (this instanceof L2PcInstance)
- {
- SystemMessage sm = new SystemMessage(SystemMessageId.EFFECT_S1_DISAPPEARED);
- sm.addString(effect.getSkill().getName());
- sendPacket(sm);
- }
- break;
- }
- }
- }
- // Update active skills in progress (In Use and Not In Use because stacked) icons on client
- updateEffectIcons();
- }
- /**
- * Active abnormal effects flags in the binary mask and send Server->Client UserInfo/CharInfo packet.<BR><BR>
- */
- public final void startAbnormalEffect(int mask)
- {
- _AbnormalEffects |= mask;
- updateAbnormalEffect();
- }
- /**
- * Active the abnormal effect Confused flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
- */
- public final void startConfused()
- {
- setIsConfused(true);
- getAI().notifyEvent(CtrlEvent.EVT_CONFUSED);
- updateAbnormalEffect();
- }
- /**
- * Active the abnormal effect Fake Death flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
- */
- public final void startFakeDeath()
- {
- setIsFakeDeath(true);
- /* Aborts any attacks/casts if fake dead */
- abortAttack();
- abortCast();
- getAI().notifyEvent(CtrlEvent.EVT_FAKE_DEATH, null);
- broadcastPacket(new ChangeWaitType(this,ChangeWaitType.WT_START_FAKEDEATH));
- }
- /**
- * Active the abnormal effect Fear flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
- */
- public final void startFear()
- {
- setIsAfraid(true);
- getAI().notifyEvent(CtrlEvent.EVT_AFFRAID);
- updateAbnormalEffect();
- }
- /**
- * Active the abnormal effect Muted flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
- */
- public final void startMuted()
- {
- setIsMuted(true);
- /* Aborts any casts if muted */
- abortCast();
- getAI().notifyEvent(CtrlEvent.EVT_MUTED);
- updateAbnormalEffect();
- }
- /**
- * Active the abnormal effect Psychical_Muted flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
- */
- public final void startPsychicalMuted()
- {
- setIsPhysicalMuted(true);
- getAI().notifyEvent(CtrlEvent.EVT_MUTED);
- updateAbnormalEffect();
- }
- /**
- * Active the abnormal effect Root flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
- */
- public final void startRooted()
- {
- setIsRooted(true);
- getAI().notifyEvent(CtrlEvent.EVT_ROOTED, null);
- updateAbnormalEffect();
- }
-
- /**
- * Active the abnormal effect Sleep flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
- */
- public final void startImmobileUntilAttacked()
- {
- setIsImmobileUntilAttacked(true);
- abortAttack();
- abortCast();
- getAI().notifyEvent(CtrlEvent.EVT_SLEEPING, null);
- updateAbnormalEffect();
- }
- /**
- * Active the abnormal effect Sleep flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet.<BR><BR>
- */
- public final void startSleeping()
- {
- setIsSleeping(true);
- /* Aborts any attacks/casts if sleeped */
- abortAttack();
- abortCast();
- getAI().notifyEvent(CtrlEvent.EVT_SLEEPING, null);
- updateAbnormalEffect();
- }
- /**
- * Launch a Stun Abnormal Effect on the L2Character.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Calculate the success rate of the Stun Abnormal Effect on this L2Character</li>
- * <li>If Stun succeed, active the abnormal effect Stun flag, notify the L2Character AI and send Server->Client UserInfo/CharInfo packet</li>
- * <li>If Stun NOT succeed, send a system message Failed to the L2PcInstance attacker</li><BR><BR>
- *
- */
- public final void startStunning()
- {
- setIsStunned(true);
- /* Aborts any attacks/casts if stunned */
- abortAttack();
- abortCast();
- getAI().notifyEvent(CtrlEvent.EVT_STUNNED, null);
- updateAbnormalEffect();
- }
- public final void startBetray()
- {
- setIsBetrayed(true);
- getAI().notifyEvent(CtrlEvent.EVT_BETRAYED, null);
- updateAbnormalEffect();
- }
- public final void stopBetray()
- {
- stopEffects(L2Effect.EffectType.BETRAY);
- setIsBetrayed(false);
- updateAbnormalEffect();
- }
- /**
- * Modify the abnormal effect map according to the mask.<BR><BR>
- */
- public final void stopAbnormalEffect(int mask)
- {
- _AbnormalEffects &= ~mask;
- updateAbnormalEffect();
- }
- /**
- * Stop all active skills effects in progress on the L2Character.<BR><BR>
- */
- public final void stopAllEffects()
- {
- // Get all active skills effects in progress on the L2Character
- L2Effect[] effects = getAllEffects();
- if (effects == null) return;
- // Go through all active skills effects
- for (L2Effect e : effects)
- {
- if (e != null)
- {
- e.exit(true);
- }
- }
- if (this instanceof L2PcInstance) ((L2PcInstance)this).updateAndBroadcastStatus(2);
- }
- /**
- * Stop a specified/all Confused abnormal L2Effect.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Delete a specified/all (if effect=null) Confused abnormal L2Effect from L2Character and update client magic icon </li>
- * <li>Set the abnormal effect flag _confused to False </li>
- * <li>Notify the L2Character AI</li>
- * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
- *
- */
- public final void stopConfused(L2Effect effect)
- {
- if (effect == null)
- stopEffects(L2Effect.EffectType.CONFUSION);
- else
- removeEffect(effect);
- setIsConfused(false);
- getAI().notifyEvent(CtrlEvent.EVT_THINK, null);
- updateAbnormalEffect();
- }
- /**
- * Stop and remove the L2Effects corresponding to the L2Skill Identifier and update client magic icon.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>.
- * The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR><BR>
- *
- * @param effectId The L2Skill Identifier of the L2Effect to remove from _effects
- *
- */
- public final void stopSkillEffects(int skillId)
- {
- // Get all skills effects on the L2Character
- L2Effect[] effects = getAllEffects();
- if (effects == null) return;
- for(L2Effect e : effects)
- {
- if (e.getSkill().getId() == skillId) e.exit();
- }
- }
- /**
- * Stop and remove all L2Effect of the selected type (ex : BUFF, DMG_OVER_TIME...) from the L2Character and update client magic icon.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>.
- * The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Remove Func added by this effect from the L2Character Calculator (Stop L2Effect)</li>
- * <li>Remove the L2Effect from _effects of the L2Character</li>
- * <li>Update active skills in progress icons on player client</li><BR><BR>
- *
- * @param type The type of effect to stop ((ex : BUFF, DMG_OVER_TIME...)
- *
- */
- public final void stopEffects(L2Effect.EffectType type)
- {
- // Get all active skills effects in progress on the L2Character
- L2Effect[] effects = getAllEffects();
- if (effects == null) return;
- // Go through all active skills effects
- for(L2Effect e : effects)
- {
- // Stop active skills effects of the selected type
- if (e.getEffectType() == type)
- e.exit();
- }
- }
- /**
- * Stop a specified/all Fake Death abnormal L2Effect.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Delete a specified/all (if effect=null) Fake Death abnormal L2Effect from L2Character and update client magic icon </li>
- * <li>Set the abnormal effect flag _fake_death to False </li>
- * <li>Notify the L2Character AI</li><BR><BR>
- *
- */
- public final void stopFakeDeath(L2Effect effect)
- {
- if (effect == null)
- stopEffects(L2Effect.EffectType.FAKE_DEATH);
- else
- removeEffect(effect);
- setIsFakeDeath(false);
- // if this is a player instance, start the grace period for this character (grace from mobs only)!
- if (this instanceof L2PcInstance)
- {
- ((L2PcInstance) this).setRecentFakeDeath(true);
- }
- ChangeWaitType revive = new ChangeWaitType(this,ChangeWaitType.WT_STOP_FAKEDEATH);
- broadcastPacket(revive);
- getAI().notifyEvent(CtrlEvent.EVT_THINK, null);
- }
- /**
- * Stop a specified/all Fear abnormal L2Effect.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Delete a specified/all (if effect=null) Fear abnormal L2Effect from L2Character and update client magic icon </li>
- * <li>Set the abnormal effect flag _affraid to False </li>
- * <li>Notify the L2Character AI</li>
- * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
- *
- */
- public final void stopFear(L2Effect effect)
- {
- if (effect == null)
- stopEffects(L2Effect.EffectType.FEAR);
- else
- removeEffect(effect);
- setIsAfraid(false);
- updateAbnormalEffect();
- }
- /**
- * Stop a specified/all Muted abnormal L2Effect.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Delete a specified/all (if effect=null) Muted abnormal L2Effect from L2Character and update client magic icon </li>
- * <li>Set the abnormal effect flag _muted to False </li>
- * <li>Notify the L2Character AI</li>
- * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
- *
- */
- public final void stopMuted(L2Effect effect)
- {
- if (effect == null)
- stopEffects(L2Effect.EffectType.MUTE);
- else
- removeEffect(effect);
- setIsMuted(false);
- updateAbnormalEffect();
- }
- public final void stopPsychicalMuted(L2Effect effect)
- {
- if (effect == null)
- stopEffects(L2Effect.EffectType.PHYSICAL_MUTE);
- else
- removeEffect(effect);
- setIsPhysicalMuted(false);
- updateAbnormalEffect();
- }
- /**
- * Stop a specified/all Root abnormal L2Effect.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Delete a specified/all (if effect=null) Root abnormal L2Effect from L2Character and update client magic icon </li>
- * <li>Set the abnormal effect flag _rooted to False </li>
- * <li>Notify the L2Character AI</li>
- * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
- *
- */
- public final void stopRooting(L2Effect effect)
- {
- if (effect == null)
- stopEffects(L2Effect.EffectType.ROOT);
- else
- removeEffect(effect);
- setIsRooted(false);
- getAI().notifyEvent(CtrlEvent.EVT_THINK, null);
- updateAbnormalEffect();
- }
-
- /**
- * Stop immobilization until attacked abnormal L2Effect.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Delete a specified/all (if effect=null) immobilization until attacked abnormal L2Effect from L2Character and update client magic icon </li>
- * <li>Set the abnormal effect flag _muted to False </li>
- * <li>Notify the L2Character AI</li>
- * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
- *
- */
- public final void stopImmobileUntilAttacked(L2Effect effect)
- {
- if (effect == null)
- stopEffects(L2Effect.EffectType.IMMOBILEUNTILATTACKED);
- else
- {
- removeEffect(effect);
- stopSkillEffects(effect.getSkill().cancelEffect());
- }
-
- setIsImmobileUntilAttacked(false);
- getAI().notifyEvent(CtrlEvent.EVT_THINK, null);
- updateAbnormalEffect();
- }
- /**
- * Stop a specified/all Sleep abnormal L2Effect.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Delete a specified/all (if effect=null) Sleep abnormal L2Effect from L2Character and update client magic icon </li>
- * <li>Set the abnormal effect flag _sleeping to False </li>
- * <li>Notify the L2Character AI</li>
- * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
- *
- */
- public final void stopSleeping(L2Effect effect)
- {
- if (effect == null)
- stopEffects(L2Effect.EffectType.SLEEP);
- else
- removeEffect(effect);
- setIsSleeping(false);
- getAI().notifyEvent(CtrlEvent.EVT_THINK, null);
- updateAbnormalEffect();
- }
- /**
- * Stop a specified/all Stun abnormal L2Effect.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Delete a specified/all (if effect=null) Stun abnormal L2Effect from L2Character and update client magic icon </li>
- * <li>Set the abnormal effect flag _stuned to False </li>
- * <li>Notify the L2Character AI</li>
- * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
- *
- */
- public final void stopStunning(L2Effect effect)
- {
- if (effect == null)
- stopEffects(L2Effect.EffectType.STUN);
- else
- removeEffect(effect);
- setIsStunned(false);
- getAI().notifyEvent(CtrlEvent.EVT_THINK, null);
- updateAbnormalEffect();
- }
-
- /**
- * Stop L2Effect: Transformation<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Remove Transformation Effect</li>
- * <li>Notify the L2Character AI</li>
- * <li>Send Server->Client UserInfo/CharInfo packet</li><BR><BR>
- *
- */
- public final void stopTransformation(L2Effect effect)
- {
- if (effect == null)
- {
- stopEffects(L2Effect.EffectType.TRANSFORMATION);
- }
- else
- {
- removeEffect(effect);
- }
-
- // if this is a player instance, then untransform, also set the transform_id column equal to 0 if not cursed.
- if (this instanceof L2PcInstance)
- {
- if (((L2PcInstance) this).getTransformation() != null)
- {
- ((L2PcInstance) this).untransform();
- }
- if(!((L2PcInstance) this).isCursedWeaponEquipped())
- {
- ((L2PcInstance) this).transformUpdateInfo();
- }
- }
-
- getAI().notifyEvent(CtrlEvent.EVT_THINK, null);
- updateAbnormalEffect();
- }
- /**
- * Not Implemented.<BR><BR>
- *
- * <B><U> Overridden in</U> :</B><BR><BR>
- * <li>L2NPCInstance</li>
- * <li>L2PcInstance</li>
- * <li>L2Summon</li>
- * <li>L2DoorInstance</li><BR><BR>
- *
- */
- public abstract void updateAbnormalEffect();
- /**
- * Update active skills in progress (In Use and Not In Use because stacked) icons on client.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * All active skills effects in progress (In Use and Not In Use because stacked) are represented by an icon on the client.<BR><BR>
- *
- * <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>
- *
- */
- public final void updateEffectIcons()
- {
- updateEffectIcons(false);
- }
-
- /**
- * Updates Effect Icons for this character(palyer/summon) and his party if any<BR>
- *
- * Overriden in:<BR>
- * L2PcInstance<BR>
- * L2Summon<BR>
- *
- * @param partyOnly
- */
- public void updateEffectIcons(boolean partyOnly)
- {
- // overriden
- }
- // Property - Public
- /**
- * Return a map of 16 bits (0x0000) containing all abnormal effect in progress for this L2Character.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * In Server->Client packet, each effect is represented by 1 bit of the map (ex : BLEEDING = 0x0001 (bit 1), SLEEP = 0x0080 (bit 8)...).
- * The map is calculated by applying a BINARY OR operation on each effect.<BR><BR>
- *
- * <B><U> Example of use </U> :</B><BR><BR>
- * <li> Server Packet : CharInfo, NpcInfo, NpcInfoPoly, UserInfo...</li><BR><BR>
- */
- public int getAbnormalEffect()
- {
- int ae = _AbnormalEffects;
- if (isStunned()) ae |= ABNORMAL_EFFECT_STUN;
- if (isRooted()) ae |= ABNORMAL_EFFECT_ROOT;
- if (isSleeping()) ae |= ABNORMAL_EFFECT_SLEEP;
- if (isConfused()) ae |= ABNORMAL_EFFECT_CONFUSED;
- if (isMuted()) ae |= ABNORMAL_EFFECT_MUTED;
- if (isAfraid()) ae |= ABNORMAL_EFFECT_AFRAID;
- if (isPhysicalMuted()) ae |= ABNORMAL_EFFECT_MUTED;
- return ae;
- }
- /**
- * Return all active skills effects in progress on the L2Character.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * All active skills effects in progress on the L2Character are identified in <B>_effects</B>.
- * The Integer key of _effects is the L2Skill Identifier that has created the effect.<BR><BR>
- *
- * @return A table containing all active skills effect in progress on the L2Character
- *
- */
- public final L2Effect[] getAllEffects()
- {
- // Create a copy of the effects set
- FastTable<L2Effect> effects = _effects;
- // If no effect found, return EMPTY_EFFECTS
- if (effects == null || effects.isEmpty()) return EMPTY_EFFECTS;
- // Return all effects in progress in a table
- int ArraySize = effects.size();
- L2Effect[] effectArray = new L2Effect[ArraySize];
- for (int i=0; i<ArraySize; i++) {
- if (i >= effects.size() || effects.get(i) == null) break;
- effectArray[i] = effects.get(i);
- }
- return effectArray;
- }
- /**
- * Return L2Effect in progress on the L2Character corresponding to the L2Skill Identifier.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * All active skills effects in progress on the L2Character are identified in <B>_effects</B>.
- *
- * @param index The L2Skill Identifier of the L2Effect to return from the _effects
- *
- * @return The L2Effect corresponding to the L2Skill Identifier
- *
- */
- public final L2Effect getFirstEffect(int index)
- {
- FastTable<L2Effect> effects = _effects;
- if (effects == null) return null;
- L2Effect e;
- L2Effect eventNotInUse = null;
- for (int i=0; i<effects.size(); i++) {
- e = effects.get(i);
- if (e.getSkill().getId() == index)
- {
- if (e.getInUse()) return e;
- else eventNotInUse = e;
- }
- }
- return eventNotInUse;
- }
- /**
- * Return the first L2Effect in progress on the L2Character created by the L2Skill.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * All active skills effects in progress on the L2Character are identified in <B>_effects</B>.
- *
- * @param skill The L2Skill whose effect must be returned
- *
- * @return The first L2Effect created by the L2Skill
- *
- */
- public final L2Effect getFirstEffect(L2Skill skill)
- {
- FastTable<L2Effect> effects = _effects;
- if (effects == null) return null;
- L2Effect e;
- L2Effect eventNotInUse = null;
- for (int i=0; i<effects.size(); i++) {
- e = effects.get(i);
- if (e.getSkill() == skill)
- {
- if (e.getInUse()) return e;
- else eventNotInUse = e;
- }
- }
- return eventNotInUse;
- }
- /**
- * Return the first L2Effect in progress on the L2Character corresponding to the Effect Type (ex : BUFF, STUN, ROOT...).<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * All active skills effects in progress on the L2Character are identified in ConcurrentHashMap(Integer,L2Effect) <B>_effects</B>.
- * The Integer key of _effects is the L2Skill Identifier that has created the L2Effect.<BR><BR>
- *
- * @param tp The Effect Type of skills whose effect must be returned
- *
- * @return The first L2Effect corresponding to the Effect Type
- *
- */
- public final L2Effect getFirstEffect(L2Effect.EffectType tp)
- {
- FastTable<L2Effect> effects = _effects;
- if (effects == null) return null;
- L2Effect e;
- L2Effect eventNotInUse = null;
- for (int i=0; i<effects.size(); i++) {
- e = effects.get(i);
- if (e.getEffectType() == tp)
- {
- if (e.getInUse()) return e;
- else eventNotInUse = e;
- }
- }
- return eventNotInUse;
- }
-
- public EffectCharge getChargeEffect()
- {
- L2Effect[] effects = getAllEffects();
- for (L2Effect e : effects)
- {
- if (e.getSkill().getSkillType() == L2Skill.SkillType.CHARGE)
- {
- return (EffectCharge)e;
- }
- }
- return null;
- }
- // =========================================================
- // =========================================================
- // NEED TO ORGANIZE AND MOVE TO PROPER PLACE
- /** This class permit to the L2Character AI to obtain informations and uses L2Character method */
- public class AIAccessor
- {
- public AIAccessor() {}
- /**
- * Return the L2Character managed by this Accessor AI.<BR><BR>
- */
- public L2Character getActor()
- {
- return L2Character.this;
- }
- /**
- * Accessor to L2Character moveToLocation() method with an interaction area.<BR><BR>
- */
- public void moveTo(int x, int y, int z, int offset)
- {
- L2Character.this.moveToLocation(x, y, z, offset);
- }
- /**
- * Accessor to L2Character moveToLocation() method without interaction area.<BR><BR>
- */
- public void moveTo(int x, int y, int z)
- {
- L2Character.this.moveToLocation(x, y, z, 0);
- }
- /**
- * Accessor to L2Character stopMove() method.<BR><BR>
- */
- public void stopMove(L2CharPosition pos)
- {
- L2Character.this.stopMove(pos);
- }
- /**
- * Accessor to L2Character doAttack() method.<BR><BR>
- */
- public void doAttack(L2Character target)
- {
- L2Character.this.doAttack(target);
- }
- /**
- * Accessor to L2Character doCast() method.<BR><BR>
- */
- public void doCast(L2Skill skill)
- {
- L2Character.this.doCast(skill);
- }
- /**
- * Create a NotifyAITask.<BR><BR>
- */
- public NotifyAITask newNotifyTask(CtrlEvent evt)
- {
- return new NotifyAITask(evt);
- }
- /**
- * Cancel the AI.<BR><BR>
- */
- public void detachAI()
- {
- _ai = null;
- }
- }
- /**
- * This class group all mouvement data.<BR><BR>
- *
- * <B><U> Data</U> :</B><BR><BR>
- * <li>_moveTimestamp : Last time position update</li>
- * <li>_xDestination, _yDestination, _zDestination : Position of the destination</li>
- * <li>_xMoveFrom, _yMoveFrom, _zMoveFrom : Position of the origin</li>
- * <li>_moveStartTime : Start time of the movement</li>
- * <li>_ticksToMove : Nb of ticks between the start and the destination</li>
- * <li>_xSpeedTicks, _ySpeedTicks : Speed in unit/ticks</li><BR><BR>
- *
- * */
- public static class MoveData
- {
- // when we retrieve x/y/z we use GameTimeControl.getGameTicks()
- // if we are moving, but move timestamp==gameticks, we don't need
- // to recalculate position
- public int _moveTimestamp;
- public int _xDestination;
- public int _yDestination;
- public int _zDestination;
- public int _xMoveFrom;
- public int _yMoveFrom;
- public int _zMoveFrom;
- public int _heading;
- public int _moveStartTime;
- public int _ticksToMove;
- public float _xSpeedTicks;
- public float _ySpeedTicks;
- public int onGeodataPathIndex;
- public List<AbstractNodeLoc> geoPath;
- public int geoPathAccurateTx;
- public int geoPathAccurateTy;
- public int geoPathGtx;
- public int geoPathGty;
- }
- /** Table containing all skillId that are disabled */
- protected List<Integer> _disabledSkills;
- private boolean _allSkillsDisabled;
- // private int _flyingRunSpeed;
- // private int _floatingWalkSpeed;
- // private int _flyingWalkSpeed;
- // private int _floatingRunSpeed;
- /** Movement data of this L2Character */
- protected MoveData _move;
- /** Orientation of the L2Character */
- private int _heading;
- /** L2Charcater targeted by the L2Character */
- private L2Object _target;
- // set by the start of casting, in game ticks
- private int _castEndTime;
- private int _castInterruptTime;
- // set by the start of attack, in game ticks
- private int _attackEndTime;
- private int _attacking;
- private int _disableBowAttackEndTime;
- private int _disableCrossBowAttackEndTime;
- /** Table of calculators containing all standard NPC calculator (ex : ACCURACY_COMBAT, EVASION_RATE */
- private static final Calculator[] NPC_STD_CALCULATOR;
- static {NPC_STD_CALCULATOR = Formulas.getInstance().getStdNPCCalculators();}
- protected L2CharacterAI _ai;
- /** Future Skill Cast */
- protected Future<?> _skillCast;
- /** Char Coords from Client */
- private int _clientX;
- private int _clientY;
- private int _clientZ;
- private int _clientHeading;
- /** List of all QuestState instance that needs to be notified of this character's death */
- private List<QuestState> _NotifyQuestOfDeathList = new FastList<QuestState>();
- /**
- * Add QuestState instance that is to be notified of character's death.<BR><BR>
- *
- * @param qs The QuestState that subscribe to this event
- *
- */
- public void addNotifyQuestOfDeath (QuestState qs)
- {
- if (qs == null || _NotifyQuestOfDeathList.contains(qs))
- return;
- _NotifyQuestOfDeathList.add(qs);
- }
- /**
- * Return a list of L2Character that attacked.<BR><BR>
- */
- public final List<QuestState> getNotifyQuestOfDeath ()
- {
- if (_NotifyQuestOfDeathList == null)
- _NotifyQuestOfDeathList = new FastList<QuestState>();
- return _NotifyQuestOfDeathList;
- }
- /**
- * Add a Func to the Calculator set of the L2Character.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * A L2Character owns a table of Calculators called <B>_calculators</B>.
- * Each Calculator (a calculator per state) own a table of Func object.
- * A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...).
- * To reduce cache memory use, L2NPCInstances who don't have skills share the same Calculator set called <B>NPC_STD_CALCULATOR</B>.<BR><BR>
- *
- * 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
- * must be create in its _calculators before addind new Func object.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>If _calculators is linked to NPC_STD_CALCULATOR, create a copy of NPC_STD_CALCULATOR in _calculators</li>
- * <li>Add the Func object to _calculators</li><BR><BR>
- *
- * @param f The Func object to add to the Calculator corresponding to the state affected
- */
- public final synchronized void addStatFunc(Func f)
- {
- if (f == null)
- return;
- // Check if Calculator set is linked to the standard Calculator set of NPC
- if (_calculators == NPC_STD_CALCULATOR)
- {
- // Create a copy of the standard NPC Calculator set
- _calculators = new Calculator[Stats.NUM_STATS];
- for (int i=0; i < Stats.NUM_STATS; i++)
- {
- if (NPC_STD_CALCULATOR[i] != null)
- _calculators[i] = new Calculator(NPC_STD_CALCULATOR[i]);
- }
- }
- // Select the Calculator of the affected state in the Calculator set
- int stat = f.stat.ordinal();
- if (_calculators[stat] == null)
- _calculators[stat] = new Calculator();
- // Add the Func to the calculator corresponding to the state
- _calculators[stat].addFunc(f);
- }
-
- /**
- * Add a list of Funcs to the Calculator set of the L2Character.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * A L2Character owns a table of Calculators called <B>_calculators</B>.
- * Each Calculator (a calculator per state) own a table of Func object.
- * A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...). <BR><BR>
- *
- * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method is ONLY for L2PcInstance</B></FONT><BR><BR>
- *
- * <B><U> Example of use </U> :</B><BR><BR>
- * <li> Equip an item from inventory</li>
- * <li> Learn a new passive skill</li>
- * <li> Use an active skill</li><BR><BR>
- *
- * @param funcs The list of Func objects to add to the Calculator corresponding to the state affected
- */
- public final synchronized void addStatFuncs(Func[] funcs)
- {
-
- FastList<Stats> modifiedStats = new FastList<Stats>();
-
- for (Func f : funcs)
- {
- modifiedStats.add(f.stat);
- addStatFunc(f);
- }
- broadcastModifiedStats(modifiedStats);
- }
- /**
- * Remove a Func from the Calculator set of the L2Character.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * A L2Character owns a table of Calculators called <B>_calculators</B>.
- * Each Calculator (a calculator per state) own a table of Func object.
- * A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...).
- * To reduce cache memory use, L2NPCInstances who don't have skills share the same Calculator set called <B>NPC_STD_CALCULATOR</B>.<BR><BR>
- *
- * 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
- * must be create in its _calculators before addind new Func object.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Remove the Func object from _calculators</li><BR><BR>
- * <li>If L2Character is a L2NPCInstance and _calculators is equal to NPC_STD_CALCULATOR,
- * free cache memory and just create a link on NPC_STD_CALCULATOR in _calculators</li><BR><BR>
- *
- * @param f The Func object to remove from the Calculator corresponding to the state affected
- */
- public final synchronized void removeStatFunc(Func f)
- {
- if (f == null)
- return;
- // Select the Calculator of the affected state in the Calculator set
- int stat = f.stat.ordinal();
- if (_calculators[stat] == null)
- return;
- // Remove the Func object from the Calculator
- _calculators[stat].removeFunc(f);
- if (_calculators[stat].size() == 0)
- _calculators[stat] = null;
- // If possible, free the memory and just create a link on NPC_STD_CALCULATOR
- if (this instanceof L2NpcInstance)
- {
- int i = 0;
- for (; i < Stats.NUM_STATS; i++)
- {
- if (!Calculator.equalsCals(_calculators[i], NPC_STD_CALCULATOR[i]))
- break;
- }
- if (i >= Stats.NUM_STATS)
- _calculators = NPC_STD_CALCULATOR;
- }
- }
- /**
- * Remove a list of Funcs from the Calculator set of the L2PcInstance.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * A L2Character owns a table of Calculators called <B>_calculators</B>.
- * Each Calculator (a calculator per state) own a table of Func object.
- * A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...). <BR><BR>
- *
- * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method is ONLY for L2PcInstance</B></FONT><BR><BR>
- *
- * <B><U> Example of use </U> :</B><BR><BR>
- * <li> Unequip an item from inventory</li>
- * <li> Stop an active skill</li><BR><BR>
- *
- * @param funcs The list of Func objects to add to the Calculator corresponding to the state affected
- */
- public final synchronized void removeStatFuncs(Func[] funcs)
- {
-
- FastList<Stats> modifiedStats = new FastList<Stats>();
-
- for (Func f : funcs)
- {
- modifiedStats.add(f.stat);
- removeStatFunc(f);
- }
-
- broadcastModifiedStats(modifiedStats);
-
- }
- /**
- * Remove all Func objects with the selected owner from the Calculator set of the L2Character.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * A L2Character owns a table of Calculators called <B>_calculators</B>.
- * Each Calculator (a calculator per state) own a table of Func object.
- * A Func object is a mathematic function that permit to calculate the modifier of a state (ex : REGENERATE_HP_RATE...).
- * To reduce cache memory use, L2NPCInstances who don't have skills share the same Calculator set called <B>NPC_STD_CALCULATOR</B>.<BR><BR>
- *
- * 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
- * must be create in its _calculators before addind new Func object.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Remove all Func objects of the selected owner from _calculators</li><BR><BR>
- * <li>If L2Character is a L2NPCInstance and _calculators is equal to NPC_STD_CALCULATOR,
- * free cache memory and just create a link on NPC_STD_CALCULATOR in _calculators</li><BR><BR>
- *
- * <B><U> Example of use </U> :</B><BR><BR>
- * <li> Unequip an item from inventory</li>
- * <li> Stop an active skill</li><BR><BR>
- *
- * @param owner The Object(Skill, Item...) that has created the effect
- */
- public final synchronized void removeStatsOwner(Object owner)
- {
- FastList<Stats> modifiedStats = null;
- // Go through the Calculator set
- for (int i=0; i < _calculators.length; i++)
- {
- if (_calculators[i] != null)
- {
- // Delete all Func objects of the selected owner
- if (modifiedStats != null)
- modifiedStats.addAll(_calculators[i].removeOwner(owner));
- else
- modifiedStats = _calculators[i].removeOwner(owner);
- if (_calculators[i].size() == 0)
- _calculators[i] = null;
- }
- }
- // If possible, free the memory and just create a link on NPC_STD_CALCULATOR
- if (this instanceof L2NpcInstance)
- {
- int i = 0;
- for (; i < Stats.NUM_STATS; i++)
- {
- if (!Calculator.equalsCals(_calculators[i], NPC_STD_CALCULATOR[i]))
- break;
- }
- if (i >= Stats.NUM_STATS)
- _calculators = NPC_STD_CALCULATOR;
- }
-
- if (owner instanceof L2Effect && !((L2Effect)owner).preventExitUpdate)
- broadcastModifiedStats(modifiedStats);
-
- }
-
- private void broadcastModifiedStats(FastList<Stats> stats)
- {
- if (stats == null || stats.isEmpty()) return;
-
- boolean broadcastFull = false;
- boolean otherStats = false;
- StatusUpdate su = null;
-
- for (Stats stat : stats)
- {
- if (stat==Stats.POWER_ATTACK_SPEED)
- {
- if (su == null) su = new StatusUpdate(getObjectId());
- su.addAttribute(StatusUpdate.ATK_SPD, getPAtkSpd());
- }
- else if (stat==Stats.MAGIC_ATTACK_SPEED)
- {
- if (su == null) su = new StatusUpdate(getObjectId());
- su.addAttribute(StatusUpdate.CAST_SPD, getMAtkSpd());
- }
- //else if (stat==Stats.MAX_HP) // TODO: self only and add more stats...
- //{
- // if (su == null) su = new StatusUpdate(getObjectId());
- // su.addAttribute(StatusUpdate.MAX_HP, getMaxHp());
- //}
- else if (stat==Stats.MAX_CP)
- {
- if (this instanceof L2PcInstance)
- {
- if (su == null) su = new StatusUpdate(getObjectId());
- su.addAttribute(StatusUpdate.MAX_CP, getMaxCp());
- }
- }
- //else if (stat==Stats.MAX_MP)
- //{
- // if (su == null) su = new StatusUpdate(getObjectId());
- // su.addAttribute(StatusUpdate.MAX_MP, getMaxMp());
- //}
- else if (stat==Stats.RUN_SPEED)
- {
- broadcastFull = true;
- }
- else
- otherStats = true;
- }
-
- if (this instanceof L2PcInstance)
- {
- if (broadcastFull)
- ((L2PcInstance)this).updateAndBroadcastStatus(2);
- else
- {
- if (otherStats)
- {
- ((L2PcInstance)this).updateAndBroadcastStatus(1);
- if (su != null)
- {
- for (L2PcInstance player : getKnownList().getKnownPlayers().values())
- {
- try { player.sendPacket(su); } catch (NullPointerException e) {}
- }
- }
- }
- else if (su != null) broadcastPacket(su);
- }
- }
- else if (this instanceof L2NpcInstance)
- {
- if (broadcastFull)
- {
- for (L2PcInstance player : getKnownList().getKnownPlayers().values())
- if (player != null)
- player.sendPacket(new NpcInfo((L2NpcInstance)this, player));
- }
- else if (su != null)
- broadcastPacket(su);
- }
- else if (this instanceof L2Summon)
- {
- if (broadcastFull)
- {
- for (L2PcInstance player : getKnownList().getKnownPlayers().values())
- if (player != null)
- player.sendPacket(new NpcInfo((L2Summon)this, player));
- }
- else if (su != null)
- broadcastPacket(su);
- }
- else if (su != null)
- broadcastPacket(su);
- }
- /**
- * Return the orientation of the L2Character.<BR><BR>
- */
- public final int getHeading()
- {
- return _heading;
- }
- /**
- * Set the orientation of the L2Character.<BR><BR>
- */
- public final void setHeading(int heading)
- {
- _heading = heading;
- }
- /**
- * Return the X destination of the L2Character or the X position if not in movement.<BR><BR>
- */
- public final int getClientX()
- {
- return _clientX;
- }
- public final int getClientY()
- {
- return _clientY;
- }
- public final int getClientZ()
- {
- return _clientZ;
- }
- public final int getClientHeading()
- {
- return _clientHeading;
- }
- public final void setClientX(int val)
- {
- _clientX=val;
- }
- public final void setClientY(int val)
- {
- _clientY=val;
- }
- public final void setClientZ(int val)
- {
- _clientZ=val;
- }
- public final void setClientHeading(int val)
- {
- _clientHeading=val;
- }
- public final int getXdestination()
- {
- MoveData m = _move;
- if (m != null)
- return m._xDestination;
- return getX();
- }
- /**
- * Return the Y destination of the L2Character or the Y position if not in movement.<BR><BR>
- */
- public final int getYdestination()
- {
- MoveData m = _move;
- if (m != null)
- return m._yDestination;
- return getY();
- }
- /**
- * Return the Z destination of the L2Character or the Z position if not in movement.<BR><BR>
- */
- public final int getZdestination()
- {
- MoveData m = _move;
- if (m != null)
- return m._zDestination;
- return getZ();
- }
- /**
- * Return True if the L2Character is in combat.<BR><BR>
- */
- public final boolean isInCombat()
- {
- return (getAI().getAttackTarget() != null);
- }
- /**
- * Return True if the L2Character is moving.<BR><BR>
- */
- public final boolean isMoving()
- {
- return _move != null;
- }
- /**
- * Return True if the L2Character is travelling a calculated path.<BR><BR>
- */
- public final boolean isOnGeodataPath()
- {
- if (_move == null) return false;
- try
- {
- if (_move.onGeodataPathIndex == -1) return false;
- if (_move.onGeodataPathIndex == _move.geoPath.size()-1)
- return false;
- }
- catch (NullPointerException e)
- {
- return false;
- }
- return true;
- }
- /**
- * Return True if the L2Character is casting.<BR><BR>
- */
- public final boolean isCastingNow()
- {
- return _castEndTime > GameTimeController.getGameTicks();
- }
- /**
- * Return True if the cast of the L2Character can be aborted.<BR><BR>
- */
- public final boolean canAbortCast()
- {
- return _castInterruptTime > GameTimeController.getGameTicks();
- }
- /**
- * Return True if the L2Character is attacking.<BR><BR>
- */
- public final boolean isAttackingNow()
- {
- return _attackEndTime > GameTimeController.getGameTicks();
- }
- /**
- * Return True if the L2Character has aborted its attack.<BR><BR>
- */
- public final boolean isAttackAborted()
- {
- return _attacking <= 0;
- }
- /**
- * Abort the attack of the L2Character and send Server->Client ActionFailed packet.<BR><BR>
- */
- public final void abortAttack()
- {
- if (isAttackingNow())
- {
- _attacking = 0;
- sendPacket(ActionFailed.STATIC_PACKET);
- }
- }
- /**
- * Returns body part (paperdoll slot) we are targeting right now
- */
- public final int getAttackingBodyPart()
- {
- return _attacking;
- }
- /**
- * Abort the cast of the L2Character and send Server->Client MagicSkillCanceld/ActionFailed packet.<BR><BR>
- */
- public final void abortCast()
- {
- if (isCastingNow())
- {
- _castEndTime = 0;
- _castInterruptTime = 0;
- if (_skillCast != null)
- {
- _skillCast.cancel(true);
- _skillCast = null;
- }
- if (getForceBuff() != null)
- getForceBuff().delete();
-
- L2Effect mog = getFirstEffect(L2Effect.EffectType.SIGNET_GROUND);
- if (mog != null)
- mog.exit();
-
- // cancels the skill hit scheduled task
- enableAllSkills(); // re-enables the skills
- if (this instanceof L2PcInstance) getAI().notifyEvent(CtrlEvent.EVT_FINISH_CASTING); // setting back previous intention
- broadcastPacket(new MagicSkillCanceld(getObjectId())); // broadcast packet to stop animations client-side
- sendPacket(ActionFailed.STATIC_PACKET); // send an "action failed" packet to the caster
- }
- }
- /**
- * Update the position of the L2Character during a movement and return True if the movement is finished.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * 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.
- * 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>
- *
- * 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.
- * Note, that the current server position can differe from the current client position even if each movement is straight foward.
- * That's why, client send regularly a Client->Server ValidatePosition packet to eventually correct the gap on the server.
- * But, it's always the server position that is used in range calculation.<BR><BR>
- *
- * 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>
- *
- * <FONT COLOR=#FF0000><B> <U>Caution</U> : The current Z position is obtained FROM THE CLIENT by the Client->Server ValidatePosition Packet.
- * But x and y positions must be calculated to avoid that players try to modify their movement speed.</B></FONT><BR><BR>
- *
- * @param gameTicks Nb of ticks since the server start
- * @return True if the movement is finished
- */
- public boolean updatePosition(int gameTicks)
- {
- // Get movement data
- MoveData m = _move;
- if (m == null)
- return true;
- if (!isVisible())
- {
- _move = null;
- return true;
- }
- // Check if the position has alreday be calculated
- if (m._moveTimestamp == gameTicks)
- return false;
- // Calculate the time between the beginning of the deplacement and now
- int elapsed = gameTicks - m._moveStartTime;
- // If estimated time needed to achieve the destination is passed,
- // the L2Character is positionned to the destination position
- if (elapsed >= m._ticksToMove)
- {
- // Set the timer of last position update to now
- m._moveTimestamp = gameTicks;
- // Set the position of the L2Character to the destination
- if (this instanceof L2BoatInstance)
- {
- super.getPosition().setXYZ(m._xDestination, m._yDestination, m._zDestination);
- ((L2BoatInstance)this).updatePeopleInTheBoat(m._xDestination, m._yDestination, m._zDestination);
- }
- else
- {
- super.getPosition().setXYZ(m._xDestination, m._yDestination, m._zDestination);
- }
- return true;
- }
- // Estimate the position of the L2Character dureing the movement according to its _xSpeedTicks and _ySpeedTicks
- // The Z position is obtained from the client
- if(this instanceof L2BoatInstance )
- {
- super.getPosition().setXYZ(m._xMoveFrom + (int)(elapsed * m._xSpeedTicks),m._yMoveFrom + (int)(elapsed * m._ySpeedTicks),super.getZ());
- ((L2BoatInstance)this).updatePeopleInTheBoat(m._xMoveFrom + (int)(elapsed * m._xSpeedTicks),m._yMoveFrom + (int)(elapsed * m._ySpeedTicks),super.getZ());
- }
- else
- {
- super.getPosition().setXYZ(m._xMoveFrom + (int)(elapsed * m._xSpeedTicks),m._yMoveFrom + (int)(elapsed * m._ySpeedTicks),super.getZ());
- if (this instanceof L2PcInstance) ((L2PcInstance)this).revalidateZone(false);
- else revalidateZone();
- }
- // Set the timer of last position update to now
- m._moveTimestamp = gameTicks;
- return false;
- }
-
- public void revalidateZone()
- {
- if (getWorldRegion() == null) return;
- getWorldRegion().revalidateZones(this);
- }
- /**
- * Stop movement of the L2Character (Called by AI Accessor only).<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Delete movement data of the L2Character </li>
- * <li>Set the current position (x,y,z), its current L2WorldRegion if necessary and its heading </li>
- * <li>Remove the L2Object object from _gmList** of GmListTable </li>
- * <li>Remove object from _knownObjects and _knownPlayer* of all surrounding L2WorldRegion L2Characters </li><BR><BR>
- *
- * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T send Server->Client packet StopMove/StopRotation </B></FONT><BR><BR>
- *
- */
- public void stopMove(L2CharPosition pos) { stopMove(pos, true); }
- public void stopMove(L2CharPosition pos, boolean updateKnownObjects)
- {
- // Delete movement data of the L2Character
- _move = null;
- //if (getAI() != null)
- // getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
- // Set the current position (x,y,z), its current L2WorldRegion if necessary and its heading
- // All data are contained in a L2CharPosition object
- if (pos != null)
- {
- getPosition().setXYZ(pos.x, pos.y, pos.z);
- setHeading(pos.heading);
- if (this instanceof L2PcInstance) ((L2PcInstance)this).revalidateZone(true);
- }
- sendPacket(new StopMove(this));
- if (Config.MOVE_BASED_KNOWNLIST) this.getKnownList().findObjects();
- }
- /**
- * Target a L2Object (add the target to the L2Character _target, _knownObject and L2Character to _KnownObject of the L2Object).<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * The L2Object (including L2Character) targeted is identified in <B>_target</B> of the L2Character<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Set the _target of L2Character to L2Object </li>
- * <li>If necessary, add L2Object to _knownObject of the L2Character </li>
- * <li>If necessary, add L2Character to _KnownObject of the L2Object </li>
- * <li>If object==null, cancel Attak or Cast </li><BR><BR>
- *
- * <B><U> Overriden in </U> :</B><BR><BR>
- * <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>
- *
- * @param object L2object to target
- *
- */
- public void setTarget(L2Object object)
- {
- if (object != null && !object.isVisible())
- object = null;
- if (object != null && object != _target)
- {
- getKnownList().addKnownObject(object);
- object.getKnownList().addKnownObject(this);
- }
- _target = object;
- }
- /**
- * Return the identifier of the L2Object targeted or -1.<BR><BR>
- */
- public final int getTargetId()
- {
- if (_target != null)
- {
- return _target.getObjectId();
- }
- return -1;
- }
- /**
- * Return the L2Object targeted or null.<BR><BR>
- */
- public final L2Object getTarget()
- {
- return _target;
- }
- // called from AIAccessor only
- /**
- * Calculate movement data for a move to location action and add the L2Character to movingObjects of GameTimeController (only called by AI Accessor).<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * 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.
- * 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>
- * 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>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Get current position of the L2Character </li>
- * <li>Calculate distance (dx,dy) between current position and destination including offset </li>
- * <li>Create and Init a MoveData object </li>
- * <li>Set the L2Character _move object to MoveData object </li>
- * <li>Add the L2Character to movingObjects of the GameTimeController </li>
- * <li>Create a task to notify the AI that L2Character arrives at a check point of the movement </li><BR><BR>
- *
- * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T send Server->Client packet MoveToPawn/CharMoveToLocation </B></FONT><BR><BR>
- *
- * <B><U> Example of use </U> :</B><BR><BR>
- * <li> AI : onIntentionMoveTo(L2CharPosition), onIntentionPickUp(L2Object), onIntentionInteract(L2Object) </li>
- * <li> FollowTask </li><BR><BR>
- *
- * @param x The X position of the destination
- * @param y The Y position of the destination
- * @param z The Y position of the destination
- * @param offset The size of the interaction area of the L2Character targeted
- *
- */
- protected void moveToLocation(int x, int y, int z, int offset)
- {
- // Get the Move Speed of the L2Charcater
- float speed = getStat().getMoveSpeed();
- if (speed <= 0 || isMovementDisabled()) return;
- // Get current position of the L2Character
- final int curX = super.getX();
- final int curY = super.getY();
- final int curZ = super.getZ();
-
- // Calculate distance (dx,dy) between current position and destination
- // TODO: improve Z axis move/follow support when dx,dy are small compared to dz
- double dx = (x - curX);
- double dy = (y - curY);
- double dz = (z - curZ);
- double distance = Math.sqrt(dx*dx + dy*dy);
-
- // make water move short and use no geodata checks for swimming chars
- // distance in a click can easily be over 3000
- if (Config.GEODATA > 0 && isInsideZone(ZONE_WATER) && distance > 700)
- {
- double divider = 700/distance;
- x = curX + (int)(divider * dx);
- y = curY + (int)(divider * dy);
- z = curZ + (int)(divider * dz);
- dx = (x - curX);
- dy = (y - curY);
- dz = (z - curZ);
- distance = Math.sqrt(dx*dx + dy*dy);
- }
- if (Config.DEBUG) _log.fine("distance to target:" + distance);
- // Define movement angles needed
- // ^
- // | X (x,y)
- // | /
- // | /distance
- // | /
- // |/ angle
- // X ---------->
- // (curx,cury)
- double cos;
- double sin;
- // Check if a movement offset is defined or no distance to go through
- if (offset > 0 || distance < 1)
- {
- // approximation for moving closer when z coordinates are different
- // TODO: handle Z axis movement better
- offset -= Math.abs(dz);
- if (offset < 5) offset = 5;
- // If no distance to go through, the movement is canceled
- if (distance < 1 || distance - offset <= 0)
- {
- sin = 0;
- cos = 1;
- distance = 0;
- x = curX;
- y = curY;
- if (Config.DEBUG) _log.fine("already in range, no movement needed.");
- // Notify the AI that the L2Character is arrived at destination
- getAI().notifyEvent(CtrlEvent.EVT_ARRIVED, null);
- return;
- }
- // Calculate movement angles needed
- sin = dy/distance;
- cos = dx/distance;
- distance -= (offset-5); // due to rounding error, we have to move a bit closer to be in range
- // Calculate the new destination with offset included
- x = curX + (int)(distance * cos);
- y = curY + (int)(distance * sin);
- }
- else
- {
- // Calculate movement angles needed
- sin = dy/distance;
- cos = dx/distance;
- }
- // Create and Init a MoveData object
- MoveData m = new MoveData();
- // GEODATA MOVEMENT CHECKS AND PATHFINDING
- m.onGeodataPathIndex = -1; // Initialize not on geodata path
-
- if (Config.GEODATA > 0
- && !isFlying() // flying chars not checked - even canSeeTarget doesn't work yet
- && (!isInsideZone(ZONE_WATER) || isInsideZone(ZONE_SIEGE)) // swimming also not checked unless in siege zone - but distance is limited
- && !(this instanceof L2NpcWalkerInstance)) // npc walkers not checked
- {
- double originalDistance = distance;
- int originalX = x;
- int originalY = y;
- int originalZ = z;
- int gtx = (originalX - L2World.MAP_MIN_X) >> 4;
- int gty = (originalY - L2World.MAP_MIN_Y) >> 4;
- // Movement checks:
- // when geodata == 2, for all characters except mobs returning home (could be changed later to teleport if pathfinding fails)
- // when geodata == 1, for l2playableinstance and l2riftinstance only
- if ((Config.GEODATA == 2 && !(this instanceof L2Attackable && ((L2Attackable)this).isReturningToSpawnPoint()))
- || this instanceof L2PcInstance
- || (this instanceof L2Summon && !(this.getAI().getIntention() == AI_INTENTION_FOLLOW)) // assuming intention_follow only when following owner
- || isAfraid()
- || this instanceof L2RiftInvaderInstance)
- {
- if (isOnGeodataPath())
- {
- if (gtx == _move.geoPathGtx && gty == _move.geoPathGty)
- return;
- else
- _move.onGeodataPathIndex = -1; // Set not on geodata path
- }
-
- if (curX < L2World.MAP_MIN_X || curX > L2World.MAP_MAX_X || curY < L2World.MAP_MIN_Y || curY > L2World.MAP_MAX_Y)
- {
- // Temporary fix for character outside world region errors
- _log.warning("Character "+this.getName()+" outside world area, in coordinates x:"+curX+" y:"+curY);
- getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
- if (this instanceof L2PcInstance) ((L2PcInstance)this).deleteMe();
- else this.onDecay();
- return;
- }
- Location destiny = GeoData.getInstance().moveCheck(curX, curY, curZ, x, y, z);
- // location different if destination wasn't reached (or just z coord is different)
- x = destiny.getX();
- y = destiny.getY();
- z = destiny.getZ();
- distance = Math.sqrt((x - curX)*(x - curX) + (y - curY)*(y - curY));
-
- }
- // Pathfinding checks. Only when geodata setting is 2, the LoS check gives shorter result
- // than the original movement was and the LoS gives a shorter distance than 2000
- // This way of detecting need for pathfinding could be changed.
- if(Config.GEODATA == 2 && originalDistance-distance > 100 && distance < 2000 && !this.isAfraid())
- {
- // Path calculation
- // Overrides previous movement check
- if(this instanceof L2PlayableInstance || this.isInCombat())
- {
- int gx = (curX - L2World.MAP_MIN_X) >> 4;
- int gy = (curY - L2World.MAP_MIN_Y) >> 4;
-
- // TODO: Find closest path node we can access, e.g.
- // Node start = GeoPathFinding.getInstance().readNode(gx, gy, (short)curZ);
- // if (start == null)
- // no path node...
- // Location temp = GeoData.getInstance().moveCheck(curX, curY, curZ, start.getLoc().getX(), start.getLoc().getY(), start.getLoc().getZ());
- // if ((temp.getX() != start.getLoc().getX()) || (temp.getY() != start.getLoc().getY()))
- // cannot reach closest...
-
- m.geoPath = GeoPathFinding.getInstance().findPath(gx, gy, (short)curZ, gtx, gty, (short)originalZ);
- if (m.geoPath == null || m.geoPath.size() < 2) // No path found
- {
- // Even though there's no path found (remember geonodes aren't perfect),
- // the mob is attacking and right now we set it so that the mob will go
- // after target anyway, is dz is small enough. Summons will follow their masters no matter what.
- if (this instanceof L2PcInstance
- || (!(this instanceof L2PlayableInstance) && Math.abs(z - curZ) > 140)
- || (this instanceof L2Summon && !((L2Summon)this).getFollowStatus()))
- {
- getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
- return;
- }
- else
- {
- x = originalX;
- y = originalY;
- z = originalZ;
- distance = originalDistance;
- }
- }
- else
- {
- m.onGeodataPathIndex = 0; // on first segment
- m.geoPathGtx = gtx;
- m.geoPathGty = gty;
- m.geoPathAccurateTx = originalX;
- m.geoPathAccurateTy = originalY;
-
- x = m.geoPath.get(m.onGeodataPathIndex).getX();
- y = m.geoPath.get(m.onGeodataPathIndex).getY();
- z = m.geoPath.get(m.onGeodataPathIndex).getZ();
-
- // check for doors in the route
- if (DoorTable.getInstance().checkIfDoorsBetween(curX, curY, curZ, x, y, z))
- {
- m.geoPath = null;
- getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
- return;
- }
- for (int i = 0; i < m.geoPath.size()-1; i++)
- {
- if (DoorTable.getInstance().checkIfDoorsBetween(m.geoPath.get(i),m.geoPath.get(i+1)))
- {
- m.geoPath = null;
- getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
- return;
- }
- }
- dx = (x - curX);
- dy = (y - curY);
- distance = Math.sqrt(dx*dx + dy*dy);
- sin = dy/distance;
- cos = dx/distance;
- }
- }
- }
- // If no distance to go through, the movement is canceled
- if (distance < 1 && (Config.GEODATA == 2
- || this instanceof L2PlayableInstance
- || this.isAfraid()
- || this instanceof L2RiftInvaderInstance))
- {
- sin = 0;
- cos = 1;
- distance = 0;
- x = curX;
- y = curY;
- if(this instanceof L2Summon) ((L2Summon)this).setFollowStatus(false);
- getAI().notifyEvent(CtrlEvent.EVT_ARRIVED, null);
- getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE); //needed?
- return;
- }
- }
- // Caclulate the Nb of ticks between the current position and the destination
- // One tick added for rounding reasons
- m._ticksToMove = 1+(int)(GameTimeController.TICKS_PER_SECOND * distance / speed);
- // Calculate the xspeed and yspeed in unit/ticks in function of the movement speed
- m._xSpeedTicks = (float)(cos * speed / GameTimeController.TICKS_PER_SECOND);
- m._ySpeedTicks = (float)(sin * speed / GameTimeController.TICKS_PER_SECOND);
- // Calculate and set the heading of the L2Character
- int heading = (int) (Math.atan2(-sin, -cos) * 10430.378);
- heading += 32768;
- setHeading(heading);
- if (Config.DEBUG)
- _log.fine("dist:"+ distance +"speed:" + speed + " ttt:" +m._ticksToMove +
- " dx:"+(int)m._xSpeedTicks + " dy:"+(int)m._ySpeedTicks + " heading:" + heading);
- m._xDestination = x;
- m._yDestination = y;
- m._zDestination = z; // this is what was requested from client
- m._heading = 0;
- m._moveStartTime = GameTimeController.getGameTicks();
- m._xMoveFrom = curX;
- m._yMoveFrom = curY;
- m._zMoveFrom = curZ;
- if (Config.DEBUG) _log.fine("time to target:" + m._ticksToMove);
- // Set the L2Character _move object to MoveData object
- _move = m;
- // Add the L2Character to movingObjects of the GameTimeController
- // The GameTimeController manage objects movement
- GameTimeController.getInstance().registerMovingObject(this);
- int tm = m._ticksToMove*GameTimeController.MILLIS_IN_TICK;
- // Create a task to notify the AI that L2Character arrives at a check point of the movement
- if (tm > 3000)
- ThreadPoolManager.getInstance().scheduleAi( new NotifyAITask(CtrlEvent.EVT_ARRIVED_REVALIDATE), 2000);
- // the CtrlEvent.EVT_ARRIVED will be sent when the character will actually arrive
- // to destination by GameTimeController
- }
-
- public boolean moveToNextRoutePoint()
- {
- if(!this.isOnGeodataPath())
- {
- // Cancel the move action
- _move = null;
- return false;
- }
- // Get the Move Speed of the L2Charcater
- float speed = getStat().getMoveSpeed();
- if (speed <= 0 || isMovementDisabled())
- {
- // Cancel the move action
- _move = null;
- return false;
- }
- // Create and Init a MoveData object
- MoveData m = new MoveData();
- // Update MoveData object
- m.onGeodataPathIndex = _move.onGeodataPathIndex + 1; // next segment
- m.geoPath = _move.geoPath;
- m.geoPathGtx = _move.geoPathGtx;
- m.geoPathGty = _move.geoPathGty;
- m.geoPathAccurateTx = _move.geoPathAccurateTx;
- m.geoPathAccurateTy = _move.geoPathAccurateTy;
-
- // Get current position of the L2Character
- m._xMoveFrom = super.getX();
- m._yMoveFrom = super.getY();
- m._zMoveFrom = super.getZ();
- if (_move.onGeodataPathIndex == _move.geoPath.size()-2)
- {
- m._xDestination = _move.geoPathAccurateTx;
- m._yDestination = _move.geoPathAccurateTy;
- m._zDestination = _move.geoPath.get(m.onGeodataPathIndex).getZ();
- }
- else
- {
- m._xDestination = _move.geoPath.get(m.onGeodataPathIndex).getX();
- m._yDestination = _move.geoPath.get(m.onGeodataPathIndex).getY();
- m._zDestination = _move.geoPath.get(m.onGeodataPathIndex).getZ();
- }
- double dx = (m._xDestination - m._xMoveFrom);
- double dy = (m._yDestination - m._yMoveFrom);
- double distance = Math.sqrt(dx*dx + dy*dy);
- double sin = dy/distance;
- double cos = dx/distance;
-
- // Caclulate the Nb of ticks between the current position and the destination
- // One tick added for rounding reasons
- m._ticksToMove = 1+(int)(GameTimeController.TICKS_PER_SECOND * distance / speed);
- // Calculate the xspeed and yspeed in unit/ticks in function of the movement speed
- m._xSpeedTicks = (float)(cos * speed / GameTimeController.TICKS_PER_SECOND);
- m._ySpeedTicks = (float)(sin * speed / GameTimeController.TICKS_PER_SECOND);
- // Calculate and set the heading of the L2Character
- int heading = (int) (Math.atan2(-sin, -cos) * 10430.378);
- heading += 32768;
- setHeading(heading);
- m._heading = 0; // ?
-
- m._moveStartTime = GameTimeController.getGameTicks();
- if (Config.DEBUG) _log.fine("time to target:" + m._ticksToMove);
-
- // Set the L2Character _move object to MoveData object
- _move = m;
-
- // Add the L2Character to movingObjects of the GameTimeController
- // The GameTimeController manage objects movement
- GameTimeController.getInstance().registerMovingObject(this);
- int tm = m._ticksToMove*GameTimeController.MILLIS_IN_TICK;
- // Create a task to notify the AI that L2Character arrives at a check point of the movement
- if (tm > 3000)
- ThreadPoolManager.getInstance().scheduleAi( new NotifyAITask(CtrlEvent.EVT_ARRIVED_REVALIDATE), 2000);
- // the CtrlEvent.EVT_ARRIVED will be sent when the character will actually arrive
- // to destination by GameTimeController
-
- // Send a Server->Client packet CharMoveToLocation to the actor and all L2PcInstance in its _knownPlayers
- MoveToLocation msg = new MoveToLocation(this);
- broadcastPacket(msg);
- return true;
- }
-
- public boolean validateMovementHeading(int heading)
- {
- MoveData md = _move;
- if (md == null) return true;
- boolean result = true;
- if (md._heading != heading)
- {
- result = (md._heading == 0);
- md._heading = heading;
- }
- return result;
- }
- /**
- * Return the distance between the current position of the L2Character and the target (x,y).<BR><BR>
- *
- * @param x X position of the target
- * @param y Y position of the target
- * @return the plan distance
- *
- * @deprecated use getPlanDistanceSq(int x, int y, int z)
- */
- @Deprecated
- public final double getDistance(int x, int y)
- {
- double dx = x - getX();
- double dy = y - getY();
- return Math.sqrt(dx*dx + dy*dy);
- }
- /**
- * Return the distance between the current position of the L2Character and the target (x,y).<BR><BR>
- *
- * @param x X position of the target
- * @param y Y position of the target
- * @return the plan distance
- *
- * @deprecated use getPlanDistanceSq(int x, int y, int z)
- */
- @Deprecated
- public final double getDistance(int x, int y, int z)
- {
- double dx = x - getX();
- double dy = y - getY();
- double dz = z - getZ();
- return Math.sqrt(dx*dx + dy*dy + dz*dz);
- }
- /**
- * Return the squared distance between the current position of the L2Character and the given object.<BR><BR>
- *
- * @param object L2Object
- * @return the squared distance
- */
- public final double getDistanceSq(L2Object object)
- {
- return getDistanceSq(object.getX(), object.getY(), object.getZ());
- }
- /**
- * Return the squared distance between the current position of the L2Character and the given x, y, z.<BR><BR>
- *
- * @param x X position of the target
- * @param y Y position of the target
- * @param z Z position of the target
- * @return the squared distance
- */
- public final double getDistanceSq(int x, int y, int z)
- {
- double dx = x - getX();
- double dy = y - getY();
- double dz = z - getZ();
- return (dx*dx + dy*dy + dz*dz);
- }
- /**
- * Return the squared plan distance between the current position of the L2Character and the given object.<BR>
- * (check only x and y, not z)<BR><BR>
- *
- * @param object L2Object
- * @return the squared plan distance
- */
- public final double getPlanDistanceSq(L2Object object)
- {
- return getPlanDistanceSq(object.getX(), object.getY());
- }
- /**
- * Return the squared plan distance between the current position of the L2Character and the given x, y, z.<BR>
- * (check only x and y, not z)<BR><BR>
- *
- * @param x X position of the target
- * @param y Y position of the target
- * @return the squared plan distance
- */
- public final double getPlanDistanceSq(int x, int y)
- {
- double dx = x - getX();
- double dy = y - getY();
- return (dx*dx + dy*dy);
- }
- /**
- * Check if this object is inside the given radius around the given object. Warning: doesn't cover collision radius!<BR><BR>
- *
- * @param object the target
- * @param radius the radius around the target
- * @param checkZ should we check Z axis also
- * @param strictCheck true if (distance < radius), false if (distance <= radius)
- * @return true is the L2Character is inside the radius.
- *
- * @see net.sf.l2j.gameserver.model.L2Character.isInsideRadius(int x, int y, int z, int radius, boolean checkZ, boolean strictCheck)
- */
- public final boolean isInsideRadius(L2Object object, int radius, boolean checkZ, boolean strictCheck)
- {
- return isInsideRadius(object.getX(), object.getY(), object.getZ(), radius, checkZ, strictCheck);
- }
- /**
- * Check if this object is inside the given plan radius around the given point. Warning: doesn't cover collision radius!<BR><BR>
- *
- * @param x X position of the target
- * @param y Y position of the target
- * @param radius the radius around the target
- * @param strictCheck true if (distance < radius), false if (distance <= radius)
- * @return true is the L2Character is inside the radius.
- */
- public final boolean isInsideRadius(int x, int y, int radius, boolean strictCheck)
- {
- return isInsideRadius(x, y, 0, radius, false, strictCheck);
- }
- /**
- * Check if this object is inside the given radius around the given point.<BR><BR>
- *
- * @param x X position of the target
- * @param y Y position of the target
- * @param z Z position of the target
- * @param radius the radius around the target
- * @param checkZ should we check Z axis also
- * @param strictCheck true if (distance < radius), false if (distance <= radius)
- * @return true is the L2Character is inside the radius.
- */
- public final boolean isInsideRadius(int x, int y, int z, int radius, boolean checkZ, boolean strictCheck)
- {
- double dx = x - getX();
- double dy = y - getY();
- double dz = z - getZ();
- if (strictCheck)
- {
- if (checkZ)
- return (dx*dx + dy*dy + dz*dz) < radius * radius;
- else
- return (dx*dx + dy*dy) < radius * radius;
- } else
- {
- if (checkZ)
- return (dx*dx + dy*dy + dz*dz) <= radius * radius;
- else
- return (dx*dx + dy*dy) <= radius * radius;
- }
- }
- // /**
- // * event that is called when the destination coordinates are reached
- // */
- // public void onTargetReached()
- // {
- // L2Character pawn = getPawnTarget();
- //
- // if (pawn != null)
- // {
- // int x = pawn.getX(), y=pawn.getY(),z = pawn.getZ();
- //
- // double distance = getDistance(x,y);
- // if (getCurrentState() == STATE_FOLLOW)
- // {
- // calculateMovement(x,y,z,distance);
- // return;
- // }
- //
- // // takes care of moving away but distance is 0 so i won't follow problem
- //
- //
- // if (((distance > getAttackRange()) && (getCurrentState() == STATE_ATTACKING)) || (pawn.isMoving() && getCurrentState() != STATE_ATTACKING))
- // {
- // calculateMovement(x,y,z,distance);
- // return;
- // }
- //
- // }
- // // update x,y,z with the current calculated position
- // stopMove();
- //
- // if (Config.DEBUG)
- // _log.fine(this.getName() +":: target reached at: x "+getX()+" y "+getY()+ " z:" + getZ());
- //
- // if (getPawnTarget() != null)
- // {
- //
- // setPawnTarget(null);
- // setMovingToPawn(false);
- // }
- // }
- //
- // public void setTo(int x, int y, int z, int heading)
- // {
- // setX(x);
- // setY(y);
- // setZ(z);
- // setHeading(heading);
- // updateCurrentWorldRegion(); //TODO: maybe not needed here
- // if (isMoving())
- // {
- // setCurrentState(STATE_IDLE);
- // StopMove setto = new StopMove(this);
- // broadcastPacket(setto);
- // }
- // else
- // {
- // ValidateLocation setto = new ValidateLocation(this);
- // broadcastPacket(setto);
- // }
- //
- // FinishRotation fr = new FinishRotation(this);
- // broadcastPacket(fr);
- // }
- // protected void startCombat()
- // {
- // if (_currentAttackTask == null )//&& !isInCombat())
- // {
- // _currentAttackTask = ThreadPoolManager.getInstance().scheduleMed(new AttackTask(), 0);
- // }
- // else
- // {
- // _log.info("multiple attacks want to start in parallel. prevented.");
- // }
- // }
- //
- /**
- * Return the Weapon Expertise Penalty of the L2Character.<BR><BR>
- */
- public float getWeaponExpertisePenalty()
- {
- return 1.f;
- }
- /**
- * Return the Armour Expertise Penalty of the L2Character.<BR><BR>
- */
- public float getArmourExpertisePenalty()
- {
- return 1.f;
- }
- /**
- * Set _attacking corresponding to Attacking Body part to CHEST.<BR><BR>
- */
- public void setAttackingBodypart()
- {
- _attacking = Inventory.PAPERDOLL_CHEST;
- }
- /**
- * Retun True if arrows are available.<BR><BR>
- *
- * <B><U> Overriden in </U> :</B><BR><BR>
- * <li> L2PcInstance</li><BR><BR>
- *
- */
- protected boolean checkAndEquipArrows()
- {
- return true;
- }
- /**
- * Retun True if bolts are available.<BR><BR>
- *
- * <B><U> Overriden in </U> :</B><BR><BR>
- * <li> L2PcInstance</li><BR><BR>
- *
- */
- protected boolean checkAndEquipBolts()
- {
- return true;
- }
- /**
- * Add Exp and Sp to the L2Character.<BR><BR>
- *
- * <B><U> Overriden in </U> :</B><BR><BR>
- * <li> L2PcInstance</li>
- * <li> L2PetInstance</li><BR><BR>
- *
- */
- public void addExpAndSp(@SuppressWarnings("unused") long addToExp, @SuppressWarnings("unused") int addToSp)
- {
- // Dummy method (overridden by players and pets)
- }
- /**
- * Return the active weapon instance (always equiped in the right hand).<BR><BR>
- *
- * <B><U> Overriden in </U> :</B><BR><BR>
- * <li> L2PcInstance</li><BR><BR>
- *
- */
- public abstract L2ItemInstance getActiveWeaponInstance();
- /**
- * Return the active weapon item (always equiped in the right hand).<BR><BR>
- *
- * <B><U> Overriden in </U> :</B><BR><BR>
- * <li> L2PcInstance</li><BR><BR>
- *
- */
- public abstract L2Weapon getActiveWeaponItem();
- /**
- * Return the secondary weapon instance (always equiped in the left hand).<BR><BR>
- *
- * <B><U> Overriden in </U> :</B><BR><BR>
- * <li> L2PcInstance</li><BR><BR>
- *
- */
- public abstract L2ItemInstance getSecondaryWeaponInstance();
- /**
- * Return the secondary weapon item (always equiped in the left hand).<BR><BR>
- *
- * <B><U> Overriden in </U> :</B><BR><BR>
- * <li> L2PcInstance</li><BR><BR>
- *
- */
- public abstract L2Weapon getSecondaryWeaponItem();
- /**
- * Manage hit process (called by Hit Task).<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <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>
- * <li>If attack isn't aborted, send a message system (critical hit, missed...) to attacker/target if they are L2PcInstance </li>
- * <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>
- * <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>
- *
- * @param target The L2Character targeted
- * @param damage Nb of HP to reduce
- * @param crit True if hit is critical
- * @param miss True if hit is missed
- * @param soulshot True if SoulShot are charged
- * @param shld True if shield is efficient
- *
- */
- protected void onHitTimer(L2Character target, int damage, boolean crit, boolean miss, boolean soulshot, boolean shld)
- {
- // 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)
- if (target == null || isAlikeDead() ||(this instanceof L2NpcInstance && ((L2NpcInstance) this).isEventMob))
- {
- getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
- return;
- }
- if ((this instanceof L2NpcInstance && target.isAlikeDead()) || target.isDead()
- || (!getKnownList().knowsObject(target) && !(this instanceof L2DoorInstance)))
- {
- //getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE, null);
- getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- if (miss)
- {
- if (target instanceof L2PcInstance)
- {
- SystemMessage sm = new SystemMessage(SystemMessageId.AVOIDED_S1S_ATTACK);
- if (this instanceof L2Summon)
- {
- int mobId = ((L2Summon)this).getTemplate().npcId;
- sm.addNpcName(mobId);
- }
- else
- {
- sm.addString(getName());
- }
- ((L2PcInstance)target).sendPacket(sm);
- }
- }
- // If attack isn't aborted, send a message system (critical hit, missed...) to attacker/target if they are L2PcInstance
- if (!isAttackAborted())
- {
- // Check Raidboss attack
- // Character will be petrified if attacking a raid that's more
- // than 8 levels lower
- if (target.isRaid())
- {
- int level = 0;
- if (this instanceof L2PcInstance)
- level = getLevel();
- else if (this instanceof L2Summon)
- level = ((L2Summon)this).getOwner().getLevel();
- if (level > target.getLevel() + 8)
- {
- L2Skill skill = SkillTable.getInstance().getInfo(4515, 1);
- if (skill != null)
- skill.getEffects(target, this);
- else
- _log.warning("Skill 4515 at level 1 is missing in DP.");
- damage = 0; // prevents messing up drop calculation
- }
- }
- sendDamageMessage(target, damage, false, crit, miss);
- // If L2Character target is a L2PcInstance, send a system message
- if (target instanceof L2PcInstance)
- {
- L2PcInstance enemy = (L2PcInstance)target;
-
- if (shld)
- {
- if (100 - Config.ALT_PERFECT_SHLD_BLOCK < Rnd.get(100))
- {
- damage = 1;
- enemy.sendPacket(new SystemMessage(SystemMessageId.YOUR_EXCELLENT_SHIELD_DEFENSE_WAS_A_SUCCESS));; //SHIELD_DEFENCE faultless
- }
- else
- enemy.sendPacket(new SystemMessage(SystemMessageId.SHIELD_DEFENCE_SUCCESSFULL));
- }
- }
- else if (target instanceof L2Summon)
- {
- L2Summon activeSummon = (L2Summon)target;
- SystemMessage sm = new SystemMessage(SystemMessageId.PET_RECEIVED_S2_DAMAGE_BY_S1);
- sm.addString(getName());
- sm.addNumber(damage);
- activeSummon.getOwner().sendPacket(sm);
- }
- if (!miss && damage > 0)
- {
- L2Weapon weapon = getActiveWeaponItem();
- boolean isBow = (weapon != null && weapon.getItemType().toString().equalsIgnoreCase("Bow"));
- if (!isBow || charIsTransformed()) // Do not reflect or absorb if weapon is of type bow
- {
- // Reduce HP of the target and calculate reflection damage to reduce HP of attacker if necessary
- double reflectPercent = target.getStat().calcStat(Stats.REFLECT_DAMAGE_PERCENT,0,null,null);
- if (reflectPercent > 0)
- {
- int reflectedDamage = (int)(reflectPercent / 100. * damage);
- damage -= reflectedDamage;
- if(reflectedDamage > target.getMaxHp()) // to prevent extreme damage when hitting a low lvl char...
- reflectedDamage = target.getMaxHp();
- getStatus().reduceHp(reflectedDamage, target, true);
- // Custom messages - nice but also more network load
- /*
- if (target instanceof L2PcInstance)
- ((L2PcInstance)target).sendMessage("You reflected " + reflectedDamage + " damage.");
- else if (target instanceof L2Summon)
- ((L2Summon)target).getOwner().sendMessage("Summon reflected " + reflectedDamage + " damage.");
- if (this instanceof L2PcInstance)
- ((L2PcInstance)this).sendMessage("Target reflected to you " + reflectedDamage + " damage.");
- else if (this instanceof L2Summon)
- ((L2Summon)this).getOwner().sendMessage("Target reflected to your summon " + reflectedDamage + " damage.");
- */
- }
- // Absorb HP from the damage inflicted
- double absorbPercent = getStat().calcStat(Stats.ABSORB_DAMAGE_PERCENT,0, null,null);
- if (absorbPercent > 0)
- {
- int maxCanAbsorb = (int)(getMaxHp() - getCurrentHp());
- int absorbDamage = (int)(absorbPercent / 100. * damage);
- if (absorbDamage > maxCanAbsorb)
- absorbDamage = maxCanAbsorb; // Can't absord more than max hp
- if (absorbDamage > 0)
- {
- setCurrentHp(getCurrentHp() + absorbDamage);
- // Custom messages - nice but also more network load
- /*
- if (this instanceof L2PcInstance)
- ((L2PcInstance)this).sendMessage("You absorbed " + absorbDamage + " damage.");
- else if (this instanceof L2Summon)
- ((L2Summon)this).getOwner().sendMessage("Summon absorbed " + absorbDamage + " damage.");
- else if (Config.DEBUG)
- _log.info(getName() + " absorbed " + absorbDamage + " damage.");
- */
- }
- }
- }
- target.reduceCurrentHp(damage, this);
- // Notify AI with EVT_ATTACKED
- target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, this);
- getAI().clientStartAutoAttack();
- // Manage attack or cast break of the target (calculating rate, sending message...)
- if (!target.isRaid() && Formulas.getInstance().calcAtkBreak(target, damage))
- {
- target.breakAttack();
- target.breakCast();
- }
- }
- // Launch weapon Special ability effect if available
- L2Weapon activeWeapon = getActiveWeaponItem();
- if (activeWeapon != null)
- activeWeapon.getSkillEffects(this, target, crit);
- /* COMMENTED OUT BY nexus - 2006-08-17
- *
- * We must not discharge the soulshouts at the onHitTimer method,
- * as this can cause unwanted soulshout consumption if the attacker
- * recharges the soulshot right after an attack request but before
- * his hit actually lands on the target.
- *
- * The soulshot discharging has been moved to the doAttack method:
- * As soon as we know that we didn't missed the hit there, then we
- * must discharge any charged soulshots.
- */
- /*
- L2ItemInstance weapon = getActiveWeaponInstance();
- if (!miss)
- {
- if (this instanceof L2Summon && !(this instanceof L2PetInstance))
- {
- if (((L2Summon)this).getChargedSoulShot() != L2ItemInstance.CHARGED_NONE)
- ((L2Summon)this).setChargedSoulShot(L2ItemInstance.CHARGED_NONE);
- }
- else
- {
- if (weapon != null && weapon.getChargedSoulshot() != L2ItemInstance.CHARGED_NONE)
- weapon.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
- }
- }
- */
- return;
- }
- getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
- }
- /**
- * Break an attack and send Server->Client ActionFailed packet and a System Message to the L2Character.<BR><BR>
- */
- public void breakAttack()
- {
- if (isAttackingNow())
- {
- // Abort the attack of the L2Character and send Server->Client ActionFailed packet
- abortAttack();
- if (this instanceof L2PcInstance)
- {
- //TODO Remove sendPacket because it's always done in abortAttack
- sendPacket(ActionFailed.STATIC_PACKET);
- // Send a system message
- sendPacket(new SystemMessage(SystemMessageId.ATTACK_FAILED));
- }
- }
- }
- /**
- * Break a cast and send Server->Client ActionFailed packet and a System Message to the L2Character.<BR><BR>
- */
- public void breakCast()
- {
- // damage can only cancel magical skills
- if (isCastingNow() && canAbortCast() && getLastSkillCast() != null && getLastSkillCast().isMagic())
- {
- // Abort the cast of the L2Character and send Server->Client MagicSkillCanceld/ActionFailed packet.
- abortCast();
- if (this instanceof L2PcInstance)
- {
- // Send a system message
- sendPacket(new SystemMessage(SystemMessageId.CASTING_INTERRUPTED));
- }
- }
- }
- /**
- * Reduce the arrow number of the L2Character.<BR><BR>
- *
- * <B><U> Overriden in </U> :</B><BR><BR>
- * <li> L2PcInstance</li><BR><BR>
- *
- */
- protected void reduceArrowCount(boolean bolts)
- {
- // default is to do nothing
- }
- /**
- * Manage Forced attack (shift + select target).<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>If L2Character or target is in a town area, send a system message TARGET_IN_PEACEZONE a Server->Client packet ActionFailed </li>
- * <li>If target is confused, send a Server->Client packet ActionFailed </li>
- * <li>If L2Character is a L2ArtefactInstance, send a Server->Client packet ActionFailed </li>
- * <li>Send a Server->Client packet MyTargetSelected to start attack and Notify AI with AI_INTENTION_ATTACK </li><BR><BR>
- *
- * @param player The L2PcInstance to attack
- *
- */
- @Override
- public void onForcedAttack(L2PcInstance player)
- {
- if (isInsidePeaceZone(player))
- {
- // If L2Character or target is in a peace zone, send a system message TARGET_IN_PEACEZONE a Server->Client packet ActionFailed
- player.sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
- player.sendPacket(ActionFailed.STATIC_PACKET);
- }
- else if (player.isInOlympiadMode() && player.getTarget() != null)
- {
- L2PcInstance target;
- if (player.getTarget() instanceof L2Summon)
- target=((L2Summon)player.getTarget()).getOwner();
- else
- target=(L2PcInstance)player.getTarget();
-
- if (target.isInOlympiadMode() && !player.isOlympiadStart() && player.getOlympiadGameId()!=target.getOlympiadGameId())
- {
- // if L2PcInstance is in Olympia and the match isn't already start, send a Server->Client packet ActionFailed
- player.sendPacket(ActionFailed.STATIC_PACKET);
- }
- }
- else if (player.getTarget() != null && !player.getTarget().isAttackable() && (player.getAccessLevel() < Config.GM_PEACEATTACK))
- {
- // If target is not attackable, send a Server->Client packet ActionFailed
- player.sendPacket(ActionFailed.STATIC_PACKET);
- }
- else if (player.isConfused())
- {
- // If target is confused, send a Server->Client packet ActionFailed
- player.sendPacket(ActionFailed.STATIC_PACKET);
- }
- else if (this instanceof L2ArtefactInstance)
- {
- // If L2Character is a L2ArtefactInstance, send a Server->Client packet ActionFailed
- player.sendPacket(ActionFailed.STATIC_PACKET);
- }
- else
- {
- // GeoData Los Check or dz > 1000
- if (!GeoData.getInstance().canSeeTarget(player, this))
- {
- player.sendPacket(new SystemMessage(SystemMessageId.CANT_SEE_TARGET));
- player.sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
- // Notify AI with AI_INTENTION_ATTACK
- player.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, this);
- }
- }
- /**
- * Return True if inside peace zone.<BR><BR>
- */
- public boolean isInsidePeaceZone(L2PcInstance attacker)
- {
- return isInsidePeaceZone(attacker, this);
- }
- public boolean isInsidePeaceZone(L2PcInstance attacker, L2Object target)
- {
- return (
- (attacker.getAccessLevel() < Config.GM_PEACEATTACK) &&
- isInsidePeaceZone((L2Object)attacker, target)
- );
- }
- public boolean isInsidePeaceZone(L2Object attacker, L2Object target)
- {
- if (target == null) return false;
- if (target instanceof L2MonsterInstance) return false;
- if (attacker instanceof L2MonsterInstance) return false;
- if (target instanceof L2NpcInstance) return false;
- if (attacker instanceof L2NpcInstance) return false;
- if (Config.ALT_GAME_KARMA_PLAYER_CAN_BE_KILLED_IN_PEACEZONE)
- {
- // allows red to be attacked and red to attack flagged players
- if (target instanceof L2PcInstance && ((L2PcInstance)target).getKarma() > 0)
- return false;
- if (target instanceof L2Summon && ((L2Summon)target).getOwner().getKarma() > 0)
- return false;
- if (attacker instanceof L2PcInstance && ((L2PcInstance)attacker).getKarma() > 0)
- {
- if(target instanceof L2PcInstance && ((L2PcInstance)target).getPvpFlag() > 0)
- return false;
- if(target instanceof L2Summon && ((L2Summon)target).getOwner().getPvpFlag() > 0)
- return false;
- }
- if (attacker instanceof L2Summon && ((L2Summon)attacker).getOwner().getKarma() > 0)
- {
- if(target instanceof L2PcInstance && ((L2PcInstance)target).getPvpFlag() > 0)
- return false;
- if(target instanceof L2Summon && ((L2Summon)target).getOwner().getPvpFlag() > 0)
- return false;
- }
- if (attacker instanceof L2Character && target instanceof L2Character)
- {
- return (((L2Character)target).isInsideZone(ZONE_PEACE) || ((L2Character)attacker).isInsideZone(ZONE_PEACE));
- }
- if (attacker instanceof L2Character)
- {
- return (TownManager.getInstance().getTown(target.getX(), target.getY(), target.getZ()) != null || ((L2Character)attacker).isInsideZone(ZONE_PEACE));
- }
- }
- return (TownManager.getInstance().getTown(target.getX(), target.getY(), target.getZ()) != null ||
- TownManager.getInstance().getTown(attacker.getX(), attacker.getY(), attacker.getZ()) != null);
- }
- /**
- * return true if this character is inside an active grid.
- */
- public Boolean isInActiveRegion()
- {
- L2WorldRegion region = getWorldRegion();
- return ((region !=null) && (region.isActive()));
- }
- /**
- * Return True if the L2Character has a Party in progress.<BR><BR>
- */
- public boolean isInParty()
- {
- return false;
- }
- /**
- * Return the L2Party object of the L2Character.<BR><BR>
- */
- public L2Party getParty()
- {
- return null;
- }
- /**
- * Return the Attack Speed of the L2Character (delay (in milliseconds) before next attack).<BR><BR>
- */
- public int calculateTimeBetweenAttacks(L2Character target, L2Weapon weapon)
- {
- double atkSpd = 0;
- if (weapon !=null && !charIsTransformed())
- {
- switch (weapon.getItemType())
- {
- case BOW:
- atkSpd = getStat().getPAtkSpd();
- return (int)(1500*345/atkSpd);
- case CROSSBOW:
- atkSpd = getStat().getPAtkSpd();
- return (int)(1200*345/atkSpd);
- case DAGGER:
- atkSpd = getStat().getPAtkSpd();
- //atkSpd /= 1.15;
- break;
- default:
- atkSpd = getStat().getPAtkSpd();
- }
- }
- else
- atkSpd = getPAtkSpd();
- return Formulas.getInstance().calcPAtkSpd(this, target, atkSpd);
- }
- public int calculateReuseTime(L2Character target, L2Weapon weapon)
- {
- if (weapon == null || charIsTransformed()) return 0;
- int reuse = weapon.getAttackReuseDelay();
- // only bows should continue for now
- if (reuse == 0) return 0;
- // else if (reuse < 10) reuse = 1500;
- reuse *= getStat().getWeaponReuseModifier(target);
- double atkSpd = getStat().getPAtkSpd();
- switch (weapon.getItemType())
- {
- case BOW:
- case CROSSBOW:
- return (int)(reuse*345/atkSpd);
- default:
- return (int)(reuse*312/atkSpd);
- }
- }
-
- /**
- * Return True if the L2Character use a dual weapon.<BR><BR>
- */
- public boolean isUsingDualWeapon()
- {
- return false;
- }
- /**
- * Add a skill to the L2Character _skills and its Func objects to the calculator set of the L2Character.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * All skills own by a L2Character are identified in <B>_skills</B><BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Replace oldSkill by newSkill or Add the newSkill </li>
- * <li>If an old skill has been replaced, remove all its Func objects of L2Character calculator set</li>
- * <li>Add Func objects of newSkill to the calculator set of the L2Character </li><BR><BR>
- *
- * <B><U> Overriden in </U> :</B><BR><BR>
- * <li> L2PcInstance : Save update in the character_skills table of the database</li><BR><BR>
- *
- * @param newSkill The L2Skill to add to the L2Character
- *
- * @return The L2Skill replaced or null if just added a new L2Skill
- *
- */
- public L2Skill addSkill(L2Skill newSkill)
- {
- L2Skill oldSkill = null;
- if (newSkill != null)
- {
- // Replace oldSkill by newSkill or Add the newSkill
- oldSkill = _skills.put(newSkill.getId(), newSkill);
- // If an old skill has been replaced, remove all its Func objects
- if (oldSkill != null)
- removeStatsOwner(oldSkill);
- // Add Func objects of newSkill to the calculator set of the L2Character
- addStatFuncs(newSkill.getStatFuncs(null, this));
- }
- return oldSkill;
- }
- /**
- * Remove a skill from the L2Character and its Func objects from calculator set of the L2Character.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * All skills own by a L2Character are identified in <B>_skills</B><BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Remove the skill from the L2Character _skills </li>
- * <li>Remove all its Func objects from the L2Character calculator set</li><BR><BR>
- *
- * <B><U> Overriden in </U> :</B><BR><BR>
- * <li> L2PcInstance : Save update in the character_skills table of the database</li><BR><BR>
- *
- * @param skill The L2Skill to remove from the L2Character
- *
- * @return The L2Skill removed
- *
- */
- public L2Skill removeSkill(L2Skill skill)
- {
- if (skill == null) return null;
- // Remove the skill from the L2Character _skills
- L2Skill oldSkill = _skills.remove(skill.getId());
- // Remove all its Func objects from the L2Character calculator set
- if (oldSkill != null)
- {
- // Stop casting if this skill is used right now
- if (this instanceof L2PcInstance)
- {
- if (((L2PcInstance)this).getCurrentSkill() != null && isCastingNow())
- {
- if (oldSkill.getId() == ((L2PcInstance)this).getCurrentSkill().getSkillId())
- abortCast();
- }
- }
- // for now, to support transformations, we have to let their
- // effects stay when skill is removed
- L2Effect e = getFirstEffect(oldSkill);
- if (e == null || e.getEffectType() != EffectType.TRANSFORMATION)
- {
- removeStatsOwner(oldSkill);
- stopSkillEffects(oldSkill.getId());
- }
- }
- return oldSkill;
- }
- /**
- * Return all skills own by the L2Character in a table of L2Skill.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * All skills own by a L2Character are identified in <B>_skills</B> the L2Character <BR><BR>
- *
- */
- public final L2Skill[] getAllSkills()
- {
- if (_skills == null)
- return new L2Skill[0];
- return _skills.values().toArray(new L2Skill[_skills.values().size()]);
- }
- /**
- * Return the level of a skill owned by the L2Character.<BR><BR>
- *
- * @param skillId The identifier of the L2Skill whose level must be returned
- *
- * @return The level of the L2Skill identified by skillId
- *
- */
- public int getSkillLevel(int skillId)
- {
- if (_skills == null)
- return -1;
- L2Skill skill = _skills.get(skillId);
- if (skill == null)
- return -1;
- return skill.getLevel();
- }
- /**
- * Return True if the skill is known by the L2Character.<BR><BR>
- *
- * @param skillId The identifier of the L2Skill to check the knowledge
- *
- */
- public final L2Skill getKnownSkill(int skillId)
- {
- if (_skills == null)
- return null;
- return _skills.get(skillId);
- }
- /**
- * Return the number of skills of type(Buff, Debuff, HEAL_PERCENT, MANAHEAL_PERCENT) affecting this L2Character.<BR><BR>
- *
- * @return The number of Buffs affecting this L2Character
- */
- public int getBuffCount() {
- L2Effect[] effects = getAllEffects();
- int numBuffs=0;
- if (effects != null) {
- for (L2Effect e : effects) {
- if (e != null) {
- if ((e.getSkill().getSkillType() == L2Skill.SkillType.BUFF ||
- e.getSkill().getSkillType() == L2Skill.SkillType.DEBUFF ||
- e.getSkill().getSkillType() == L2Skill.SkillType.REFLECT ||
- e.getSkill().getSkillType() == L2Skill.SkillType.HEAL_PERCENT ||
- e.getSkill().getSkillType() == L2Skill.SkillType.MANAHEAL_PERCENT) &&
- !(e.getSkill().getId() > 4360 && e.getSkill().getId() < 4367)) { // 7s buffs
- numBuffs++;
- }
- }
- }
- }
- return numBuffs;
- }
- /**
- * Removes the first Buff of this L2Character.<BR><BR>
- *
- * @param preferSkill If != 0 the given skill Id will be removed instead of first
- */
- public void removeFirstBuff(int preferSkill) {
- L2Effect[] effects = getAllEffects();
- L2Effect removeMe=null;
- if (effects != null) {
- for (L2Effect e : effects) {
- if (e != null) {
- if ((e.getSkill().getSkillType() == L2Skill.SkillType.BUFF ||
- e.getSkill().getSkillType() == L2Skill.SkillType.DEBUFF ||
- e.getSkill().getSkillType() == L2Skill.SkillType.REFLECT ||
- e.getSkill().getSkillType() == L2Skill.SkillType.HEAL_PERCENT ||
- e.getSkill().getSkillType() == L2Skill.SkillType.MANAHEAL_PERCENT) &&
- !(e.getSkill().getId() > 4360 && e.getSkill().getId() < 4367)) {
- if (preferSkill == 0) { removeMe=e; break; }
- else if (e.getSkill().getId() == preferSkill) { removeMe=e; break; }
- else if (removeMe==null) removeMe=e;
- }
- }
- }
- }
- if (removeMe != null) removeMe.exit();
- }
- public int getDanceCount()
- {
- int danceCount = 0;
- L2Effect[] effects = getAllEffects();
- for (L2Effect effect : effects)
- {
- if (effect == null)
- continue;
- if (effect.getSkill().isDance() && effect.getInUse())
- danceCount++;
- }
- return danceCount;
- }
- /**
- * Checks if the given skill stacks with an existing one.<BR><BR>
- *
- * @param checkSkill the skill to be checked
- *
- * @return Returns whether or not this skill will stack
- */
- public boolean doesStack(L2Skill checkSkill) {
- if (_effects == null || _effects.size() < 1 ||
- checkSkill._effectTemplates == null ||
- checkSkill._effectTemplates.length < 1 ||
- checkSkill._effectTemplates[0].stackType == null) return false;
- String stackType=checkSkill._effectTemplates[0].stackType;
- if (stackType.equals("none")) return false;
- for (int i=0; i<_effects.size(); i++) {
- if (_effects.get(i).getStackType() != null &&
- _effects.get(i).getStackType().equals(stackType)) return true;
- }
- return false;
- }
- /**
- * Manage the magic skill launching task (MP, HP, Item consummation...) and display the magic skill animation on client.<BR><BR>
- *
- * <B><U> Actions</U> :</B><BR><BR>
- * <li>Send a Server->Client packet MagicSkillLaunched (to display magic skill animation) to all L2PcInstance of L2Charcater _knownPlayers</li>
- * <li>Consumme MP, HP and Item if necessary</li>
- * <li>Send a Server->Client packet StatusUpdate with MP modification to the L2PcInstance</li>
- * <li>Launch the magic skill in order to calculate its effects</li>
- * <li>If the skill type is PDAM, notify the AI of the target with AI_INTENTION_ATTACK</li>
- * <li>Notify the AI of the L2Character with EVT_FINISH_CASTING</li><BR><BR>
- *
- * <FONT COLOR=#FF0000><B> <U>Caution</U> : A magic skill casting MUST BE in progress</B></FONT><BR><BR>
- *
- * @param skill The L2Skill to use
- *
- */
- public void onMagicLaunchedTimer(L2Object[] targets, L2Skill skill, int coolTime, boolean instant)
- {
- if (skill == null || targets == null || targets.length <= 0)
- {
- _skillCast = null;
- enableAllSkills();
- getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
- return;
- }
- // Escaping from under skill's radius and peace zone check. First version, not perfect in AoE skills.
- int escapeRange = 0;
- if(skill.getEffectRange() > escapeRange) escapeRange = skill.getEffectRange();
- else if(skill.getCastRange() < 0 && skill.getSkillRadius() > 80) escapeRange = skill.getSkillRadius();
- if (escapeRange > 0)
- {
- List<L2Character> targetList = new FastList<L2Character>();
- for (int i = 0; i < targets.length; i++)
- {
- if (targets[i] instanceof L2Character)
- {
- if (!Util.checkIfInRange(escapeRange, this, targets[i], true))
- continue;
- if(skill.isOffensive())
- {
- if(this instanceof L2PcInstance)
- {
- if(((L2Character)targets[i]).isInsidePeaceZone((L2PcInstance)this))
- continue;
- }
- else
- {
- if(((L2Character)targets[i]).isInsidePeaceZone(this, targets[i]))
- continue;
- }
- }
- targetList.add((L2Character)targets[i]);
- }
- //else
- //{
- // if (Config.DEBUG)
- // _log.warning("Class cast bad: "+targets[i].getClass().toString());
- //}
- }
- if(targetList.isEmpty())
- {
- abortCast();
- return;
- }
- else targets = targetList.toArray(new L2Character[targetList.size()]);
- }
- // Ensure that a cast is in progress
- // Check if player is using fake death.
- // Potions can be used while faking death.
- if (!isCastingNow() || (isAlikeDead() && !skill.isPotion()))
- {
- _skillCast = null;
- enableAllSkills();
-
- getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
- _castEndTime = 0;
- _castInterruptTime = 0;
- return;
- }
-
- // Get the display identifier of the skill
- int magicId = skill.getDisplayId();
- // Get the level of the skill
- int level = getSkillLevel(skill.getId());
- if (level < 1)
- level = 1;
- // Send a Server->Client packet MagicSkillLaunched to the L2Character AND to all L2PcInstance in the _KnownPlayers of the L2Character
- if (!skill.isPotion()) broadcastPacket(new MagicSkillLaunched(this, magicId, level, targets));
-
- if (instant)
- onMagicHitTimer(targets, skill, coolTime, true);
- else
- _skillCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 2), 200);
-
- }
-
- /*
- * Runs in the end of skill casting
- */
- public void onMagicHitTimer(L2Object[] targets, L2Skill skill, int coolTime, boolean instant)
- {
- if (skill == null || targets == null || targets.length <= 0)
- {
- _skillCast = null;
- enableAllSkills();
- getAI().notifyEvent(CtrlEvent.EVT_CANCEL);
- return;
- }
- if(getForceBuff() != null)
- {
- _skillCast = null;
- enableAllSkills();
- getForceBuff().delete();
- return;
- }
- L2Effect mog = getFirstEffect(L2Effect.EffectType.SIGNET_GROUND);
- if (mog != null)
- {
- _skillCast = null;
- enableAllSkills();
- mog.exit();
- return;
- }
- try {
-
- // Go through targets table
- for (int i = 0;i < targets.length;i++)
- {
- if (targets[i] instanceof L2PlayableInstance)
- {
- L2Character target = (L2Character) targets[i];
- if (skill.getSkillType() == L2Skill.SkillType.BUFF)
- {
- SystemMessage smsg = new SystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
- smsg.addString(skill.getName());
- target.sendPacket(smsg);
- }
- if (this instanceof L2PcInstance && target instanceof L2Summon)
- {
- ((L2Summon)target).getOwner().sendPacket(new PetInfo((L2Summon)target));
- sendPacket(new NpcInfo((L2Summon)target, this));
- // The PetInfo packet wipes the PartySpelled (list of active spells' icons). Re-add them
- ((L2Summon)target).updateEffectIcons(true);
- }
- }
- }
- StatusUpdate su = new StatusUpdate(getObjectId());
- boolean isSendStatus = false;
- // Consume MP of the L2Character and Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
- double mpConsume = getStat().getMpConsume(skill);
- if (mpConsume > 0)
- {
- getStatus().reduceMp(calcStat(Stats.MP_CONSUME_RATE,mpConsume,null,null));
- su.addAttribute(StatusUpdate.CUR_MP, (int) getCurrentMp());
- isSendStatus = true;
- }
- // Consume HP if necessary and Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
- if (skill.getHpConsume() > 0)
- {
- double consumeHp;
- consumeHp = calcStat(Stats.HP_CONSUME_RATE,skill.getHpConsume(),null,null);
- if(consumeHp+1 >= getCurrentHp())
- consumeHp = getCurrentHp()-1.0;
- getStatus().reduceHp(consumeHp, this);
- su.addAttribute(StatusUpdate.CUR_HP, (int) getCurrentHp());
- isSendStatus = true;
- }
- // Send a Server->Client packet StatusUpdate with MP modification to the L2PcInstance
- if (isSendStatus) sendPacket(su);
- // Consume Items if necessary and Send the Server->Client packet InventoryUpdate with Item modification to all the L2Character
- if (skill.getItemConsume() > 0)
- consumeItem(skill.getItemConsumeId(), skill.getItemConsume());
- // Consume Souls if necessary
- if (skill.getSoulConsumeCount() > 0)
- {
- if (this instanceof L2PcInstance)
- {
- ((L2PcInstance)this).decreaseSouls(skill.getSoulConsumeCount());
- sendPacket(new EtcStatusUpdate((L2PcInstance)this));
- }
- }
- // Launch the magic skill in order to calculate its effects
- callSkill(skill, targets);
- }
- catch (NullPointerException e) {}
-
- if (instant || coolTime == 0)
- onMagicFinalizer(skill);
- else
- _skillCast = ThreadPoolManager.getInstance().scheduleEffect(new MagicUseTask(targets, skill, coolTime, 3), coolTime);
- }
- /*
- * Runs after skill hitTime+coolTime
- */
- public void onMagicFinalizer(L2Skill skill)
- {
- _skillCast = null;
- _castEndTime = 0;
- _castInterruptTime = 0;
- enableAllSkills();
-
- // If the skill type is listed here, notify the AI of the target with AI_INTENTION_ATTACK
- // for offensive skills the nextintention is always null unless player wants action after skill
- // Note: this might also work
- // if (skill.isOffensive() && getAI().getNextIntention() == null
- // && !(skill.getSkillType() == SkillType.UNLOCK) && !(skill.getSkillType() == SkillType.DELUXE_KEY_UNLOCK) && !(skill.getSkillType() == SkillType.MDAM))
- if (getAI().getNextIntention() == null && skill.getSkillType() == SkillType.PDAM || skill.getSkillType() == SkillType.BLOW
- || skill.getSkillType() == SkillType.DRAIN_SOUL || skill.getSkillType() == SkillType.SOW
- || skill.getSkillType() == SkillType.SPOIL)
- {
- if ((getTarget() != null) && (getTarget() instanceof L2Character))
- getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, getTarget());
- }
- if (skill.isOffensive() && !(skill.getSkillType() == SkillType.UNLOCK) && !(skill.getSkillType() == SkillType.DELUXE_KEY_UNLOCK))
- getAI().clientStartAutoAttack();
- // Notify the AI of the L2Character with EVT_FINISH_CASTING
- getAI().notifyEvent(CtrlEvent.EVT_FINISH_CASTING);
- /*
- * If character is a player, then wipe their current cast state and
- * check if a skill is queued.
- *
- * If there is a queued skill, launch it and wipe the queue.
- */
- if (this instanceof L2PcInstance)
- {
- L2PcInstance currPlayer = (L2PcInstance)this;
- SkillDat queuedSkill = currPlayer.getQueuedSkill();
-
- // Rescuing old skill cast task if exist
- if (skill.isPotion())
- queuedSkill = currPlayer.getCurrentSkill();
- currPlayer.setCurrentSkill(null, false, false);
- if (queuedSkill != null)
- {
- currPlayer.setQueuedSkill(null, false, false);
- // DON'T USE : Recursive call to useMagic() method
- // currPlayer.useMagic(queuedSkill.getSkill(), queuedSkill.isCtrlPressed(), queuedSkill.isShiftPressed());
- ThreadPoolManager.getInstance().executeTask(new QueuedMagicUseTask(currPlayer, queuedSkill.getSkill(), queuedSkill.isCtrlPressed(), queuedSkill.isShiftPressed()) );
- }
- }
- }
- /**
- * Reduce the item number of the L2Character.<BR><BR>
- *
- * <B><U> Overriden in </U> :</B><BR><BR>
- * <li> L2PcInstance</li><BR><BR>
- *
- */
- public void consumeItem(@SuppressWarnings("unused") int itemConsumeId, @SuppressWarnings("unused") int itemCount)
- {
- }
- /**
- * Enable a skill (remove it from _disabledSkills of the L2Character).<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * All skills disabled are identified by their skillId in <B>_disabledSkills</B> of the L2Character <BR><BR>
- *
- * @param skillId The identifier of the L2Skill to enable
- *
- */
- public void enableSkill(int skillId)
- {
- if (_disabledSkills == null) return;
- _disabledSkills.remove(new Integer(skillId));
- if (this instanceof L2PcInstance)
- removeTimeStamp(skillId);
- }
- /**
- * Disable a skill (add it to _disabledSkills of the L2Character).<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * All skills disabled are identified by their skillId in <B>_disabledSkills</B> of the L2Character <BR><BR>
- *
- * @param skillId The identifier of the L2Skill to disable
- *
- */
- public void disableSkill(int skillId)
- {
- if (_disabledSkills == null) _disabledSkills = Collections.synchronizedList(new FastList<Integer>());
- _disabledSkills.add(skillId);
- }
- /**
- * Disable this skill id for the duration of the delay in milliseconds.
- * @param skillId
- * @param delay (seconds * 1000)
- */
- public void disableSkill(int skillId, long delay)
- {
- disableSkill(skillId);
- if (delay > 10) ThreadPoolManager.getInstance().scheduleAi(new EnableSkill(skillId), delay);
- }
- /**
- * Check if a skill is disabled.<BR><BR>
- *
- * <B><U> Concept</U> :</B><BR><BR>
- * All skills disabled are identified by their skillId in <B>_disabledSkills</B> of the L2Character <BR><BR>
- *
- * @param skillId The identifier of the L2Skill to disable
- *
- */
- public boolean isSkillDisabled(int skillId)
- {
- if (isAllSkillsDisabled()) return true;
- if (_disabledSkills == null) return false;
- return _disabledSkills.contains(skillId);
- }
- /**
- * Disable all skills (set _allSkillsDisabled to True).<BR><BR>
- */
- public void disableAllSkills()
- {
- if (Config.DEBUG) _log.fine("all skills disabled");
- _allSkillsDisabled = true;
- }
- /**
- * Enable all skills (set _allSkillsDisabled to False).<BR><BR>
- */
- public void enableAllSkills()
- {
- if (Config.DEBUG) _log.fine("all skills enabled");
- _allSkillsDisabled = false;
- }
- /**
- * Launch the magic skill and calculate its effects on each target contained in the targets table.<BR><BR>
- *
- * @param skill The L2Skill to use
- * @param targets The table of L2Object targets
- *
- */
- public void callSkill(L2Skill skill, L2Object[] targets)
- {
- try
- {
- // Get the skill handler corresponding to the skill type (PDAM, MDAM, SWEEP...) started in gameserver
- ISkillHandler handler = SkillHandler.getInstance().getSkillHandler(skill.getSkillType());
- L2Weapon activeWeapon = getActiveWeaponItem();
- L2PcInstance player = null;
- if (this instanceof L2PcInstance)
- player = (L2PcInstance)this;
- else if (this instanceof L2Summon)
- player = ((L2Summon)this).getOwner();
- else if (this instanceof L2Trap)
- player = ((L2Trap)this).getOwner();
-
- // Check if the toggle skill effects are already in progress on the L2Character
- if(skill.isToggle() && getFirstEffect(skill.getId()) != null)
- return;
-
- // Initial checks
- for (L2Object trg : targets)
- {
- if (trg instanceof L2Character)
- {
- // Set some values inside target's instance for later use
- L2Character target = (L2Character) trg;
- // Check Raidboss attack and
- // check buffing chars who attack raidboss. Results in mute.
- L2Object target2 = target.getTarget();
- if ((target.isRaid() && getLevel() > target.getLevel() + 8)
- || (target2 instanceof L2Character && (((L2Character)target2).isRaid()
- && getLevel() > ((L2Character)target2).getLevel() + 8)))
- {
- if (skill.isMagic())
- {
- L2Skill tempSkill = SkillTable.getInstance().getInfo(4215, 1);
- if(tempSkill != null)
- tempSkill.getEffects(target, this);
- else
- _log.warning("Skill 4215 at level 1 is missing in DP.");
- }
- else
- {
- L2Skill tempSkill = SkillTable.getInstance().getInfo(4515, 1);
- if(tempSkill != null)
- tempSkill.getEffects(target, this);
- else
- _log.warning("Skill 4515 at level 1 is missing in DP.");
- }
- return;
- }
-
- // Check if over-hit is possible
- if(skill.isOverhit())
- {
- if(target instanceof L2Attackable)
- ((L2Attackable)target).overhitEnabled(true);
- }
- // Launch weapon Special ability skill effect if available
- if (activeWeapon != null && !target.isDead())
- {
- if (activeWeapon.getSkillEffects(this, target, skill).length > 0 && this instanceof L2PcInstance)
- {
- sendPacket(SystemMessage.sendString("Target affected by weapon special ability!"));
- }
- }
- }
- }
- // Launch the magic skill and calculate its effects
- if (handler != null)
- handler.useSkill(this, skill, targets);
- else
- skill.useSkill(this, targets);
- if (player != null)
- {
- for (L2Object target : targets)
- {
- // EVT_ATTACKED and PvPStatus
- if (target instanceof L2Character)
- {
- if (skill.isOffensive())
- {
- if (target instanceof L2PcInstance || target instanceof L2Summon || target instanceof L2Trap)
- {
- // Signets are a special case, casted on target_self but don't harm self
- if (skill.getSkillType() != L2Skill.SkillType.SIGNET && skill.getSkillType() != L2Skill.SkillType.SIGNET_CASTTIME)
- {
- ((L2Character)target).getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, player);
- player.updatePvPStatus((L2Character)target);
- }
- }
- else if (target instanceof L2Attackable)
- {
- // notify the AI that she is attacked
- ((L2Character)target).getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, player);
- }
- }
- else
- {
- if (target instanceof L2PcInstance)
- {
- // Casting non offensive skill on player with pvp flag set or with karma
- if (!target.equals(this) &&
- (((L2PcInstance)target).getPvpFlag() > 0 ||
- ((L2PcInstance)target).getKarma() > 0)) player.updatePvPStatus();
- }
- else if (target instanceof L2Attackable
- && !(skill.getSkillType() == L2Skill.SkillType.SUMMON)
- && !(skill.getSkillType() == L2Skill.SkillType.BEAST_FEED)
- && !(skill.getSkillType() == L2Skill.SkillType.UNLOCK)
- && !(skill.getSkillType() == L2Skill.SkillType.DELUXE_KEY_UNLOCK))
- player.updatePvPStatus();
- }
- }
- }
- // Mobs in range 1000 see spell
- for (L2Object spMob : player.getKnownList().getKnownObjects().values())
- {
- if (spMob instanceof L2NpcInstance)
- {
- L2NpcInstance npcMob = (L2NpcInstance) spMob;
-
- if ( (npcMob.isInsideRadius(player, 1000, true, true)) &&
- (npcMob.getTemplate().getEventQuests(Quest.QuestEventType.ON_SKILL_SEE) !=null) )
- for (Quest quest: npcMob.getTemplate().getEventQuests(Quest.QuestEventType.ON_SKILL_SEE))
- quest.notifySkillSee(npcMob, player, skill, targets, this instanceof L2Summon);
-
- /**************** FULMINUS COMMENT START***************/
- if (skill.getAggroPoints() > 0)
- {
- if (npcMob.isInsideRadius(player, 1000, true, true)
- && npcMob.hasAI()
- && npcMob.getAI().getIntention() == AI_INTENTION_ATTACK)
- {
- L2Object npcTarget = npcMob.getTarget();
- for (L2Object target : targets)
- if (npcTarget == target || npcMob == target)
- npcMob.seeSpell(player, target, skill);
- }
- }
- /**************** FULMINUS COMMENT END ***************/
- // the section within "Fulminus Comment" should be deleted from core and placed
- // within the mob's AI Script's onSkillSee, which is called by quest.notifySkillSee
- }
- }
- }
- }
- catch (Exception e)
- {
- _log.log(Level.WARNING, "", e);
- }
- }
-
- public void seeSpell(L2PcInstance caster, L2Object target, L2Skill skill)
- {
- // TODO: Aggro calculation due to spells ought to be inside the AI script's onSkillSee.
- // when it is added there, this function will no longer be needed here. (Fulminus)
- if (this instanceof L2Attackable)
- ((L2Attackable)this).addDamageHate(caster, 0, -skill.getAggroPoints());
- }
-
- /**
- * Return True if the L2Character is behind the target and can't be seen.<BR><BR>
- */
- public boolean isBehind(L2Object target)
- {
- double angleChar, angleTarget, angleDiff, maxAngleDiff = 45;
- if(target == null)
- return false;
- if (target instanceof L2Character)
- {
- L2Character target1 = (L2Character) target;
- angleChar = Util.calculateAngleFrom(this, target1);
- angleTarget = Util.convertHeadingToDegree(target1.getHeading());
- angleDiff = angleChar - angleTarget;
- if (angleDiff <= -360 + maxAngleDiff) angleDiff += 360;
- if (angleDiff >= 360 - maxAngleDiff) angleDiff -= 360;
- if (Math.abs(angleDiff) <= maxAngleDiff)
- {
- if (Config.DEBUG)
- _log.info("Char " + getName() + " is behind " + target.getName());
- return true;
- }
- }
- else
- {
- _log.fine("isBehindTarget's target not an L2 Character.");
- }
- return false;
- }
- public boolean isBehindTarget()
- {
- return isBehind(getTarget());
- }
- /**
- * Return True if the target is facing the L2Character.<BR><BR>
- */
- public boolean isInFrontOf(L2Character target)
- {
- double angleChar, angleTarget, angleDiff, maxAngleDiff = 45;
- if(target == null)
- return false;
- angleTarget = Util.calculateAngleFrom(target, this);
- angleChar = Util.convertHeadingToDegree(target.getHeading());
- angleDiff = angleChar - angleTarget;
- if (angleDiff <= -360 + maxAngleDiff) angleDiff += 360;
- if (angleDiff >= 360 - maxAngleDiff) angleDiff -= 360;
- if (Math.abs(angleDiff) <= maxAngleDiff)
- return true;
- return false;
- }
- /** Returns true if target is in front of L2Character (shield def etc) */
- public boolean isFacing(L2Object target, int maxAngle)
- {
- double angleChar, angleTarget, angleDiff, maxAngleDiff;
- if(target == null)
- return false;
- maxAngleDiff = maxAngle / 2;
- angleTarget = Util.calculateAngleFrom(this, target);
- angleChar = Util.convertHeadingToDegree(this.getHeading());
- angleDiff = angleChar - angleTarget;
- if (angleDiff <= -360 + maxAngleDiff) angleDiff += 360;
- if (angleDiff >= 360 - maxAngleDiff) angleDiff -= 360;
- if (Math.abs(angleDiff) <= maxAngleDiff)
- return true;
- return false;
- }
-
- public boolean isInFrontOfTarget()
- {
- L2Object target = getTarget();
- if (target instanceof L2Character)
- return isInFrontOf((L2Character)target);
- else
- return false;
- }
- /**
- * Return 1.<BR><BR>
- */
- public double getLevelMod()
- {
- return 1;
- }
- public final void setSkillCast(Future<?> newSkillCast)
- {
- _skillCast = newSkillCast;
- }
- public final void setSkillCastEndTime(int newSkillCastEndTime)
- {
- _castEndTime = newSkillCastEndTime;
- // for interrupt -12 ticks; first removing the extra second and then -200 ms
- _castInterruptTime = newSkillCastEndTime-12;
- }
- private Future<?> _PvPRegTask;
- private long _pvpFlagLasts;
- public void setPvpFlagLasts(long time)
- {
- _pvpFlagLasts = time;
- }
- public long getPvpFlagLasts()
- {
- return _pvpFlagLasts;
- }
- public void startPvPFlag()
- {
- updatePvPFlag(1);
- _PvPRegTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new PvPFlag(), 1000, 1000);
- }
- public void stopPvpRegTask()
- {
- if (_PvPRegTask != null)
- _PvPRegTask.cancel(true);
- }
- public void stopPvPFlag()
- {
- stopPvpRegTask();
- updatePvPFlag(0);
- _PvPRegTask = null;
- }
- public void updatePvPFlag(int value) {
- if (!(this instanceof L2PcInstance))
- return;
- L2PcInstance player = (L2PcInstance)this;
- if (player.getPvpFlag() == value)
- return;
- player.setPvpFlag(value);
- player.sendPacket(new UserInfo(player));
- for (L2PcInstance target : getKnownList().getKnownPlayers().values()) {
- target.sendPacket(new RelationChanged(player, player.getRelation(player), player.isAutoAttackable(target)));
- }
- }
- // public void checkPvPFlag()
- // {
- // if (Config.DEBUG) _log.fine("Checking PvpFlag");
- // _PvPRegTask = ThreadPoolManager.getInstance().scheduleLowAtFixedRate(
- // new PvPFlag(), 1000, 5000);
- // _PvPRegActive = true;
- // // _log.fine("PvP recheck");
- // }
- //
- /**
- * Return a Random Damage in function of the weapon.<BR><BR>
- */
- public final int getRandomDamage(@SuppressWarnings("unused") L2Character target)
- {
- L2Weapon weaponItem = getActiveWeaponItem();
- if (weaponItem == null)
- return 5+(int)Math.sqrt(getLevel());
- return weaponItem.getRandomDamage();
- }
- @Override
- public String toString()
- {
- return "mob "+getObjectId();
- }
- public int getAttackEndTime()
- {
- return _attackEndTime;
- }
- /**
- * Not Implemented.<BR><BR>
- */
- public abstract int getLevel();
- // =========================================================
- // =========================================================
- // Stat - NEED TO REMOVE ONCE L2CHARSTAT IS COMPLETE
- // Property - Public
- public final double calcStat(Stats stat, double init, L2Character target, L2Skill skill) { return getStat().calcStat(stat, init, target, skill); }
- // Property - Public
- public int getAccuracy() { return getStat().getAccuracy(); }
- public final float getAttackSpeedMultiplier() { return getStat().getAttackSpeedMultiplier(); }
- public int getCON() { return getStat().getCON(); }
- public int getDEX() { return getStat().getDEX(); }
- public final double getCriticalDmg(L2Character target, double init) { return getStat().getCriticalDmg(target, init); }
- public int getCriticalHit(L2Character target, L2Skill skill) { return getStat().getCriticalHit(target, skill); }
- public int getEvasionRate(L2Character target) { return getStat().getEvasionRate(target); }
- public int getINT() { return getStat().getINT(); }
- public final int getMagicalAttackRange(L2Skill skill) { return getStat().getMagicalAttackRange(skill); }
- public final int getMaxCp() { return getStat().getMaxCp(); }
- public int getMAtk(L2Character target, L2Skill skill) { return getStat().getMAtk(target, skill); }
- public int getMAtkSpd() { return getStat().getMAtkSpd(); }
- public int getMaxMp() { return getStat().getMaxMp(); }
- public int getMaxHp() { return getStat().getMaxHp(); }
- public final int getMCriticalHit(L2Character target, L2Skill skill) { return getStat().getMCriticalHit(target, skill); }
- public int getMDef(L2Character target, L2Skill skill) { return getStat().getMDef(target, skill); }
- public int getMEN() { return getStat().getMEN(); }
- public double getMReuseRate(L2Skill skill) { return getStat().getMReuseRate(skill); }
- public float getMovementSpeedMultiplier() { return getStat().getMovementSpeedMultiplier(); }
- public int getPAtk(L2Character target) { return getStat().getPAtk(target); }
- public double getPAtkAnimals(L2Character target) { return getStat().getPAtkAnimals(target); }
- public double getPAtkDragons(L2Character target) { return getStat().getPAtkDragons(target); }
- public double getPAtkInsects(L2Character target) { return getStat().getPAtkInsects(target); }
- public double getPAtkMonsters(L2Character target) { return getStat().getPAtkMonsters(target); }
- public double getPAtkPlants(L2Character target) { return getStat().getPAtkPlants(target); }
- public double getPAtkGiants(L2Character target) { return getStat().getPAtkGiants(target); }
- public double getPDefAnimals(L2Character target) { return getStat().getPDefAnimals(target); }
- public double getPDefDragons(L2Character target) { return getStat().getPDefDragons(target); }
- public double getPDefInsects(L2Character target) { return getStat().getPDefInsects(target); }
- public double getPDefMonsters(L2Character target) { return getStat().getPDefMonsters(target); }
- public double getPDefPlants(L2Character target) { return getStat().getPDefPlants(target); }
- public double getPDefGiants(L2Character target) { return getStat().getPDefGiants(target); }
-
- public int getPAtkSpd() { return getStat().getPAtkSpd(); }
- public double getPAtkUndead(L2Character target) { return getStat().getPAtkUndead(target); }
- public double getPDefUndead(L2Character target) { return getStat().getPDefUndead(target); }
- public int getPDef(L2Character target) { return getStat().getPDef(target); }
- public final int getPhysicalAttackRange() { return getStat().getPhysicalAttackRange(); }
- public int getRunSpeed() { return getStat().getRunSpeed(); }
- public final int getShldDef() { return getStat().getShldDef(); }
- public int getSTR() { return getStat().getSTR(); }
- public final int getWalkSpeed() { return getStat().getWalkSpeed(); }
- public int getWIT() { return getStat().getWIT(); }
- // =========================================================
- // =========================================================
- // Status - NEED TO REMOVE ONCE L2CHARTATUS IS COMPLETE
- // Method - Public
- public void addStatusListener(L2Character object) { getStatus().addStatusListener(object); }
- public void reduceCurrentHp(double i, L2Character attacker) { reduceCurrentHp(i, attacker, true); }
- public void reduceCurrentHp(double i, L2Character attacker, boolean awake)
- {
- if (Config.L2JMOD_CHAMPION_ENABLE && isChampion() && Config.L2JMOD_CHAMPION_HP != 0)
- getStatus().reduceHp(i/Config.L2JMOD_CHAMPION_HP, attacker, awake);
- else
- getStatus().reduceHp(i, attacker, awake);
- }
- public void reduceCurrentMp(double i) { getStatus().reduceMp(i); }
- public void removeStatusListener(L2Character object) { getStatus().removeStatusListener(object); }
- protected void stopHpMpRegeneration() { getStatus().stopHpMpRegeneration(); }
- // Property - Public
- public final double getCurrentCp() { return getStatus().getCurrentCp(); }
- public final void setCurrentCp(Double newCp) { setCurrentCp((double) newCp); }
- public final void setCurrentCp(double newCp) { getStatus().setCurrentCp(newCp); }
- public final double getCurrentHp() { return getStatus().getCurrentHp(); }
- public final void setCurrentHp(double newHp) { getStatus().setCurrentHp(newHp); }
- public final void setCurrentHpMp(double newHp, double newMp){ getStatus().setCurrentHpMp(newHp, newMp); }
- public final double getCurrentMp() { return getStatus().getCurrentMp(); }
- public final void setCurrentMp(Double newMp) { setCurrentMp((double)newMp); }
- public final void setCurrentMp(double newMp) { getStatus().setCurrentMp(newMp); }
- // =========================================================
- public void setAiClass(String aiClass)
- {
- _aiClass = aiClass;
- }
- public String getAiClass()
- {
- return _aiClass;
- }
- public L2Character getLastBuffer()
- {
- return _lastBuffer;
- }
- public void setChampion(boolean champ)
- {
- _champion = champ;
- }
- public boolean isChampion()
- {
- return _champion;
- }
- public int getLastHealAmount()
- {
- return _lastHealAmount;
- }
- public void setLastBuffer(L2Character buffer)
- {
- _lastBuffer = buffer;
- }
- public void setLastHealAmount(int hp)
- {
- _lastHealAmount = hp;
- }
- /**
- * Check if character reflected skill
- * @param skill
- * @return
- */
- public boolean reflectSkill(L2Skill skill)
- {
- double reflect = calcStat(skill.isMagic() ? Stats.REFLECT_SKILL_MAGIC : Stats.REFLECT_SKILL_PHYSIC, 0, null, null);
- if( Rnd.get(100) < reflect)
- return true;
- return false;
- }
- /**
- * Check player max buff count
- * @return max buff count
- */
- public int getMaxBuffCount()
- {
- return Config.BUFFS_MAX_AMOUNT + Math.max(0, getSkillLevel(L2Skill.SKILL_DIVINE_INSPIRATION));
- }
- /**
- * Send system message about damage.<BR><BR>
- *
- * <B><U> Overriden in </U> :</B><BR><BR>
- * <li> L2PcInstance
- * <li> L2SummonInstance
- * <li> L2PetInstance</li><BR><BR>
- *
- */
- public void sendDamageMessage(@SuppressWarnings("unused") L2Character target, int damage, boolean mcrit, boolean pcrit, boolean miss)
- {
- }
- public ForceBuff getForceBuff()
- {
- return null;
- }
-
- public int getAttackElement()
- {
- return getStat().getAttackElement();
- }
- public int getAttackElementValue()
- {
- return (int)getStat().getAttackElementValue();
- }
- public int getDefAttrFire()
- {
- return (int)getStat().getElementAttributeFire();
- }
-
- public int getDefAttrWater()
- {
- return (int)getStat().getElementAttributeWater();
- }
-
- public int getDefAttrEarth()
- {
- return (int)getStat().getElementAttributeEarth();
- }
-
- public int getDefAttrWind()
- {
- return (int)getStat().getElementAttributeWind();
- }
-
- public int getDefAttrHoly()
- {
- return (int)getStat().getElementAttributeHoly();
- }
-
- public int getDefAttrUnholy()
- {
- return (int)getStat().getElementAttributeUnholy();
- }
- public boolean mustFallDownOnDeath()
- {
- return isDead();
- }
-
- public final void startPhysicalAttackMuted()
- {
- setIsPhysicalAttackMuted(true);
- }
-
- public final void stopPhysicalAttackMuted(L2Effect effect)
- {
- if (effect == null)
- stopEffects(L2Effect.EffectType.PHYSICAL_ATTACK_MUTE);
- else
- removeEffect(effect);
-
- setIsPhysicalAttackMuted(false);
- }
- }
|