Skill.java 49 KB

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