L2Skill.java 53 KB

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