L2Skill.java 53 KB

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