L2Skill.java 51 KB

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