Skill.java 50 KB

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