L2Skill.java 51 KB

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