L2Skill.java 44 KB

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