L2Skill.java 48 KB

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