L2Skill.java 50 KB

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