Skill.java 50 KB

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