Skill.java 49 KB

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