L2Skill.java 53 KB

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