L2Skill.java 54 KB

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