Skill.java 50 KB

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