L2Skill.java 48 KB

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