L2Skill.java 52 KB

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