L2Skill.java 50 KB

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