L2Skill.java 42 KB

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