L2Skill.java 48 KB

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