2
0

L2Skill.java 47 KB

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