L2Skill.java 42 KB

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