L2Skill.java 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.model;
  16. import java.util.ArrayList;
  17. import java.util.Collection;
  18. import java.util.List;
  19. import java.util.logging.Logger;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.GeoData;
  22. import com.l2jserver.gameserver.datatables.GMSkillTable;
  23. import com.l2jserver.gameserver.datatables.HeroSkillTable;
  24. import com.l2jserver.gameserver.datatables.SkillTable;
  25. import com.l2jserver.gameserver.datatables.SkillTreeTable;
  26. import com.l2jserver.gameserver.model.actor.L2Attackable;
  27. import com.l2jserver.gameserver.model.actor.L2Character;
  28. import com.l2jserver.gameserver.model.actor.L2Npc;
  29. import com.l2jserver.gameserver.model.actor.L2Playable;
  30. import com.l2jserver.gameserver.model.actor.L2Summon;
  31. import com.l2jserver.gameserver.model.actor.instance.L2ArtefactInstance;
  32. import com.l2jserver.gameserver.model.actor.instance.L2ChestInstance;
  33. import com.l2jserver.gameserver.model.actor.instance.L2CubicInstance;
  34. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  35. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  36. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  37. import com.l2jserver.gameserver.model.actor.instance.L2SiegeFlagInstance;
  38. import com.l2jserver.gameserver.model.actor.instance.L2SummonInstance;
  39. import com.l2jserver.gameserver.model.entity.TvTEvent;
  40. import com.l2jserver.gameserver.network.SystemMessageId;
  41. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  42. import com.l2jserver.gameserver.skills.Env;
  43. import com.l2jserver.gameserver.skills.Formulas;
  44. import com.l2jserver.gameserver.skills.Stats;
  45. import com.l2jserver.gameserver.skills.conditions.Condition;
  46. import com.l2jserver.gameserver.skills.funcs.Func;
  47. import com.l2jserver.gameserver.skills.funcs.FuncTemplate;
  48. import com.l2jserver.gameserver.taskmanager.DecayTaskManager;
  49. import com.l2jserver.gameserver.templates.StatsSet;
  50. import com.l2jserver.gameserver.templates.effects.EffectTemplate;
  51. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  52. import com.l2jserver.gameserver.util.Util;
  53. import javolution.util.FastList;
  54. /**
  55. * This class...
  56. *
  57. * @version $Revision: 1.3.2.8.2.22 $ $Date: 2005/04/06 16:13:42 $
  58. */
  59. public abstract class L2Skill implements IChanceSkillTrigger
  60. {
  61. protected static final Logger _log = Logger.getLogger(L2Skill.class.getName());
  62. private static final L2Object[] _emptyTargetList = new L2Object[0];
  63. public static final int SKILL_LUCKY = 194;
  64. public static final int SKILL_CREATE_COMMON = 1320;
  65. public static final int SKILL_CREATE_DWARVEN = 172;
  66. public static final int SKILL_CRYSTALLIZE = 248;
  67. public static final int SKILL_DIVINE_INSPIRATION = 1405;
  68. public static final int SKILL_CLAN_LUCK = 390;
  69. public static final boolean geoEnabled = Config.GEODATA > 0;
  70. public static enum SkillOpType
  71. {
  72. OP_PASSIVE, OP_ACTIVE, OP_TOGGLE
  73. }
  74. /** Target types of skills : SELF, PARTY, CLAN, PET... */
  75. public static enum SkillTargetType
  76. {
  77. TARGET_NONE,
  78. TARGET_SELF,
  79. TARGET_ONE,
  80. TARGET_PARTY,
  81. TARGET_ALLY,
  82. TARGET_CLAN,
  83. TARGET_PET,
  84. TARGET_SUMMON,
  85. TARGET_AREA,
  86. TARGET_FRONT_AREA,
  87. TARGET_BEHIND_AREA,
  88. TARGET_AURA,
  89. TARGET_FRONT_AURA,
  90. TARGET_BEHIND_AURA,
  91. TARGET_CORPSE,
  92. TARGET_UNDEAD,
  93. TARGET_AREA_UNDEAD,
  94. TARGET_MULTIFACE,
  95. TARGET_CORPSE_ALLY,
  96. TARGET_CORPSE_CLAN,
  97. TARGET_CORPSE_PLAYER,
  98. TARGET_CORPSE_PET,
  99. TARGET_AREA_CORPSE_MOB,
  100. TARGET_CORPSE_MOB,
  101. TARGET_UNLOCKABLE,
  102. TARGET_HOLY,
  103. TARGET_FLAGPOLE,
  104. TARGET_PARTY_MEMBER,
  105. TARGET_PARTY_OTHER,
  106. TARGET_PARTY_CLAN,
  107. TARGET_ENEMY_SUMMON,
  108. TARGET_OWNER_PET,
  109. TARGET_GROUND,
  110. TARGET_PARTY_NOTME,
  111. TARGET_AREA_SUMMON
  112. }
  113. //conditional values
  114. public final static int COND_RUNNING = 0x0001;
  115. public final static int COND_WALKING = 0x0002;
  116. public final static int COND_SIT = 0x0004;
  117. public final static int COND_BEHIND = 0x0008;
  118. public final static int COND_CRIT = 0x0010;
  119. public final static int COND_LOWHP = 0x0020;
  120. public final static int COND_ROBES = 0x0040;
  121. public final static int COND_CHARGES = 0x0080;
  122. public final static int COND_SHIELD = 0x0100;
  123. private static final Func[] _emptyFunctionSet = new Func[0];
  124. private static final L2Effect[] _emptyEffectSet = new L2Effect[0];
  125. // these two build the primary key
  126. private final int _id;
  127. private final int _level;
  128. /** Identifier for a skill that client can't display */
  129. private int _displayId;
  130. // not needed, just for easier debug
  131. private final String _name;
  132. private final SkillOpType _operateType;
  133. private final boolean _magic;
  134. private final boolean _staticReuse;
  135. private final boolean _staticHitTime;
  136. private final int _mpConsume;
  137. private final int _mpInitialConsume;
  138. private final int _hpConsume;
  139. private final int _cpConsume;
  140. private final int _targetConsume;
  141. private final int _targetConsumeId;
  142. private final int _itemConsume;
  143. private final int _itemConsumeId;
  144. private final int _castRange;
  145. private final int _effectRange;
  146. // Abnormal levels for skills and their canceling, e.g. poison vs negate
  147. private final int _abnormalLvl; // e.g. poison or bleed lvl 2
  148. // Note: see also _effectAbnormalLvl
  149. private final int _negateLvl; // abnormalLvl is negated with negateLvl
  150. private final int[] _negateId; // cancels the effect of skill ID
  151. private final L2SkillType[] _negateStats; // lists the effect types that are canceled
  152. private final int _maxNegatedEffects; // maximum number of effects to negate
  153. private final boolean _stayAfterDeath; // skill should stay after death
  154. // kill by damage over time
  155. private final boolean _killByDOT;
  156. private final int _refId;
  157. // all times in milliseconds
  158. private final int _hitTime;
  159. private final int[] _hitTimings;
  160. //private final int _skillInterruptTime;
  161. private final int _coolTime;
  162. private final int _reuseHashCode;
  163. private final int _reuseDelay;
  164. private final int _buffDuration;
  165. // for item skills delay on equip
  166. private final int _equipDelay;
  167. /** Target type of the skill : SELF, PARTY, CLAN, PET... */
  168. private final SkillTargetType _targetType;
  169. private final int _feed;
  170. // base success chance
  171. private final double _power;
  172. private final double _pvpPower;
  173. private final int _magicLevel;
  174. private final int _levelDepend;
  175. private final boolean _ignoreResists;
  176. private final boolean _removedOnAnyActionExceptMove;
  177. private final boolean _isNeutral;
  178. // Effecting area of the skill, in radius.
  179. // The radius center varies according to the _targetType:
  180. // "caster" if targetType = AURA/PARTY/CLAN or "target" if targetType = AREA
  181. private final int _skillRadius;
  182. private final L2SkillType _skillType;
  183. private final L2SkillType _effectType; // additional effect has a type
  184. private final int _effectAbnormalLvl; // abnormal level for the additional effect type, e.g. poison lvl 1
  185. private final int _effectId;
  186. private final int _effectLvl; // normal effect level
  187. private final boolean _nextActionIsAttack;
  188. private final boolean _isPotion;
  189. private final byte _element;
  190. private final int _elementPower;
  191. private final Stats _stat;
  192. private final int _condition;
  193. private final int _conditionValue;
  194. private final boolean _overhit;
  195. private final int _weaponsAllowed;
  196. private final int _armorsAllowed;
  197. private final int _minPledgeClass;
  198. private final boolean _isOffensive;
  199. private final int _maxCharges;
  200. private final int _numCharges;
  201. private final int _triggeredId;
  202. private final int _triggeredLevel;
  203. private final String _chanceType;
  204. private final int _soulMaxConsume;
  205. private final int _soulConsume;
  206. private final int _numSouls;
  207. private final int _expNeeded;
  208. private final int _critChance;
  209. private final float _dependOnTargetBuff;
  210. private final int _transformId;
  211. private final int _transformDuration;
  212. private final int _afterEffectId;
  213. private final int _afterEffectLvl;
  214. private final boolean _isHeroSkill; // If true the skill is a Hero Skill
  215. private final boolean _isGMSkill; // True if skill is GM skill
  216. private final int _baseCritRate; // percent of success for skill critical hit (especially for PDAM & BLOW - they're not affected by rCrit values or buffs). Default loads -1 for all other skills but 0 to PDAM & BLOW
  217. private final int _lethalEffect1; // percent of success for lethal 1st effect (hit cp to 1 or if mob hp to 50%) (only for PDAM skills)
  218. private final int _lethalEffect2; // percent of success for lethal 2nd effect (hit cp,hp to 1 or if mob hp to 1) (only for PDAM skills)
  219. private final boolean _directHpDmg; // If true then dmg is being make directly
  220. private final boolean _isDance; // If true then casting more dances will cost more MP
  221. private final int _nextDanceCost;
  222. private final float _sSBoost; //If true skill will have SoulShot boost (power*2)
  223. private final int _aggroPoints;
  224. protected Condition _preCondition;
  225. protected Condition _itemPreCondition;
  226. protected FuncTemplate[] _funcTemplates;
  227. protected EffectTemplate[] _effectTemplates;
  228. protected EffectTemplate[] _effectTemplatesSelf;
  229. protected ChanceCondition _chanceCondition = null;
  230. // Flying support
  231. private final String _flyType;
  232. private final int _flyRadius;
  233. private final float _flyCourse;
  234. private final boolean _isDebuff;
  235. private final String _attribute;
  236. private final boolean _ignoreShield;
  237. private final boolean _isSuicideAttack;
  238. private final boolean _canBeReflected;
  239. private final boolean _canBeDispeled;
  240. private final boolean _isClanSkill;
  241. protected L2Skill(StatsSet set)
  242. {
  243. _id = set.getInteger("skill_id");
  244. _level = set.getInteger("level");
  245. _refId = set.getInteger("referenceId", 0);
  246. _displayId = set.getInteger("displayId", _id);
  247. _name = set.getString("name");
  248. _operateType = set.getEnum("operateType", SkillOpType.class);
  249. _magic = set.getBool("isMagic", false);
  250. _staticReuse = set.getBool("staticReuse", false);
  251. _staticHitTime = set.getBool("staticHitTime", false);
  252. _isPotion = set.getBool("isPotion", false);
  253. _mpConsume = set.getInteger("mpConsume", 0);
  254. _mpInitialConsume = set.getInteger("mpInitialConsume", 0);
  255. _hpConsume = set.getInteger("hpConsume", 0);
  256. _cpConsume = set.getInteger("cpConsume", 0);
  257. _targetConsume = set.getInteger("targetConsumeCount", 0);
  258. _targetConsumeId = set.getInteger("targetConsumeId", 0);
  259. _itemConsume = set.getInteger("itemConsumeCount", 0);
  260. _itemConsumeId = set.getInteger("itemConsumeId", 0);
  261. _afterEffectId = set.getInteger("afterEffectId", 0);
  262. _afterEffectLvl = set.getInteger("afterEffectLvl", 1);
  263. _castRange = set.getInteger("castRange", -1);
  264. _effectRange = set.getInteger("effectRange", -1);
  265. _abnormalLvl = set.getInteger("abnormalLvl", -1);
  266. _effectAbnormalLvl = set.getInteger("effectAbnormalLvl", -1); // support for a separate effect abnormal lvl, e.g. poison inside a different skill
  267. _negateLvl = set.getInteger("negateLvl", -1);
  268. _attribute = set.getString("attribute","");
  269. String str = set.getString("negateStats", "");
  270. if (str == "")
  271. _negateStats = new L2SkillType[0];
  272. else
  273. {
  274. String[] stats = str.split(" ");
  275. L2SkillType[] array = new L2SkillType[stats.length];
  276. for (int i = 0; i < stats.length; i++)
  277. {
  278. L2SkillType type = null;
  279. try
  280. {
  281. type = Enum.valueOf(L2SkillType.class, stats[i]);
  282. }
  283. catch (Exception e)
  284. {
  285. throw new IllegalArgumentException("SkillId: "+_id+"Enum value of type "+L2SkillType.class.getName()+"required, but found: "+stats[i]);
  286. }
  287. array[i] = type;
  288. }
  289. _negateStats = array;
  290. }
  291. String negateId = set.getString("negateId", null);
  292. if (negateId != null)
  293. {
  294. String[] valuesSplit = negateId.split(",");
  295. _negateId = new int[valuesSplit.length];
  296. for (int i = 0; i < valuesSplit.length;i++)
  297. {
  298. _negateId[i] = Integer.parseInt(valuesSplit[i]);
  299. }
  300. }
  301. else
  302. _negateId = new int[0];
  303. _maxNegatedEffects = set.getInteger("maxNegated", 0);
  304. _stayAfterDeath = set.getBool("stayAfterDeath", false);
  305. _killByDOT = set.getBool("killByDOT", false);
  306. _isNeutral = set.getBool("neutral",false);
  307. _hitTime = set.getInteger("hitTime", 0);
  308. String hitTimings = set.getString("hitTimings", null);
  309. if (hitTimings != null)
  310. {
  311. try
  312. {
  313. String [] valuesSplit = hitTimings.split(",");
  314. _hitTimings = new int[valuesSplit.length];
  315. for (int i = 0; i < valuesSplit.length; i++)
  316. _hitTimings[i] = Integer.parseInt(valuesSplit[i]);
  317. }
  318. catch (Exception e)
  319. {
  320. throw new IllegalArgumentException("SkillId: "+_id+" invalid hitTimings value: "+hitTimings+", \"percent,percent,...percent\" required");
  321. }
  322. }
  323. else
  324. _hitTimings = new int[0];
  325. _coolTime = set.getInteger("coolTime", 0);
  326. _isDebuff = set.getBool("isDebuff", false);
  327. _feed = set.getInteger("feed", 0);
  328. String reuseHash = set.getString("sharedReuse", null);
  329. if (reuseHash != null)
  330. {
  331. try
  332. {
  333. String[] valuesSplit = reuseHash.split("-");
  334. _reuseHashCode = SkillTable.getSkillHashCode(Integer.parseInt(valuesSplit[0]), Integer.parseInt(valuesSplit[1]));
  335. }
  336. catch (Exception e)
  337. {
  338. throw new IllegalArgumentException("SkillId: "+_id+" invalid sharedReuse value: "+reuseHash+", \"skillId-skillLvl\" required");
  339. }
  340. }
  341. else
  342. _reuseHashCode = SkillTable.getSkillHashCode(_id, _level);
  343. if (Config.ENABLE_MODIFY_SKILL_REUSE && Config.SKILL_REUSE_LIST.containsKey(_id))
  344. {
  345. if ( Config.DEBUG )
  346. _log.info("*** Skill " + _name + " (" + _level + ") changed reuse from " + set.getInteger("reuseDelay", 0) + " to " + Config.SKILL_REUSE_LIST.get(_id) + " seconds.");
  347. _reuseDelay = Config.SKILL_REUSE_LIST.get(_id);
  348. }
  349. else
  350. {
  351. _reuseDelay = set.getInteger("reuseDelay", 0);
  352. }
  353. _buffDuration = set.getInteger("buffDuration", 0);
  354. _equipDelay = set.getInteger("equipDelay", 0);
  355. _skillRadius = set.getInteger("skillRadius", 80);
  356. _targetType = set.getEnum("target", SkillTargetType.class);
  357. _power = set.getFloat("power", 0.f);
  358. _pvpPower = set.getFloat("pvpPower", (float)getPower());
  359. _magicLevel = set.getInteger("magicLvl", SkillTreeTable.getInstance().getMinSkillLevel(_id, _level));
  360. _levelDepend = set.getInteger("lvlDepend", 0);
  361. _ignoreResists = set.getBool("ignoreResists", false);
  362. _removedOnAnyActionExceptMove = set.getBool("removedOnAnyActionExceptMove", false);
  363. _stat = set.getEnum("stat", Stats.class, null);
  364. _ignoreShield = set.getBool("ignoreShld", false);
  365. _skillType = set.getEnum("skillType", L2SkillType.class);
  366. _effectType = set.getEnum("effectType", L2SkillType.class, null);
  367. _effectId = set.getInteger("effectId", 0);
  368. _effectLvl = set.getInteger("effectLevel", 0);
  369. _nextActionIsAttack = set.getBool("nextActionAttack", false);
  370. _element = set.getByte("element", (byte)-1);
  371. _elementPower = set.getInteger("elementPower", 0);
  372. _condition = set.getInteger("condition", 0);
  373. _conditionValue = set.getInteger("conditionValue", 0);
  374. _overhit = set.getBool("overHit", false);
  375. _isSuicideAttack = set.getBool("isSuicideAttack", false);
  376. _weaponsAllowed = set.getInteger("weaponsAllowed", 0);
  377. _armorsAllowed = set.getInteger("armorsAllowed", 0);
  378. _minPledgeClass = set.getInteger("minPledgeClass", 0);
  379. _isOffensive = set.getBool("offensive", isSkillTypeOffensive());
  380. _maxCharges = set.getInteger("maxCharges", 0);
  381. _numCharges = set.getInteger("numCharges", 0);
  382. _triggeredId = set.getInteger("triggeredId", 0);
  383. _triggeredLevel = set.getInteger("triggeredLevel", 0);
  384. _chanceType = set.getString("chanceType", "");
  385. if (_chanceType != "" && !_chanceType.isEmpty())
  386. _chanceCondition = ChanceCondition.parse(set);
  387. _numSouls = set.getInteger("num_souls", 0);
  388. _soulMaxConsume = set.getInteger("soulMaxConsumeCount", 0);
  389. _soulConsume = set.getInteger("soulConsumeCount", 0);
  390. _expNeeded = set.getInteger("expNeeded", 0);
  391. _critChance = set.getInteger("critChance", 0);
  392. _transformId = set.getInteger("transformId", 0);
  393. _transformDuration = set.getInteger("transformDuration", 0);
  394. _isHeroSkill = HeroSkillTable.isHeroSkill(_id);
  395. _isGMSkill = GMSkillTable.isGMSkill(_id);
  396. _baseCritRate = set.getInteger("baseCritRate", (_skillType == L2SkillType.PDAM || _skillType == L2SkillType.BLOW) ? 0 : -1);
  397. _lethalEffect1 = set.getInteger("lethal1",0);
  398. _lethalEffect2 = set.getInteger("lethal2",0);
  399. _directHpDmg = set.getBool("dmgDirectlyToHp",false);
  400. _isDance = set.getBool("isDance",false);
  401. _nextDanceCost = set.getInteger("nextDanceCost", 0);
  402. _sSBoost = set.getFloat("SSBoost", 0.f);
  403. _aggroPoints = set.getInteger("aggroPoints", 0);
  404. _flyType = set.getString("flyType", null);
  405. _flyRadius = set.getInteger("flyRadius", 200);
  406. _flyCourse = set.getFloat("flyCourse", 0);
  407. _canBeReflected = set.getBool("canBeReflected", true);
  408. _canBeDispeled = set.getBool("canBeDispeled", true);
  409. _isClanSkill = set.getBool("isClanSkill", false);
  410. _dependOnTargetBuff = set.getFloat("dependOnTargetBuff", 0);
  411. }
  412. public abstract void useSkill(L2Character caster, L2Object[] targets);
  413. public final boolean isPotion()
  414. {
  415. return _isPotion;
  416. }
  417. public final int getArmorsAllowed()
  418. {
  419. return _armorsAllowed;
  420. }
  421. public final int getConditionValue()
  422. {
  423. return _conditionValue;
  424. }
  425. public final L2SkillType getSkillType()
  426. {
  427. return _skillType;
  428. }
  429. public final byte getElement()
  430. {
  431. return _element;
  432. }
  433. public final int getElementPower()
  434. {
  435. return _elementPower;
  436. }
  437. /**
  438. * Return the target type of the skill : SELF, PARTY, CLAN, PET...<BR><BR>
  439. *
  440. */
  441. public final SkillTargetType getTargetType()
  442. {
  443. return _targetType;
  444. }
  445. public final int getCondition()
  446. {
  447. return _condition;
  448. }
  449. public final boolean isOverhit()
  450. {
  451. return _overhit;
  452. }
  453. public final boolean killByDOT()
  454. {
  455. return _killByDOT;
  456. }
  457. public final boolean isSuicideAttack()
  458. {
  459. return _isSuicideAttack;
  460. }
  461. public final boolean allowOnTransform()
  462. {
  463. return isPassive();
  464. }
  465. /**
  466. * Return the power of the skill.<BR><BR>
  467. */
  468. public final double getPower(L2Character activeChar, boolean isPvP)
  469. {
  470. if (activeChar == null)
  471. return getPower(isPvP);
  472. switch (_skillType)
  473. {
  474. case DEATHLINK:
  475. {
  476. return getPower(isPvP) * Math.pow(1.7165 - activeChar.getCurrentHp() / activeChar.getMaxHp(), 2) * 0.577;
  477. /*
  478. * DrHouse:
  479. * Rolling back to old formula (look below) for DEATHLINK due to this one based on logarithm is not
  480. * accurate enough. Commented here because probably is a matter of just adjusting a constant
  481. if(activeChar.getCurrentHp() / activeChar.getMaxHp() > 0.005)
  482. return _power*(-0.45*Math.log(activeChar.getCurrentHp()/activeChar.getMaxHp())+1.);
  483. else
  484. return _power*(-0.45*Math.log(0.005)+1.);
  485. */
  486. }
  487. case FATAL:
  488. {
  489. return getPower(isPvP)*3.5*(1-activeChar.getCurrentHp()/activeChar.getMaxHp());
  490. }
  491. default:
  492. return getPower(isPvP);
  493. }
  494. }
  495. public final double getPower()
  496. {
  497. return _power;
  498. }
  499. public final double getPower(boolean isPvP)
  500. {
  501. return isPvP ? _pvpPower : _power;
  502. }
  503. public final L2SkillType[] getNegateStats()
  504. {
  505. return _negateStats;
  506. }
  507. public final int getAbnormalLvl()
  508. {
  509. return _abnormalLvl;
  510. }
  511. public final int getNegateLvl()
  512. {
  513. return _negateLvl;
  514. }
  515. public final int[] getNegateId()
  516. {
  517. return _negateId;
  518. }
  519. public final int getMagicLevel()
  520. {
  521. return _magicLevel;
  522. }
  523. public final int getMaxNegatedEffects()
  524. {
  525. return _maxNegatedEffects;
  526. }
  527. public final int getLevelDepend()
  528. {
  529. return _levelDepend;
  530. }
  531. /**
  532. * Return true if skill should ignore all resistances
  533. */
  534. public final boolean ignoreResists()
  535. {
  536. return _ignoreResists;
  537. }
  538. /**
  539. * Return true if skill effects should be removed on any action except movement
  540. */
  541. public final boolean isRemovedOnAnyActionExceptMove()
  542. {
  543. return _removedOnAnyActionExceptMove;
  544. }
  545. /**
  546. * Return the additional effect Id.<BR><BR>
  547. */
  548. public final int getEffectId()
  549. {
  550. return _effectId;
  551. }
  552. /**
  553. * Return the additional effect level.<BR><BR>
  554. */
  555. public final int getEffectLvl()
  556. {
  557. return _effectLvl;
  558. }
  559. public final int getEffectAbnormalLvl()
  560. {
  561. return _effectAbnormalLvl;
  562. }
  563. /**
  564. * Return the additional effect skill type (ex : STUN, PARALYZE,...).<BR><BR>
  565. */
  566. public final L2SkillType getEffectType()
  567. {
  568. return _effectType;
  569. }
  570. /**
  571. * Return true if character should attack target after skill
  572. */
  573. public final boolean nextActionIsAttack()
  574. {
  575. return _nextActionIsAttack;
  576. }
  577. /**
  578. * @return Returns the buffDuration.
  579. */
  580. public final int getBuffDuration()
  581. {
  582. return _buffDuration;
  583. }
  584. /**
  585. * @return Returns the castRange.
  586. */
  587. public final int getCastRange()
  588. {
  589. return _castRange;
  590. }
  591. /**
  592. * @return Returns the cpConsume;
  593. */
  594. public final int getCpConsume()
  595. {
  596. return _cpConsume;
  597. }
  598. /**
  599. * @return Returns the effectRange.
  600. */
  601. public final int getEffectRange()
  602. {
  603. return _effectRange;
  604. }
  605. /**
  606. * @return Returns the hpConsume.
  607. */
  608. public final int getHpConsume()
  609. {
  610. return _hpConsume;
  611. }
  612. /**
  613. * @return Returns the id.
  614. */
  615. public final int getId()
  616. {
  617. return _id;
  618. }
  619. /**
  620. * @return Returns the boolean _isDebuff.
  621. */
  622. public final boolean isDebuff()
  623. {
  624. return _isDebuff;
  625. }
  626. public int getDisplayId()
  627. {
  628. return _displayId;
  629. }
  630. public void setDisplayId(int id)
  631. {
  632. _displayId = id;
  633. }
  634. public int getTriggeredId()
  635. {
  636. return _triggeredId;
  637. }
  638. public int getTriggeredLevel()
  639. {
  640. return _triggeredLevel;
  641. }
  642. public boolean triggerAnotherSkill()
  643. {
  644. return _triggeredId > 1;
  645. }
  646. /**
  647. * Return the skill type (ex : BLEED, SLEEP, WATER...).<BR><BR>
  648. */
  649. public final Stats getStat()
  650. {
  651. return _stat;
  652. }
  653. /**
  654. * @return Returns the _targetConsumeId.
  655. */
  656. public final int getTargetConsumeId()
  657. {
  658. return _targetConsumeId;
  659. }
  660. /**
  661. * @return Returns the targetConsume.
  662. */
  663. public final int getTargetConsume()
  664. {
  665. return _targetConsume;
  666. }
  667. /**
  668. * @return Returns the itemConsume.
  669. */
  670. public final int getItemConsume()
  671. {
  672. return _itemConsume;
  673. }
  674. /**
  675. * @return Returns the itemConsumeId.
  676. */
  677. public final int getItemConsumeId()
  678. {
  679. return _itemConsumeId;
  680. }
  681. /**
  682. * @return Returns the level.
  683. */
  684. public final int getLevel()
  685. {
  686. return _level;
  687. }
  688. /**
  689. * @return Returns the magic.
  690. */
  691. public final boolean isMagic()
  692. {
  693. return _magic;
  694. }
  695. /**
  696. * @return Returns true to set static reuse.
  697. */
  698. public final boolean isStaticReuse()
  699. {
  700. return _staticReuse;
  701. }
  702. /**
  703. * @return Returns true to set static hittime.
  704. */
  705. public final boolean isStaticHitTime()
  706. {
  707. return _staticHitTime;
  708. }
  709. /**
  710. * @return Returns the mpConsume.
  711. */
  712. public final int getMpConsume()
  713. {
  714. return _mpConsume;
  715. }
  716. /**
  717. * @return Returns the mpInitialConsume.
  718. */
  719. public final int getMpInitialConsume()
  720. {
  721. return _mpInitialConsume;
  722. }
  723. /**
  724. * @return Returns the name.
  725. */
  726. public final String getName()
  727. {
  728. return _name;
  729. }
  730. /**
  731. * @return Returns the reuseDelay.
  732. */
  733. public final int getReuseDelay()
  734. {
  735. return _reuseDelay;
  736. }
  737. public final int getReuseHashCode()
  738. {
  739. return _reuseHashCode;
  740. }
  741. public final int getEquipDelay()
  742. {
  743. return _equipDelay;
  744. }
  745. public final int getHitTime()
  746. {
  747. return _hitTime;
  748. }
  749. public final int getHitCounts()
  750. {
  751. return _hitTimings.length;
  752. }
  753. public final int[] getHitTimings()
  754. {
  755. return _hitTimings;
  756. }
  757. /**
  758. * @return Returns the coolTime.
  759. */
  760. public final int getCoolTime()
  761. {
  762. return _coolTime;
  763. }
  764. public final int getSkillRadius()
  765. {
  766. return _skillRadius;
  767. }
  768. public final boolean isActive()
  769. {
  770. return _operateType == SkillOpType.OP_ACTIVE;
  771. }
  772. public final boolean isPassive()
  773. {
  774. return _operateType == SkillOpType.OP_PASSIVE;
  775. }
  776. public final boolean isToggle()
  777. {
  778. return _operateType == SkillOpType.OP_TOGGLE;
  779. }
  780. public final boolean isChance()
  781. {
  782. return _chanceCondition != null && isPassive();
  783. }
  784. public final boolean isDance()
  785. {
  786. return _isDance;
  787. }
  788. public final int getNextDanceMpCost()
  789. {
  790. return _nextDanceCost;
  791. }
  792. public final float getSSBoost()
  793. {
  794. return _sSBoost;
  795. }
  796. public final int getAggroPoints()
  797. {
  798. return _aggroPoints;
  799. }
  800. public final boolean useSoulShot()
  801. {
  802. switch (getSkillType())
  803. {
  804. case PDAM:
  805. case CHARGEDAM:
  806. case BLOW:
  807. return true;
  808. default:
  809. return false;
  810. }
  811. }
  812. public final boolean useSpiritShot()
  813. {
  814. return isMagic();
  815. }
  816. public final boolean useFishShot()
  817. {
  818. return ((getSkillType() == L2SkillType.PUMPING) || (getSkillType() == L2SkillType.REELING) );
  819. }
  820. public final int getWeaponsAllowed()
  821. {
  822. return _weaponsAllowed;
  823. }
  824. public int getMinPledgeClass() { return _minPledgeClass; }
  825. public final boolean isPvpSkill()
  826. {
  827. switch (_skillType)
  828. {
  829. case DOT:
  830. case BLEED:
  831. case CONFUSION:
  832. case POISON:
  833. case DEBUFF:
  834. case AGGDEBUFF:
  835. case STUN:
  836. case ROOT:
  837. case FEAR:
  838. case SLEEP:
  839. case MDOT:
  840. case MUTE:
  841. case WEAKNESS:
  842. case PARALYZE:
  843. case CANCEL:
  844. case MAGE_BANE:
  845. case WARRIOR_BANE:
  846. case BETRAY:
  847. case DISARM:
  848. case AGGDAMAGE:
  849. case STEAL_BUFF:
  850. case AGGREDUCE_CHAR:
  851. case MANADAM:
  852. return true;
  853. default:
  854. return false;
  855. }
  856. }
  857. public final boolean isOffensive()
  858. {
  859. return _isOffensive;
  860. }
  861. public final boolean isNeutral()
  862. {
  863. return _isNeutral;
  864. }
  865. public final boolean isHeroSkill()
  866. {
  867. return _isHeroSkill;
  868. }
  869. public final boolean isGMSkill()
  870. {
  871. return _isGMSkill;
  872. }
  873. public final int getNumCharges()
  874. {
  875. return _numCharges;
  876. }
  877. public final int getNumSouls()
  878. {
  879. return _numSouls;
  880. }
  881. public final int getMaxSoulConsumeCount()
  882. {
  883. return _soulMaxConsume;
  884. }
  885. public final int getSoulConsumeCount()
  886. {
  887. return _soulConsume;
  888. }
  889. public final int getExpNeeded()
  890. {
  891. return _expNeeded;
  892. }
  893. public final int getCritChance()
  894. {
  895. return _critChance;
  896. }
  897. public final int getTransformId()
  898. {
  899. return _transformId;
  900. }
  901. public final int getTransformDuration()
  902. {
  903. return _transformDuration;
  904. }
  905. public final int getBaseCritRate()
  906. {
  907. return _baseCritRate;
  908. }
  909. public final int getLethalChance1()
  910. {
  911. return _lethalEffect1;
  912. }
  913. public final int getLethalChance2()
  914. {
  915. return _lethalEffect2;
  916. }
  917. public final boolean getDmgDirectlyToHP()
  918. {
  919. return _directHpDmg;
  920. }
  921. public final String getFlyType()
  922. {
  923. return _flyType;
  924. }
  925. public final int getFlyRadius()
  926. {
  927. return _flyRadius;
  928. }
  929. public final float getFlyCourse()
  930. {
  931. return _flyCourse;
  932. }
  933. public final boolean isSkillTypeOffensive()
  934. {
  935. switch (_skillType)
  936. {
  937. case PDAM:
  938. case MDAM:
  939. case CPDAM:
  940. case DOT:
  941. case CPDAMPERCENT:
  942. case BLEED:
  943. case POISON:
  944. case AGGDAMAGE:
  945. case DEBUFF:
  946. case AGGDEBUFF:
  947. case STUN:
  948. case ROOT:
  949. case CONFUSION:
  950. case ERASE:
  951. case BLOW:
  952. case FATAL:
  953. case FEAR:
  954. case DRAIN:
  955. case SLEEP:
  956. case CHARGEDAM:
  957. case CONFUSE_MOB_ONLY:
  958. case DEATHLINK:
  959. case DETECT_WEAKNESS:
  960. case MANADAM:
  961. case MDOT:
  962. case MUTE:
  963. case SOULSHOT:
  964. case SPIRITSHOT:
  965. case SPOIL:
  966. case WEAKNESS:
  967. case MANA_BY_LEVEL:
  968. case SWEEP:
  969. case PARALYZE:
  970. case DRAIN_SOUL:
  971. case AGGREDUCE:
  972. case CANCEL:
  973. case MAGE_BANE:
  974. case WARRIOR_BANE:
  975. case AGGREMOVE:
  976. case AGGREDUCE_CHAR:
  977. case BETRAY:
  978. case DELUXE_KEY_UNLOCK:
  979. case SOW:
  980. case HARVEST:
  981. case DISARM:
  982. case STEAL_BUFF:
  983. case INSTANT_JUMP:
  984. return true;
  985. default:
  986. return this.isDebuff();
  987. }
  988. }
  989. public final boolean is7Signs()
  990. {
  991. if (_id > 4360 && _id < 4367)
  992. return true;
  993. return false;
  994. }
  995. public final boolean isStayAfterDeath()
  996. {
  997. return _stayAfterDeath;
  998. }
  999. // int weapons[] = {L2Weapon.WEAPON_TYPE_ETC, L2Weapon.WEAPON_TYPE_BOW,
  1000. // L2Weapon.WEAPON_TYPE_POLE, L2Weapon.WEAPON_TYPE_DUALFIST,
  1001. // L2Weapon.WEAPON_TYPE_DUAL, L2Weapon.WEAPON_TYPE_BLUNT,
  1002. // L2Weapon.WEAPON_TYPE_SWORD, L2Weapon.WEAPON_TYPE_DAGGER};
  1003. public final boolean getWeaponDependancy(L2Character activeChar)
  1004. {
  1005. if(getWeaponDependancy(activeChar,false))
  1006. {
  1007. return true;
  1008. }
  1009. else
  1010. {
  1011. SystemMessage message = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  1012. message.addSkillName(this);
  1013. activeChar.sendPacket(message);
  1014. return false;
  1015. }
  1016. }
  1017. public final boolean getWeaponDependancy(L2Character activeChar,boolean chance)
  1018. {
  1019. int weaponsAllowed = getWeaponsAllowed();
  1020. //check to see if skill has a weapon dependency.
  1021. if (weaponsAllowed == 0)
  1022. return true;
  1023. int mask = 0;
  1024. if (activeChar.getActiveWeaponItem() != null)
  1025. mask |= activeChar.getActiveWeaponItem().getItemType().mask();
  1026. if (activeChar.getSecondaryWeaponItem() != null)
  1027. mask |= activeChar.getSecondaryWeaponItem().getItemType().mask();
  1028. if ((mask & weaponsAllowed) != 0)
  1029. return true;
  1030. return false;
  1031. }
  1032. public boolean checkCondition(L2Character activeChar, L2Object target, boolean itemOrWeapon)
  1033. {
  1034. if (activeChar.isGM() && !Config.GM_SKILL_RESTRICTION)
  1035. return true;
  1036. if ((getCondition() & L2Skill.COND_SHIELD) != 0)
  1037. {
  1038. /*
  1039. L2Armor armorPiece;
  1040. L2ItemInstance dummy;
  1041. dummy = activeChar.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  1042. armorPiece = (L2Armor) dummy.getItem();
  1043. */
  1044. //TODO add checks for shield here.
  1045. }
  1046. Condition preCondition = _preCondition;
  1047. if(itemOrWeapon) preCondition = _itemPreCondition;
  1048. if (preCondition == null) return true;
  1049. Env env = new Env();
  1050. env.player = activeChar;
  1051. if (target instanceof L2Character) // TODO: object or char?
  1052. env.target = (L2Character)target;
  1053. env.skill = this;
  1054. if (!preCondition.test(env))
  1055. {
  1056. String msg = preCondition.getMessage();
  1057. int msgId = preCondition.getMessageId();
  1058. if (msgId != 0)
  1059. {
  1060. SystemMessage sm = new SystemMessage(msgId);
  1061. if (preCondition.isAddName())
  1062. sm.addSkillName(_id);
  1063. activeChar.sendPacket(sm);
  1064. }
  1065. else if (msg != null)
  1066. {
  1067. activeChar.sendMessage(msg);
  1068. }
  1069. return false;
  1070. }
  1071. return true;
  1072. }
  1073. public final L2Object[] getTargetList(L2Character activeChar, boolean onlyFirst)
  1074. {
  1075. // Init to null the target of the skill
  1076. L2Character target = null;
  1077. // Get the L2Objcet targeted by the user of the skill at this moment
  1078. L2Object objTarget = activeChar.getTarget();
  1079. // If the L2Object targeted is a L2Character, it becomes the L2Character target
  1080. if (objTarget instanceof L2Character)
  1081. {
  1082. target = (L2Character) objTarget;
  1083. }
  1084. return getTargetList(activeChar, onlyFirst, target);
  1085. }
  1086. /**
  1087. * Return all targets of the skill in a table in function a the skill type.<BR><BR>
  1088. *
  1089. * <B><U> Values of skill type</U> :</B><BR><BR>
  1090. * <li>ONE : The skill can only be used on the L2PcInstance targeted, or on the caster if it's a L2PcInstance and no L2PcInstance targeted</li>
  1091. * <li>SELF</li>
  1092. * <li>HOLY, UNDEAD</li>
  1093. * <li>PET</li>
  1094. * <li>AURA, AURA_CLOSE</li>
  1095. * <li>AREA</li>
  1096. * <li>MULTIFACE</li>
  1097. * <li>PARTY, CLAN</li>
  1098. * <li>CORPSE_PLAYER, CORPSE_MOB, CORPSE_CLAN</li>
  1099. * <li>UNLOCKABLE</li>
  1100. * <li>ITEM</li><BR><BR>
  1101. *
  1102. * @param activeChar The L2Character who use the skill
  1103. *
  1104. */
  1105. public final L2Object[] getTargetList(L2Character activeChar, boolean onlyFirst, L2Character target)
  1106. {
  1107. List<L2Character> targetList = new FastList<L2Character>();
  1108. // Get the target type of the skill
  1109. // (ex : ONE, SELF, HOLY, PET, AURA, AURA_CLOSE, AREA, MULTIFACE, PARTY, CLAN, CORPSE_PLAYER, CORPSE_MOB, CORPSE_CLAN, UNLOCKABLE, ITEM, UNDEAD)
  1110. SkillTargetType targetType = getTargetType();
  1111. // Get the type of the skill
  1112. // (ex : PDAM, MDAM, DOT, BLEED, POISON, HEAL, HOT, MANAHEAL, MANARECHARGE, AGGDAMAGE, BUFF, DEBUFF, STUN, ROOT, RESURRECT, PASSIVE...)
  1113. L2SkillType skillType = getSkillType();
  1114. switch (targetType)
  1115. {
  1116. // The skill can only be used on the L2Character targeted, or on the caster itself
  1117. case TARGET_ONE:
  1118. {
  1119. boolean canTargetSelf = false;
  1120. switch (skillType)
  1121. {
  1122. case BUFF:
  1123. case HEAL:
  1124. case HOT:
  1125. case HEAL_PERCENT:
  1126. case MANARECHARGE:
  1127. case MANAHEAL:
  1128. case NEGATE:
  1129. case CANCEL_DEBUFF:
  1130. case REFLECT:
  1131. case COMBATPOINTHEAL:
  1132. case BALANCE_LIFE:
  1133. case HPMPCPHEAL_PERCENT:
  1134. case HPMPHEAL_PERCENT:
  1135. canTargetSelf = true;
  1136. break;
  1137. }
  1138. // Check for null target or any other invalid target
  1139. if (target == null || target.isDead() || (target == activeChar && !canTargetSelf))
  1140. {
  1141. activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1142. return _emptyTargetList;
  1143. }
  1144. // If a target is found, return it in a table else send a system message TARGET_IS_INCORRECT
  1145. return new L2Character[] {target};
  1146. }
  1147. case TARGET_SELF:
  1148. case TARGET_GROUND:
  1149. {
  1150. return new L2Character[] {activeChar};
  1151. }
  1152. case TARGET_HOLY:
  1153. {
  1154. if (activeChar instanceof L2PcInstance)
  1155. {
  1156. if (target instanceof L2ArtefactInstance)
  1157. return new L2Character[] {target};
  1158. }
  1159. return _emptyTargetList;
  1160. }
  1161. case TARGET_FLAGPOLE:
  1162. {
  1163. return new L2Character[] {activeChar};
  1164. }
  1165. case TARGET_PET:
  1166. {
  1167. target = activeChar.getPet();
  1168. if (target != null && !target.isDead()) return new L2Character[] {target};
  1169. return _emptyTargetList;
  1170. }
  1171. case TARGET_SUMMON:
  1172. {
  1173. target = activeChar.getPet();
  1174. if (target != null && !target.isDead() && target instanceof L2SummonInstance) return new L2Character[] {target};
  1175. return _emptyTargetList;
  1176. }
  1177. case TARGET_OWNER_PET:
  1178. {
  1179. if (activeChar instanceof L2Summon)
  1180. {
  1181. target = ((L2Summon)activeChar).getOwner();
  1182. if (target != null && !target.isDead())
  1183. return new L2Character[]{target};
  1184. }
  1185. return _emptyTargetList;
  1186. }
  1187. case TARGET_CORPSE_PET:
  1188. {
  1189. if (activeChar instanceof L2PcInstance)
  1190. {
  1191. target = activeChar.getPet();
  1192. if (target != null && target.isDead())
  1193. return new L2Character[]{target};
  1194. }
  1195. return _emptyTargetList;
  1196. }
  1197. case TARGET_AURA:
  1198. case TARGET_FRONT_AURA:
  1199. case TARGET_BEHIND_AURA:
  1200. {
  1201. final boolean srcInArena = (activeChar.isInsideZone(L2Character.ZONE_PVP) && !activeChar.isInsideZone(L2Character.ZONE_SIEGE));
  1202. final L2PcInstance sourcePlayer = activeChar.getActingPlayer();
  1203. // Go through the L2Character _knownList
  1204. final Collection<L2Character> objs = activeChar.getKnownList().getKnownCharactersInRadius(getSkillRadius());
  1205. //synchronized (activeChar.getKnownList().getKnownObjects())
  1206. if (getSkillType() == L2SkillType.DUMMY)
  1207. {
  1208. if (onlyFirst)
  1209. return new L2Character[] { activeChar };
  1210. targetList.add(activeChar);
  1211. for (L2Character obj : objs)
  1212. {
  1213. if (!(obj == activeChar
  1214. || obj == sourcePlayer
  1215. || obj instanceof L2Npc
  1216. || obj instanceof L2Attackable))
  1217. continue;
  1218. targetList.add(obj);
  1219. }
  1220. }
  1221. else
  1222. {
  1223. for (L2Character obj : objs)
  1224. {
  1225. if (obj instanceof L2Attackable || obj instanceof L2Playable)
  1226. {
  1227. switch (targetType)
  1228. {
  1229. case TARGET_FRONT_AURA:
  1230. if (!obj.isInFrontOf(activeChar))
  1231. continue;
  1232. break;
  1233. case TARGET_BEHIND_AURA:
  1234. if(!obj.isBehind(activeChar))
  1235. continue;
  1236. break;
  1237. }
  1238. if (!checkForAreaOffensiveSkills(activeChar, obj, this, srcInArena))
  1239. continue;
  1240. if (onlyFirst)
  1241. return new L2Character[] { obj };
  1242. targetList.add(obj);
  1243. }
  1244. }
  1245. }
  1246. return targetList.toArray(new L2Character[targetList.size()]);
  1247. }
  1248. case TARGET_AREA_SUMMON:
  1249. {
  1250. target = activeChar.getPet();
  1251. if (target == null || !(target instanceof L2SummonInstance) || target.isDead())
  1252. return _emptyTargetList;
  1253. if(onlyFirst)
  1254. return new L2Character[]{target};
  1255. final boolean srcInArena = (activeChar.isInsideZone(L2Character.ZONE_PVP) && !activeChar.isInsideZone(L2Character.ZONE_SIEGE));
  1256. final Collection<L2Character> objs = target.getKnownList().getKnownCharacters();
  1257. final int radius = getSkillRadius();
  1258. for (L2Character obj : objs)
  1259. {
  1260. if (obj == null || obj == target || obj == activeChar)
  1261. continue;
  1262. if (!Util.checkIfInRange(radius, target, obj, true))
  1263. continue;
  1264. if (!(obj instanceof L2Attackable || obj instanceof L2Playable))
  1265. continue;
  1266. if (!checkForAreaOffensiveSkills(activeChar, obj, this, srcInArena))
  1267. continue;
  1268. targetList.add(obj);
  1269. }
  1270. if (targetList.isEmpty())
  1271. return _emptyTargetList;
  1272. return targetList.toArray(new L2Character[targetList.size()]);
  1273. }
  1274. case TARGET_AREA:
  1275. case TARGET_FRONT_AREA:
  1276. case TARGET_BEHIND_AREA:
  1277. {
  1278. if (((target == null || target == activeChar || target.isAlikeDead()) && getCastRange() >= 0) ||
  1279. (!(target instanceof L2Attackable || target instanceof L2Playable)))
  1280. {
  1281. activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1282. return _emptyTargetList;
  1283. }
  1284. final L2Character origin;
  1285. final boolean srcInArena = (activeChar.isInsideZone(L2Character.ZONE_PVP) && !activeChar.isInsideZone(L2Character.ZONE_SIEGE));
  1286. final int radius = getSkillRadius();
  1287. if (getCastRange() >= 0)
  1288. {
  1289. if (!checkForAreaOffensiveSkills(activeChar, target, this, srcInArena))
  1290. return _emptyTargetList;
  1291. if(onlyFirst)
  1292. return new L2Character[]{target};
  1293. origin = target;
  1294. targetList.add(origin); // Add target to target list
  1295. }
  1296. else
  1297. origin = activeChar;
  1298. final Collection<L2Character> objs = activeChar.getKnownList().getKnownCharacters();
  1299. //synchronized (activeChar.getKnownList().getKnownObjects())
  1300. {
  1301. for (L2Character obj : objs)
  1302. {
  1303. if (!(obj instanceof L2Attackable
  1304. || obj instanceof L2Playable))
  1305. continue;
  1306. if (obj == origin)
  1307. continue;
  1308. if (Util.checkIfInRange(radius, origin, obj, true))
  1309. {
  1310. switch (targetType)
  1311. {
  1312. case TARGET_FRONT_AREA:
  1313. if (!obj.isInFrontOf(activeChar))
  1314. continue;
  1315. break;
  1316. case TARGET_BEHIND_AREA:
  1317. if (!obj.isBehind(activeChar))
  1318. continue;
  1319. break;
  1320. }
  1321. if (!checkForAreaOffensiveSkills(activeChar, obj, this, srcInArena))
  1322. continue;
  1323. targetList.add(obj);
  1324. }
  1325. }
  1326. }
  1327. if (targetList.isEmpty())
  1328. return _emptyTargetList;
  1329. return targetList.toArray(new L2Character[targetList.size()]);
  1330. }
  1331. case TARGET_MULTIFACE:
  1332. {
  1333. if ((!(target instanceof L2Attackable) && !(target instanceof L2Playable)))
  1334. {
  1335. activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1336. return _emptyTargetList;
  1337. }
  1338. if (!onlyFirst)
  1339. targetList.add(target);
  1340. else
  1341. return new L2Character[] {target};
  1342. final int radius = getSkillRadius();
  1343. final Collection<L2Character> objs = activeChar.getKnownList().getKnownCharactersInRadius(radius);
  1344. //synchronized (activeChar.getKnownList().getKnownObjects())
  1345. {
  1346. for (L2Character obj : objs)
  1347. {
  1348. if (obj instanceof L2Attackable && obj != target)
  1349. targetList.add(obj);
  1350. if (targetList.isEmpty())
  1351. {
  1352. activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_CANT_FOUND));
  1353. return _emptyTargetList;
  1354. }
  1355. }
  1356. }
  1357. return targetList.toArray(new L2Character[targetList.size()]);
  1358. //TODO multiface targets all around right now. need it to just get targets
  1359. //the character is facing.
  1360. }
  1361. case TARGET_PARTY:
  1362. {
  1363. if (onlyFirst)
  1364. return new L2Character[]{activeChar};
  1365. targetList.add(activeChar);
  1366. final int radius = getSkillRadius();
  1367. L2PcInstance player = activeChar.getActingPlayer();
  1368. if (activeChar instanceof L2Summon)
  1369. {
  1370. if (addCharacter(activeChar, player, radius, false))
  1371. targetList.add(player);
  1372. }
  1373. else if (activeChar instanceof L2PcInstance)
  1374. {
  1375. if (addSummon(activeChar, player, radius, false))
  1376. targetList.add(player.getPet());
  1377. }
  1378. if (activeChar.isInParty())
  1379. {
  1380. // Get a list of Party Members
  1381. for(L2PcInstance partyMember : activeChar.getParty().getPartyMembers())
  1382. {
  1383. if (partyMember == null || partyMember == player)
  1384. continue;
  1385. if (addCharacter(activeChar, partyMember, radius, false))
  1386. targetList.add(partyMember);
  1387. if (addSummon(activeChar, partyMember, radius, false))
  1388. targetList.add(partyMember.getPet());
  1389. }
  1390. }
  1391. return targetList.toArray(new L2Character[targetList.size()]);
  1392. }
  1393. case TARGET_PARTY_MEMBER:
  1394. {
  1395. if ((target != null
  1396. && target == activeChar)
  1397. || (target != null
  1398. && activeChar.isInParty()
  1399. && target.isInParty()
  1400. && activeChar.getParty().getPartyLeaderOID() == target.getParty().getPartyLeaderOID())
  1401. || (target != null
  1402. && activeChar instanceof L2PcInstance
  1403. && target instanceof L2Summon
  1404. && activeChar.getPet() == target)
  1405. || (target != null
  1406. && activeChar instanceof L2Summon
  1407. && target instanceof L2PcInstance
  1408. && activeChar == target.getPet()))
  1409. {
  1410. if (!target.isDead())
  1411. {
  1412. // If a target is found, return it in a table else send a system message TARGET_IS_INCORRECT
  1413. return new L2Character[]{target};
  1414. }
  1415. else
  1416. return _emptyTargetList;
  1417. }
  1418. else
  1419. {
  1420. activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1421. return _emptyTargetList;
  1422. }
  1423. }
  1424. case TARGET_PARTY_OTHER:
  1425. {
  1426. if (target != null && target != activeChar
  1427. && activeChar.isInParty() && target.isInParty()
  1428. && activeChar.getParty().getPartyLeaderOID() == target.getParty().getPartyLeaderOID())
  1429. {
  1430. if (!target.isDead())
  1431. {
  1432. if (target instanceof L2PcInstance)
  1433. {
  1434. switch (getId())
  1435. {
  1436. // FORCE BUFFS may cancel here but there should be a proper condition
  1437. case 426:
  1438. if (!((L2PcInstance)target).isMageClass())
  1439. return new L2Character[]{target};
  1440. else
  1441. return _emptyTargetList;
  1442. case 427:
  1443. if (((L2PcInstance)target).isMageClass())
  1444. return new L2Character[]{target};
  1445. else
  1446. return _emptyTargetList;
  1447. }
  1448. }
  1449. return new L2Character[]{target};
  1450. }
  1451. else
  1452. return _emptyTargetList;
  1453. }
  1454. else
  1455. {
  1456. activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1457. return _emptyTargetList;
  1458. }
  1459. }
  1460. case TARGET_CORPSE_ALLY:
  1461. case TARGET_ALLY:
  1462. {
  1463. if (activeChar instanceof L2Playable)
  1464. {
  1465. final L2PcInstance player = activeChar.getActingPlayer();
  1466. if (player == null)
  1467. return _emptyTargetList;
  1468. if (player.isInOlympiadMode())
  1469. return new L2Character[] {player};
  1470. final boolean isCorpseType = targetType == SkillTargetType.TARGET_CORPSE_ALLY;
  1471. if (!isCorpseType)
  1472. {
  1473. if (onlyFirst)
  1474. return new L2Character[] {player};
  1475. targetList.add(player);
  1476. }
  1477. final int radius = getSkillRadius();
  1478. if (addSummon(activeChar, player, radius, isCorpseType))
  1479. targetList.add(player.getPet());
  1480. if (player.getClan() != null)
  1481. {
  1482. // Get all visible objects in a spherical area near the L2Character
  1483. final Collection<L2PcInstance> objs = activeChar.getKnownList().getKnownPlayersInRadius(radius);
  1484. //synchronized (activeChar.getKnownList().getKnownObjects())
  1485. {
  1486. for (L2PcInstance obj : objs)
  1487. {
  1488. if (obj == null)
  1489. continue;
  1490. if ((obj.getAllyId() == 0 || obj.getAllyId() != player.getAllyId())
  1491. && (obj.getClan() == null || obj.getClanId() != player.getClanId()))
  1492. continue;
  1493. if (player.isInDuel())
  1494. {
  1495. if (player.getDuelId() != obj.getDuelId())
  1496. continue;
  1497. if (player.isInParty() && obj.isInParty() && player.getParty().getPartyLeaderOID() != obj.getParty().getPartyLeaderOID())
  1498. continue;
  1499. }
  1500. // Don't add this target if this is a Pc->Pc pvp
  1501. // casting and pvp condition not met
  1502. if (!player.checkPvpSkill(obj, this))
  1503. continue;
  1504. if (!TvTEvent.checkForTvTSkill(player, obj, this))
  1505. continue;
  1506. if (!onlyFirst && addSummon(activeChar, obj, radius, isCorpseType))
  1507. targetList.add(obj.getPet());
  1508. if (!addCharacter(activeChar, obj, radius, isCorpseType))
  1509. continue;
  1510. if (isCorpseType)
  1511. {
  1512. // Siege battlefield resurrect has been made possible for participants
  1513. if (getSkillType() == L2SkillType.RESURRECT)
  1514. {
  1515. if (obj.isInsideZone(L2Character.ZONE_SIEGE) && !obj.isInSiege())
  1516. continue;
  1517. }
  1518. }
  1519. if (onlyFirst)
  1520. return new L2Character[] { obj };
  1521. targetList.add(obj);
  1522. }
  1523. }
  1524. }
  1525. }
  1526. return targetList.toArray(new L2Character[targetList.size()]);
  1527. }
  1528. case TARGET_CORPSE_CLAN:
  1529. case TARGET_CLAN:
  1530. {
  1531. if (activeChar instanceof L2Playable)
  1532. {
  1533. final L2PcInstance player = activeChar.getActingPlayer();
  1534. if (player == null)
  1535. return _emptyTargetList;
  1536. if (player.isInOlympiadMode())
  1537. return new L2Character[] {player};
  1538. final boolean isCorpseType = targetType == SkillTargetType.TARGET_CORPSE_CLAN;
  1539. if (!isCorpseType)
  1540. {
  1541. if (onlyFirst)
  1542. return new L2Character[] {player};
  1543. targetList.add(player);
  1544. }
  1545. final int radius = getSkillRadius();
  1546. final L2Clan clan = player.getClan();
  1547. if (addSummon(activeChar, player, radius, isCorpseType))
  1548. targetList.add(player.getPet());
  1549. if (clan != null)
  1550. {
  1551. L2PcInstance obj;
  1552. // Get Clan Members
  1553. for (L2ClanMember member : clan.getMembers())
  1554. {
  1555. obj = member.getPlayerInstance();
  1556. if (obj == null || obj == player)
  1557. continue;
  1558. if (player.isInDuel())
  1559. {
  1560. if (player.getDuelId() != obj.getDuelId())
  1561. continue;
  1562. if (player.isInParty() && obj.isInParty() && player.getParty().getPartyLeaderOID() != obj.getParty().getPartyLeaderOID())
  1563. continue;
  1564. }
  1565. // Don't add this target if this is a Pc->Pc pvp casting and pvp condition not met
  1566. if (!player.checkPvpSkill(obj, this))
  1567. continue;
  1568. if (!TvTEvent.checkForTvTSkill(player, obj, this))
  1569. continue;
  1570. if (!onlyFirst && addSummon(activeChar, obj, radius, isCorpseType))
  1571. targetList.add(obj.getPet());
  1572. if (!addCharacter(activeChar, obj, radius, isCorpseType))
  1573. continue;
  1574. if (isCorpseType)
  1575. {
  1576. if (getSkillType() == L2SkillType.RESURRECT)
  1577. {
  1578. // check target is not in a active siege zone
  1579. if (obj.isInsideZone(L2Character.ZONE_SIEGE) && !obj.isInSiege())
  1580. continue;
  1581. }
  1582. }
  1583. if (onlyFirst)
  1584. return new L2Character[] {obj};
  1585. targetList.add(obj);
  1586. }
  1587. }
  1588. }
  1589. else if (activeChar instanceof L2Npc)
  1590. {
  1591. // for buff purposes, returns one unbuffed friendly mob nearby or mob itself?
  1592. final L2Npc npc = (L2Npc) activeChar;
  1593. final Collection<L2Object> objs = activeChar.getKnownList().getKnownObjects().values();
  1594. //synchronized (activeChar.getKnownList().getKnownObjects())
  1595. {
  1596. for (L2Object newTarget : objs)
  1597. {
  1598. if (newTarget instanceof L2Npc
  1599. && ((L2Npc) newTarget).getFactionId() == npc.getFactionId())
  1600. {
  1601. if (!Util.checkIfInRange(getCastRange(), activeChar, newTarget, true))
  1602. continue;
  1603. if (((L2Npc) newTarget).getFirstEffect(this) != null)
  1604. {
  1605. targetList.add((L2Npc) newTarget);
  1606. break;
  1607. }
  1608. }
  1609. }
  1610. }
  1611. if (targetList.isEmpty())
  1612. {
  1613. targetList.add(activeChar);
  1614. }
  1615. }
  1616. return targetList.toArray(new L2Character[targetList.size()]);
  1617. }
  1618. case TARGET_PARTY_CLAN:
  1619. {
  1620. if (onlyFirst)
  1621. return new L2Character[]{activeChar};
  1622. final L2PcInstance player = activeChar.getActingPlayer();
  1623. if (player == null)
  1624. return _emptyTargetList;
  1625. targetList.add(player);
  1626. final int radius = getSkillRadius();
  1627. final boolean hasClan = player.getClan() != null;
  1628. final boolean hasParty = player.isInParty();
  1629. if (addSummon(activeChar, player, radius, false))
  1630. targetList.add(player.getPet());
  1631. // if player in olympiad mode or not in clan and not in party
  1632. if (player.isInOlympiadMode() || !(hasClan || hasParty))
  1633. return targetList.toArray(new L2Character[targetList.size()]);
  1634. // Get all visible objects in a spherical area near the L2Character
  1635. final Collection<L2PcInstance> objs = activeChar.getKnownList().getKnownPlayersInRadius(radius);
  1636. //synchronized (activeChar.getKnownList().getKnownObjects())
  1637. {
  1638. for (L2PcInstance obj : objs)
  1639. {
  1640. if (obj == null)
  1641. continue;
  1642. if (player.isInDuel())
  1643. {
  1644. if (player.getDuelId() != obj.getDuelId())
  1645. continue;
  1646. if (hasParty && obj.isInParty() && player.getParty().getPartyLeaderOID() != obj.getParty().getPartyLeaderOID())
  1647. continue;
  1648. }
  1649. if (!((hasClan && obj.getClanId() == player.getClanId())
  1650. || (hasParty && obj.isInParty() && player.getParty().getPartyLeaderOID() == obj.getParty().getPartyLeaderOID())))
  1651. continue;
  1652. // Don't add this target if this is a Pc->Pc pvp
  1653. // casting and pvp condition not met
  1654. if (!player.checkPvpSkill(obj, this))
  1655. continue;
  1656. if (!TvTEvent.checkForTvTSkill(player, obj, this))
  1657. continue;
  1658. if (!onlyFirst && addSummon(activeChar, obj, radius, false))
  1659. targetList.add(obj.getPet());
  1660. if (!addCharacter(activeChar, obj, radius, false))
  1661. continue;
  1662. if (onlyFirst)
  1663. return new L2Character[] { obj };
  1664. targetList.add(obj);
  1665. }
  1666. }
  1667. return targetList.toArray(new L2Character[targetList.size()]);
  1668. }
  1669. case TARGET_CORPSE_PLAYER:
  1670. {
  1671. if (target != null && target.isDead())
  1672. {
  1673. final L2PcInstance player;
  1674. if (activeChar instanceof L2PcInstance)
  1675. player = (L2PcInstance) activeChar;
  1676. else
  1677. player = null;
  1678. final L2PcInstance targetPlayer;
  1679. if (target instanceof L2PcInstance)
  1680. targetPlayer = (L2PcInstance) target;
  1681. else
  1682. targetPlayer = null;
  1683. final L2PetInstance targetPet;
  1684. if (target instanceof L2PetInstance)
  1685. targetPet = (L2PetInstance) target;
  1686. else
  1687. targetPet = null;
  1688. if (player != null && (targetPlayer != null || targetPet != null))
  1689. {
  1690. boolean condGood = true;
  1691. if (getSkillType() == L2SkillType.RESURRECT)
  1692. {
  1693. if (targetPlayer != null)
  1694. {
  1695. // check target is not in a active siege zone
  1696. if (targetPlayer.isInsideZone(L2Character.ZONE_SIEGE) && !targetPlayer.isInSiege())
  1697. {
  1698. condGood = false;
  1699. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_BE_RESURRECTED_DURING_SIEGE));
  1700. }
  1701. if (targetPlayer.isFestivalParticipant()) // Check to see if the current player target is in a festival.
  1702. {
  1703. condGood = false;
  1704. activeChar.sendMessage("You may not resurrect participants in a festival.");
  1705. }
  1706. if (targetPlayer.isReviveRequested())
  1707. {
  1708. if (targetPlayer.isRevivingPet())
  1709. player.sendPacket(new SystemMessage(SystemMessageId.MASTER_CANNOT_RES)); // While a pet is attempting to resurrect, it cannot help in resurrecting its master.
  1710. else
  1711. player.sendPacket(new SystemMessage(SystemMessageId.RES_HAS_ALREADY_BEEN_PROPOSED)); // Resurrection is already been proposed.
  1712. condGood = false;
  1713. }
  1714. }
  1715. else if (targetPet != null)
  1716. {
  1717. if (targetPet.getOwner() != player)
  1718. {
  1719. if (targetPet.getOwner().isReviveRequested())
  1720. {
  1721. if (targetPet.getOwner().isRevivingPet())
  1722. player.sendPacket(new SystemMessage(SystemMessageId.RES_HAS_ALREADY_BEEN_PROPOSED)); // Resurrection is already been proposed.
  1723. else
  1724. player.sendPacket(new SystemMessage(SystemMessageId.CANNOT_RES_PET2)); // A pet cannot be resurrected while it's owner is in the process of resurrecting.
  1725. condGood = false;
  1726. }
  1727. }
  1728. }
  1729. }
  1730. if (condGood)
  1731. {
  1732. if (!onlyFirst)
  1733. {
  1734. targetList.add(target);
  1735. return targetList.toArray(new L2Object[targetList.size()]);
  1736. }
  1737. else
  1738. return new L2Character[] {target};
  1739. }
  1740. }
  1741. }
  1742. activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1743. return _emptyTargetList;
  1744. }
  1745. case TARGET_CORPSE_MOB:
  1746. {
  1747. if (!(target instanceof L2Attackable) || !target.isDead())
  1748. {
  1749. activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1750. return _emptyTargetList;
  1751. }
  1752. // Corpse mob only available for half time
  1753. switch (getSkillType())
  1754. {
  1755. case DRAIN:
  1756. case SUMMON:
  1757. {
  1758. if (DecayTaskManager.getInstance().getTasks().containsKey(target)
  1759. && (System.currentTimeMillis() - DecayTaskManager.getInstance().getTasks().get(target)) > DecayTaskManager.ATTACKABLE_DECAY_TIME / 2)
  1760. {
  1761. activeChar.sendPacket(new SystemMessage(SystemMessageId.CORPSE_TOO_OLD_SKILL_NOT_USED));
  1762. return _emptyTargetList;
  1763. }
  1764. }
  1765. }
  1766. if (!onlyFirst)
  1767. {
  1768. targetList.add(target);
  1769. return targetList.toArray(new L2Object[targetList.size()]);
  1770. }
  1771. else
  1772. return new L2Character[] {target};
  1773. }
  1774. case TARGET_AREA_CORPSE_MOB:
  1775. {
  1776. if ((!(target instanceof L2Attackable)) || !target.isDead())
  1777. {
  1778. activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1779. return _emptyTargetList;
  1780. }
  1781. if (onlyFirst)
  1782. return new L2Character[] {target};
  1783. targetList.add(target);
  1784. final boolean srcInArena = (activeChar.isInsideZone(L2Character.ZONE_PVP) && !activeChar.isInsideZone(L2Character.ZONE_SIEGE));
  1785. final int radius = getSkillRadius();
  1786. final Collection<L2Character> objs = activeChar.getKnownList().getKnownCharacters();
  1787. //synchronized (activeChar.getKnownList().getKnownObjects())
  1788. {
  1789. for (L2Character obj : objs)
  1790. {
  1791. if (!(obj instanceof L2Attackable || obj instanceof L2Playable)
  1792. || !Util.checkIfInRange(radius, target, obj, true))
  1793. continue;
  1794. if (!checkForAreaOffensiveSkills(activeChar, obj, this, srcInArena))
  1795. continue;
  1796. targetList.add(obj);
  1797. }
  1798. }
  1799. if (targetList.isEmpty())
  1800. return _emptyTargetList;
  1801. return targetList.toArray(new L2Character[targetList.size()]);
  1802. }
  1803. case TARGET_UNLOCKABLE:
  1804. {
  1805. if (!(target instanceof L2DoorInstance) && !(target instanceof L2ChestInstance))
  1806. {
  1807. //activeChar.sendPacket(new SystemMessage(SystemMessage.TARGET_IS_INCORRECT));
  1808. return _emptyTargetList;
  1809. }
  1810. if (!onlyFirst)
  1811. {
  1812. targetList.add(target);
  1813. return targetList.toArray(new L2Object[targetList.size()]);
  1814. }
  1815. else return new L2Character[] {target};
  1816. }
  1817. case TARGET_UNDEAD:
  1818. {
  1819. if (target instanceof L2Npc || target instanceof L2SummonInstance)
  1820. {
  1821. if (!target.isUndead() || target.isDead())
  1822. {
  1823. activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1824. return _emptyTargetList;
  1825. }
  1826. if (!onlyFirst)
  1827. targetList.add(target);
  1828. else
  1829. return new L2Character[] {target};
  1830. return targetList.toArray(new L2Object[targetList.size()]);
  1831. }
  1832. else
  1833. {
  1834. activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1835. return _emptyTargetList;
  1836. }
  1837. }
  1838. case TARGET_AREA_UNDEAD:
  1839. {
  1840. final L2Character cha;
  1841. final int radius = getSkillRadius();
  1842. if (getCastRange() >= 0 && (target instanceof L2Npc || target instanceof L2SummonInstance)
  1843. && target.isUndead() && !target.isAlikeDead())
  1844. {
  1845. cha = target;
  1846. if (!onlyFirst)
  1847. targetList.add(cha); // Add target to target list
  1848. else
  1849. return new L2Character[] {cha};
  1850. }
  1851. else cha = activeChar;
  1852. final Collection<L2Character> objs = activeChar.getKnownList().getKnownCharacters();
  1853. //synchronized (cha.getKnownList().getKnownObjects())
  1854. {
  1855. for (L2Character obj : objs)
  1856. {
  1857. if (!Util.checkIfInRange(radius, cha, obj, true))
  1858. continue;
  1859. if (obj instanceof L2Npc)
  1860. target = obj;
  1861. else if (obj instanceof L2SummonInstance)
  1862. target = obj;
  1863. else
  1864. continue;
  1865. if (!target.isAlikeDead()) // If target is not
  1866. // dead/fake death and not
  1867. // self
  1868. {
  1869. if (!target.isUndead())
  1870. continue;
  1871. if (geoEnabled && !GeoData.getInstance().canSeeTarget(activeChar, target))
  1872. continue;
  1873. if (!onlyFirst)
  1874. targetList.add(obj);
  1875. else
  1876. return new L2Character[] { obj };
  1877. }
  1878. }
  1879. }
  1880. if (targetList.isEmpty()) return _emptyTargetList;
  1881. return targetList.toArray(new L2Character[targetList.size()]);
  1882. }
  1883. case TARGET_ENEMY_SUMMON:
  1884. {
  1885. if(target instanceof L2Summon)
  1886. {
  1887. L2Summon targetSummon = (L2Summon)target;
  1888. if (activeChar instanceof L2PcInstance && activeChar.getPet() != targetSummon && !targetSummon.isDead()
  1889. && (targetSummon.getOwner().getPvpFlag() != 0 || targetSummon.getOwner().getKarma() > 0)
  1890. || (targetSummon.getOwner().isInsideZone(L2Character.ZONE_PVP) && ((L2PcInstance)activeChar).isInsideZone(L2Character.ZONE_PVP))
  1891. || (targetSummon.getOwner().isInDuel() && ((L2PcInstance)activeChar).isInDuel() && targetSummon.getOwner().getDuelId() == ((L2PcInstance)activeChar).getDuelId()))
  1892. return new L2Character[]{targetSummon};
  1893. }
  1894. return _emptyTargetList;
  1895. }
  1896. case TARGET_PARTY_NOTME:
  1897. {
  1898. //target all party members except yourself
  1899. if (onlyFirst)
  1900. return new L2Character[] { activeChar };
  1901. L2PcInstance player = null;
  1902. if (activeChar instanceof L2Summon)
  1903. {
  1904. player = ((L2Summon) activeChar).getOwner();
  1905. targetList.add(player);
  1906. }
  1907. else if (activeChar instanceof L2PcInstance)
  1908. {
  1909. player = (L2PcInstance) activeChar;
  1910. if (activeChar.getPet() != null)
  1911. targetList.add(activeChar.getPet());
  1912. }
  1913. if (activeChar.getParty() != null)
  1914. {
  1915. List<L2PcInstance> partyList = activeChar.getParty().getPartyMembers();
  1916. for (L2PcInstance partyMember : partyList)
  1917. {
  1918. if (partyMember == null)
  1919. continue;
  1920. if (partyMember == player)
  1921. continue;
  1922. if (!partyMember.isDead() && Util.checkIfInRange(getSkillRadius(), activeChar, partyMember, true))
  1923. {
  1924. targetList.add(partyMember);
  1925. if (partyMember.getPet() != null && !partyMember.getPet().isDead())
  1926. {
  1927. targetList.add(partyMember.getPet());
  1928. }
  1929. }
  1930. }
  1931. }
  1932. return targetList.toArray(new L2Character[targetList.size()]);
  1933. }
  1934. default:
  1935. {
  1936. activeChar.sendMessage("Target type of skill is not currently handled");
  1937. return _emptyTargetList;
  1938. }
  1939. }//end switch
  1940. }
  1941. public final L2Object[] getTargetList(L2Character activeChar)
  1942. {
  1943. return getTargetList(activeChar, false);
  1944. }
  1945. public final L2Object getFirstOfTargetList(L2Character activeChar)
  1946. {
  1947. L2Object[] targets;
  1948. targets = getTargetList(activeChar, true);
  1949. if (targets.length == 0)
  1950. return null;
  1951. else
  1952. return targets[0];
  1953. }
  1954. /*
  1955. * Check if should be target added to the target list
  1956. * false if target is dead, target same as caster,
  1957. * target inside peace zone, target in the same party with caster,
  1958. * caster can see target
  1959. * Additional checks if not in PvP zones (arena, siege):
  1960. * target in not the same clan and alliance with caster,
  1961. * and usual skill PvP check.
  1962. * If TvT event is active - performing additional checks.
  1963. *
  1964. * Caution: distance is not checked.
  1965. */
  1966. public static final boolean checkForAreaOffensiveSkills(L2Character caster, L2Character target, L2Skill skill, boolean sourceInArena)
  1967. {
  1968. if (target == null || target.isDead() || target == caster)
  1969. return false;
  1970. final L2PcInstance player = caster.getActingPlayer();
  1971. if (player != null)
  1972. {
  1973. final L2PcInstance targetPlayer = target.getActingPlayer();
  1974. if (targetPlayer != null)
  1975. {
  1976. if (targetPlayer == caster || targetPlayer == player)
  1977. return false;
  1978. if (targetPlayer.inObserverMode())
  1979. return false;
  1980. if (skill.isOffensive() && player.getSiegeState() > 0 && player.isInsideZone(L2Character.ZONE_SIEGE)
  1981. && player.getSiegeState() == targetPlayer.getSiegeState()
  1982. && player.getSiegeSide() == targetPlayer.getSiegeSide())
  1983. return false;
  1984. if (target.isInsideZone(L2Character.ZONE_PEACE))
  1985. return false;
  1986. if (player.isInParty() && targetPlayer.isInParty())
  1987. {
  1988. // Same party
  1989. if (player.getParty().getPartyLeaderOID() == targetPlayer.getParty().getPartyLeaderOID())
  1990. return false;
  1991. // Same commandchannel
  1992. if (player.getParty().getCommandChannel() != null
  1993. && player.getParty().getCommandChannel() == targetPlayer.getParty().getCommandChannel())
  1994. return false;
  1995. }
  1996. if (!TvTEvent.checkForTvTSkill(player, targetPlayer, skill))
  1997. return false;
  1998. if (!sourceInArena && !(targetPlayer.isInsideZone(L2Character.ZONE_PVP) && !targetPlayer.isInsideZone(L2Character.ZONE_SIEGE)))
  1999. {
  2000. if (player.getAllyId() != 0 && player.getAllyId() == targetPlayer.getAllyId())
  2001. return false;
  2002. if (player.getClanId() != 0 && player.getClanId() == targetPlayer.getClanId())
  2003. return false;
  2004. if (!player.checkPvpSkill(targetPlayer, skill, (caster instanceof L2Summon)))
  2005. return false;
  2006. }
  2007. }
  2008. }
  2009. else
  2010. {
  2011. // source is not playable
  2012. if (!(target instanceof L2Playable))
  2013. return false;
  2014. }
  2015. if (geoEnabled && !GeoData.getInstance().canSeeTarget(caster, target))
  2016. return false;
  2017. return true;
  2018. }
  2019. public static final boolean addSummon(L2Character caster, L2PcInstance owner, int radius, boolean isDead)
  2020. {
  2021. final L2Summon summon = owner.getPet();
  2022. if (summon == null)
  2023. return false;
  2024. return addCharacter(caster, summon, radius, isDead);
  2025. }
  2026. public static final boolean addCharacter(L2Character caster, L2Character target, int radius, boolean isDead)
  2027. {
  2028. if (isDead != target.isDead())
  2029. return false;
  2030. if (radius > 0 && !Util.checkIfInRange(radius, caster, target, true))
  2031. return false;
  2032. return true;
  2033. }
  2034. public final Func[] getStatFuncs(L2Effect effect, L2Character player)
  2035. {
  2036. if (_funcTemplates == null)
  2037. return _emptyFunctionSet;
  2038. if (!(player instanceof L2Playable) && !(player instanceof L2Attackable))
  2039. return _emptyFunctionSet;
  2040. ArrayList<Func> funcs = new ArrayList<Func>(_funcTemplates.length);
  2041. Env env = new Env();
  2042. env.player = player;
  2043. env.skill = this;
  2044. Func f;
  2045. for (FuncTemplate t : _funcTemplates)
  2046. {
  2047. f = t.getFunc(env, this); // skill is owner
  2048. if (f != null)
  2049. funcs.add(f);
  2050. }
  2051. if (funcs.isEmpty())
  2052. return _emptyFunctionSet;
  2053. return funcs.toArray(new Func[funcs.size()]);
  2054. }
  2055. public boolean hasEffects()
  2056. {
  2057. return (_effectTemplates != null && _effectTemplates.length > 0);
  2058. }
  2059. public EffectTemplate[] getEffectTemplates()
  2060. {
  2061. return _effectTemplates;
  2062. }
  2063. /**
  2064. * Env is used to pass parameters for secondary effects (shield and ss/bss/bsss)
  2065. *
  2066. * @return an array with the effects that have been added to effector
  2067. */
  2068. public final L2Effect[] getEffects(L2Character effector, L2Character effected, Env env)
  2069. {
  2070. if (isPassive()) return _emptyEffectSet;
  2071. if (_effectTemplates == null)
  2072. return _emptyEffectSet;
  2073. // doors and siege flags cannot receive any effects
  2074. if (effected instanceof L2DoorInstance ||effected instanceof L2SiegeFlagInstance )
  2075. return _emptyEffectSet;
  2076. if (effector != effected)
  2077. {
  2078. if (effected.isInvul())
  2079. return _emptyEffectSet;
  2080. if ((isOffensive() || isDebuff()) && effector instanceof L2PcInstance && ((L2PcInstance)effector).isGM())
  2081. {
  2082. if (!((L2PcInstance)effector).getAccessLevel().canGiveDamage())
  2083. return _emptyEffectSet;
  2084. }
  2085. }
  2086. ArrayList<L2Effect> effects = new ArrayList<L2Effect>(_effectTemplates.length);
  2087. if (env == null)
  2088. env = new Env();
  2089. env.skillMastery = Formulas.calcSkillMastery(effector, this);
  2090. env.player = effector;
  2091. env.target = effected;
  2092. env.skill = this;
  2093. for (EffectTemplate et : _effectTemplates)
  2094. {
  2095. boolean success = true;
  2096. if (et.effectPower > -1)
  2097. success = Formulas.calcEffectSuccess(effector, effected, et, this, env.shld, env.ss, env.sps, env.bss);
  2098. if (success)
  2099. {
  2100. L2Effect e = et.getEffect(env);
  2101. if (e != null)
  2102. {
  2103. e.scheduleEffect();
  2104. effects.add(e);
  2105. }
  2106. }
  2107. // display fail message only for effects with icons
  2108. else if (et.icon && effector instanceof L2PcInstance)
  2109. {
  2110. SystemMessage sm = new SystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  2111. sm.addCharName(effected);
  2112. sm.addSkillName(this);
  2113. ((L2PcInstance)effector).sendPacket(sm);
  2114. }
  2115. }
  2116. if (effects.isEmpty()) return _emptyEffectSet;
  2117. return effects.toArray(new L2Effect[effects.size()]);
  2118. }
  2119. /**
  2120. * Warning: this method doesn't consider modifier (shield, ss, sps, bss) for secondary effects
  2121. *
  2122. */
  2123. public final L2Effect[] getEffects(L2Character effector, L2Character effected)
  2124. {
  2125. return getEffects(effector, effected, null);
  2126. }
  2127. /**
  2128. * This method has suffered some changes in CT2.2 ->CT2.3<br>
  2129. * Effect engine is now supporting secondary effects with independent
  2130. * success/fail calculus from effect skill. Env parameter has been added to
  2131. * pass parameters like soulshot, spiritshots, blessed spiritshots or shield deffence.
  2132. * Some other optimizations have been done
  2133. * <br><br>
  2134. * This new feature works following next rules:
  2135. * <li> To enable feature, effectPower must be over -1 (check DocumentSkill#attachEffect for further information)</li>
  2136. * <li> If main skill fails, secondary effect always fail</li>
  2137. */
  2138. public final L2Effect[] getEffects(L2CubicInstance effector, L2Character effected, Env env)
  2139. {
  2140. if (isPassive()) return _emptyEffectSet;
  2141. if (_effectTemplates == null)
  2142. return _emptyEffectSet;
  2143. if (effected.isInvul()) return _emptyEffectSet;
  2144. if ((isDebuff() || isOffensive()) && effector.getOwner() != effected &&
  2145. effector.getOwner().isGM() &&
  2146. !effector.getOwner().getAccessLevel().canGiveDamage())
  2147. {
  2148. return _emptyEffectSet;
  2149. }
  2150. ArrayList<L2Effect> effects = new ArrayList<L2Effect>(_effectTemplates.length);
  2151. if (env == null)
  2152. env = new Env();
  2153. env.player = effector.getOwner();
  2154. env.cubic = effector;
  2155. env.target = effected;
  2156. env.skill = this;
  2157. for (EffectTemplate et : _effectTemplates)
  2158. {
  2159. boolean success = true;
  2160. if (et.effectPower > -1)
  2161. success = Formulas.calcEffectSuccess(effector.getOwner(), effected, et, this, env.shld, env.ss, env.sps, env.bss);
  2162. if (success)
  2163. {
  2164. L2Effect e = et.getEffect(env);
  2165. if (e != null)
  2166. {
  2167. e.scheduleEffect();
  2168. effects.add(e);
  2169. }
  2170. }
  2171. }
  2172. if (effects.isEmpty()) return _emptyEffectSet;
  2173. return effects.toArray(new L2Effect[effects.size()]);
  2174. }
  2175. public final L2Effect[] getEffectsSelf(L2Character effector)
  2176. {
  2177. if (isPassive()) return _emptyEffectSet;
  2178. if (_effectTemplatesSelf == null) return _emptyEffectSet;
  2179. List<L2Effect> effects = new FastList<L2Effect>();
  2180. for (EffectTemplate et : _effectTemplatesSelf)
  2181. {
  2182. Env env = new Env();
  2183. env.player = effector;
  2184. env.target = effector;
  2185. env.skill = this;
  2186. L2Effect e = et.getEffect(env);
  2187. if (e != null)
  2188. {
  2189. e.scheduleEffect();
  2190. effects.add(e);
  2191. }
  2192. }
  2193. if (effects.isEmpty()) return _emptyEffectSet;
  2194. return effects.toArray(new L2Effect[effects.size()]);
  2195. }
  2196. public final void attach(FuncTemplate f)
  2197. {
  2198. if (_funcTemplates == null)
  2199. {
  2200. _funcTemplates = new FuncTemplate[] {f};
  2201. }
  2202. else
  2203. {
  2204. int len = _funcTemplates.length;
  2205. FuncTemplate[] tmp = new FuncTemplate[len + 1];
  2206. System.arraycopy(_funcTemplates, 0, tmp, 0, len);
  2207. tmp[len] = f;
  2208. _funcTemplates = tmp;
  2209. }
  2210. }
  2211. public final void attach(EffectTemplate effect)
  2212. {
  2213. if (_effectTemplates == null)
  2214. {
  2215. _effectTemplates = new EffectTemplate[] {effect};
  2216. }
  2217. else
  2218. {
  2219. int len = _effectTemplates.length;
  2220. EffectTemplate[] tmp = new EffectTemplate[len + 1];
  2221. System.arraycopy(_effectTemplates, 0, tmp, 0, len);
  2222. tmp[len] = effect;
  2223. _effectTemplates = tmp;
  2224. }
  2225. }
  2226. public final void attachSelf(EffectTemplate effect)
  2227. {
  2228. if (_effectTemplatesSelf == null)
  2229. {
  2230. _effectTemplatesSelf = new EffectTemplate[] {effect};
  2231. }
  2232. else
  2233. {
  2234. int len = _effectTemplatesSelf.length;
  2235. EffectTemplate[] tmp = new EffectTemplate[len + 1];
  2236. System.arraycopy(_effectTemplatesSelf, 0, tmp, 0, len);
  2237. tmp[len] = effect;
  2238. _effectTemplatesSelf = tmp;
  2239. }
  2240. }
  2241. public final void attach(Condition c, boolean itemOrWeapon)
  2242. {
  2243. if(itemOrWeapon) _itemPreCondition = c;
  2244. else _preCondition = c;
  2245. }
  2246. @Override
  2247. public String toString()
  2248. {
  2249. return "" + _name + "[id=" + _id + ",lvl=" + _level + "]";
  2250. }
  2251. /**
  2252. * @return pet food
  2253. */
  2254. public int getFeed()
  2255. {
  2256. return _feed;
  2257. }
  2258. /**
  2259. * used for tracking item id in case that item consume cannot be used
  2260. * @return reference item id
  2261. */
  2262. public int getReferenceItemId()
  2263. {
  2264. return _refId;
  2265. }
  2266. public final int getMaxCharges()
  2267. {
  2268. return _maxCharges;
  2269. }
  2270. public int getAfterEffectId()
  2271. {
  2272. return _afterEffectId;
  2273. }
  2274. public int getAfterEffectLvl()
  2275. {
  2276. return _afterEffectLvl;
  2277. }
  2278. @Override
  2279. public boolean triggersChanceSkill()
  2280. {
  2281. return _triggeredId > 0 && isChance();
  2282. }
  2283. @Override
  2284. public int getTriggeredChanceId()
  2285. {
  2286. return _triggeredId;
  2287. }
  2288. @Override
  2289. public int getTriggeredChanceLevel()
  2290. {
  2291. return _triggeredLevel;
  2292. }
  2293. @Override
  2294. public ChanceCondition getTriggeredChanceCondition()
  2295. {
  2296. return _chanceCondition;
  2297. }
  2298. public String getAttributeName()
  2299. {
  2300. return _attribute;
  2301. }
  2302. public boolean ignoreShield()
  2303. {
  2304. return _ignoreShield;
  2305. }
  2306. public boolean canBeReflected()
  2307. {
  2308. return _canBeReflected;
  2309. }
  2310. public boolean canBeDispeled()
  2311. {
  2312. return _canBeDispeled;
  2313. }
  2314. public boolean isClanSkill()
  2315. {
  2316. return _isClanSkill;
  2317. }
  2318. public float getDependOnTargetBuff()
  2319. {
  2320. return _dependOnTargetBuff;
  2321. }
  2322. }