Skill.java 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856
  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()) || isSelfContinuous();
  737. }
  738. public boolean isSelfContinuous()
  739. {
  740. return (_operateType != null) && _operateType.isSelfContinuous();
  741. }
  742. public boolean isChance()
  743. {
  744. return (_chanceCondition != null) && isPassive();
  745. }
  746. public boolean isChanneling()
  747. {
  748. return (_operateType != null) && _operateType.isChanneling();
  749. }
  750. public boolean isTriggeredSkill()
  751. {
  752. return _isTriggeredSkill;
  753. }
  754. /**
  755. * Verify if the skill is a transformation skill.
  756. * @return {@code true} if the skill is a transformation, {@code false} otherwise
  757. */
  758. public boolean isTransformation()
  759. {
  760. return _abnormalType == AbnormalType.TRANSFORM;
  761. }
  762. public int getEffectPoint()
  763. {
  764. return _effectPoint;
  765. }
  766. public boolean useSoulShot()
  767. {
  768. return (hasEffectType(L2EffectType.PHYSICAL_ATTACK, L2EffectType.PHYSICAL_ATTACK_HP_LINK));
  769. }
  770. public boolean useSpiritShot()
  771. {
  772. return _magic == 1;
  773. }
  774. public boolean useFishShot()
  775. {
  776. return hasEffectType(L2EffectType.FISHING);
  777. }
  778. public int getMinPledgeClass()
  779. {
  780. return _minPledgeClass;
  781. }
  782. public boolean isHeroSkill()
  783. {
  784. return _isHeroSkill;
  785. }
  786. public boolean isGMSkill()
  787. {
  788. return _isGMSkill;
  789. }
  790. public boolean is7Signs()
  791. {
  792. return _isSevenSigns;
  793. }
  794. /**
  795. * Verify if this is a healing potion skill.
  796. * @return {@code true} if this is a healing potion skill, {@code false} otherwise
  797. */
  798. public boolean isHealingPotionSkill()
  799. {
  800. return getAbnormalType() == AbnormalType.HP_RECOVER;
  801. }
  802. public int getChargeConsume()
  803. {
  804. return _chargeConsume;
  805. }
  806. public int getMaxSoulConsumeCount()
  807. {
  808. return _soulMaxConsume;
  809. }
  810. public int getBaseCritRate()
  811. {
  812. return _baseCritRate;
  813. }
  814. public boolean getDmgDirectlyToHP()
  815. {
  816. return _directHpDmg;
  817. }
  818. public FlyType getFlyType()
  819. {
  820. return _flyType;
  821. }
  822. public int getFlyRadius()
  823. {
  824. return _flyRadius;
  825. }
  826. public float getFlyCourse()
  827. {
  828. return _flyCourse;
  829. }
  830. public boolean isStayAfterDeath()
  831. {
  832. return _stayAfterDeath;
  833. }
  834. public boolean isStayOnSubclassChange()
  835. {
  836. return _stayOnSubclassChange;
  837. }
  838. public boolean isBad()
  839. {
  840. return _effectPoint < 0;
  841. }
  842. public boolean checkCondition(L2Character activeChar, L2Object target, boolean itemOrWeapon)
  843. {
  844. if (activeChar.canOverrideCond(PcCondOverride.SKILL_CONDITIONS) && !Config.GM_SKILL_RESTRICTION)
  845. {
  846. return true;
  847. }
  848. final List<Condition> preCondition = itemOrWeapon ? _itemPreCondition : _preCondition;
  849. if ((preCondition == null) || preCondition.isEmpty())
  850. {
  851. return true;
  852. }
  853. final Env env = new Env();
  854. env.setCharacter(activeChar);
  855. if (target instanceof L2Character)
  856. {
  857. env.setTarget((L2Character) target);
  858. }
  859. env.setSkill(this);
  860. for (Condition cond : preCondition)
  861. {
  862. if (!cond.test(env))
  863. {
  864. final String msg = cond.getMessage();
  865. final int msgId = cond.getMessageId();
  866. if (msgId != 0)
  867. {
  868. final SystemMessage sm = SystemMessage.getSystemMessage(msgId);
  869. if (cond.isAddName())
  870. {
  871. sm.addSkillName(_id);
  872. }
  873. activeChar.sendPacket(sm);
  874. }
  875. else if (msg != null)
  876. {
  877. activeChar.sendMessage(msg);
  878. }
  879. return false;
  880. }
  881. }
  882. return true;
  883. }
  884. public L2Object[] getTargetList(L2Character activeChar, boolean onlyFirst)
  885. {
  886. // Init to null the target of the skill
  887. L2Character target = null;
  888. // Get the L2Objcet targeted by the user of the skill at this moment
  889. L2Object objTarget = activeChar.getTarget();
  890. // If the L2Object targeted is a L2Character, it becomes the L2Character target
  891. if (objTarget instanceof L2Character)
  892. {
  893. target = (L2Character) objTarget;
  894. }
  895. return getTargetList(activeChar, onlyFirst, target);
  896. }
  897. /**
  898. * Return all targets of the skill in a table in function a the skill type.<br>
  899. * <B><U>Values of skill type</U>:</B>
  900. * <ul>
  901. * <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>
  902. * <li>SELF</li>
  903. * <li>HOLY, UNDEAD</li>
  904. * <li>PET</li>
  905. * <li>AURA, AURA_CLOSE</li>
  906. * <li>AREA</li>
  907. * <li>MULTIFACE</li>
  908. * <li>PARTY, CLAN</li>
  909. * <li>CORPSE_PLAYER, CORPSE_MOB, CORPSE_CLAN</li>
  910. * <li>UNLOCKABLE</li>
  911. * <li>ITEM</li>
  912. * <ul>
  913. * @param activeChar The L2Character who use the skill
  914. * @param onlyFirst
  915. * @param target
  916. * @return
  917. */
  918. public L2Object[] getTargetList(L2Character activeChar, boolean onlyFirst, L2Character target)
  919. {
  920. final ITargetTypeHandler handler = TargetHandler.getInstance().getHandler(getTargetType());
  921. if (handler != null)
  922. {
  923. try
  924. {
  925. return handler.getTargetList(this, activeChar, onlyFirst, target);
  926. }
  927. catch (Exception e)
  928. {
  929. _log.log(Level.WARNING, "Exception in L2Skill.getTargetList(): " + e.getMessage(), e);
  930. }
  931. }
  932. activeChar.sendMessage("Target type of skill is not currently handled.");
  933. return EMPTY_TARGET_LIST;
  934. }
  935. public L2Object[] getTargetList(L2Character activeChar)
  936. {
  937. return getTargetList(activeChar, false);
  938. }
  939. public L2Object getFirstOfTargetList(L2Character activeChar)
  940. {
  941. L2Object[] targets = getTargetList(activeChar, true);
  942. if (targets.length == 0)
  943. {
  944. return null;
  945. }
  946. return targets[0];
  947. }
  948. /**
  949. * Check if should be target added to the target list false if target is dead, target same as caster,<br>
  950. * 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>
  951. * 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.
  952. * @param caster
  953. * @param target
  954. * @param skill
  955. * @param sourceInArena
  956. * @return
  957. */
  958. public static final boolean checkForAreaOffensiveSkills(L2Character caster, L2Character target, Skill skill, boolean sourceInArena)
  959. {
  960. if ((target == null) || target.isDead() || (target == caster))
  961. {
  962. return false;
  963. }
  964. final L2PcInstance player = caster.getActingPlayer();
  965. final L2PcInstance targetPlayer = target.getActingPlayer();
  966. if (player != null)
  967. {
  968. if (targetPlayer != null)
  969. {
  970. if ((targetPlayer == caster) || (targetPlayer == player))
  971. {
  972. return false;
  973. }
  974. if (targetPlayer.inObserverMode())
  975. {
  976. return false;
  977. }
  978. if (skill.isBad() && (player.getSiegeState() > 0) && player.isInsideZone(ZoneId.SIEGE) && (player.getSiegeState() == targetPlayer.getSiegeState()) && (player.getSiegeSide() == targetPlayer.getSiegeSide()))
  979. {
  980. return false;
  981. }
  982. if (skill.isBad() && target.isInsideZone(ZoneId.PEACE))
  983. {
  984. return false;
  985. }
  986. if (player.isInParty() && targetPlayer.isInParty())
  987. {
  988. // Same party
  989. if (player.getParty().getLeaderObjectId() == targetPlayer.getParty().getLeaderObjectId())
  990. {
  991. return false;
  992. }
  993. // Same command channel
  994. if (player.getParty().isInCommandChannel() && (player.getParty().getCommandChannel() == targetPlayer.getParty().getCommandChannel()))
  995. {
  996. return false;
  997. }
  998. }
  999. if (!TvTEvent.checkForTvTSkill(player, targetPlayer, skill))
  1000. {
  1001. return false;
  1002. }
  1003. if (!sourceInArena && !(targetPlayer.isInsideZone(ZoneId.PVP) && !targetPlayer.isInsideZone(ZoneId.SIEGE)))
  1004. {
  1005. if ((player.getAllyId() != 0) && (player.getAllyId() == targetPlayer.getAllyId()))
  1006. {
  1007. return false;
  1008. }
  1009. if ((player.getClanId() != 0) && (player.getClanId() == targetPlayer.getClanId()))
  1010. {
  1011. return false;
  1012. }
  1013. if (!player.checkPvpSkill(targetPlayer, skill, (caster instanceof L2Summon)))
  1014. {
  1015. return false;
  1016. }
  1017. }
  1018. }
  1019. }
  1020. else
  1021. {
  1022. // target is mob
  1023. if ((targetPlayer == null) && (target instanceof L2Attackable) && (caster instanceof L2Attackable))
  1024. {
  1025. if (!((L2Attackable) caster).isInEnemyClan((L2Attackable) target))
  1026. {
  1027. return false;
  1028. }
  1029. }
  1030. }
  1031. if ((Config.GEODATA > 0) && !GeoData.getInstance().canSeeTarget(caster, target))
  1032. {
  1033. return false;
  1034. }
  1035. return true;
  1036. }
  1037. public static final boolean addSummon(L2Character caster, L2PcInstance owner, int radius, boolean isDead)
  1038. {
  1039. if (!owner.hasSummon())
  1040. {
  1041. return false;
  1042. }
  1043. return addCharacter(caster, owner.getSummon(), radius, isDead);
  1044. }
  1045. public static final boolean addCharacter(L2Character caster, L2Character target, int radius, boolean isDead)
  1046. {
  1047. if (isDead != target.isDead())
  1048. {
  1049. return false;
  1050. }
  1051. if ((radius > 0) && !Util.checkIfInRange(radius, caster, target, true))
  1052. {
  1053. return false;
  1054. }
  1055. return true;
  1056. }
  1057. public List<Func> getStatFuncs(AbstractEffect effect, L2Character player)
  1058. {
  1059. if (_funcTemplates == null)
  1060. {
  1061. return Collections.<Func> emptyList();
  1062. }
  1063. if (!(player instanceof L2Playable) && !(player instanceof L2Attackable))
  1064. {
  1065. return Collections.<Func> emptyList();
  1066. }
  1067. final List<Func> funcs = new ArrayList<>(_funcTemplates.size());
  1068. final Env env = new Env();
  1069. env.setCharacter(player);
  1070. env.setSkill(this);
  1071. for (FuncTemplate t : _funcTemplates)
  1072. {
  1073. Func f = t.getFunc(env, this); // skill is owner
  1074. if (f != null)
  1075. {
  1076. funcs.add(f);
  1077. }
  1078. }
  1079. return funcs;
  1080. }
  1081. /**
  1082. * Gets the skill effects.
  1083. * @param effectScope the effect scope
  1084. * @return the list of effects for the give scope
  1085. */
  1086. public List<AbstractEffect> getEffects(EffectScope effectScope)
  1087. {
  1088. return _effectLists.get(effectScope);
  1089. }
  1090. /**
  1091. * Verify if this skill has effects for the given scope.
  1092. * @param effectScope the effect scope
  1093. * @return {@code true} if this skill has effects for the given scope, {@code false} otherwise
  1094. */
  1095. public boolean hasEffects(EffectScope effectScope)
  1096. {
  1097. List<AbstractEffect> effects = _effectLists.get(effectScope);
  1098. return (effects != null) && !effects.isEmpty();
  1099. }
  1100. /**
  1101. * Applies the effects from this skill to the target for the given effect scope.
  1102. * @param effectScope the effect scope
  1103. * @param info the buff info
  1104. * @param applyInstantEffects if {@code true} instant effects will be applied to the effected
  1105. * @param addContinuousEffects if {@code true} continuous effects will be applied to the effected
  1106. */
  1107. public void applyEffectScope(EffectScope effectScope, BuffInfo info, boolean applyInstantEffects, boolean addContinuousEffects)
  1108. {
  1109. if ((effectScope != null) && hasEffects(effectScope))
  1110. {
  1111. for (AbstractEffect effect : getEffects(effectScope))
  1112. {
  1113. if (effect != null)
  1114. {
  1115. if (effect.isInstant())
  1116. {
  1117. if (applyInstantEffects && effect.calcSuccess(info))
  1118. {
  1119. effect.onStart(info);
  1120. }
  1121. }
  1122. else if (addContinuousEffects)
  1123. {
  1124. if (effect.canStart(info))
  1125. {
  1126. info.addEffect(effect);
  1127. }
  1128. }
  1129. }
  1130. }
  1131. }
  1132. }
  1133. /**
  1134. * Method overload for {@link Skill#applyEffects(L2Character, L2CubicInstance, L2Character, boolean, boolean, boolean, int)}.<br>
  1135. * Simplify the calls.
  1136. * @param effector the caster of the skill
  1137. * @param effected the target of the effect
  1138. */
  1139. public void applyEffects(L2Character effector, L2Character effected)
  1140. {
  1141. applyEffects(effector, null, effected, false, false, true, 0);
  1142. }
  1143. /**
  1144. * Method overload for {@link Skill#applyEffects(L2Character, L2CubicInstance, L2Character, boolean, boolean, boolean, int)}.<br>
  1145. * Simplify the calls, allowing abnormal time time customization.
  1146. * @param effector the caster of the skill
  1147. * @param effected the target of the effect
  1148. * @param instant if {@code true} instant effects will be applied to the effected
  1149. * @param abnormalTime custom abnormal time, if equal or lesser than zero will be ignored
  1150. */
  1151. public void applyEffects(L2Character effector, L2Character effected, boolean instant, int abnormalTime)
  1152. {
  1153. applyEffects(effector, null, effected, false, false, instant, abnormalTime);
  1154. }
  1155. /**
  1156. * Applies the effects from this skill to the target.
  1157. * @param effector the caster of the skill
  1158. * @param cubic the cubic that cast the skill, can be {@code null}
  1159. * @param effected the target of the effect
  1160. * @param self if {@code true} self-effects will be casted on the caster
  1161. * @param passive if {@code true} passive effects will be applied to the effector
  1162. * @param instant if {@code true} instant effects will be applied to the effected
  1163. * @param abnormalTime custom abnormal time, if equal or lesser than zero will be ignored
  1164. */
  1165. public void applyEffects(L2Character effector, L2CubicInstance cubic, L2Character effected, boolean self, boolean passive, boolean instant, int abnormalTime)
  1166. {
  1167. // null targets cannot receive any effects.
  1168. if (effected == null)
  1169. {
  1170. return;
  1171. }
  1172. // Check bad skills against target.
  1173. if ((effector != effected) && isBad() && (effected.isInvul() || (effector.isGM() && !effector.getAccessLevel().canGiveDamage())))
  1174. {
  1175. return;
  1176. }
  1177. if (effected.isInvulAgainst(getId(), getLevel()))
  1178. {
  1179. effected.sendDebugMessage("Skill " + toString() + " has been ignored (invul against)");
  1180. return;
  1181. }
  1182. final Env env = new Env();
  1183. env.setSkillMastery(Formulas.calcSkillMastery(effector, this));
  1184. env.setCharacter(effector);
  1185. env.setCubic(cubic);
  1186. env.setTarget(effected);
  1187. env.setSkill(this);
  1188. boolean addContinuousEffects = !passive && (_operateType.isToggle() || (_operateType.isContinuous() && Formulas.calcEffectSuccess(env)));
  1189. if (!self && !passive)
  1190. {
  1191. final BuffInfo info = new BuffInfo(env);
  1192. if (addContinuousEffects && (abnormalTime > 0))
  1193. {
  1194. info.setAbnormalTime(abnormalTime);
  1195. }
  1196. applyEffectScope(EffectScope.GENERAL, info, instant, addContinuousEffects);
  1197. EffectScope pvpOrPveEffectScope = effector.isPlayable() && effected.isAttackable() ? EffectScope.PVE : effector.isPlayable() && effected.isPlayable() ? EffectScope.PVP : null;
  1198. applyEffectScope(pvpOrPveEffectScope, info, instant, addContinuousEffects);
  1199. applyEffectScope(EffectScope.CHANNELING, info, instant, addContinuousEffects);
  1200. if (addContinuousEffects)
  1201. {
  1202. effected.getEffectList().add(info);
  1203. }
  1204. // Support for buff sharing feature.
  1205. if (addContinuousEffects && effected.isPlayer() && effected.hasServitor() && isContinuous() && !isDebuff())
  1206. {
  1207. applyEffects(effector, effected.getSummon(), false, 0);
  1208. }
  1209. }
  1210. if (self)
  1211. {
  1212. addContinuousEffects = !passive && (_operateType.isToggle() || ((_operateType.isContinuous() || _operateType.isSelfContinuous()) && Formulas.calcEffectSuccess(env)));
  1213. env.setTarget(effector);
  1214. final BuffInfo info = new BuffInfo(env);
  1215. if (addContinuousEffects && (abnormalTime > 0))
  1216. {
  1217. info.setAbnormalTime(abnormalTime);
  1218. }
  1219. applyEffectScope(EffectScope.SELF, info, instant, addContinuousEffects);
  1220. if (addContinuousEffects)
  1221. {
  1222. info.getEffector().getEffectList().add(info);
  1223. }
  1224. // Support for buff sharing feature.
  1225. // Avoiding Servitor Share since it's implementation already "shares" the effect.
  1226. if (addContinuousEffects && info.getEffected().isPlayer() && info.getEffected().hasServitor() && isContinuous() && !isDebuff() && (getId() != CommonSkill.SERVITOR_SHARE.getId()))
  1227. {
  1228. applyEffects(effector, info.getEffected().getSummon(), false, 0);
  1229. }
  1230. }
  1231. if (passive)
  1232. {
  1233. env.setTarget(effector);
  1234. final BuffInfo info = new BuffInfo(env);
  1235. applyEffectScope(EffectScope.PASSIVE, info, false, true);
  1236. effector.getEffectList().add(info);
  1237. }
  1238. }
  1239. /**
  1240. * Activates the skill to the targets.
  1241. * @param caster the caster
  1242. * @param targets the targets
  1243. */
  1244. public void activateSkill(L2Character caster, L2Object[] targets)
  1245. {
  1246. switch (getId())
  1247. {
  1248. // TODO: replace with AI
  1249. case 5852:
  1250. case 5853:
  1251. {
  1252. final L2BlockInstance block = targets[0] instanceof L2BlockInstance ? (L2BlockInstance) targets[0] : null;
  1253. final L2PcInstance player = caster.isPlayer() ? (L2PcInstance) caster : null;
  1254. if ((block == null) || (player == null))
  1255. {
  1256. return;
  1257. }
  1258. final int arena = player.getBlockCheckerArena();
  1259. if (arena != -1)
  1260. {
  1261. final ArenaParticipantsHolder holder = HandysBlockCheckerManager.getInstance().getHolder(arena);
  1262. if (holder == null)
  1263. {
  1264. return;
  1265. }
  1266. final int team = holder.getPlayerTeam(player);
  1267. final int color = block.getColorEffect();
  1268. if ((team == 0) && (color == 0x00))
  1269. {
  1270. block.changeColor(player, holder, team);
  1271. }
  1272. else if ((team == 1) && (color == 0x53))
  1273. {
  1274. block.changeColor(player, holder, team);
  1275. }
  1276. }
  1277. break;
  1278. }
  1279. default:
  1280. {
  1281. for (L2Character target : (L2Character[]) targets)
  1282. {
  1283. if (Formulas.calcBuffDebuffReflection(target, this))
  1284. {
  1285. // if skill is reflected instant effects should be casted on target
  1286. // and continuous effects on caster
  1287. applyEffects(target, caster, false, 0);
  1288. final Env env = new Env();
  1289. env.setCharacter(caster);
  1290. env.setTarget(target);
  1291. env.setSkill(this);
  1292. final BuffInfo info = new BuffInfo(env);
  1293. applyEffectScope(EffectScope.GENERAL, info, true, false);
  1294. EffectScope pvpOrPveEffectScope = caster.isPlayable() && target.isAttackable() ? EffectScope.PVE : caster.isPlayable() && target.isPlayable() ? EffectScope.PVP : null;
  1295. applyEffectScope(pvpOrPveEffectScope, info, true, false);
  1296. applyEffectScope(EffectScope.CHANNELING, info, true, false);
  1297. }
  1298. else
  1299. {
  1300. applyEffects(caster, target);
  1301. }
  1302. }
  1303. break;
  1304. }
  1305. }
  1306. // Self Effect
  1307. if (hasEffects(EffectScope.SELF))
  1308. {
  1309. if (caster.isAffectedBySkill(getId()))
  1310. {
  1311. caster.stopSkillEffects(true, getId());
  1312. }
  1313. applyEffects(caster, null, caster, true, false, true, 0);
  1314. }
  1315. if (useSpiritShot())
  1316. {
  1317. caster.setChargedShot(caster.isChargedShot(ShotType.BLESSED_SPIRITSHOTS) ? ShotType.BLESSED_SPIRITSHOTS : ShotType.SPIRITSHOTS, false);
  1318. }
  1319. else if (useSoulShot())
  1320. {
  1321. caster.setChargedShot(ShotType.SOULSHOTS, false);
  1322. }
  1323. }
  1324. public void attach(FuncTemplate f)
  1325. {
  1326. if (_funcTemplates == null)
  1327. {
  1328. _funcTemplates = new ArrayList<>(1);
  1329. }
  1330. _funcTemplates.add(f);
  1331. }
  1332. /**
  1333. * Adds an effect to the effect list for the give effect scope.
  1334. * @param effectScope the effect scope
  1335. * @param effect the effect to add
  1336. */
  1337. public void addEffect(EffectScope effectScope, AbstractEffect effect)
  1338. {
  1339. List<AbstractEffect> effects = _effectLists.get(effectScope);
  1340. if (effects == null)
  1341. {
  1342. effects = new ArrayList<>(1);
  1343. _effectLists.put(effectScope, effects);
  1344. }
  1345. effects.add(effect);
  1346. }
  1347. public void attach(Condition c, boolean itemOrWeapon)
  1348. {
  1349. if (itemOrWeapon)
  1350. {
  1351. if (_itemPreCondition == null)
  1352. {
  1353. _itemPreCondition = new ArrayList<>();
  1354. }
  1355. _itemPreCondition.add(c);
  1356. }
  1357. else
  1358. {
  1359. if (_preCondition == null)
  1360. {
  1361. _preCondition = new ArrayList<>();
  1362. }
  1363. _preCondition.add(c);
  1364. }
  1365. }
  1366. @Override
  1367. public String toString()
  1368. {
  1369. return "Skill " + _name + "(" + _id + "," + _level + ")";
  1370. }
  1371. /**
  1372. * @return pet food
  1373. */
  1374. public int getFeed()
  1375. {
  1376. return _feed;
  1377. }
  1378. /**
  1379. * used for tracking item id in case that item consume cannot be used
  1380. * @return reference item id
  1381. */
  1382. public int getReferenceItemId()
  1383. {
  1384. return _refId;
  1385. }
  1386. @Override
  1387. public boolean triggersChanceSkill()
  1388. {
  1389. return (_triggeredId > 0) && isChance();
  1390. }
  1391. @Override
  1392. public int getTriggeredChanceId()
  1393. {
  1394. return _triggeredId;
  1395. }
  1396. @Override
  1397. public int getTriggeredChanceLevel()
  1398. {
  1399. return _triggeredLevel;
  1400. }
  1401. @Override
  1402. public ChanceCondition getTriggeredChanceCondition()
  1403. {
  1404. return _chanceCondition;
  1405. }
  1406. public String getAttributeName()
  1407. {
  1408. return _attribute;
  1409. }
  1410. /**
  1411. * @return the _blowChance
  1412. */
  1413. public int getBlowChance()
  1414. {
  1415. return _blowChance;
  1416. }
  1417. public boolean ignoreShield()
  1418. {
  1419. return _ignoreShield;
  1420. }
  1421. public boolean canBeDispeled()
  1422. {
  1423. return _canBeDispeled;
  1424. }
  1425. /**
  1426. * Verify if the skill can be stolen.
  1427. * @return {@code true} if skill can be stolen, {@code false} otherwise
  1428. */
  1429. public boolean canBeStolen()
  1430. {
  1431. return !isPassive() && !isToggle() && !isDebuff() && !isHeroSkill() && !isGMSkill() && !(isStatic() && (getId() != CommonSkill.CARAVANS_SECRET_MEDICINE.getId())) && canBeDispeled() && (getId() != CommonSkill.SERVITOR_SHARE.getId());
  1432. }
  1433. public boolean isClanSkill()
  1434. {
  1435. return _isClanSkill;
  1436. }
  1437. public boolean isExcludedFromCheck()
  1438. {
  1439. return _excludedFromCheck;
  1440. }
  1441. public boolean isSimultaneousCast()
  1442. {
  1443. return _simultaneousCast;
  1444. }
  1445. /**
  1446. * Parse an extractable skill.
  1447. * @param skillId the skill Id
  1448. * @param skillLvl the skill level
  1449. * @param values the values to parse
  1450. * @return the parsed extractable skill
  1451. * @author Zoey76
  1452. */
  1453. private L2ExtractableSkill parseExtractableSkill(int skillId, int skillLvl, String values)
  1454. {
  1455. final String[] prodLists = values.split(";");
  1456. final List<L2ExtractableProductItem> products = new ArrayList<>();
  1457. String[] prodData;
  1458. for (String prodList : prodLists)
  1459. {
  1460. prodData = prodList.split(",");
  1461. if (prodData.length < 3)
  1462. {
  1463. _log.warning("Extractable skills data: Error in Skill Id: " + skillId + " Level: " + skillLvl + " -> wrong seperator!");
  1464. }
  1465. List<ItemHolder> items = null;
  1466. double chance = 0;
  1467. int prodId = 0;
  1468. int quantity = 0;
  1469. final int lenght = prodData.length - 1;
  1470. try
  1471. {
  1472. items = new ArrayList<>(lenght / 2);
  1473. for (int j = 0; j < lenght; j++)
  1474. {
  1475. prodId = Integer.parseInt(prodData[j]);
  1476. quantity = Integer.parseInt(prodData[j += 1]);
  1477. if ((prodId <= 0) || (quantity <= 0))
  1478. {
  1479. _log.warning("Extractable skills data: Error in Skill Id: " + skillId + " Level: " + skillLvl + " wrong production Id: " + prodId + " or wrond quantity: " + quantity + "!");
  1480. }
  1481. items.add(new ItemHolder(prodId, quantity));
  1482. }
  1483. chance = Double.parseDouble(prodData[lenght]);
  1484. }
  1485. catch (Exception e)
  1486. {
  1487. _log.warning("Extractable skills data: Error in Skill Id: " + skillId + " Level: " + skillLvl + " -> incomplete/invalid production data or wrong seperator!");
  1488. }
  1489. products.add(new L2ExtractableProductItem(items, chance));
  1490. }
  1491. if (products.isEmpty())
  1492. {
  1493. _log.warning("Extractable skills data: Error in Skill Id: " + skillId + " Level: " + skillLvl + " -> There are no production items!");
  1494. }
  1495. return new L2ExtractableSkill(SkillData.getSkillHashCode(skillId, skillLvl), products);
  1496. }
  1497. /**
  1498. * Parses all the abnormal visual effects.
  1499. * @param abnormalVisualEffects the abnormal visual effects list
  1500. */
  1501. private void parseAbnormalVisualEffect(String abnormalVisualEffects)
  1502. {
  1503. if (abnormalVisualEffects != null)
  1504. {
  1505. final String[] data = abnormalVisualEffects.split(";");
  1506. List<AbnormalVisualEffect> avesEvent = null;
  1507. List<AbnormalVisualEffect> avesSpecial = null;
  1508. List<AbnormalVisualEffect> aves = null;
  1509. for (String ave2 : data)
  1510. {
  1511. final AbnormalVisualEffect ave = AbnormalVisualEffect.valueOf(ave2);
  1512. if (ave != null)
  1513. {
  1514. if (ave.isEvent())
  1515. {
  1516. if (avesEvent == null)
  1517. {
  1518. avesEvent = new ArrayList<>(1);
  1519. }
  1520. avesEvent.add(ave);
  1521. continue;
  1522. }
  1523. if (ave.isSpecial())
  1524. {
  1525. if (avesSpecial == null)
  1526. {
  1527. avesSpecial = new ArrayList<>(1);
  1528. }
  1529. avesSpecial.add(ave);
  1530. continue;
  1531. }
  1532. if (aves == null)
  1533. {
  1534. aves = new ArrayList<>(1);
  1535. }
  1536. aves.add(ave);
  1537. }
  1538. }
  1539. if (avesEvent != null)
  1540. {
  1541. _abnormalVisualEffectsEvent = avesEvent.toArray(new AbnormalVisualEffect[avesEvent.size()]);
  1542. }
  1543. if (avesSpecial != null)
  1544. {
  1545. _abnormalVisualEffectsSpecial = avesSpecial.toArray(new AbnormalVisualEffect[avesSpecial.size()]);
  1546. }
  1547. if (aves != null)
  1548. {
  1549. _abnormalVisualEffects = aves.toArray(new AbnormalVisualEffect[aves.size()]);
  1550. }
  1551. }
  1552. }
  1553. public L2ExtractableSkill getExtractableSkill()
  1554. {
  1555. return _extractableItems;
  1556. }
  1557. /**
  1558. * @param effectType Effect type to check if its present on this skill effects.
  1559. * @param effectTypes Effect types to check if are present on this skill effects.
  1560. * @return {@code true} if at least one of specified {@link L2EffectType} types is present on this skill effects, {@code false} otherwise.
  1561. */
  1562. public boolean hasEffectType(L2EffectType effectType, L2EffectType... effectTypes)
  1563. {
  1564. if (_effectTypes == null)
  1565. {
  1566. synchronized (this)
  1567. {
  1568. if (_effectTypes == null)
  1569. {
  1570. Set<Byte> effectTypesSet = new HashSet<>();
  1571. for (List<AbstractEffect> effectList : _effectLists.values())
  1572. {
  1573. if (effectList != null)
  1574. {
  1575. for (AbstractEffect effect : effectList)
  1576. {
  1577. if (effect == null)
  1578. {
  1579. continue;
  1580. }
  1581. effectTypesSet.add((byte) effect.getEffectType().ordinal());
  1582. }
  1583. }
  1584. }
  1585. Byte[] effectTypesArray = effectTypesSet.toArray(new Byte[effectTypesSet.size()]);
  1586. Arrays.sort(effectTypesArray);
  1587. _effectTypes = effectTypesArray;
  1588. }
  1589. }
  1590. }
  1591. if (Arrays.binarySearch(_effectTypes, (byte) effectType.ordinal()) >= 0)
  1592. {
  1593. return true;
  1594. }
  1595. for (L2EffectType type : effectTypes)
  1596. {
  1597. if (Arrays.binarySearch(_effectTypes, (byte) type.ordinal()) >= 0)
  1598. {
  1599. return true;
  1600. }
  1601. }
  1602. return false;
  1603. }
  1604. /**
  1605. * @return icon of the current skill.
  1606. */
  1607. public String getIcon()
  1608. {
  1609. return _icon;
  1610. }
  1611. public int getChannelingTickInterval()
  1612. {
  1613. return _channelingTickInterval;
  1614. }
  1615. public int getChannelingTickInitialDelay()
  1616. {
  1617. return _channelingTickInitialDelay;
  1618. }
  1619. }