L2Skill.java 53 KB

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