Skill.java 49 KB

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