L2Skill.java 51 KB

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