L2Skill.java 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668
  1. /*
  2. * Copyright (C) 2004-2013 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.model.skills;
  20. import java.util.ArrayList;
  21. import java.util.Arrays;
  22. import java.util.Collections;
  23. import java.util.List;
  24. import java.util.logging.Level;
  25. import java.util.logging.Logger;
  26. import com.l2jserver.Config;
  27. import com.l2jserver.gameserver.GeoData;
  28. import com.l2jserver.gameserver.datatables.SkillTable;
  29. import com.l2jserver.gameserver.datatables.SkillTreesData;
  30. import com.l2jserver.gameserver.handler.ITargetTypeHandler;
  31. import com.l2jserver.gameserver.handler.TargetHandler;
  32. import com.l2jserver.gameserver.model.ChanceCondition;
  33. import com.l2jserver.gameserver.model.L2ExtractableProductItem;
  34. import com.l2jserver.gameserver.model.L2ExtractableSkill;
  35. import com.l2jserver.gameserver.model.L2Object;
  36. import com.l2jserver.gameserver.model.PcCondOverride;
  37. import com.l2jserver.gameserver.model.StatsSet;
  38. import com.l2jserver.gameserver.model.actor.L2Attackable;
  39. import com.l2jserver.gameserver.model.actor.L2Character;
  40. import com.l2jserver.gameserver.model.actor.L2Playable;
  41. import com.l2jserver.gameserver.model.actor.L2Summon;
  42. import com.l2jserver.gameserver.model.actor.instance.L2CubicInstance;
  43. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  44. import com.l2jserver.gameserver.model.actor.instance.L2SiegeFlagInstance;
  45. import com.l2jserver.gameserver.model.conditions.Condition;
  46. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  47. import com.l2jserver.gameserver.model.effects.L2Effect;
  48. import com.l2jserver.gameserver.model.effects.L2EffectType;
  49. import com.l2jserver.gameserver.model.entity.TvTEvent;
  50. import com.l2jserver.gameserver.model.holders.ItemHolder;
  51. import com.l2jserver.gameserver.model.interfaces.IChanceSkillTrigger;
  52. import com.l2jserver.gameserver.model.interfaces.IIdentifiable;
  53. import com.l2jserver.gameserver.model.skills.funcs.Func;
  54. import com.l2jserver.gameserver.model.skills.funcs.FuncTemplate;
  55. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  56. import com.l2jserver.gameserver.model.stats.BaseStats;
  57. import com.l2jserver.gameserver.model.stats.Env;
  58. import com.l2jserver.gameserver.model.stats.Formulas;
  59. import com.l2jserver.gameserver.model.stats.TraitType;
  60. import com.l2jserver.gameserver.model.zone.ZoneId;
  61. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  62. import com.l2jserver.gameserver.util.Util;
  63. import com.l2jserver.util.Rnd;
  64. public abstract class L2Skill implements IChanceSkillTrigger, IIdentifiable
  65. {
  66. protected static final Logger _log = Logger.getLogger(L2Skill.class.getName());
  67. private static final L2Object[] EMPTY_TARGET_LIST = new L2Object[0];
  68. private static final List<L2Effect> EMPTY_EFFECT_LIST = Collections.<L2Effect> emptyList();
  69. public static final int SKILL_CREATE_DWARVEN = 172;
  70. public static final int SKILL_EXPERTISE = 239;
  71. public static final int SKILL_CRYSTALLIZE = 248;
  72. public static final int SKILL_CLAN_LUCK = 390;
  73. public static final int SKILL_ONYX_BEAST_TRANSFORMATION = 617;
  74. public static final int SKILL_CREATE_COMMON = 1320;
  75. public static final int SKILL_DIVINE_INSPIRATION = 1405;
  76. public static final int SKILL_NPC_RACE = 4416;
  77. public static final boolean geoEnabled = Config.GEODATA > 0;
  78. /** Skill Id. */
  79. private final int _id;
  80. /** Skill level. */
  81. private final int _level;
  82. /** Custom skill Id displayed by the client. */
  83. private final int _displayId;
  84. /** Custom skill level displayed by the client. */
  85. private final int _displayLevel;
  86. /** Skill client's name. */
  87. private final String _name;
  88. /** Operative type: passive, active, toggle. */
  89. private final L2SkillOpType _operateType;
  90. private final int _magic;
  91. private final TraitType _traitType;
  92. private final boolean _staticReuse;
  93. /** MP consumption. */
  94. private final int _mpConsume;
  95. /** Initial MP consumption. */
  96. private final int _mpInitialConsume;
  97. /** HP consumption. */
  98. private final int _hpConsume;
  99. /** Amount of items consumed by this skill from caster. */
  100. private final int _itemConsumeCount;
  101. /** Id of item consumed by this skill from caster. */
  102. private final int _itemConsumeId;
  103. /** Cast range: how far can be the target. */
  104. private final int _castRange;
  105. /** Effect range: how far the skill affect the target. */
  106. private final int _effectRange;
  107. /** Abnormal instant, used for herbs mostly. */
  108. private final boolean _isAbnormalInstant;
  109. /** Abnormal level, global effect level. */
  110. private final int _abnormalLvl;
  111. /** Abnormal type: global effect "group". */
  112. private final AbnormalType _abnormalType;
  113. /** Abnormal time: global effect duration time. */
  114. private final int _abnormalTime;
  115. /** If {@code true} this skill's effect should stay after death. */
  116. private final boolean _stayAfterDeath;
  117. /** If {@code true} this skill's effect should stay after class-subclass change. */
  118. private final boolean _stayOnSubclassChange;
  119. private final int _refId;
  120. // all times in milliseconds
  121. private final int _hitTime;
  122. private final int[] _hitTimings;
  123. // private final int _skillInterruptTime;
  124. private final int _coolTime;
  125. private final int _reuseHashCode;
  126. private final int _reuseDelay;
  127. /** Target type of the skill : SELF, PARTY, CLAN, PET... */
  128. private final L2TargetType _targetType;
  129. private final int _feed;
  130. // base success chance
  131. private final double _power;
  132. private final double _pvpPower;
  133. private final double _pvePower;
  134. private final int _magicLevel;
  135. private final int _lvlBonusRate;
  136. private final int _activateRate;
  137. private final int _minChance;
  138. private final int _maxChance;
  139. private final int _blowChance;
  140. // Effecting area of the skill, in radius.
  141. // The radius center varies according to the _targetType:
  142. // "caster" if targetType = AURA/PARTY/CLAN or "target" if targetType = AREA
  143. private final int _affectRange;
  144. private final int[] _affectLimit = new int[2];
  145. private final L2SkillType _skillType;
  146. private final int _effectId;
  147. private final int _effectLvl; // normal effect level
  148. private final boolean _nextActionIsAttack;
  149. private final boolean _removedOnAnyActionExceptMove;
  150. private final boolean _removedOnDamage;
  151. private final byte _element;
  152. private final int _elementPower;
  153. private final BaseStats _saveVs;
  154. private final boolean _overhit;
  155. private final int _minPledgeClass;
  156. private final int _chargeConsume;
  157. private final int _triggeredId;
  158. private final int _triggeredLevel;
  159. private final String _chanceType;
  160. private final int _soulMaxConsume;
  161. private final boolean _dependOnTargetBuff;
  162. private final int _afterEffectId;
  163. private final int _afterEffectLvl;
  164. private final boolean _isHeroSkill; // If true the skill is a Hero Skill
  165. private final boolean _isGMSkill; // True if skill is GM skill
  166. private final boolean _isSevenSigns;
  167. private final int _baseCritRate; // percent of success for skill critical hit (especially for PhysicalAttack & Blow - they're not affected by rCrit values or buffs).
  168. private final boolean _directHpDmg; // If true then damage is being make directly
  169. private final boolean _isTriggeredSkill; // If true the skill will take activation buff slot instead of a normal buff slot
  170. private final int _effectPoint;
  171. // Condition lists
  172. private List<Condition> _preCondition;
  173. private List<Condition> _itemPreCondition;
  174. // Function lists
  175. private List<FuncTemplate> _funcTemplates;
  176. // Effect lists
  177. private List<EffectTemplate> _effectTemplates;
  178. private List<EffectTemplate> _effectTemplatesSelf;
  179. private List<EffectTemplate> _effectTemplatesPassive;
  180. protected ChanceCondition _chanceCondition = null;
  181. // Flying support
  182. private final String _flyType;
  183. private final int _flyRadius;
  184. private final float _flyCourse;
  185. private final boolean _isDebuff;
  186. private final String _attribute;
  187. private final boolean _ignoreShield;
  188. private final boolean _isSuicideAttack;
  189. private final boolean _canBeDispeled;
  190. private final boolean _isClanSkill;
  191. private final boolean _excludedFromCheck;
  192. private final boolean _simultaneousCast;
  193. private L2ExtractableSkill _extractableItems = null;
  194. private int _npcId = 0;
  195. private final String _icon;
  196. private byte[] _effectTypes;
  197. protected L2Skill(StatsSet set)
  198. {
  199. _isAbnormalInstant = set.getBoolean("abnormalInstant", false);
  200. _id = set.getInt("skill_id");
  201. _level = set.getInt("level");
  202. _refId = set.getInt("referenceId", 0);
  203. _displayId = set.getInt("displayId", _id);
  204. _displayLevel = set.getInt("displayLevel", _level);
  205. _name = set.getString("name", "");
  206. _operateType = set.getEnum("operateType", L2SkillOpType.class);
  207. _magic = set.getInt("isMagic", 0);
  208. _traitType = set.getEnum("trait", TraitType.class, TraitType.NONE);
  209. _staticReuse = set.getBoolean("staticReuse", false);
  210. _mpConsume = set.getInt("mpConsume", 0);
  211. _mpInitialConsume = set.getInt("mpInitialConsume", 0);
  212. _hpConsume = set.getInt("hpConsume", 0);
  213. _itemConsumeCount = set.getInt("itemConsumeCount", 0);
  214. _itemConsumeId = set.getInt("itemConsumeId", 0);
  215. _afterEffectId = set.getInt("afterEffectId", 0);
  216. _afterEffectLvl = set.getInt("afterEffectLvl", 1);
  217. _castRange = set.getInt("castRange", -1);
  218. _effectRange = set.getInt("effectRange", -1);
  219. _abnormalLvl = set.getInt("abnormalLvl", 0);
  220. _abnormalType = set.getEnum("abnormalType", AbnormalType.class, AbnormalType.NONE);
  221. int abnormalTime = set.getInt("abnormalTime", 1); // TODO: Should be 0, but instant effects need it until implementation is done.
  222. if (Config.ENABLE_MODIFY_SKILL_DURATION && Config.SKILL_DURATION_LIST.containsKey(getId()))
  223. {
  224. if ((getLevel() < 100) || (getLevel() > 140))
  225. {
  226. abnormalTime = Config.SKILL_DURATION_LIST.get(getId());
  227. }
  228. else if ((getLevel() >= 100) && (getLevel() < 140))
  229. {
  230. abnormalTime += Config.SKILL_DURATION_LIST.get(getId());
  231. }
  232. }
  233. _abnormalTime = abnormalTime;
  234. _attribute = set.getString("attribute", "");
  235. _stayAfterDeath = set.getBoolean("stayAfterDeath", false);
  236. _stayOnSubclassChange = set.getBoolean("stayOnSubclassChange", true);
  237. _hitTime = set.getInt("hitTime", 0);
  238. String hitTimings = set.getString("hitTimings", null);
  239. if (hitTimings != null)
  240. {
  241. try
  242. {
  243. String[] valuesSplit = hitTimings.split(",");
  244. _hitTimings = new int[valuesSplit.length];
  245. for (int i = 0; i < valuesSplit.length; i++)
  246. {
  247. _hitTimings[i] = Integer.parseInt(valuesSplit[i]);
  248. }
  249. }
  250. catch (Exception e)
  251. {
  252. throw new IllegalArgumentException("SkillId: " + _id + " invalid hitTimings value: " + hitTimings + ", \"percent,percent,...percent\" required");
  253. }
  254. }
  255. else
  256. {
  257. _hitTimings = new int[0];
  258. }
  259. _coolTime = set.getInt("coolTime", 0);
  260. _isDebuff = set.getBoolean("isDebuff", false);
  261. _feed = set.getInt("feed", 0);
  262. _reuseHashCode = SkillTable.getSkillHashCode(_id, _level);
  263. if (Config.ENABLE_MODIFY_SKILL_REUSE && Config.SKILL_REUSE_LIST.containsKey(_id))
  264. {
  265. if (Config.DEBUG)
  266. {
  267. _log.info("*** Skill " + _name + " (" + _level + ") changed reuse from " + set.getInt("reuseDelay", 0) + " to " + Config.SKILL_REUSE_LIST.get(_id) + " seconds.");
  268. }
  269. _reuseDelay = Config.SKILL_REUSE_LIST.get(_id);
  270. }
  271. else
  272. {
  273. _reuseDelay = set.getInt("reuseDelay", 0);
  274. }
  275. _affectRange = set.getInt("affectRange", 0);
  276. final String affectLimit = set.getString("affectLimit", null);
  277. if (affectLimit != null)
  278. {
  279. try
  280. {
  281. String[] valuesSplit = affectLimit.split("-");
  282. _affectLimit[0] = Integer.parseInt(valuesSplit[0]);
  283. _affectLimit[1] = Integer.parseInt(valuesSplit[1]);
  284. }
  285. catch (Exception e)
  286. {
  287. throw new IllegalArgumentException("SkillId: " + _id + " invalid affectLimit value: " + affectLimit + ", \"percent-percent\" required");
  288. }
  289. }
  290. _targetType = set.getEnum("targetType", L2TargetType.class);
  291. _power = set.getFloat("power", 0.f);
  292. _pvpPower = set.getFloat("pvpPower", (float) getPower());
  293. _pvePower = set.getFloat("pvePower", (float) getPower());
  294. _magicLevel = set.getInt("magicLvl", 0);
  295. _lvlBonusRate = set.getInt("lvlBonusRate", 0);
  296. _activateRate = set.getInt("activateRate", -1);
  297. _minChance = set.getInt("minChance", Config.MIN_ABNORMAL_STATE_SUCCESS_RATE);
  298. _maxChance = set.getInt("maxChance", Config.MAX_ABNORMAL_STATE_SUCCESS_RATE);
  299. _ignoreShield = set.getBoolean("ignoreShld", false);
  300. _skillType = set.getEnum("skillType", L2SkillType.class, L2SkillType.DUMMY);
  301. _effectId = set.getInt("effectId", 0);
  302. _effectLvl = set.getInt("effectLevel", 0);
  303. _nextActionIsAttack = set.getBoolean("nextActionAttack", false);
  304. _removedOnAnyActionExceptMove = set.getBoolean("removedOnAnyActionExceptMove", false);
  305. _removedOnDamage = set.getBoolean("removedOnDamage", false);
  306. _element = set.getByte("element", (byte) -1);
  307. _elementPower = set.getInt("elementPower", 0);
  308. _saveVs = set.getEnum("saveVs", BaseStats.class, BaseStats.NULL);
  309. _overhit = set.getBoolean("overHit", false);
  310. _isSuicideAttack = set.getBoolean("isSuicideAttack", false);
  311. _minPledgeClass = set.getInt("minPledgeClass", 0);
  312. _chargeConsume = set.getInt("chargeConsume", 0);
  313. _triggeredId = set.getInt("triggeredId", 0);
  314. _triggeredLevel = set.getInt("triggeredLevel", 1);
  315. _chanceType = set.getString("chanceType", "");
  316. if (!_chanceType.isEmpty())
  317. {
  318. _chanceCondition = ChanceCondition.parse(set);
  319. }
  320. _soulMaxConsume = set.getInt("soulMaxConsumeCount", 0);
  321. _blowChance = set.getInt("blowChance", 0);
  322. _isHeroSkill = SkillTreesData.getInstance().isHeroSkill(_id, _level);
  323. _isGMSkill = SkillTreesData.getInstance().isGMSkill(_id, _level);
  324. _isSevenSigns = (_id > 4360) && (_id < 4367);
  325. _isClanSkill = SkillTreesData.getInstance().isClanSkill(_id, _level);
  326. _baseCritRate = set.getInt("baseCritRate", 0);
  327. _directHpDmg = set.getBoolean("dmgDirectlyToHp", false);
  328. _isTriggeredSkill = set.getBoolean("isTriggeredSkill", false);
  329. _effectPoint = set.getInt("effectPoint", 0);
  330. _flyType = set.getString("flyType", null);
  331. _flyRadius = set.getInt("flyRadius", 0);
  332. _flyCourse = set.getFloat("flyCourse", 0);
  333. _canBeDispeled = set.getBoolean("canBeDispeled", true);
  334. _excludedFromCheck = set.getBoolean("excludedFromCheck", false);
  335. _dependOnTargetBuff = set.getBoolean("dependOnTargetBuff", false);
  336. _simultaneousCast = set.getBoolean("simultaneousCast", false);
  337. String capsuled_items = set.getString("capsuled_items_skill", null);
  338. if (capsuled_items != null)
  339. {
  340. if (capsuled_items.isEmpty())
  341. {
  342. _log.warning("Empty Extractable Item Skill data in Skill Id: " + _id);
  343. }
  344. _extractableItems = parseExtractableSkill(_id, _level, capsuled_items);
  345. }
  346. _npcId = set.getInt("npcId", 0);
  347. _icon = set.getString("icon", "icon.skill0000");
  348. }
  349. public abstract void useSkill(L2Character caster, L2Object[] targets);
  350. public final L2SkillType getSkillType()
  351. {
  352. return _skillType;
  353. }
  354. public final TraitType getTraitType()
  355. {
  356. return _traitType;
  357. }
  358. public final byte getElement()
  359. {
  360. return _element;
  361. }
  362. public final int getElementPower()
  363. {
  364. return _elementPower;
  365. }
  366. /**
  367. * Return the target type of the skill : SELF, PARTY, CLAN, PET...
  368. * @return
  369. */
  370. public final L2TargetType getTargetType()
  371. {
  372. return _targetType;
  373. }
  374. public final boolean isOverhit()
  375. {
  376. return _overhit;
  377. }
  378. public final boolean isSuicideAttack()
  379. {
  380. return _isSuicideAttack;
  381. }
  382. public final boolean allowOnTransform()
  383. {
  384. return isPassive();
  385. }
  386. /**
  387. * Return the power of the skill.
  388. * @param activeChar
  389. * @param target
  390. * @param isPvP
  391. * @param isPvE
  392. * @return
  393. */
  394. public final double getPower(L2Character activeChar, L2Character target, boolean isPvP, boolean isPvE)
  395. {
  396. if (activeChar == null)
  397. {
  398. return getPower(isPvP, isPvE);
  399. }
  400. if (hasEffectType(L2EffectType.DEATH_LINK))
  401. {
  402. return getPower(isPvP, isPvE) * (-((activeChar.getCurrentHp() * 2) / activeChar.getMaxHp()) + 2);
  403. }
  404. if (hasEffectType(L2EffectType.PHYSICAL_ATTACK_HP_LINK))
  405. {
  406. return getPower(isPvP, isPvE) * (-((target.getCurrentHp() * 2) / target.getMaxHp()) + 2);
  407. }
  408. return getPower(isPvP, isPvE);
  409. }
  410. public final double getPower()
  411. {
  412. return _power;
  413. }
  414. public final double getPower(boolean isPvP, boolean isPvE)
  415. {
  416. return isPvE ? _pvePower : isPvP ? _pvpPower : _power;
  417. }
  418. /**
  419. * @return {@code true} if the skill is abnormal instant, {@code false} otherwise
  420. */
  421. public final boolean isAbnormalInstant()
  422. {
  423. return _isAbnormalInstant;
  424. }
  425. public final int getAbnormalLvl()
  426. {
  427. return _abnormalLvl;
  428. }
  429. public final AbnormalType getAbnormalType()
  430. {
  431. return _abnormalType;
  432. }
  433. public final int getAbnormalTime()
  434. {
  435. return _abnormalTime;
  436. }
  437. public final int getMagicLevel()
  438. {
  439. return _magicLevel;
  440. }
  441. public final int getLvlBonusRate()
  442. {
  443. return _lvlBonusRate;
  444. }
  445. public final int getActivateRate()
  446. {
  447. return _activateRate;
  448. }
  449. /**
  450. * Return custom minimum skill/effect chance.
  451. * @return
  452. */
  453. public final int getMinChance()
  454. {
  455. return _minChance;
  456. }
  457. /**
  458. * Return custom maximum skill/effect chance.
  459. * @return
  460. */
  461. public final int getMaxChance()
  462. {
  463. return _maxChance;
  464. }
  465. /**
  466. * Return true if skill effects should be removed on any action except movement
  467. * @return
  468. */
  469. public final boolean isRemovedOnAnyActionExceptMove()
  470. {
  471. return _removedOnAnyActionExceptMove;
  472. }
  473. /**
  474. * @return {@code true} if skill effects should be removed on damage
  475. */
  476. public final boolean isRemovedOnDamage()
  477. {
  478. return _removedOnDamage;
  479. }
  480. /**
  481. * Return the additional effect Id.
  482. * @return
  483. */
  484. public final int getEffectId()
  485. {
  486. return _effectId;
  487. }
  488. /**
  489. * Return the additional effect level.
  490. * @return
  491. */
  492. public final int getEffectLvl()
  493. {
  494. return _effectLvl;
  495. }
  496. /**
  497. * Return true if character should attack target after skill
  498. * @return
  499. */
  500. public final boolean nextActionIsAttack()
  501. {
  502. return _nextActionIsAttack;
  503. }
  504. /**
  505. * @return Returns the castRange.
  506. */
  507. public final int getCastRange()
  508. {
  509. return _castRange;
  510. }
  511. /**
  512. * @return Returns the effectRange.
  513. */
  514. public final int getEffectRange()
  515. {
  516. return _effectRange;
  517. }
  518. /**
  519. * @return Returns the hpConsume.
  520. */
  521. public final int getHpConsume()
  522. {
  523. return _hpConsume;
  524. }
  525. /**
  526. * Gets the skill ID.
  527. * @return the skill ID
  528. */
  529. @Override
  530. public final int getId()
  531. {
  532. return _id;
  533. }
  534. /**
  535. * @return Returns the boolean _isDebuff.
  536. */
  537. public final boolean isDebuff()
  538. {
  539. return _isDebuff;
  540. }
  541. public int getDisplayId()
  542. {
  543. return _displayId;
  544. }
  545. public int getDisplayLevel()
  546. {
  547. return _displayLevel;
  548. }
  549. public int getTriggeredId()
  550. {
  551. return _triggeredId;
  552. }
  553. public int getTriggeredLevel()
  554. {
  555. return _triggeredLevel;
  556. }
  557. public boolean triggerAnotherSkill()
  558. {
  559. return _triggeredId > 1;
  560. }
  561. /**
  562. * Return skill saveVs base stat (STR, INT ...).
  563. * @return
  564. */
  565. public final BaseStats getSaveVs()
  566. {
  567. return _saveVs;
  568. }
  569. /**
  570. * @return Returns the itemConsume.
  571. */
  572. public final int getItemConsume()
  573. {
  574. return _itemConsumeCount;
  575. }
  576. /**
  577. * @return Returns the itemConsumeId.
  578. */
  579. public final int getItemConsumeId()
  580. {
  581. return _itemConsumeId;
  582. }
  583. /**
  584. * @return Returns the level.
  585. */
  586. public final int getLevel()
  587. {
  588. return _level;
  589. }
  590. /**
  591. * @return Returns true to set physical skills.
  592. */
  593. public final boolean isPhysical()
  594. {
  595. return _magic == 0;
  596. }
  597. /**
  598. * @return Returns true to set magic skills.
  599. */
  600. public final boolean isMagic()
  601. {
  602. return _magic == 1;
  603. }
  604. /**
  605. * @return Returns true to set static skills.
  606. */
  607. public final boolean isStatic()
  608. {
  609. return _magic == 2;
  610. }
  611. /**
  612. * @return Returns true to set dance skills.
  613. */
  614. public final boolean isDance()
  615. {
  616. return _magic == 3;
  617. }
  618. /**
  619. * @return Returns true to set static reuse.
  620. */
  621. public final boolean isStaticReuse()
  622. {
  623. return _staticReuse;
  624. }
  625. /**
  626. * @return Returns the mpConsume.
  627. */
  628. public final int getMpConsume()
  629. {
  630. return _mpConsume;
  631. }
  632. /**
  633. * @return Returns the mpInitialConsume.
  634. */
  635. public final int getMpInitialConsume()
  636. {
  637. return _mpInitialConsume;
  638. }
  639. /**
  640. * @return the skill name
  641. */
  642. public final String getName()
  643. {
  644. return _name;
  645. }
  646. /**
  647. * @return the reuse delay
  648. */
  649. public final int getReuseDelay()
  650. {
  651. return _reuseDelay;
  652. }
  653. public final int getReuseHashCode()
  654. {
  655. return _reuseHashCode;
  656. }
  657. public final int getHitTime()
  658. {
  659. return _hitTime;
  660. }
  661. public final int getHitCounts()
  662. {
  663. return _hitTimings.length;
  664. }
  665. public final int[] getHitTimings()
  666. {
  667. return _hitTimings;
  668. }
  669. /**
  670. * @return the cool time
  671. */
  672. public final int getCoolTime()
  673. {
  674. return _coolTime;
  675. }
  676. public final int getAffectRange()
  677. {
  678. return _affectRange;
  679. }
  680. public final int getAffectLimit()
  681. {
  682. return (_affectLimit[0] + Rnd.get(_affectLimit[1]));
  683. }
  684. public final boolean isActive()
  685. {
  686. return (_operateType != null) && _operateType.isActive();
  687. }
  688. public final boolean isPassive()
  689. {
  690. return (_operateType != null) && _operateType.isPassive();
  691. }
  692. public final boolean isToggle()
  693. {
  694. return (_operateType != null) && _operateType.isToggle();
  695. }
  696. public final boolean isChance()
  697. {
  698. return (_chanceCondition != null) && isPassive();
  699. }
  700. public final boolean isTriggeredSkill()
  701. {
  702. return _isTriggeredSkill;
  703. }
  704. public final int getEffectPoint()
  705. {
  706. return _effectPoint;
  707. }
  708. public final boolean useSoulShot()
  709. {
  710. return (hasEffectType(L2EffectType.PHYSICAL_ATTACK, L2EffectType.PHYSICAL_ATTACK_HP_LINK, L2EffectType.FATAL_BLOW, L2EffectType.ENERGY_ATTACK));
  711. }
  712. public final boolean useSpiritShot()
  713. {
  714. return _magic == 1;
  715. }
  716. public final boolean useFishShot()
  717. {
  718. return ((getSkillType() == L2SkillType.PUMPING) || (getSkillType() == L2SkillType.REELING));
  719. }
  720. public int getMinPledgeClass()
  721. {
  722. return _minPledgeClass;
  723. }
  724. public final boolean isHeroSkill()
  725. {
  726. return _isHeroSkill;
  727. }
  728. public final boolean isGMSkill()
  729. {
  730. return _isGMSkill;
  731. }
  732. public final boolean is7Signs()
  733. {
  734. return _isSevenSigns;
  735. }
  736. public final int getChargeConsume()
  737. {
  738. return _chargeConsume;
  739. }
  740. public final int getMaxSoulConsumeCount()
  741. {
  742. return _soulMaxConsume;
  743. }
  744. public final int getBaseCritRate()
  745. {
  746. return _baseCritRate;
  747. }
  748. public final boolean getDmgDirectlyToHP()
  749. {
  750. return _directHpDmg;
  751. }
  752. public final String getFlyType()
  753. {
  754. return _flyType;
  755. }
  756. public final int getFlyRadius()
  757. {
  758. return _flyRadius;
  759. }
  760. public final float getFlyCourse()
  761. {
  762. return _flyCourse;
  763. }
  764. public final boolean isStayAfterDeath()
  765. {
  766. return _stayAfterDeath;
  767. }
  768. public final boolean isStayOnSubclassChange()
  769. {
  770. return _stayOnSubclassChange;
  771. }
  772. public final boolean isBad()
  773. {
  774. return _effectPoint < 0;
  775. }
  776. public boolean checkCondition(L2Character activeChar, L2Object target, boolean itemOrWeapon)
  777. {
  778. if (activeChar.canOverrideCond(PcCondOverride.SKILL_CONDITIONS) && !Config.GM_SKILL_RESTRICTION)
  779. {
  780. return true;
  781. }
  782. final List<Condition> preCondition = itemOrWeapon ? _itemPreCondition : _preCondition;
  783. if ((preCondition == null) || preCondition.isEmpty())
  784. {
  785. return true;
  786. }
  787. final Env env = new Env();
  788. env.setCharacter(activeChar);
  789. if (target instanceof L2Character)
  790. {
  791. env.setTarget((L2Character) target);
  792. }
  793. env.setSkill(this);
  794. for (Condition cond : preCondition)
  795. {
  796. if (!cond.test(env))
  797. {
  798. final String msg = cond.getMessage();
  799. final int msgId = cond.getMessageId();
  800. if (msgId != 0)
  801. {
  802. final SystemMessage sm = SystemMessage.getSystemMessage(msgId);
  803. if (cond.isAddName())
  804. {
  805. sm.addSkillName(_id);
  806. }
  807. activeChar.sendPacket(sm);
  808. }
  809. else if (msg != null)
  810. {
  811. activeChar.sendMessage(msg);
  812. }
  813. return false;
  814. }
  815. }
  816. return true;
  817. }
  818. public final L2Object[] getTargetList(L2Character activeChar, boolean onlyFirst)
  819. {
  820. // Init to null the target of the skill
  821. L2Character target = null;
  822. // Get the L2Objcet targeted by the user of the skill at this moment
  823. L2Object objTarget = activeChar.getTarget();
  824. // If the L2Object targeted is a L2Character, it becomes the L2Character target
  825. if (objTarget instanceof L2Character)
  826. {
  827. target = (L2Character) objTarget;
  828. }
  829. return getTargetList(activeChar, onlyFirst, target);
  830. }
  831. /**
  832. * Return all targets of the skill in a table in function a the skill type.<br>
  833. * <B><U>Values of skill type</U>:</B>
  834. * <ul>
  835. * <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>
  836. * <li>SELF</li>
  837. * <li>HOLY, UNDEAD</li>
  838. * <li>PET</li>
  839. * <li>AURA, AURA_CLOSE</li>
  840. * <li>AREA</li>
  841. * <li>MULTIFACE</li>
  842. * <li>PARTY, CLAN</li>
  843. * <li>CORPSE_PLAYER, CORPSE_MOB, CORPSE_CLAN</li>
  844. * <li>UNLOCKABLE</li>
  845. * <li>ITEM</li>
  846. * <ul>
  847. * @param activeChar The L2Character who use the skill
  848. * @param onlyFirst
  849. * @param target
  850. * @return
  851. */
  852. public final L2Object[] getTargetList(L2Character activeChar, boolean onlyFirst, L2Character target)
  853. {
  854. final ITargetTypeHandler handler = TargetHandler.getInstance().getHandler(getTargetType());
  855. if (handler != null)
  856. {
  857. try
  858. {
  859. return handler.getTargetList(this, activeChar, onlyFirst, target);
  860. }
  861. catch (Exception e)
  862. {
  863. _log.log(Level.WARNING, "Exception in L2Skill.getTargetList(): " + e.getMessage(), e);
  864. }
  865. }
  866. activeChar.sendMessage("Target type of skill is not currently handled.");
  867. return EMPTY_TARGET_LIST;
  868. }
  869. public final L2Object[] getTargetList(L2Character activeChar)
  870. {
  871. return getTargetList(activeChar, false);
  872. }
  873. public final L2Object getFirstOfTargetList(L2Character activeChar)
  874. {
  875. L2Object[] targets = getTargetList(activeChar, true);
  876. if (targets.length == 0)
  877. {
  878. return null;
  879. }
  880. return targets[0];
  881. }
  882. /**
  883. * Check if should be target added to the target list false if target is dead, target same as caster,<br>
  884. * target inside peace zone, target in the same party with caster, caster can see target Additional checks if not in PvP zones (arena, siege):<br>
  885. * target in not the same clan and alliance with caster, and usual skill PvP check. If TvT event is active - performing additional checks. Caution: distance is not checked.
  886. * @param caster
  887. * @param target
  888. * @param skill
  889. * @param sourceInArena
  890. * @return
  891. */
  892. public static final boolean checkForAreaOffensiveSkills(L2Character caster, L2Character target, L2Skill skill, boolean sourceInArena)
  893. {
  894. if ((target == null) || target.isDead() || (target == caster))
  895. {
  896. return false;
  897. }
  898. final L2PcInstance player = caster.getActingPlayer();
  899. final L2PcInstance targetPlayer = target.getActingPlayer();
  900. if (player != null)
  901. {
  902. if (targetPlayer != null)
  903. {
  904. if ((targetPlayer == caster) || (targetPlayer == player))
  905. {
  906. return false;
  907. }
  908. if (targetPlayer.inObserverMode())
  909. {
  910. return false;
  911. }
  912. if (skill.isBad() && (player.getSiegeState() > 0) && player.isInsideZone(ZoneId.SIEGE) && (player.getSiegeState() == targetPlayer.getSiegeState()) && (player.getSiegeSide() == targetPlayer.getSiegeSide()))
  913. {
  914. return false;
  915. }
  916. if (skill.isBad() && target.isInsideZone(ZoneId.PEACE))
  917. {
  918. return false;
  919. }
  920. if (player.isInParty() && targetPlayer.isInParty())
  921. {
  922. // Same party
  923. if (player.getParty().getLeaderObjectId() == targetPlayer.getParty().getLeaderObjectId())
  924. {
  925. return false;
  926. }
  927. // Same command channel
  928. if (player.getParty().isInCommandChannel() && (player.getParty().getCommandChannel() == targetPlayer.getParty().getCommandChannel()))
  929. {
  930. return false;
  931. }
  932. }
  933. if (!TvTEvent.checkForTvTSkill(player, targetPlayer, skill))
  934. {
  935. return false;
  936. }
  937. if (!sourceInArena && !(targetPlayer.isInsideZone(ZoneId.PVP) && !targetPlayer.isInsideZone(ZoneId.SIEGE)))
  938. {
  939. if ((player.getAllyId() != 0) && (player.getAllyId() == targetPlayer.getAllyId()))
  940. {
  941. return false;
  942. }
  943. if ((player.getClanId() != 0) && (player.getClanId() == targetPlayer.getClanId()))
  944. {
  945. return false;
  946. }
  947. if (!player.checkPvpSkill(targetPlayer, skill, (caster instanceof L2Summon)))
  948. {
  949. return false;
  950. }
  951. }
  952. }
  953. }
  954. else
  955. {
  956. // target is mob
  957. if ((targetPlayer == null) && (target instanceof L2Attackable) && (caster instanceof L2Attackable))
  958. {
  959. String casterEnemyClan = ((L2Attackable) caster).getEnemyClan();
  960. if ((casterEnemyClan == null) || casterEnemyClan.isEmpty())
  961. {
  962. return false;
  963. }
  964. String targetClan = ((L2Attackable) target).getClan();
  965. if ((targetClan == null) || targetClan.isEmpty())
  966. {
  967. return false;
  968. }
  969. if (!casterEnemyClan.equals(targetClan))
  970. {
  971. return false;
  972. }
  973. }
  974. }
  975. if (geoEnabled && !GeoData.getInstance().canSeeTarget(caster, target))
  976. {
  977. return false;
  978. }
  979. return true;
  980. }
  981. public static final boolean addSummon(L2Character caster, L2PcInstance owner, int radius, boolean isDead)
  982. {
  983. if (!owner.hasSummon())
  984. {
  985. return false;
  986. }
  987. return addCharacter(caster, owner.getSummon(), radius, isDead);
  988. }
  989. public static final boolean addCharacter(L2Character caster, L2Character target, int radius, boolean isDead)
  990. {
  991. if (isDead != target.isDead())
  992. {
  993. return false;
  994. }
  995. if ((radius > 0) && !Util.checkIfInRange(radius, caster, target, true))
  996. {
  997. return false;
  998. }
  999. return true;
  1000. }
  1001. public final List<Func> getStatFuncs(L2Effect effect, L2Character player)
  1002. {
  1003. if (_funcTemplates == null)
  1004. {
  1005. return Collections.<Func> emptyList();
  1006. }
  1007. if (!(player instanceof L2Playable) && !(player instanceof L2Attackable))
  1008. {
  1009. return Collections.<Func> emptyList();
  1010. }
  1011. final List<Func> funcs = new ArrayList<>(_funcTemplates.size());
  1012. final Env env = new Env();
  1013. env.setCharacter(player);
  1014. env.setSkill(this);
  1015. for (FuncTemplate t : _funcTemplates)
  1016. {
  1017. Func f = t.getFunc(env, this); // skill is owner
  1018. if (f != null)
  1019. {
  1020. funcs.add(f);
  1021. }
  1022. }
  1023. return funcs;
  1024. }
  1025. public boolean hasEffects()
  1026. {
  1027. return (_effectTemplates != null) && !_effectTemplates.isEmpty();
  1028. }
  1029. public List<EffectTemplate> getEffectTemplates()
  1030. {
  1031. return _effectTemplates;
  1032. }
  1033. public List<EffectTemplate> getEffectTemplatesPassive()
  1034. {
  1035. return _effectTemplatesPassive;
  1036. }
  1037. public boolean hasSelfEffects()
  1038. {
  1039. return (_effectTemplatesSelf != null) && !_effectTemplatesSelf.isEmpty();
  1040. }
  1041. public boolean hasPassiveEffects()
  1042. {
  1043. return (_effectTemplatesPassive != null) && !_effectTemplatesPassive.isEmpty();
  1044. }
  1045. /**
  1046. * Env is used to pass parameters for secondary effects (shield and ss/bss/bsss)
  1047. * @param effector
  1048. * @param effected
  1049. * @param env
  1050. * @return an array with the effects that have been added to effector
  1051. */
  1052. public final List<L2Effect> getEffects(L2Character effector, L2Character effected, Env env)
  1053. {
  1054. if ((effected == null) || !hasEffects() || isPassive())
  1055. {
  1056. return EMPTY_EFFECT_LIST;
  1057. }
  1058. // doors and siege flags cannot receive any effects
  1059. if (effected.isDoor() || (effected instanceof L2SiegeFlagInstance))
  1060. {
  1061. return EMPTY_EFFECT_LIST;
  1062. }
  1063. if ((effector != effected) && isBad())
  1064. {
  1065. if (effected.isInvul())
  1066. {
  1067. return EMPTY_EFFECT_LIST;
  1068. }
  1069. if (effector.isPlayer() && effector.isGM())
  1070. {
  1071. if (!effector.getAccessLevel().canGiveDamage())
  1072. {
  1073. return EMPTY_EFFECT_LIST;
  1074. }
  1075. }
  1076. }
  1077. if (env == null)
  1078. {
  1079. env = new Env();
  1080. }
  1081. env.setSkillMastery(Formulas.calcSkillMastery(effector, this));
  1082. env.setCharacter(effector);
  1083. env.setTarget(effected);
  1084. env.setSkill(this);
  1085. boolean addContinuousEffects = _operateType.isToggle() || (_operateType.isContinuous() && Formulas.calcEffectSuccess(env));
  1086. final List<L2Effect> effects = new ArrayList<>(_effectTemplates.size());
  1087. for (EffectTemplate et : _effectTemplates)
  1088. {
  1089. final L2Effect e = et.getEffect(env);
  1090. if (e != null)
  1091. {
  1092. if ((e.isInstant() && e.calcSuccess()) || (!e.isInstant() && addContinuousEffects))
  1093. {
  1094. e.scheduleEffect();
  1095. effects.add(e);
  1096. }
  1097. }
  1098. }
  1099. effected.getEffectList().add(effects);
  1100. return effects;
  1101. }
  1102. /**
  1103. * Warning: this method doesn't consider modifier (shield, ss, sps, bss) for secondary effects
  1104. * @param effector
  1105. * @param effected
  1106. * @return
  1107. */
  1108. public final List<L2Effect> getEffects(L2Character effector, L2Character effected)
  1109. {
  1110. return getEffects(effector, effected, null);
  1111. }
  1112. public final List<L2Effect> getEffects(L2CubicInstance effector, L2Character effected, Env env)
  1113. {
  1114. if ((effector == null) || (effected == null) || !hasEffects() || isPassive())
  1115. {
  1116. return EMPTY_EFFECT_LIST;
  1117. }
  1118. if ((effector.getOwner() != effected) && isBad())
  1119. {
  1120. if (effected.isInvul())
  1121. {
  1122. return EMPTY_EFFECT_LIST;
  1123. }
  1124. if (effector.getOwner().isGM() && !effector.getOwner().getAccessLevel().canGiveDamage())
  1125. {
  1126. return EMPTY_EFFECT_LIST;
  1127. }
  1128. }
  1129. if (env == null)
  1130. {
  1131. env = new Env();
  1132. }
  1133. env.setCharacter(effector.getOwner());
  1134. env.setCubic(effector);
  1135. env.setTarget(effected);
  1136. env.setSkill(this);
  1137. boolean addContinuousEffects = _operateType.isToggle() || (_operateType.isContinuous() && Formulas.calcEffectSuccess(env));
  1138. final List<L2Effect> effects = new ArrayList<>(_effectTemplates.size());
  1139. for (EffectTemplate et : _effectTemplates)
  1140. {
  1141. final L2Effect e = et.getEffect(env);
  1142. if (e != null)
  1143. {
  1144. if ((e.isInstant() && e.calcSuccess()) || (!e.isInstant() && addContinuousEffects))
  1145. {
  1146. e.scheduleEffect();
  1147. effects.add(e);
  1148. }
  1149. }
  1150. }
  1151. return effects;
  1152. }
  1153. public final List<L2Effect> getEffectsSelf(L2Character effector)
  1154. {
  1155. if ((effector == null) || !hasSelfEffects() || isPassive())
  1156. {
  1157. return EMPTY_EFFECT_LIST;
  1158. }
  1159. final Env env = new Env();
  1160. env.setCharacter(effector);
  1161. env.setTarget(effector);
  1162. env.setSkill(this);
  1163. boolean addContinuousEffects = _operateType.isToggle() || (_operateType.isContinuous() && Formulas.calcEffectSuccess(env));
  1164. final List<L2Effect> effects = new ArrayList<>(_effectTemplatesSelf.size());
  1165. for (EffectTemplate et : _effectTemplatesSelf)
  1166. {
  1167. final L2Effect e = et.getEffect(env);
  1168. if (e != null)
  1169. {
  1170. if ((e.isInstant() && e.calcSuccess()) || (!e.isInstant() && addContinuousEffects))
  1171. {
  1172. e.setSelfEffect();
  1173. e.scheduleEffect();
  1174. effects.add(e);
  1175. }
  1176. }
  1177. }
  1178. effector.getEffectList().add(effects);
  1179. return effects;
  1180. }
  1181. public final List<L2Effect> getPassiveEffects(L2Character effector)
  1182. {
  1183. if ((effector == null) || !hasPassiveEffects())
  1184. {
  1185. return EMPTY_EFFECT_LIST;
  1186. }
  1187. final Env env = new Env();
  1188. env.setCharacter(effector);
  1189. env.setTarget(effector);
  1190. env.setSkill(this);
  1191. final List<L2Effect> effects = new ArrayList<>(_effectTemplatesPassive.size());
  1192. for (EffectTemplate et : _effectTemplatesPassive)
  1193. {
  1194. final L2Effect e = et.getEffect(env);
  1195. if (e != null)
  1196. {
  1197. if (!e.isInstant())
  1198. {
  1199. e.scheduleEffect();
  1200. effects.add(e);
  1201. }
  1202. }
  1203. }
  1204. effector.getEffectList().add(effects);
  1205. return effects;
  1206. }
  1207. public final void attach(FuncTemplate f)
  1208. {
  1209. if (_funcTemplates == null)
  1210. {
  1211. _funcTemplates = new ArrayList<>(1);
  1212. }
  1213. _funcTemplates.add(f);
  1214. }
  1215. public final void attach(EffectTemplate effect)
  1216. {
  1217. if (_effectTemplates == null)
  1218. {
  1219. _effectTemplates = new ArrayList<>(1);
  1220. }
  1221. _effectTemplates.add(effect);
  1222. }
  1223. public final void attachSelf(EffectTemplate effect)
  1224. {
  1225. if (_effectTemplatesSelf == null)
  1226. {
  1227. _effectTemplatesSelf = new ArrayList<>(1);
  1228. }
  1229. _effectTemplatesSelf.add(effect);
  1230. }
  1231. public final void attachPassive(EffectTemplate effect)
  1232. {
  1233. if (_effectTemplatesPassive == null)
  1234. {
  1235. _effectTemplatesPassive = new ArrayList<>(1);
  1236. }
  1237. _effectTemplatesPassive.add(effect);
  1238. }
  1239. public final void attach(Condition c, boolean itemOrWeapon)
  1240. {
  1241. if (itemOrWeapon)
  1242. {
  1243. if (_itemPreCondition == null)
  1244. {
  1245. _itemPreCondition = new ArrayList<>();
  1246. }
  1247. _itemPreCondition.add(c);
  1248. }
  1249. else
  1250. {
  1251. if (_preCondition == null)
  1252. {
  1253. _preCondition = new ArrayList<>();
  1254. }
  1255. _preCondition.add(c);
  1256. }
  1257. }
  1258. @Override
  1259. public String toString()
  1260. {
  1261. return "Skill " + _name + "(" + _id + "," + _level + ")";
  1262. }
  1263. /**
  1264. * @return pet food
  1265. */
  1266. public int getFeed()
  1267. {
  1268. return _feed;
  1269. }
  1270. /**
  1271. * used for tracking item id in case that item consume cannot be used
  1272. * @return reference item id
  1273. */
  1274. public int getReferenceItemId()
  1275. {
  1276. return _refId;
  1277. }
  1278. public int getAfterEffectId()
  1279. {
  1280. return _afterEffectId;
  1281. }
  1282. public int getAfterEffectLvl()
  1283. {
  1284. return _afterEffectLvl;
  1285. }
  1286. @Override
  1287. public boolean triggersChanceSkill()
  1288. {
  1289. return (_triggeredId > 0) && isChance();
  1290. }
  1291. @Override
  1292. public int getTriggeredChanceId()
  1293. {
  1294. return _triggeredId;
  1295. }
  1296. @Override
  1297. public int getTriggeredChanceLevel()
  1298. {
  1299. return _triggeredLevel;
  1300. }
  1301. @Override
  1302. public ChanceCondition getTriggeredChanceCondition()
  1303. {
  1304. return _chanceCondition;
  1305. }
  1306. public String getAttributeName()
  1307. {
  1308. return _attribute;
  1309. }
  1310. /**
  1311. * @return the _blowChance
  1312. */
  1313. public int getBlowChance()
  1314. {
  1315. return _blowChance;
  1316. }
  1317. public boolean ignoreShield()
  1318. {
  1319. return _ignoreShield;
  1320. }
  1321. public boolean canBeDispeled()
  1322. {
  1323. return _canBeDispeled;
  1324. }
  1325. public boolean isClanSkill()
  1326. {
  1327. return _isClanSkill;
  1328. }
  1329. public boolean isExcludedFromCheck()
  1330. {
  1331. return _excludedFromCheck;
  1332. }
  1333. public boolean getDependOnTargetBuff()
  1334. {
  1335. return _dependOnTargetBuff;
  1336. }
  1337. public boolean isSimultaneousCast()
  1338. {
  1339. return _simultaneousCast;
  1340. }
  1341. /**
  1342. * Parse an extractable skill.
  1343. * @param skillId the skill Id
  1344. * @param skillLvl the skill level
  1345. * @param values the values to parse
  1346. * @return the parsed extractable skill
  1347. * @author Zoey76
  1348. */
  1349. private L2ExtractableSkill parseExtractableSkill(int skillId, int skillLvl, String values)
  1350. {
  1351. final String[] prodLists = values.split(";");
  1352. final List<L2ExtractableProductItem> products = new ArrayList<>();
  1353. String[] prodData;
  1354. for (String prodList : prodLists)
  1355. {
  1356. prodData = prodList.split(",");
  1357. if (prodData.length < 3)
  1358. {
  1359. _log.warning("Extractable skills data: Error in Skill Id: " + skillId + " Level: " + skillLvl + " -> wrong seperator!");
  1360. }
  1361. List<ItemHolder> items = null;
  1362. double chance = 0;
  1363. int prodId = 0;
  1364. int quantity = 0;
  1365. final int lenght = prodData.length - 1;
  1366. try
  1367. {
  1368. items = new ArrayList<>(lenght / 2);
  1369. for (int j = 0; j < lenght; j++)
  1370. {
  1371. prodId = Integer.parseInt(prodData[j]);
  1372. quantity = Integer.parseInt(prodData[j += 1]);
  1373. if ((prodId <= 0) || (quantity <= 0))
  1374. {
  1375. _log.warning("Extractable skills data: Error in Skill Id: " + skillId + " Level: " + skillLvl + " wrong production Id: " + prodId + " or wrond quantity: " + quantity + "!");
  1376. }
  1377. items.add(new ItemHolder(prodId, quantity));
  1378. }
  1379. chance = Double.parseDouble(prodData[lenght]);
  1380. }
  1381. catch (Exception e)
  1382. {
  1383. _log.warning("Extractable skills data: Error in Skill Id: " + skillId + " Level: " + skillLvl + " -> incomplete/invalid production data or wrong seperator!");
  1384. }
  1385. products.add(new L2ExtractableProductItem(items, chance));
  1386. }
  1387. if (products.isEmpty())
  1388. {
  1389. _log.warning("Extractable skills data: Error in Skill Id: " + skillId + " Level: " + skillLvl + " -> There are no production items!");
  1390. }
  1391. return new L2ExtractableSkill(SkillTable.getSkillHashCode(skillId, skillLvl), products);
  1392. }
  1393. public L2ExtractableSkill getExtractableSkill()
  1394. {
  1395. return _extractableItems;
  1396. }
  1397. /**
  1398. * @return the _npcId
  1399. */
  1400. public int getNpcId()
  1401. {
  1402. return _npcId;
  1403. }
  1404. /**
  1405. * @param types
  1406. * @return {@code true} if at least one of specified {@link L2EffectType} types present on the current skill's effects, {@code false} otherwise.
  1407. */
  1408. public boolean hasEffectType(L2EffectType... types)
  1409. {
  1410. if (hasEffects() && (types != null) && (types.length > 0))
  1411. {
  1412. if (_effectTypes == null)
  1413. {
  1414. _effectTypes = new byte[_effectTemplates.size()];
  1415. final Env env = new Env();
  1416. env.setSkill(this);
  1417. int i = 0;
  1418. for (EffectTemplate et : _effectTemplates)
  1419. {
  1420. final L2Effect e = et.getEffect(env, true);
  1421. if (e == null)
  1422. {
  1423. continue;
  1424. }
  1425. _effectTypes[i++] = (byte) e.getEffectType().ordinal();
  1426. }
  1427. Arrays.sort(_effectTypes);
  1428. }
  1429. for (L2EffectType type : types)
  1430. {
  1431. if (Arrays.binarySearch(_effectTypes, (byte) type.ordinal()) >= 0)
  1432. {
  1433. return true;
  1434. }
  1435. }
  1436. }
  1437. return false;
  1438. }
  1439. /**
  1440. * @return icon of the current skill.
  1441. */
  1442. public String getIcon()
  1443. {
  1444. return _icon;
  1445. }
  1446. }