L2Skill.java 44 KB

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