L2Skill.java 53 KB

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