L2Skill.java 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892
  1. /*
  2. * Copyright (C) 2004-2013 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.SkillTable;
  33. import com.l2jserver.gameserver.datatables.SkillTreesData;
  34. import com.l2jserver.gameserver.handler.ITargetTypeHandler;
  35. import com.l2jserver.gameserver.handler.TargetHandler;
  36. import com.l2jserver.gameserver.model.ChanceCondition;
  37. import com.l2jserver.gameserver.model.L2ExtractableProductItem;
  38. import com.l2jserver.gameserver.model.L2ExtractableSkill;
  39. import com.l2jserver.gameserver.model.L2Object;
  40. import com.l2jserver.gameserver.model.PcCondOverride;
  41. import com.l2jserver.gameserver.model.StatsSet;
  42. import com.l2jserver.gameserver.model.actor.L2Attackable;
  43. import com.l2jserver.gameserver.model.actor.L2Character;
  44. import com.l2jserver.gameserver.model.actor.L2Playable;
  45. import com.l2jserver.gameserver.model.actor.L2Summon;
  46. import com.l2jserver.gameserver.model.actor.instance.L2CubicInstance;
  47. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  48. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  49. import com.l2jserver.gameserver.model.actor.instance.L2SiegeFlagInstance;
  50. import com.l2jserver.gameserver.model.conditions.Condition;
  51. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  52. import com.l2jserver.gameserver.model.effects.L2Effect;
  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.IChanceSkillTrigger;
  57. import com.l2jserver.gameserver.model.skills.funcs.Func;
  58. import com.l2jserver.gameserver.model.skills.funcs.FuncTemplate;
  59. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  60. import com.l2jserver.gameserver.model.stats.BaseStats;
  61. import com.l2jserver.gameserver.model.stats.Env;
  62. import com.l2jserver.gameserver.model.stats.Formulas;
  63. import com.l2jserver.gameserver.model.zone.ZoneId;
  64. import com.l2jserver.gameserver.network.SystemMessageId;
  65. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  66. import com.l2jserver.gameserver.util.Util;
  67. import com.l2jserver.util.Rnd;
  68. public abstract class L2Skill implements IChanceSkillTrigger
  69. {
  70. protected static final Logger _log = Logger.getLogger(L2Skill.class.getName());
  71. private static final L2Object[] EMPTY_TARGET_LIST = new L2Object[0];
  72. private static final L2Effect[] EMPTY_EFFECT_SET = new L2Effect[0];
  73. public static final int SKILL_CREATE_DWARVEN = 172;
  74. public static final int SKILL_EXPERTISE = 239;
  75. public static final int SKILL_CRYSTALLIZE = 248;
  76. public static final int SKILL_CLAN_LUCK = 390;
  77. public static final int SKILL_ONYX_BEAST_TRANSFORMATION = 617;
  78. public static final int SKILL_CREATE_COMMON = 1320;
  79. public static final int SKILL_DIVINE_INSPIRATION = 1405;
  80. public static final int SKILL_NPC_RACE = 4416;
  81. public static final boolean geoEnabled = Config.GEODATA > 0;
  82. // conditional values
  83. public static final int COND_RUNNING = 0x0001;
  84. public static final int COND_WALKING = 0x0002;
  85. public static final int COND_SIT = 0x0004;
  86. public static final int COND_BEHIND = 0x0008;
  87. public static final int COND_CRIT = 0x0010;
  88. public static final int COND_LOWHP = 0x0020;
  89. public static final int COND_ROBES = 0x0040;
  90. public static final int COND_CHARGES = 0x0080;
  91. public static final int COND_SHIELD = 0x0100;
  92. /** Skill Id. */
  93. private final int _id;
  94. /** Skill level. */
  95. private final int _level;
  96. /** Custom skill Id displayed by the client. */
  97. private final int _displayId;
  98. /** Custom skill level displayed by the client. */
  99. private final int _displayLevel;
  100. /** Skill client's name. */
  101. private final String _name;
  102. /** Operative type: passive, active, toggle. */
  103. private final L2SkillOpType _operateType;
  104. private final int _magic;
  105. private final L2TraitType _traitType;
  106. private final boolean _staticReuse;
  107. private final boolean _staticDamage; // Damage dealing skills do static damage based on the power value.
  108. /** MP consumption. */
  109. private final int _mpConsume;
  110. /** Initial MP consumption. */
  111. private final int _mpInitialConsume;
  112. /** HP consumption. */
  113. private final int _hpConsume;
  114. /** CP consumption. */
  115. private final int _cpConsume;
  116. /** Amount of items consumed by this skill from target. */
  117. private final int _targetConsumeCount;
  118. /** Id of item consumed by this skill from target. */
  119. private final int _targetConsumeId;
  120. /** Amount of items consumed by this skill from caster. */
  121. private final int _itemConsumeCount;
  122. /** Id of item consumed by this skill from caster. */
  123. private final int _itemConsumeId;
  124. /** Cast range: how far can be the target. */
  125. private final int _castRange;
  126. /** Effect range: how far the skill affect the target. */
  127. private final int _effectRange;
  128. /** Abnormal level, global effect level. */
  129. private final int _abnormalLvl;
  130. /** Abnormal type: global effect "group". */
  131. private final AbnormalType _abnormalType;
  132. /** Abnormal time: global effect duration time. */
  133. private final int _abnormalTime;
  134. /** Abnormal type map for types that this skills might remove. */
  135. private final Map<AbnormalType, Byte> _negateAbnormals;
  136. /** Abnormal type set for abnormal types that this effect skill blocks. */
  137. private final Set<AbnormalType> _blockBuffSlots;
  138. /** Maximum amount of effects removed. */
  139. private final int _maxNegatedEffects;
  140. /** If {@code true} this skill's effect should stay after death. */
  141. private final boolean _stayAfterDeath;
  142. /** If {@code true} this skill's effect should stay after class-subclass change. */
  143. private final boolean _stayOnSubclassChange;
  144. /** If {@code true} this skill might kill by damage over time. */
  145. private final boolean _killByDOT;
  146. private final int _refId;
  147. // all times in milliseconds
  148. private final int _hitTime;
  149. private final int[] _hitTimings;
  150. // private final int _skillInterruptTime;
  151. private final int _coolTime;
  152. private final int _reuseHashCode;
  153. private final int _reuseDelay;
  154. /** Target type of the skill : SELF, PARTY, CLAN, PET... */
  155. private final L2TargetType _targetType;
  156. private final int _feed;
  157. // base success chance
  158. private final double _power;
  159. private final double _pvpPower;
  160. private final double _pvePower;
  161. private final int _magicLevel;
  162. private final int _lvlBonusRate;
  163. private final int _minChance;
  164. private final int _maxChance;
  165. private final int _blowChance;
  166. // Effecting area of the skill, in radius.
  167. // The radius center varies according to the _targetType:
  168. // "caster" if targetType = AURA/PARTY/CLAN or "target" if targetType = AREA
  169. private final int _affectRange;
  170. private final int[] _affectLimit = new int[2];
  171. private final L2SkillType _skillType;
  172. private final int _effectId;
  173. private final int _effectLvl; // normal effect level
  174. private final boolean _nextActionIsAttack;
  175. private final boolean _removedOnAnyActionExceptMove;
  176. private final boolean _removedOnDamage;
  177. private final byte _element;
  178. private final int _elementPower;
  179. private final BaseStats _saveVs;
  180. private final int _condition;
  181. private final int _conditionValue;
  182. private final boolean _overhit;
  183. private final int _minPledgeClass;
  184. private final boolean _isOffensive;
  185. private final boolean _isPVP;
  186. private final int _chargeConsume;
  187. private final int _triggeredId;
  188. private final int _triggeredLevel;
  189. private final String _chanceType;
  190. private final int _soulMaxConsume;
  191. private final int _numSouls;
  192. private final int _expNeeded;
  193. private final int _critChance;
  194. private final boolean _dependOnTargetBuff;
  195. private final int _afterEffectId;
  196. private final int _afterEffectLvl;
  197. private final boolean _isHeroSkill; // If true the skill is a Hero Skill
  198. private final boolean _isGMSkill; // True if skill is GM skill
  199. private final boolean _isSevenSigns;
  200. private final int _baseCritRate; // percent of success for skill critical hit (especially for PDAM & BLOW - they're not affected by rCrit values or buffs). Default loads -1 for all other skills but 0 to PDAM & BLOW
  201. private final int _halfKillRate;
  202. private final int _lethalStrikeRate;
  203. private final boolean _directHpDmg; // If true then damage is being make directly
  204. private final boolean _isTriggeredSkill; // If true the skill will take activation buff slot instead of a normal buff slot
  205. private final float _sSBoost; // If true skill will have SoulShot boost (power*2)
  206. private final int _aggroPoints;
  207. // Condition lists
  208. private List<Condition> _preCondition;
  209. private List<Condition> _itemPreCondition;
  210. // Function lists
  211. private List<FuncTemplate> _funcTemplates;
  212. // Effect lists
  213. private List<EffectTemplate> _effectTemplates;
  214. private List<EffectTemplate> _effectTemplatesSelf;
  215. private List<EffectTemplate> _effectTemplatesPassive;
  216. protected ChanceCondition _chanceCondition = null;
  217. // Flying support
  218. private final String _flyType;
  219. private final int _flyRadius;
  220. private final float _flyCourse;
  221. private final boolean _isDebuff;
  222. private final String _attribute;
  223. private final boolean _ignoreShield;
  224. private final boolean _isSuicideAttack;
  225. private final boolean _canBeReflected;
  226. private final boolean _canBeDispeled;
  227. private final boolean _isClanSkill;
  228. private final boolean _excludedFromCheck;
  229. private final boolean _simultaneousCast;
  230. private L2ExtractableSkill _extractableItems = null;
  231. private int _npcId = 0;
  232. private byte[] _effectTypes;
  233. protected L2Skill(StatsSet set)
  234. {
  235. _id = set.getInteger("skill_id");
  236. _level = set.getInteger("level");
  237. _refId = set.getInteger("referenceId", 0);
  238. _displayId = set.getInteger("displayId", _id);
  239. _displayLevel = set.getInteger("displayLevel", _level);
  240. _name = set.getString("name", "");
  241. _operateType = set.getEnum("operateType", L2SkillOpType.class);
  242. _magic = set.getInteger("isMagic", 0);
  243. _traitType = set.getEnum("trait", L2TraitType.class, L2TraitType.NONE);
  244. _staticReuse = set.getBool("staticReuse", false);
  245. _staticDamage = set.getBool("staticDamage", false);
  246. _mpConsume = set.getInteger("mpConsume", 0);
  247. _mpInitialConsume = set.getInteger("mpInitialConsume", 0);
  248. _hpConsume = set.getInteger("hpConsume", 0);
  249. _cpConsume = set.getInteger("cpConsume", 0);
  250. _targetConsumeCount = set.getInteger("targetConsumeCount", 0);
  251. _targetConsumeId = set.getInteger("targetConsumeId", 0);
  252. _itemConsumeCount = set.getInteger("itemConsumeCount", 0);
  253. _itemConsumeId = set.getInteger("itemConsumeId", 0);
  254. _afterEffectId = set.getInteger("afterEffectId", 0);
  255. _afterEffectLvl = set.getInteger("afterEffectLvl", 1);
  256. _castRange = set.getInteger("castRange", -1);
  257. _effectRange = set.getInteger("effectRange", -1);
  258. _abnormalLvl = set.getInteger("abnormalLvl", 0);
  259. _abnormalType = set.getEnum("abnormalType", AbnormalType.class, AbnormalType.NONE);
  260. int abnormalTime = set.getInteger("abnormalTime", 1); // TODO: Should be 0, but instant effects need it until implementation is done.
  261. if (Config.ENABLE_MODIFY_SKILL_DURATION && Config.SKILL_DURATION_LIST.containsKey(getId()))
  262. {
  263. if ((getLevel() < 100) || (getLevel() > 140))
  264. {
  265. abnormalTime = Config.SKILL_DURATION_LIST.get(getId());
  266. }
  267. else if ((getLevel() >= 100) && (getLevel() < 140))
  268. {
  269. abnormalTime += Config.SKILL_DURATION_LIST.get(getId());
  270. }
  271. }
  272. _abnormalTime = abnormalTime;
  273. _attribute = set.getString("attribute", "");
  274. String negateAbnormals = set.getString("negateAbnormals", null);
  275. if ((negateAbnormals != null) && !negateAbnormals.isEmpty())
  276. {
  277. _negateAbnormals = new EnumMap<>(AbnormalType.class);
  278. for (String ngtStack : negateAbnormals.split(";"))
  279. {
  280. String[] ngt = ngtStack.split(",");
  281. final AbnormalType type = AbnormalType.getAbnormalType(ngt[0]);
  282. if (ngt.length == 1) // Only abnormalType is present, without abnormalLvl
  283. {
  284. _negateAbnormals.put(type, Byte.MAX_VALUE);
  285. }
  286. else if (ngt.length == 2) // Both abnormalType and abnormalLvl are present
  287. {
  288. try
  289. {
  290. _negateAbnormals.put(type, Byte.parseByte(ngt[1]));
  291. }
  292. catch (Exception e)
  293. {
  294. throw new IllegalArgumentException("SkillId: " + _id + " Byte value required, but found: " + ngt[1]);
  295. }
  296. }
  297. else
  298. {
  299. throw new IllegalArgumentException("SkillId: " + _id + ": Incorrect negate Abnormals for " + ngtStack + ". Lvl: abnormalType1,abnormalLvl1;abnormalType2,abnormalLvl2;abnormalType3,abnormalLvl3... or abnormalType1;abnormalType2;abnormalType3...");
  300. }
  301. }
  302. }
  303. else
  304. {
  305. _negateAbnormals = Collections.<AbnormalType, Byte> emptyMap();
  306. }
  307. String blockBuffSlots = set.getString("blockBuffSlot", null);
  308. if ((blockBuffSlots != null) && !blockBuffSlots.isEmpty())
  309. {
  310. _blockBuffSlots = new HashSet<>();
  311. for (String slot : blockBuffSlots.split(";"))
  312. {
  313. _blockBuffSlots.add(AbnormalType.getAbnormalType(slot));
  314. }
  315. }
  316. else
  317. {
  318. _blockBuffSlots = Collections.<AbnormalType> emptySet();
  319. }
  320. _maxNegatedEffects = set.getInteger("maxNegated", 0);
  321. _stayAfterDeath = set.getBool("stayAfterDeath", false);
  322. _stayOnSubclassChange = set.getBool("stayOnSubclassChange", true);
  323. _killByDOT = set.getBool("killByDOT", false);
  324. _hitTime = set.getInteger("hitTime", 0);
  325. String hitTimings = set.getString("hitTimings", null);
  326. if (hitTimings != null)
  327. {
  328. try
  329. {
  330. String[] valuesSplit = hitTimings.split(",");
  331. _hitTimings = new int[valuesSplit.length];
  332. for (int i = 0; i < valuesSplit.length; i++)
  333. {
  334. _hitTimings[i] = Integer.parseInt(valuesSplit[i]);
  335. }
  336. }
  337. catch (Exception e)
  338. {
  339. throw new IllegalArgumentException("SkillId: " + _id + " invalid hitTimings value: " + hitTimings + ", \"percent,percent,...percent\" required");
  340. }
  341. }
  342. else
  343. {
  344. _hitTimings = new int[0];
  345. }
  346. _coolTime = set.getInteger("coolTime", 0);
  347. _isDebuff = set.getBool("isDebuff", false);
  348. _feed = set.getInteger("feed", 0);
  349. _reuseHashCode = SkillTable.getSkillHashCode(_id, _level);
  350. if (Config.ENABLE_MODIFY_SKILL_REUSE && Config.SKILL_REUSE_LIST.containsKey(_id))
  351. {
  352. if (Config.DEBUG)
  353. {
  354. _log.info("*** Skill " + _name + " (" + _level + ") changed reuse from " + set.getInteger("reuseDelay", 0) + " to " + Config.SKILL_REUSE_LIST.get(_id) + " seconds.");
  355. }
  356. _reuseDelay = Config.SKILL_REUSE_LIST.get(_id);
  357. }
  358. else
  359. {
  360. _reuseDelay = set.getInteger("reuseDelay", 0);
  361. }
  362. _affectRange = set.getInteger("affectRange", 0);
  363. final String affectLimit = set.getString("affectLimit", null);
  364. if (affectLimit != null)
  365. {
  366. try
  367. {
  368. String[] valuesSplit = affectLimit.split("-");
  369. _affectLimit[0] = Integer.parseInt(valuesSplit[0]);
  370. _affectLimit[1] = Integer.parseInt(valuesSplit[1]);
  371. }
  372. catch (Exception e)
  373. {
  374. throw new IllegalArgumentException("SkillId: " + _id + " invalid affectLimit value: " + affectLimit + ", \"percent-percent\" required");
  375. }
  376. }
  377. _targetType = set.getEnum("targetType", L2TargetType.class);
  378. _power = set.getFloat("power", 0.f);
  379. _pvpPower = set.getFloat("pvpPower", (float) getPower());
  380. _pvePower = set.getFloat("pvePower", (float) getPower());
  381. _magicLevel = set.getInteger("magicLvl", 0);
  382. _lvlBonusRate = set.getInteger("lvlBonusRate", 0);
  383. _minChance = set.getInteger("minChance", Config.MIN_ABNORMAL_STATE_SUCCESS_RATE);
  384. _maxChance = set.getInteger("maxChance", Config.MAX_ABNORMAL_STATE_SUCCESS_RATE);
  385. _ignoreShield = set.getBool("ignoreShld", false);
  386. _skillType = set.getEnum("skillType", L2SkillType.class, L2SkillType.DUMMY);
  387. _effectId = set.getInteger("effectId", 0);
  388. _effectLvl = set.getInteger("effectLevel", 0);
  389. _nextActionIsAttack = set.getBool("nextActionAttack", false);
  390. _removedOnAnyActionExceptMove = set.getBool("removedOnAnyActionExceptMove", false);
  391. _removedOnDamage = set.getBool("removedOnDamage", _skillType == L2SkillType.SLEEP);
  392. _element = set.getByte("element", (byte) -1);
  393. _elementPower = set.getInteger("elementPower", 0);
  394. _saveVs = set.getEnum("saveVs", BaseStats.class, BaseStats.NULL);
  395. _condition = set.getInteger("condition", 0);
  396. _conditionValue = set.getInteger("conditionValue", 0);
  397. _overhit = set.getBool("overHit", false);
  398. _isSuicideAttack = set.getBool("isSuicideAttack", false);
  399. _minPledgeClass = set.getInteger("minPledgeClass", 0);
  400. _isOffensive = set.getBool("offensive", false);
  401. _isPVP = set.getBool("pvp", false);
  402. _chargeConsume = set.getInteger("chargeConsume", 0);
  403. _triggeredId = set.getInteger("triggeredId", 0);
  404. _triggeredLevel = set.getInteger("triggeredLevel", 1);
  405. _chanceType = set.getString("chanceType", "");
  406. if (!_chanceType.isEmpty())
  407. {
  408. _chanceCondition = ChanceCondition.parse(set);
  409. }
  410. _numSouls = set.getInteger("num_souls", 0);
  411. _soulMaxConsume = set.getInteger("soulMaxConsumeCount", 0);
  412. _blowChance = set.getInteger("blowChance", 0);
  413. _expNeeded = set.getInteger("expNeeded", 0);
  414. _critChance = set.getInteger("critChance", 0);
  415. _isHeroSkill = SkillTreesData.getInstance().isHeroSkill(_id, _level);
  416. _isGMSkill = SkillTreesData.getInstance().isGMSkill(_id, _level);
  417. _isSevenSigns = (_id > 4360) && (_id < 4367);
  418. _isClanSkill = SkillTreesData.getInstance().isClanSkill(_id, _level);
  419. _baseCritRate = set.getInteger("baseCritRate", ((_skillType == L2SkillType.PDAM) || (_skillType == L2SkillType.BLOW)) ? 0 : -1);
  420. _halfKillRate = set.getInteger("halfKillRate", 0);
  421. _lethalStrikeRate = set.getInteger("lethalStrikeRate", 0);
  422. _directHpDmg = set.getBool("dmgDirectlyToHp", false);
  423. _isTriggeredSkill = set.getBool("isTriggeredSkill", false);
  424. _sSBoost = set.getFloat("SSBoost", 0.f);
  425. _aggroPoints = set.getInteger("aggroPoints", 0);
  426. _flyType = set.getString("flyType", null);
  427. _flyRadius = set.getInteger("flyRadius", 0);
  428. _flyCourse = set.getFloat("flyCourse", 0);
  429. _canBeReflected = set.getBool("canBeReflected", true);
  430. _canBeDispeled = set.getBool("canBeDispeled", true);
  431. _excludedFromCheck = set.getBool("excludedFromCheck", false);
  432. _dependOnTargetBuff = set.getBool("dependOnTargetBuff", false);
  433. _simultaneousCast = set.getBool("simultaneousCast", false);
  434. String capsuled_items = set.getString("capsuled_items_skill", null);
  435. if (capsuled_items != null)
  436. {
  437. if (capsuled_items.isEmpty())
  438. {
  439. _log.warning("Empty Extractable Item Skill data in Skill Id: " + _id);
  440. }
  441. _extractableItems = parseExtractableSkill(_id, _level, capsuled_items);
  442. }
  443. _npcId = set.getInteger("npcId", 0);
  444. }
  445. public abstract void useSkill(L2Character caster, L2Object[] targets);
  446. public final int getConditionValue()
  447. {
  448. return _conditionValue;
  449. }
  450. public final L2SkillType getSkillType()
  451. {
  452. return _skillType;
  453. }
  454. public final L2TraitType getTraitType()
  455. {
  456. return _traitType;
  457. }
  458. public final byte getElement()
  459. {
  460. return _element;
  461. }
  462. public final int getElementPower()
  463. {
  464. return _elementPower;
  465. }
  466. /**
  467. * Return the target type of the skill : SELF, PARTY, CLAN, PET...
  468. * @return
  469. */
  470. public final L2TargetType getTargetType()
  471. {
  472. return _targetType;
  473. }
  474. public final int getCondition()
  475. {
  476. return _condition;
  477. }
  478. public final boolean isOverhit()
  479. {
  480. return _overhit;
  481. }
  482. public final boolean killByDOT()
  483. {
  484. return _killByDOT;
  485. }
  486. public final boolean isSuicideAttack()
  487. {
  488. return _isSuicideAttack;
  489. }
  490. public final boolean allowOnTransform()
  491. {
  492. return isPassive();
  493. }
  494. /**
  495. * Return the power of the skill.
  496. * @param activeChar
  497. * @param target
  498. * @param isPvP
  499. * @param isPvE
  500. * @return
  501. */
  502. public final double getPower(L2Character activeChar, L2Character target, boolean isPvP, boolean isPvE)
  503. {
  504. if (activeChar == null)
  505. {
  506. return getPower(isPvP, isPvE);
  507. }
  508. switch (_skillType)
  509. {
  510. case DEATHLINK:
  511. {
  512. return getPower(isPvP, isPvE) * (-((activeChar.getCurrentHp() * 2) / activeChar.getMaxHp()) + 2);
  513. }
  514. case FATAL:
  515. {
  516. return getPower(isPvP, isPvE) * (-((target.getCurrentHp() * 2) / target.getMaxHp()) + 2);
  517. }
  518. default:
  519. {
  520. return getPower(isPvP, isPvE);
  521. }
  522. }
  523. }
  524. public final double getPower()
  525. {
  526. return _power;
  527. }
  528. public final double getPower(boolean isPvP, boolean isPvE)
  529. {
  530. return isPvE ? _pvePower : isPvP ? _pvpPower : _power;
  531. }
  532. public final Map<AbnormalType, Byte> getNegateAbnormals()
  533. {
  534. return _negateAbnormals;
  535. }
  536. public final Set<AbnormalType> getBlockBuffSlots()
  537. {
  538. return _blockBuffSlots;
  539. }
  540. public final int getAbnormalLvl()
  541. {
  542. return _abnormalLvl;
  543. }
  544. public final AbnormalType getAbnormalType()
  545. {
  546. return _abnormalType;
  547. }
  548. public final int getAbnormalTime()
  549. {
  550. return _abnormalTime;
  551. }
  552. public final int getMagicLevel()
  553. {
  554. return _magicLevel;
  555. }
  556. public final int getMaxNegatedEffects()
  557. {
  558. return _maxNegatedEffects;
  559. }
  560. public final int getLvlBonusRate()
  561. {
  562. return _lvlBonusRate;
  563. }
  564. /**
  565. * Return custom minimum skill/effect chance.
  566. * @return
  567. */
  568. public final int getMinChance()
  569. {
  570. return _minChance;
  571. }
  572. /**
  573. * Return custom maximum skill/effect chance.
  574. * @return
  575. */
  576. public final int getMaxChance()
  577. {
  578. return _maxChance;
  579. }
  580. /**
  581. * Return true if skill effects should be removed on any action except movement
  582. * @return
  583. */
  584. public final boolean isRemovedOnAnyActionExceptMove()
  585. {
  586. return _removedOnAnyActionExceptMove;
  587. }
  588. /**
  589. * @return {@code true} if skill effects should be removed on damage
  590. */
  591. public final boolean isRemovedOnDamage()
  592. {
  593. return _removedOnDamage;
  594. }
  595. /**
  596. * Return the additional effect Id.
  597. * @return
  598. */
  599. public final int getEffectId()
  600. {
  601. return _effectId;
  602. }
  603. /**
  604. * Return the additional effect level.
  605. * @return
  606. */
  607. public final int getEffectLvl()
  608. {
  609. return _effectLvl;
  610. }
  611. /**
  612. * Return true if character should attack target after skill
  613. * @return
  614. */
  615. public final boolean nextActionIsAttack()
  616. {
  617. return _nextActionIsAttack;
  618. }
  619. /**
  620. * @return Returns the castRange.
  621. */
  622. public final int getCastRange()
  623. {
  624. return _castRange;
  625. }
  626. /**
  627. * @return Returns the cpConsume;
  628. */
  629. public final int getCpConsume()
  630. {
  631. return _cpConsume;
  632. }
  633. /**
  634. * @return Returns the effectRange.
  635. */
  636. public final int getEffectRange()
  637. {
  638. return _effectRange;
  639. }
  640. /**
  641. * @return Returns the hpConsume.
  642. */
  643. public final int getHpConsume()
  644. {
  645. return _hpConsume;
  646. }
  647. /**
  648. * @return Returns the id.
  649. */
  650. public final int getId()
  651. {
  652. return _id;
  653. }
  654. /**
  655. * @return Returns the boolean _isDebuff.
  656. */
  657. public final boolean isDebuff()
  658. {
  659. return _isDebuff;
  660. }
  661. public int getDisplayId()
  662. {
  663. return _displayId;
  664. }
  665. public int getDisplayLevel()
  666. {
  667. return _displayLevel;
  668. }
  669. public int getTriggeredId()
  670. {
  671. return _triggeredId;
  672. }
  673. public int getTriggeredLevel()
  674. {
  675. return _triggeredLevel;
  676. }
  677. public boolean triggerAnotherSkill()
  678. {
  679. return _triggeredId > 1;
  680. }
  681. /**
  682. * Return skill saveVs base stat (STR, INT ...).
  683. * @return
  684. */
  685. public final BaseStats getSaveVs()
  686. {
  687. return _saveVs;
  688. }
  689. /**
  690. * @return Returns the _targetConsumeId.
  691. */
  692. public final int getTargetConsumeId()
  693. {
  694. return _targetConsumeId;
  695. }
  696. /**
  697. * @return Returns the targetConsume.
  698. */
  699. public final int getTargetConsume()
  700. {
  701. return _targetConsumeCount;
  702. }
  703. /**
  704. * @return Returns the itemConsume.
  705. */
  706. public final int getItemConsume()
  707. {
  708. return _itemConsumeCount;
  709. }
  710. /**
  711. * @return Returns the itemConsumeId.
  712. */
  713. public final int getItemConsumeId()
  714. {
  715. return _itemConsumeId;
  716. }
  717. /**
  718. * @return Returns the level.
  719. */
  720. public final int getLevel()
  721. {
  722. return _level;
  723. }
  724. /**
  725. * @return Returns true to set physical skills.
  726. */
  727. public final boolean isPhysical()
  728. {
  729. return _magic == 0;
  730. }
  731. /**
  732. * @return Returns true to set magic skills.
  733. */
  734. public final boolean isMagic()
  735. {
  736. return _magic == 1;
  737. }
  738. /**
  739. * @return Returns true to set static skills.
  740. */
  741. public final boolean isStatic()
  742. {
  743. return _magic == 2;
  744. }
  745. public final boolean isDance()
  746. {
  747. return _magic == 3;
  748. }
  749. /**
  750. * @return Returns true to set static reuse.
  751. */
  752. public final boolean isStaticReuse()
  753. {
  754. return _staticReuse;
  755. }
  756. public final boolean isStaticDamage()
  757. {
  758. return _staticDamage;
  759. }
  760. /**
  761. * @return Returns the mpConsume.
  762. */
  763. public final int getMpConsume()
  764. {
  765. return _mpConsume;
  766. }
  767. /**
  768. * @return Returns the mpInitialConsume.
  769. */
  770. public final int getMpInitialConsume()
  771. {
  772. return _mpInitialConsume;
  773. }
  774. /**
  775. * @return the skill name
  776. */
  777. public final String getName()
  778. {
  779. return _name;
  780. }
  781. /**
  782. * @return the reuse delay
  783. */
  784. public final int getReuseDelay()
  785. {
  786. return _reuseDelay;
  787. }
  788. public final int getReuseHashCode()
  789. {
  790. return _reuseHashCode;
  791. }
  792. public final int getHitTime()
  793. {
  794. return _hitTime;
  795. }
  796. public final int getHitCounts()
  797. {
  798. return _hitTimings.length;
  799. }
  800. public final int[] getHitTimings()
  801. {
  802. return _hitTimings;
  803. }
  804. /**
  805. * @return the cool time
  806. */
  807. public final int getCoolTime()
  808. {
  809. return _coolTime;
  810. }
  811. public final int getAffectRange()
  812. {
  813. return _affectRange;
  814. }
  815. public final int getAffectLimit()
  816. {
  817. return (_affectLimit[0] + Rnd.get(_affectLimit[1]));
  818. }
  819. public final boolean isActive()
  820. {
  821. return (_operateType != null) && _operateType.isActive();
  822. }
  823. public final boolean isPassive()
  824. {
  825. return (_operateType != null) && _operateType.isPassive();
  826. }
  827. public final boolean isToggle()
  828. {
  829. return (_operateType != null) && _operateType.isToggle();
  830. }
  831. public final boolean isChance()
  832. {
  833. return (_chanceCondition != null) && isPassive();
  834. }
  835. public final boolean isTriggeredSkill()
  836. {
  837. return _isTriggeredSkill;
  838. }
  839. public final float getSSBoost()
  840. {
  841. return _sSBoost;
  842. }
  843. public final int getAggroPoints()
  844. {
  845. return _aggroPoints;
  846. }
  847. public final boolean useSoulShot()
  848. {
  849. switch (getSkillType())
  850. {
  851. case PDAM:
  852. case CHARGEDAM:
  853. case BLOW:
  854. return true;
  855. default:
  856. return false;
  857. }
  858. }
  859. public final boolean useSpiritShot()
  860. {
  861. return _magic == 1;
  862. }
  863. public final boolean useFishShot()
  864. {
  865. return ((getSkillType() == L2SkillType.PUMPING) || (getSkillType() == L2SkillType.REELING));
  866. }
  867. public int getMinPledgeClass()
  868. {
  869. return _minPledgeClass;
  870. }
  871. public final boolean isOffensive()
  872. {
  873. return _isOffensive || isPVP();
  874. }
  875. public final boolean isPVP()
  876. {
  877. return _isPVP;
  878. }
  879. public final boolean isHeroSkill()
  880. {
  881. return _isHeroSkill;
  882. }
  883. public final boolean isGMSkill()
  884. {
  885. return _isGMSkill;
  886. }
  887. public final boolean is7Signs()
  888. {
  889. return _isSevenSigns;
  890. }
  891. public final int getChargeConsume()
  892. {
  893. return _chargeConsume;
  894. }
  895. public final int getNumSouls()
  896. {
  897. return _numSouls;
  898. }
  899. public final int getMaxSoulConsumeCount()
  900. {
  901. return _soulMaxConsume;
  902. }
  903. public final int getExpNeeded()
  904. {
  905. return _expNeeded;
  906. }
  907. public final int getCritChance()
  908. {
  909. return _critChance;
  910. }
  911. public final int getBaseCritRate()
  912. {
  913. return _baseCritRate;
  914. }
  915. public final int getHalfKillRate()
  916. {
  917. return _halfKillRate;
  918. }
  919. public final int getLethalStrikeRate()
  920. {
  921. return _lethalStrikeRate;
  922. }
  923. public final boolean getDmgDirectlyToHP()
  924. {
  925. return _directHpDmg;
  926. }
  927. public final String getFlyType()
  928. {
  929. return _flyType;
  930. }
  931. public final int getFlyRadius()
  932. {
  933. return _flyRadius;
  934. }
  935. public final float getFlyCourse()
  936. {
  937. return _flyCourse;
  938. }
  939. public final boolean isStayAfterDeath()
  940. {
  941. return _stayAfterDeath;
  942. }
  943. public final boolean isStayOnSubclassChange()
  944. {
  945. return _stayOnSubclassChange;
  946. }
  947. public boolean checkCondition(L2Character activeChar, L2Object target, boolean itemOrWeapon)
  948. {
  949. if (activeChar.canOverrideCond(PcCondOverride.SKILL_CONDITIONS) && !Config.GM_SKILL_RESTRICTION)
  950. {
  951. return true;
  952. }
  953. if ((getCondition() & L2Skill.COND_SHIELD) != 0)
  954. {
  955. // L2ItemInstance dummy = activeChar.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  956. // L2Armor armorPiece = (L2Armor) dummy.getItem();
  957. // TODO add checks for shield here.
  958. }
  959. List<Condition> preCondition = _preCondition;
  960. if (itemOrWeapon)
  961. {
  962. preCondition = _itemPreCondition;
  963. }
  964. if ((preCondition == null) || preCondition.isEmpty())
  965. {
  966. return true;
  967. }
  968. for (Condition cond : preCondition)
  969. {
  970. Env env = new Env();
  971. env.setCharacter(activeChar);
  972. if (target instanceof L2Character)
  973. {
  974. env.setTarget((L2Character) target);
  975. }
  976. env.setSkill(this);
  977. if (!cond.test(env))
  978. {
  979. String msg = cond.getMessage();
  980. int msgId = cond.getMessageId();
  981. if (msgId != 0)
  982. {
  983. SystemMessage sm = SystemMessage.getSystemMessage(msgId);
  984. if (cond.isAddName())
  985. {
  986. sm.addSkillName(_id);
  987. }
  988. activeChar.sendPacket(sm);
  989. }
  990. else if (msg != null)
  991. {
  992. activeChar.sendMessage(msg);
  993. }
  994. return false;
  995. }
  996. }
  997. return true;
  998. }
  999. public final L2Object[] getTargetList(L2Character activeChar, boolean onlyFirst)
  1000. {
  1001. // Init to null the target of the skill
  1002. L2Character target = null;
  1003. // Get the L2Objcet targeted by the user of the skill at this moment
  1004. L2Object objTarget = activeChar.getTarget();
  1005. // If the L2Object targeted is a L2Character, it becomes the L2Character target
  1006. if (objTarget instanceof L2Character)
  1007. {
  1008. target = (L2Character) objTarget;
  1009. }
  1010. return getTargetList(activeChar, onlyFirst, target);
  1011. }
  1012. /**
  1013. * Return all targets of the skill in a table in function a the skill type.<br>
  1014. * <B><U>Values of skill type</U>:</B>
  1015. * <ul>
  1016. * <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>
  1017. * <li>SELF</li>
  1018. * <li>HOLY, UNDEAD</li>
  1019. * <li>PET</li>
  1020. * <li>AURA, AURA_CLOSE</li>
  1021. * <li>AREA</li>
  1022. * <li>MULTIFACE</li>
  1023. * <li>PARTY, CLAN</li>
  1024. * <li>CORPSE_PLAYER, CORPSE_MOB, CORPSE_CLAN</li>
  1025. * <li>UNLOCKABLE</li>
  1026. * <li>ITEM</li>
  1027. * <ul>
  1028. * @param activeChar The L2Character who use the skill
  1029. * @param onlyFirst
  1030. * @param target
  1031. * @return
  1032. */
  1033. public final L2Object[] getTargetList(L2Character activeChar, boolean onlyFirst, L2Character target)
  1034. {
  1035. final ITargetTypeHandler handler = TargetHandler.getInstance().getHandler(getTargetType());
  1036. if (handler != null)
  1037. {
  1038. try
  1039. {
  1040. return handler.getTargetList(this, activeChar, onlyFirst, target);
  1041. }
  1042. catch (Exception e)
  1043. {
  1044. _log.log(Level.WARNING, "Exception in L2Skill.getTargetList(): " + e.getMessage(), e);
  1045. }
  1046. }
  1047. activeChar.sendMessage("Target type of skill is not currently handled.");
  1048. return EMPTY_TARGET_LIST;
  1049. }
  1050. public final L2Object[] getTargetList(L2Character activeChar)
  1051. {
  1052. return getTargetList(activeChar, false);
  1053. }
  1054. public final L2Object getFirstOfTargetList(L2Character activeChar)
  1055. {
  1056. L2Object[] targets = getTargetList(activeChar, true);
  1057. if (targets.length == 0)
  1058. {
  1059. return null;
  1060. }
  1061. return targets[0];
  1062. }
  1063. /**
  1064. * Check if should be target added to the target list false if target is dead, target same as caster,<br>
  1065. * 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>
  1066. * 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.
  1067. * @param caster
  1068. * @param target
  1069. * @param skill
  1070. * @param sourceInArena
  1071. * @return
  1072. */
  1073. public static final boolean checkForAreaOffensiveSkills(L2Character caster, L2Character target, L2Skill skill, boolean sourceInArena)
  1074. {
  1075. if ((target == null) || target.isDead() || (target == caster))
  1076. {
  1077. return false;
  1078. }
  1079. final L2PcInstance player = caster.getActingPlayer();
  1080. final L2PcInstance targetPlayer = target.getActingPlayer();
  1081. if (player != null)
  1082. {
  1083. if (targetPlayer != null)
  1084. {
  1085. if ((targetPlayer == caster) || (targetPlayer == player))
  1086. {
  1087. return false;
  1088. }
  1089. if (targetPlayer.inObserverMode())
  1090. {
  1091. return false;
  1092. }
  1093. if (skill.isOffensive() && (player.getSiegeState() > 0) && player.isInsideZone(ZoneId.SIEGE) && (player.getSiegeState() == targetPlayer.getSiegeState()) && (player.getSiegeSide() == targetPlayer.getSiegeSide()))
  1094. {
  1095. return false;
  1096. }
  1097. if (skill.isOffensive() && target.isInsideZone(ZoneId.PEACE))
  1098. {
  1099. return false;
  1100. }
  1101. if (player.isInParty() && targetPlayer.isInParty())
  1102. {
  1103. // Same party
  1104. if (player.getParty().getLeaderObjectId() == targetPlayer.getParty().getLeaderObjectId())
  1105. {
  1106. return false;
  1107. }
  1108. // Same command channel
  1109. if (player.getParty().isInCommandChannel() && (player.getParty().getCommandChannel() == targetPlayer.getParty().getCommandChannel()))
  1110. {
  1111. return false;
  1112. }
  1113. }
  1114. if (!TvTEvent.checkForTvTSkill(player, targetPlayer, skill))
  1115. {
  1116. return false;
  1117. }
  1118. if (!sourceInArena && !(targetPlayer.isInsideZone(ZoneId.PVP) && !targetPlayer.isInsideZone(ZoneId.SIEGE)))
  1119. {
  1120. if ((player.getAllyId() != 0) && (player.getAllyId() == targetPlayer.getAllyId()))
  1121. {
  1122. return false;
  1123. }
  1124. if ((player.getClanId() != 0) && (player.getClanId() == targetPlayer.getClanId()))
  1125. {
  1126. return false;
  1127. }
  1128. if (!player.checkPvpSkill(targetPlayer, skill, (caster instanceof L2Summon)))
  1129. {
  1130. return false;
  1131. }
  1132. }
  1133. }
  1134. }
  1135. else
  1136. {
  1137. // target is mob
  1138. if ((targetPlayer == null) && (target instanceof L2Attackable) && (caster instanceof L2Attackable))
  1139. {
  1140. String casterEnemyClan = ((L2Attackable) caster).getEnemyClan();
  1141. if ((casterEnemyClan == null) || casterEnemyClan.isEmpty())
  1142. {
  1143. return false;
  1144. }
  1145. String targetClan = ((L2Attackable) target).getClan();
  1146. if ((targetClan == null) || targetClan.isEmpty())
  1147. {
  1148. return false;
  1149. }
  1150. if (!casterEnemyClan.equals(targetClan))
  1151. {
  1152. return false;
  1153. }
  1154. }
  1155. }
  1156. if (geoEnabled && !GeoData.getInstance().canSeeTarget(caster, target))
  1157. {
  1158. return false;
  1159. }
  1160. return true;
  1161. }
  1162. public static final boolean addSummon(L2Character caster, L2PcInstance owner, int radius, boolean isDead)
  1163. {
  1164. if (!owner.hasSummon())
  1165. {
  1166. return false;
  1167. }
  1168. return addCharacter(caster, owner.getSummon(), radius, isDead);
  1169. }
  1170. public static final boolean addCharacter(L2Character caster, L2Character target, int radius, boolean isDead)
  1171. {
  1172. if (isDead != target.isDead())
  1173. {
  1174. return false;
  1175. }
  1176. if ((radius > 0) && !Util.checkIfInRange(radius, caster, target, true))
  1177. {
  1178. return false;
  1179. }
  1180. return true;
  1181. }
  1182. public final List<Func> getStatFuncs(L2Effect effect, L2Character player)
  1183. {
  1184. if (_funcTemplates == null)
  1185. {
  1186. return Collections.<Func> emptyList();
  1187. }
  1188. if (!(player instanceof L2Playable) && !(player instanceof L2Attackable))
  1189. {
  1190. return Collections.<Func> emptyList();
  1191. }
  1192. final List<Func> funcs = new ArrayList<>(_funcTemplates.size());
  1193. final Env env = new Env();
  1194. env.setCharacter(player);
  1195. env.setSkill(this);
  1196. for (FuncTemplate t : _funcTemplates)
  1197. {
  1198. Func f = t.getFunc(env, this); // skill is owner
  1199. if (f != null)
  1200. {
  1201. funcs.add(f);
  1202. }
  1203. }
  1204. return funcs;
  1205. }
  1206. public boolean hasEffects()
  1207. {
  1208. return (_effectTemplates != null) && !_effectTemplates.isEmpty();
  1209. }
  1210. public List<EffectTemplate> getEffectTemplates()
  1211. {
  1212. return _effectTemplates;
  1213. }
  1214. public List<EffectTemplate> getEffectTemplatesPassive()
  1215. {
  1216. return _effectTemplatesPassive;
  1217. }
  1218. public boolean hasSelfEffects()
  1219. {
  1220. return (_effectTemplatesSelf != null) && !_effectTemplatesSelf.isEmpty();
  1221. }
  1222. public boolean hasPassiveEffects()
  1223. {
  1224. return (_effectTemplatesPassive != null) && !_effectTemplatesPassive.isEmpty();
  1225. }
  1226. /**
  1227. * Env is used to pass parameters for secondary effects (shield and ss/bss/bsss)
  1228. * @param effector
  1229. * @param effected
  1230. * @param env
  1231. * @return an array with the effects that have been added to effector
  1232. */
  1233. public final L2Effect[] getEffects(L2Character effector, L2Character effected, Env env)
  1234. {
  1235. if (!hasEffects() || isPassive())
  1236. {
  1237. return EMPTY_EFFECT_SET;
  1238. }
  1239. // doors and siege flags cannot receive any effects
  1240. if ((effected instanceof L2DoorInstance) || (effected instanceof L2SiegeFlagInstance))
  1241. {
  1242. return EMPTY_EFFECT_SET;
  1243. }
  1244. if (effector != effected)
  1245. {
  1246. if (isOffensive() || isDebuff())
  1247. {
  1248. if (effected.isInvul())
  1249. {
  1250. return EMPTY_EFFECT_SET;
  1251. }
  1252. if ((effector instanceof L2PcInstance) && ((L2PcInstance) effector).isGM())
  1253. {
  1254. if (!((L2PcInstance) effector).getAccessLevel().canGiveDamage())
  1255. {
  1256. return EMPTY_EFFECT_SET;
  1257. }
  1258. }
  1259. }
  1260. }
  1261. final List<L2Effect> effects = new ArrayList<>(_effectTemplates.size());
  1262. if (env == null)
  1263. {
  1264. env = new Env();
  1265. }
  1266. env.setSkillMastery(Formulas.calcSkillMastery(effector, this));
  1267. env.setCharacter(effector);
  1268. env.setTarget(effected);
  1269. env.setSkill(this);
  1270. for (EffectTemplate et : _effectTemplates)
  1271. {
  1272. if (Formulas.calcEffectSuccess(effector, effected, et, this, env.getShield(), env.isSoulShot(), env.isSpiritShot(), env.isBlessedSpiritShot()))
  1273. {
  1274. L2Effect e = et.getEffect(env);
  1275. if (e != null)
  1276. {
  1277. e.scheduleEffect();
  1278. effects.add(e);
  1279. }
  1280. }
  1281. // display fail message only for effects with icons
  1282. else if (et.isIconDisplay() && effector.isPlayer())
  1283. {
  1284. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  1285. sm.addCharName(effected);
  1286. sm.addSkillName(this);
  1287. effector.sendPacket(sm);
  1288. }
  1289. }
  1290. final L2Effect[] list = effects.toArray(new L2Effect[effects.size()]);
  1291. effected.getEffectList().add(list);
  1292. return effects.isEmpty() ? EMPTY_EFFECT_SET : list;
  1293. }
  1294. /**
  1295. * Warning: this method doesn't consider modifier (shield, ss, sps, bss) for secondary effects
  1296. * @param effector
  1297. * @param effected
  1298. * @return
  1299. */
  1300. public final L2Effect[] getEffects(L2Character effector, L2Character effected)
  1301. {
  1302. return getEffects(effector, effected, null);
  1303. }
  1304. /**
  1305. * This method has suffered some changes in CT2.2 ->CT2.3<br>
  1306. * Effect engine is now supporting secondary effects with independent success/fail calculus from effect skill.<br>
  1307. * Env parameter has been added to pass parameters like soulshot, spiritshots, blessed spiritshots or shield defense.<br>
  1308. * Some other optimizations have been done<br>
  1309. * This new feature works following next rules:
  1310. * <ul>
  1311. * <li>To enable feature, effectPower must be over -1 (check DocumentSkill#attachEffect for further information)</li>
  1312. * <li>If main skill fails, secondary effect always fail</li>
  1313. * </ul>
  1314. * @param effector
  1315. * @param effected
  1316. * @param env
  1317. * @return
  1318. */
  1319. public final L2Effect[] getEffects(L2CubicInstance effector, L2Character effected, Env env)
  1320. {
  1321. if (!hasEffects() || isPassive())
  1322. {
  1323. return EMPTY_EFFECT_SET;
  1324. }
  1325. if (effector.getOwner() != effected)
  1326. {
  1327. if (isDebuff() || isOffensive())
  1328. {
  1329. if (effected.isInvul())
  1330. {
  1331. return EMPTY_EFFECT_SET;
  1332. }
  1333. if (effector.getOwner().isGM() && !effector.getOwner().getAccessLevel().canGiveDamage())
  1334. {
  1335. return EMPTY_EFFECT_SET;
  1336. }
  1337. }
  1338. }
  1339. List<L2Effect> effects = new ArrayList<>(_effectTemplates.size());
  1340. if (env == null)
  1341. {
  1342. env = new Env();
  1343. }
  1344. env.setCharacter(effector.getOwner());
  1345. env.setCubic(effector);
  1346. env.setTarget(effected);
  1347. env.setSkill(this);
  1348. for (EffectTemplate et : _effectTemplates)
  1349. {
  1350. if (Formulas.calcEffectSuccess(effector.getOwner(), effected, et, this, env.getShield(), env.isSoulShot(), env.isSpiritShot(), env.isBlessedSpiritShot()))
  1351. {
  1352. L2Effect e = et.getEffect(env);
  1353. if (e != null)
  1354. {
  1355. e.scheduleEffect();
  1356. effects.add(e);
  1357. }
  1358. }
  1359. }
  1360. if (effects.isEmpty())
  1361. {
  1362. return EMPTY_EFFECT_SET;
  1363. }
  1364. return effects.toArray(new L2Effect[effects.size()]);
  1365. }
  1366. public final L2Effect[] getEffectsSelf(L2Character effector)
  1367. {
  1368. if (!hasSelfEffects() || isPassive())
  1369. {
  1370. return EMPTY_EFFECT_SET;
  1371. }
  1372. final List<L2Effect> effects = new ArrayList<>(_effectTemplatesSelf.size());
  1373. for (EffectTemplate et : _effectTemplatesSelf)
  1374. {
  1375. Env env = new Env();
  1376. env.setCharacter(effector);
  1377. env.setTarget(effector);
  1378. env.setSkill(this);
  1379. L2Effect e = et.getEffect(env);
  1380. if (e != null)
  1381. {
  1382. e.setSelfEffect();
  1383. e.scheduleEffect();
  1384. effects.add(e);
  1385. }
  1386. }
  1387. if (effects.isEmpty())
  1388. {
  1389. return EMPTY_EFFECT_SET;
  1390. }
  1391. return effects.toArray(new L2Effect[effects.size()]);
  1392. }
  1393. public final L2Effect[] getPassiveEffects(L2Character effector)
  1394. {
  1395. if (!hasPassiveEffects())
  1396. {
  1397. return EMPTY_EFFECT_SET;
  1398. }
  1399. final List<L2Effect> effects = new ArrayList<>(_effectTemplatesPassive.size());
  1400. for (EffectTemplate et : _effectTemplatesPassive)
  1401. {
  1402. Env env = new Env();
  1403. env.setCharacter(effector);
  1404. env.setTarget(effector);
  1405. env.setSkill(this);
  1406. L2Effect e = et.getEffect(env);
  1407. if (e != null)
  1408. {
  1409. e.scheduleEffect();
  1410. effects.add(e);
  1411. }
  1412. }
  1413. return effects.isEmpty() ? EMPTY_EFFECT_SET : effects.toArray(new L2Effect[effects.size()]);
  1414. }
  1415. public final void attach(FuncTemplate f)
  1416. {
  1417. if (_funcTemplates == null)
  1418. {
  1419. _funcTemplates = new ArrayList<>(1);
  1420. }
  1421. _funcTemplates.add(f);
  1422. }
  1423. public final void attach(EffectTemplate effect)
  1424. {
  1425. if (_effectTemplates == null)
  1426. {
  1427. _effectTemplates = new ArrayList<>(1);
  1428. }
  1429. _effectTemplates.add(effect);
  1430. }
  1431. public final void attachSelf(EffectTemplate effect)
  1432. {
  1433. if (_effectTemplatesSelf == null)
  1434. {
  1435. _effectTemplatesSelf = new ArrayList<>(1);
  1436. }
  1437. _effectTemplatesSelf.add(effect);
  1438. }
  1439. public final void attachPassive(EffectTemplate effect)
  1440. {
  1441. if (_effectTemplatesPassive == null)
  1442. {
  1443. _effectTemplatesPassive = new ArrayList<>(1);
  1444. }
  1445. _effectTemplatesPassive.add(effect);
  1446. }
  1447. public final void attach(Condition c, boolean itemOrWeapon)
  1448. {
  1449. if (itemOrWeapon)
  1450. {
  1451. if (_itemPreCondition == null)
  1452. {
  1453. _itemPreCondition = new ArrayList<>();
  1454. }
  1455. _itemPreCondition.add(c);
  1456. }
  1457. else
  1458. {
  1459. if (_preCondition == null)
  1460. {
  1461. _preCondition = new ArrayList<>();
  1462. }
  1463. _preCondition.add(c);
  1464. }
  1465. }
  1466. @Override
  1467. public String toString()
  1468. {
  1469. return "Skill " + _name + "(" + _id + "," + _level + ")";
  1470. }
  1471. /**
  1472. * @return pet food
  1473. */
  1474. public int getFeed()
  1475. {
  1476. return _feed;
  1477. }
  1478. /**
  1479. * used for tracking item id in case that item consume cannot be used
  1480. * @return reference item id
  1481. */
  1482. public int getReferenceItemId()
  1483. {
  1484. return _refId;
  1485. }
  1486. public int getAfterEffectId()
  1487. {
  1488. return _afterEffectId;
  1489. }
  1490. public int getAfterEffectLvl()
  1491. {
  1492. return _afterEffectLvl;
  1493. }
  1494. @Override
  1495. public boolean triggersChanceSkill()
  1496. {
  1497. return (_triggeredId > 0) && isChance();
  1498. }
  1499. @Override
  1500. public int getTriggeredChanceId()
  1501. {
  1502. return _triggeredId;
  1503. }
  1504. @Override
  1505. public int getTriggeredChanceLevel()
  1506. {
  1507. return _triggeredLevel;
  1508. }
  1509. @Override
  1510. public ChanceCondition getTriggeredChanceCondition()
  1511. {
  1512. return _chanceCondition;
  1513. }
  1514. public String getAttributeName()
  1515. {
  1516. return _attribute;
  1517. }
  1518. /**
  1519. * @return the _blowChance
  1520. */
  1521. public int getBlowChance()
  1522. {
  1523. return _blowChance;
  1524. }
  1525. public boolean ignoreShield()
  1526. {
  1527. return _ignoreShield;
  1528. }
  1529. public boolean canBeReflected()
  1530. {
  1531. return _canBeReflected;
  1532. }
  1533. public boolean canBeDispeled()
  1534. {
  1535. return _canBeDispeled;
  1536. }
  1537. public boolean isClanSkill()
  1538. {
  1539. return _isClanSkill;
  1540. }
  1541. public boolean isExcludedFromCheck()
  1542. {
  1543. return _excludedFromCheck;
  1544. }
  1545. public boolean getDependOnTargetBuff()
  1546. {
  1547. return _dependOnTargetBuff;
  1548. }
  1549. public boolean isSimultaneousCast()
  1550. {
  1551. return _simultaneousCast;
  1552. }
  1553. /**
  1554. * Parse an extractable skill.
  1555. * @param skillId the skill Id
  1556. * @param skillLvl the skill level
  1557. * @param values the values to parse
  1558. * @return the parsed extractable skill
  1559. * @author Zoey76
  1560. */
  1561. private L2ExtractableSkill parseExtractableSkill(int skillId, int skillLvl, String values)
  1562. {
  1563. final String[] prodLists = values.split(";");
  1564. final List<L2ExtractableProductItem> products = new ArrayList<>();
  1565. String[] prodData;
  1566. for (String prodList : prodLists)
  1567. {
  1568. prodData = prodList.split(",");
  1569. if (prodData.length < 3)
  1570. {
  1571. _log.warning("Extractable skills data: Error in Skill Id: " + skillId + " Level: " + skillLvl + " -> wrong seperator!");
  1572. }
  1573. List<ItemHolder> items = null;
  1574. double chance = 0;
  1575. int prodId = 0;
  1576. int quantity = 0;
  1577. final int lenght = prodData.length - 1;
  1578. try
  1579. {
  1580. items = new ArrayList<>(lenght / 2);
  1581. for (int j = 0; j < lenght; j++)
  1582. {
  1583. prodId = Integer.parseInt(prodData[j]);
  1584. quantity = Integer.parseInt(prodData[j += 1]);
  1585. if ((prodId <= 0) || (quantity <= 0))
  1586. {
  1587. _log.warning("Extractable skills data: Error in Skill Id: " + skillId + " Level: " + skillLvl + " wrong production Id: " + prodId + " or wrond quantity: " + quantity + "!");
  1588. }
  1589. items.add(new ItemHolder(prodId, quantity));
  1590. }
  1591. chance = Double.parseDouble(prodData[lenght]);
  1592. }
  1593. catch (Exception e)
  1594. {
  1595. _log.warning("Extractable skills data: Error in Skill Id: " + skillId + " Level: " + skillLvl + " -> incomplete/invalid production data or wrong seperator!");
  1596. }
  1597. products.add(new L2ExtractableProductItem(items, chance));
  1598. }
  1599. if (products.isEmpty())
  1600. {
  1601. _log.warning("Extractable skills data: Error in Skill Id: " + skillId + " Level: " + skillLvl + " -> There are no production items!");
  1602. }
  1603. return new L2ExtractableSkill(SkillTable.getSkillHashCode(skillId, skillLvl), products);
  1604. }
  1605. public L2ExtractableSkill getExtractableSkill()
  1606. {
  1607. return _extractableItems;
  1608. }
  1609. /**
  1610. * @return the _npcId
  1611. */
  1612. public int getNpcId()
  1613. {
  1614. return _npcId;
  1615. }
  1616. /**
  1617. * @param types
  1618. * @return {@code true} if at least one of specified {@link L2EffectType} types present on the current skill's effects, {@code false} otherwise.
  1619. */
  1620. public boolean hasEffectType(L2EffectType... types)
  1621. {
  1622. if (hasEffects() && (types != null) && (types.length > 0))
  1623. {
  1624. if (_effectTypes == null)
  1625. {
  1626. _effectTypes = new byte[_effectTemplates.size()];
  1627. final Env env = new Env();
  1628. env.setSkill(this);
  1629. int i = 0;
  1630. for (EffectTemplate et : _effectTemplates)
  1631. {
  1632. final L2Effect e = et.getEffect(env, true);
  1633. if (e == null)
  1634. {
  1635. continue;
  1636. }
  1637. _effectTypes[i++] = (byte) e.getEffectType().ordinal();
  1638. }
  1639. Arrays.sort(_effectTypes);
  1640. }
  1641. for (L2EffectType type : types)
  1642. {
  1643. if (Arrays.binarySearch(_effectTypes, (byte) type.ordinal()) >= 0)
  1644. {
  1645. return true;
  1646. }
  1647. }
  1648. }
  1649. return false;
  1650. }
  1651. }