L2Skill.java 54 KB

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