L2Skill.java 53 KB

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