L2Skill.java 48 KB

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