L2Skill.java 53 KB

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