L2Skill.java 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065
  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.Collection;
  18. import java.util.List;
  19. import java.util.Map;
  20. import java.util.StringTokenizer;
  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.model.actor.L2Attackable;
  31. import com.l2jserver.gameserver.model.actor.L2Character;
  32. import com.l2jserver.gameserver.model.actor.L2Npc;
  33. import com.l2jserver.gameserver.model.actor.L2Playable;
  34. import com.l2jserver.gameserver.model.actor.L2Summon;
  35. import com.l2jserver.gameserver.model.actor.instance.L2ArtefactInstance;
  36. import com.l2jserver.gameserver.model.actor.instance.L2ChestInstance;
  37. import com.l2jserver.gameserver.model.actor.instance.L2CubicInstance;
  38. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  39. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  40. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  41. import com.l2jserver.gameserver.model.actor.instance.L2SiegeFlagInstance;
  42. import com.l2jserver.gameserver.model.actor.instance.L2SummonInstance;
  43. import com.l2jserver.gameserver.model.entity.TvTEvent;
  44. import com.l2jserver.gameserver.network.SystemMessageId;
  45. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  46. import com.l2jserver.gameserver.skills.BaseStats;
  47. import com.l2jserver.gameserver.skills.Env;
  48. import com.l2jserver.gameserver.skills.Formulas;
  49. import com.l2jserver.gameserver.skills.Stats;
  50. import com.l2jserver.gameserver.skills.conditions.Condition;
  51. import com.l2jserver.gameserver.skills.funcs.Func;
  52. import com.l2jserver.gameserver.skills.funcs.FuncTemplate;
  53. import com.l2jserver.gameserver.templates.StatsSet;
  54. import com.l2jserver.gameserver.templates.effects.EffectTemplate;
  55. import com.l2jserver.gameserver.templates.item.L2Armor;
  56. import com.l2jserver.gameserver.templates.item.L2ArmorType;
  57. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  58. import com.l2jserver.gameserver.util.Util;
  59. /**
  60. * This class...
  61. *
  62. * @version $Revision: 1.3.2.8.2.22 $ $Date: 2005/04/06 16:13:42 $
  63. */
  64. public abstract class L2Skill implements IChanceSkillTrigger
  65. {
  66. protected static final Logger _log = Logger.getLogger(L2Skill.class.getName());
  67. private static final L2Object[] _emptyTargetList = new L2Object[0];
  68. public static final int SKILL_LUCKY = 194;
  69. public static final int SKILL_CREATE_COMMON = 1320;
  70. public static final int SKILL_CREATE_DWARVEN = 172;
  71. public static final int SKILL_CRYSTALLIZE = 248;
  72. public static final int SKILL_DIVINE_INSPIRATION = 1405;
  73. public static final int SKILL_CLAN_LUCK = 390;
  74. public static final boolean geoEnabled = Config.GEODATA > 0;
  75. public static enum SkillOpType
  76. {
  77. OP_PASSIVE, OP_ACTIVE, OP_TOGGLE
  78. }
  79. /** Target types of skills : SELF, PARTY, CLAN, PET... */
  80. public static enum SkillTargetType
  81. {
  82. TARGET_NONE,
  83. TARGET_SELF,
  84. TARGET_ONE,
  85. TARGET_PARTY,
  86. TARGET_ALLY,
  87. TARGET_CLAN,
  88. TARGET_PET,
  89. TARGET_SUMMON,
  90. TARGET_AREA,
  91. TARGET_FRONT_AREA,
  92. TARGET_BEHIND_AREA,
  93. TARGET_AURA,
  94. TARGET_AURA_CORPSE_MOB,
  95. TARGET_FRONT_AURA,
  96. TARGET_BEHIND_AURA,
  97. TARGET_CORPSE,
  98. TARGET_UNDEAD,
  99. TARGET_AREA_UNDEAD,
  100. TARGET_CORPSE_ALLY,
  101. TARGET_CORPSE_CLAN,
  102. TARGET_CORPSE_PLAYER,
  103. TARGET_CORPSE_PET,
  104. TARGET_AREA_CORPSE_MOB,
  105. TARGET_CORPSE_MOB,
  106. TARGET_UNLOCKABLE,
  107. TARGET_HOLY,
  108. TARGET_FLAGPOLE,
  109. TARGET_PARTY_MEMBER,
  110. TARGET_PARTY_OTHER,
  111. TARGET_PARTY_CLAN,
  112. TARGET_ENEMY_SUMMON,
  113. TARGET_OWNER_PET,
  114. TARGET_GROUND,
  115. TARGET_PARTY_NOTME,
  116. TARGET_AREA_SUMMON,
  117. TARGET_CLAN_MEMBER
  118. }
  119. public static enum SkillTraitType
  120. {
  121. NONE,
  122. BLEED,
  123. BOSS,
  124. DEATH,
  125. DERANGEMENT,
  126. ETC,
  127. GUST,
  128. HOLD,
  129. PARALYZE,
  130. PHYSICAL_BLOCKADE,
  131. POISON,
  132. SHOCK,
  133. SLEEP,
  134. VALAKAS
  135. }
  136. //conditional values
  137. public final static int COND_RUNNING = 0x0001;
  138. public final static int COND_WALKING = 0x0002;
  139. public final static int COND_SIT = 0x0004;
  140. public final static int COND_BEHIND = 0x0008;
  141. public final static int COND_CRIT = 0x0010;
  142. public final static int COND_LOWHP = 0x0020;
  143. public final static int COND_ROBES = 0x0040;
  144. public final static int COND_CHARGES = 0x0080;
  145. public final static int COND_SHIELD = 0x0100;
  146. private static final Func[] _emptyFunctionSet = new Func[0];
  147. private static final L2Effect[] _emptyEffectSet = new L2Effect[0];
  148. // these two build the primary key
  149. private final int _id;
  150. private final int _level;
  151. /** Identifier for a skill that client can't display */
  152. private int _displayId;
  153. // not needed, just for easier debug
  154. private final String _name;
  155. private final SkillOpType _operateType;
  156. private final boolean _magic;
  157. private final SkillTraitType _traitType;
  158. private final boolean _staticReuse;
  159. private final boolean _staticHitTime;
  160. private final boolean _staticDamage; // Damage dealing skills do static damage based on the power value.
  161. private final int _mpConsume;
  162. private final int _mpInitialConsume;
  163. private final int _hpConsume;
  164. private final int _cpConsume;
  165. private final int _targetConsume;
  166. private final int _targetConsumeId;
  167. private final int _itemConsume;
  168. private final int _itemConsumeId;
  169. private final int _castRange;
  170. private final int _effectRange;
  171. // Abnormal levels for skills and their canceling, e.g. poison vs negate
  172. private final int _abnormalLvl; // e.g. poison or bleed lvl 2
  173. // Note: see also _effectAbnormalLvl
  174. private final int _negateLvl; // abnormalLvl is negated with negateLvl
  175. private final int[] _negateId; // cancels the effect of skill ID
  176. private final L2SkillType[] _negateStats; // lists the effect types that are canceled
  177. private final Map<String, Byte> _negateAbnormals; // lists the effect abnormal types with order below the presented that are canceled
  178. private final int _maxNegatedEffects; // maximum number of effects to negate
  179. private final boolean _stayAfterDeath; // skill should stay after death
  180. private final boolean _stayOnSubclassChange; // skill should stay on subclass change
  181. // kill by damage over time
  182. private final boolean _killByDOT;
  183. private final int _refId;
  184. // all times in milliseconds
  185. private final int _hitTime;
  186. private final int[] _hitTimings;
  187. //private final int _skillInterruptTime;
  188. private final int _coolTime;
  189. private final int _reuseHashCode;
  190. private final int _reuseDelay;
  191. private final int _buffDuration;
  192. // for item skills delay on equip
  193. private final int _equipDelay;
  194. /** Target type of the skill : SELF, PARTY, CLAN, PET... */
  195. private final SkillTargetType _targetType;
  196. private final int _feed;
  197. // base success chance
  198. private final double _power;
  199. private final double _pvpPower;
  200. private final double _pvePower;
  201. private final int _magicLevel;
  202. private final int _levelDepend;
  203. private final boolean _ignoreResists;
  204. private final int _minChance;
  205. private final int _maxChance;
  206. private final int _blowChance;
  207. private final boolean _isNeutral;
  208. // Effecting area of the skill, in radius.
  209. // The radius center varies according to the _targetType:
  210. // "caster" if targetType = AURA/PARTY/CLAN or "target" if targetType = AREA
  211. private final int _skillRadius;
  212. private final L2SkillType _skillType;
  213. private final L2SkillType _effectType; // additional effect has a type
  214. private final int _effectAbnormalLvl; // abnormal level for the additional effect type, e.g. poison lvl 1
  215. private final int _effectId;
  216. private final int _effectLvl; // normal effect level
  217. private final boolean _nextActionIsAttack;
  218. private final boolean _removedOnAnyActionExceptMove;
  219. private final boolean _removedOnDamage;
  220. private final boolean _isPotion;
  221. private final byte _element;
  222. private final int _elementPower;
  223. private final Stats _stat;
  224. private final BaseStats _saveVs;
  225. private final int _condition;
  226. private final int _conditionValue;
  227. private final boolean _overhit;
  228. private final int _weaponsAllowed;
  229. private final int _armorsAllowed;
  230. private final int _minPledgeClass;
  231. private final boolean _isOffensive;
  232. private final int _maxCharges;
  233. private final int _numCharges;
  234. private final int _triggeredId;
  235. private final int _triggeredLevel;
  236. private final String _chanceType;
  237. private final int _soulMaxConsume;
  238. private final int _soulConsume;
  239. private final int _numSouls;
  240. private final int _expNeeded;
  241. private final int _critChance;
  242. private final float _dependOnTargetBuff;
  243. private final int _transformId;
  244. private final int _transformDuration;
  245. private final int _afterEffectId;
  246. private final int _afterEffectLvl;
  247. private final boolean _isHeroSkill; // If true the skill is a Hero Skill
  248. private final boolean _isGMSkill; // True if skill is GM skill
  249. 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
  250. 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)
  251. 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)
  252. private final boolean _directHpDmg; // If true then dmg is being make directly
  253. private final boolean _isTriggeredSkill; // If true the skill will take activation buff slot instead of a normal buff slot
  254. private final boolean _isDance; // If true then casting more dances will cost more MP
  255. private final int _nextDanceCost;
  256. private final float _sSBoost; //If true skill will have SoulShot boost (power*2)
  257. private final int _aggroPoints;
  258. protected List<Condition> _preCondition;
  259. protected List<Condition> _itemPreCondition;
  260. protected FuncTemplate[] _funcTemplates;
  261. protected EffectTemplate[] _effectTemplates;
  262. protected EffectTemplate[] _effectTemplatesSelf;
  263. protected EffectTemplate[] _effectTemplatesPassive;
  264. protected ChanceCondition _chanceCondition = null;
  265. // Flying support
  266. private final String _flyType;
  267. private final int _flyRadius;
  268. private final float _flyCourse;
  269. private final boolean _isDebuff;
  270. private final String _attribute;
  271. private final boolean _ignoreShield;
  272. private final boolean _isSuicideAttack;
  273. private final boolean _canBeReflected;
  274. private final boolean _canBeDispeled;
  275. private final boolean _isClanSkill;
  276. private final boolean _excludedFromCheck;
  277. private final boolean _simultaneousCast;
  278. private L2ExtractableSkill _extractableItems = null;
  279. protected L2Skill(StatsSet set)
  280. {
  281. _id = set.getInteger("skill_id");
  282. _level = set.getInteger("level");
  283. _refId = set.getInteger("referenceId", 0);
  284. _displayId = set.getInteger("displayId", _id);
  285. _name = set.getString("name");
  286. _operateType = set.getEnum("operateType", SkillOpType.class);
  287. _magic = set.getBool("isMagic", false);
  288. _traitType = set.getEnum("trait", SkillTraitType.class, SkillTraitType.NONE);
  289. _staticReuse = set.getBool("staticReuse", false);
  290. _staticHitTime = set.getBool("staticHitTime", false);
  291. _staticDamage = set.getBool("staticDamage", false);
  292. _isPotion = set.getBool("isPotion", false);
  293. _mpConsume = set.getInteger("mpConsume", 0);
  294. _mpInitialConsume = set.getInteger("mpInitialConsume", 0);
  295. _hpConsume = set.getInteger("hpConsume", 0);
  296. _cpConsume = set.getInteger("cpConsume", 0);
  297. _targetConsume = set.getInteger("targetConsumeCount", 0);
  298. _targetConsumeId = set.getInteger("targetConsumeId", 0);
  299. _itemConsume = set.getInteger("itemConsumeCount", 0);
  300. _itemConsumeId = set.getInteger("itemConsumeId", 0);
  301. _afterEffectId = set.getInteger("afterEffectId", 0);
  302. _afterEffectLvl = set.getInteger("afterEffectLvl", 1);
  303. _castRange = set.getInteger("castRange", -1);
  304. _effectRange = set.getInteger("effectRange", -1);
  305. _abnormalLvl = set.getInteger("abnormalLvl", -1);
  306. _effectAbnormalLvl = set.getInteger("effectAbnormalLvl", -1); // support for a separate effect abnormal lvl, e.g. poison inside a different skill
  307. _negateLvl = set.getInteger("negateLvl", -1);
  308. _attribute = set.getString("attribute","");
  309. String str = set.getString("negateStats", "");
  310. if (str == "")
  311. _negateStats = new L2SkillType[0];
  312. else
  313. {
  314. String[] stats = str.split(" ");
  315. L2SkillType[] array = new L2SkillType[stats.length];
  316. for (int i = 0; i < stats.length; i++)
  317. {
  318. L2SkillType type = null;
  319. try
  320. {
  321. type = Enum.valueOf(L2SkillType.class, stats[i]);
  322. }
  323. catch (Exception e)
  324. {
  325. throw new IllegalArgumentException("SkillId: "+_id+"Enum value of type "+L2SkillType.class.getName()+"required, but found: "+stats[i]);
  326. }
  327. array[i] = type;
  328. }
  329. _negateStats = array;
  330. }
  331. String negateAbnormals = set.getString("negateAbnormals", null);
  332. if (negateAbnormals != null && negateAbnormals != "")
  333. {
  334. _negateAbnormals = new FastMap<String, Byte>();
  335. for (String ngtStack : negateAbnormals.split(";"))
  336. {
  337. String[] ngt = ngtStack.split(",");
  338. if (ngt.length == 1) // Only abnormalType is present, without abnormalLvl
  339. {
  340. _negateAbnormals.put(ngt[0], Byte.MAX_VALUE);
  341. }
  342. else if (ngt.length == 2) // Both abnormalType and abnormalLvl are present
  343. {
  344. try
  345. {
  346. _negateAbnormals.put(ngt[0], Byte.parseByte(ngt[1]));
  347. }
  348. catch (Exception e)
  349. {
  350. throw new IllegalArgumentException("SkillId: "+_id+" Byte value required, but found: "+ngt[1]);
  351. }
  352. }
  353. else // If not both from above, then smth is messed up... throw an error.
  354. throw new IllegalArgumentException("SkillId: "+_id+": Incorrect negate Abnormals for "+ngtStack+". Lvl: abnormalType1,abnormalLvl1;abnormalType2,abnormalLvl2;abnormalType3,abnormalLvl3... or abnormalType1;abnormalType2;abnormalType3...");
  355. }
  356. }
  357. else
  358. _negateAbnormals = null;
  359. String negateId = set.getString("negateId", null);
  360. if (negateId != null)
  361. {
  362. String[] valuesSplit = negateId.split(",");
  363. _negateId = new int[valuesSplit.length];
  364. for (int i = 0; i < valuesSplit.length;i++)
  365. {
  366. _negateId[i] = Integer.parseInt(valuesSplit[i]);
  367. }
  368. }
  369. else
  370. _negateId = new int[0];
  371. _maxNegatedEffects = set.getInteger("maxNegated", 0);
  372. _stayAfterDeath = set.getBool("stayAfterDeath", false);
  373. _stayOnSubclassChange = set.getBool("stayOnSubclassChange", true);
  374. _killByDOT = set.getBool("killByDOT", false);
  375. _isNeutral = set.getBool("neutral",false);
  376. _hitTime = set.getInteger("hitTime", 0);
  377. String hitTimings = set.getString("hitTimings", null);
  378. if (hitTimings != null)
  379. {
  380. try
  381. {
  382. String [] valuesSplit = hitTimings.split(",");
  383. _hitTimings = new int[valuesSplit.length];
  384. for (int i = 0; i < valuesSplit.length; i++)
  385. _hitTimings[i] = Integer.parseInt(valuesSplit[i]);
  386. }
  387. catch (Exception e)
  388. {
  389. throw new IllegalArgumentException("SkillId: "+_id+" invalid hitTimings value: "+hitTimings+", \"percent,percent,...percent\" required");
  390. }
  391. }
  392. else
  393. _hitTimings = new int[0];
  394. _coolTime = set.getInteger("coolTime", 0);
  395. _isDebuff = set.getBool("isDebuff", false);
  396. _feed = set.getInteger("feed", 0);
  397. String reuseHash = set.getString("sharedReuse", null);
  398. if (reuseHash != null)
  399. {
  400. try
  401. {
  402. String[] valuesSplit = reuseHash.split("-");
  403. _reuseHashCode = SkillTable.getSkillHashCode(Integer.parseInt(valuesSplit[0]), Integer.parseInt(valuesSplit[1]));
  404. }
  405. catch (Exception e)
  406. {
  407. throw new IllegalArgumentException("SkillId: "+_id+" invalid sharedReuse value: "+reuseHash+", \"skillId-skillLvl\" required");
  408. }
  409. }
  410. else
  411. _reuseHashCode = SkillTable.getSkillHashCode(_id, _level);
  412. if (Config.ENABLE_MODIFY_SKILL_REUSE && Config.SKILL_REUSE_LIST.containsKey(_id))
  413. {
  414. if ( Config.DEBUG )
  415. _log.info("*** Skill " + _name + " (" + _level + ") changed reuse from " + set.getInteger("reuseDelay", 0) + " to " + Config.SKILL_REUSE_LIST.get(_id) + " seconds.");
  416. _reuseDelay = Config.SKILL_REUSE_LIST.get(_id);
  417. }
  418. else
  419. {
  420. _reuseDelay = set.getInteger("reuseDelay", 0);
  421. }
  422. _buffDuration = set.getInteger("buffDuration", 0);
  423. _equipDelay = set.getInteger("equipDelay", 0);
  424. _skillRadius = set.getInteger("skillRadius", 80);
  425. _targetType = set.getEnum("target", SkillTargetType.class);
  426. _power = set.getFloat("power", 0.f);
  427. _pvpPower = set.getFloat("pvpPower", (float)getPower());
  428. _pvePower = set.getFloat("pvePower", (float)getPower());
  429. _magicLevel = set.getInteger("magicLvl", 0);
  430. _levelDepend = set.getInteger("lvlDepend", 0);
  431. _ignoreResists = set.getBool("ignoreResists", false);
  432. _minChance = set.getInteger("minChance", Config.MIN_DEBUFF_CHANCE);
  433. _maxChance = set.getInteger("maxChance", Config.MAX_DEBUFF_CHANCE);
  434. _stat = set.getEnum("stat", Stats.class, null);
  435. _ignoreShield = set.getBool("ignoreShld", false);
  436. _skillType = set.getEnum("skillType", L2SkillType.class);
  437. _effectType = set.getEnum("effectType", L2SkillType.class, null);
  438. _effectId = set.getInteger("effectId", 0);
  439. _effectLvl = set.getInteger("effectLevel", 0);
  440. _nextActionIsAttack = set.getBool("nextActionAttack", false);
  441. _removedOnAnyActionExceptMove = set.getBool("removedOnAnyActionExceptMove", false);
  442. _removedOnDamage = set.getBool("removedOnDamage", _skillType == L2SkillType.SLEEP);
  443. _element = set.getByte("element", (byte)-1);
  444. _elementPower = set.getInteger("elementPower", 0);
  445. _saveVs = set.getEnum("saveVs", BaseStats.class, null);
  446. _condition = set.getInteger("condition", 0);
  447. _conditionValue = set.getInteger("conditionValue", 0);
  448. _overhit = set.getBool("overHit", false);
  449. _isSuicideAttack = set.getBool("isSuicideAttack", false);
  450. String weaponsAllowedString = set.getString("weaponsAllowed", null);
  451. if (weaponsAllowedString != null && !weaponsAllowedString.trim().isEmpty())
  452. {
  453. int mask = 0;
  454. StringTokenizer st = new StringTokenizer(weaponsAllowedString, ",");
  455. while (st.hasMoreTokens())
  456. {
  457. int old = mask;
  458. String item = st.nextToken().trim();
  459. if (ItemTable._weaponTypes.containsKey(item))
  460. mask |= ItemTable._weaponTypes.get(item).mask();
  461. if (ItemTable._armorTypes.containsKey(item)) // for shield
  462. mask |= ItemTable._armorTypes.get(item).mask();
  463. if (old == mask)
  464. _log.info("[weaponsAllowed] Unknown item type name: "+item);
  465. }
  466. _weaponsAllowed = mask;
  467. }
  468. else
  469. _weaponsAllowed = 0;
  470. _armorsAllowed = set.getInteger("armorsAllowed", 0);
  471. _minPledgeClass = set.getInteger("minPledgeClass", 0);
  472. _isOffensive = set.getBool("offensive", isSkillTypeOffensive());
  473. _maxCharges = set.getInteger("maxCharges", 0);
  474. _numCharges = set.getInteger("numCharges", 0);
  475. _triggeredId = set.getInteger("triggeredId", 0);
  476. _triggeredLevel = set.getInteger("triggeredLevel", 0);
  477. _chanceType = set.getString("chanceType", "");
  478. if (_chanceType != "" && !_chanceType.isEmpty())
  479. _chanceCondition = ChanceCondition.parse(set);
  480. _numSouls = set.getInteger("num_souls", 0);
  481. _soulMaxConsume = set.getInteger("soulMaxConsumeCount", 0);
  482. _blowChance = set.getInteger("blowChance", 0);
  483. _soulConsume = set.getInteger("soulConsumeCount", 0);
  484. _expNeeded = set.getInteger("expNeeded", 0);
  485. _critChance = set.getInteger("critChance", 0);
  486. _transformId = set.getInteger("transformId", 0);
  487. _transformDuration = set.getInteger("transformDuration", 0);
  488. _isHeroSkill = HeroSkillTable.isHeroSkill(_id);
  489. _isGMSkill = GMSkillTable.isGMSkill(_id);
  490. _baseCritRate = set.getInteger("baseCritRate", (_skillType == L2SkillType.PDAM || _skillType == L2SkillType.BLOW) ? 0 : -1);
  491. _lethalEffect1 = set.getInteger("lethal1",0);
  492. _lethalEffect2 = set.getInteger("lethal2",0);
  493. _directHpDmg = set.getBool("dmgDirectlyToHp",false);
  494. _isTriggeredSkill = set.getBool("isTriggeredSkill",false);
  495. _isDance = set.getBool("isDance",false);
  496. _nextDanceCost = set.getInteger("nextDanceCost", 0);
  497. _sSBoost = set.getFloat("SSBoost", 0.f);
  498. _aggroPoints = set.getInteger("aggroPoints", 0);
  499. _flyType = set.getString("flyType", null);
  500. _flyRadius = set.getInteger("flyRadius", 0);
  501. _flyCourse = set.getFloat("flyCourse", 0);
  502. _canBeReflected = set.getBool("canBeReflected", true);
  503. _canBeDispeled = set.getBool("canBeDispeled", true);
  504. _isClanSkill = set.getBool("isClanSkill", false);
  505. _excludedFromCheck = set.getBool("excludedFromCheck", false);
  506. _dependOnTargetBuff = set.getFloat("dependOnTargetBuff", 0);
  507. _simultaneousCast = set.getBool("simultaneousCast", false);
  508. String capsuled_items = set.getString("capsuled_items_skill", null);
  509. if (capsuled_items != null)
  510. {
  511. if (capsuled_items.isEmpty())
  512. _log.warning("Empty Extractable Item Skill data in Skill Id: " + _id);
  513. _extractableItems = parseExtractableSkill(_id, _level, capsuled_items);
  514. }
  515. }
  516. public abstract void useSkill(L2Character caster, L2Object[] targets);
  517. public final boolean isPotion()
  518. {
  519. return _isPotion;
  520. }
  521. public final int getArmorsAllowed()
  522. {
  523. return _armorsAllowed;
  524. }
  525. public final int getConditionValue()
  526. {
  527. return _conditionValue;
  528. }
  529. public final L2SkillType getSkillType()
  530. {
  531. return _skillType;
  532. }
  533. public final SkillTraitType getTraitType()
  534. {
  535. return _traitType;
  536. }
  537. public final byte getElement()
  538. {
  539. return _element;
  540. }
  541. public final int getElementPower()
  542. {
  543. return _elementPower;
  544. }
  545. /**
  546. * Return the target type of the skill : SELF, PARTY, CLAN, PET...<BR><BR>
  547. * @return
  548. */
  549. public final SkillTargetType getTargetType()
  550. {
  551. return _targetType;
  552. }
  553. public final int getCondition()
  554. {
  555. return _condition;
  556. }
  557. public final boolean isOverhit()
  558. {
  559. return _overhit;
  560. }
  561. public final boolean killByDOT()
  562. {
  563. return _killByDOT;
  564. }
  565. public final boolean isSuicideAttack()
  566. {
  567. return _isSuicideAttack;
  568. }
  569. public final boolean allowOnTransform()
  570. {
  571. return isPassive();
  572. }
  573. /**
  574. * Return the power of the skill.
  575. * @param activeChar
  576. * @param target
  577. * @param isPvP
  578. * @param isPvE
  579. * @return
  580. */
  581. public final double getPower(L2Character activeChar, L2Character target, boolean isPvP, boolean isPvE)
  582. {
  583. if (activeChar == null)
  584. return getPower(isPvP, isPvE);
  585. switch (_skillType)
  586. {
  587. case DEATHLINK:
  588. {
  589. return getPower(isPvP, isPvE) * Math.pow(1.7165 - activeChar.getCurrentHp() / activeChar.getMaxHp(), 2) * 0.577;
  590. /*
  591. * DrHouse:
  592. * Rolling back to old formula (look below) for DEATHLINK due to this one based on logarithm is not
  593. * accurate enough. Commented here because probably is a matter of just adjusting a constant
  594. if(activeChar.getCurrentHp() / activeChar.getMaxHp() > 0.005)
  595. return _power*(-0.45*Math.log(activeChar.getCurrentHp()/activeChar.getMaxHp())+1.);
  596. else
  597. return _power*(-0.45*Math.log(0.005)+1.);
  598. */
  599. }
  600. case FATAL:
  601. {
  602. return getPower(isPvP, isPvE)*3.5*(1-target.getCurrentHp()/target.getMaxHp());
  603. }
  604. default:
  605. return getPower(isPvP, isPvE);
  606. }
  607. }
  608. public final double getPower()
  609. {
  610. return _power;
  611. }
  612. public final double getPower(boolean isPvP, boolean isPvE)
  613. {
  614. return isPvE ? _pvePower : isPvP ? _pvpPower : _power;
  615. }
  616. public final L2SkillType[] getNegateStats()
  617. {
  618. return _negateStats;
  619. }
  620. public final Map<String, Byte> getNegateAbnormals()
  621. {
  622. return _negateAbnormals;
  623. }
  624. public final int getAbnormalLvl()
  625. {
  626. return _abnormalLvl;
  627. }
  628. public final int getNegateLvl()
  629. {
  630. return _negateLvl;
  631. }
  632. public final int[] getNegateId()
  633. {
  634. return _negateId;
  635. }
  636. public final int getMagicLevel()
  637. {
  638. return _magicLevel;
  639. }
  640. public final int getMaxNegatedEffects()
  641. {
  642. return _maxNegatedEffects;
  643. }
  644. public final int getLevelDepend()
  645. {
  646. return _levelDepend;
  647. }
  648. /**
  649. * Return true if skill should ignore all resistances
  650. * @return
  651. */
  652. public final boolean ignoreResists()
  653. {
  654. return _ignoreResists;
  655. }
  656. /**
  657. * Return minimum skill/effect land rate (default is 1).
  658. * @return
  659. */
  660. public final int getMinChance()
  661. {
  662. return _minChance;
  663. }
  664. /**
  665. * Return maximum skill/effect land rate (default is 99).
  666. * @return
  667. */
  668. public final int getMaxChance()
  669. {
  670. return _maxChance;
  671. }
  672. /**
  673. * Return true if skill effects should be removed on any action except movement
  674. * @return
  675. */
  676. public final boolean isRemovedOnAnyActionExceptMove()
  677. {
  678. return _removedOnAnyActionExceptMove;
  679. }
  680. /**
  681. * Return true if skill effects should be removed on damage
  682. * @return
  683. */
  684. public final boolean isRemovedOnDamage()
  685. {
  686. return _removedOnDamage;
  687. }
  688. /**
  689. * Return the additional effect Id.<BR><BR>
  690. * @return
  691. */
  692. public final int getEffectId()
  693. {
  694. return _effectId;
  695. }
  696. /**
  697. * Return the additional effect level.<BR><BR>
  698. * @return
  699. */
  700. public final int getEffectLvl()
  701. {
  702. return _effectLvl;
  703. }
  704. public final int getEffectAbnormalLvl()
  705. {
  706. return _effectAbnormalLvl;
  707. }
  708. /**
  709. * Return the additional effect skill type (ex : STUN, PARALYZE,...).<BR><BR>
  710. * @return
  711. */
  712. public final L2SkillType getEffectType()
  713. {
  714. return _effectType;
  715. }
  716. /**
  717. * Return true if character should attack target after skill
  718. * @return
  719. */
  720. public final boolean nextActionIsAttack()
  721. {
  722. return _nextActionIsAttack;
  723. }
  724. /**
  725. * @return Returns the buffDuration.
  726. */
  727. public final int getBuffDuration()
  728. {
  729. return _buffDuration;
  730. }
  731. /**
  732. * @return Returns the castRange.
  733. */
  734. public final int getCastRange()
  735. {
  736. return _castRange;
  737. }
  738. /**
  739. * @return Returns the cpConsume;
  740. */
  741. public final int getCpConsume()
  742. {
  743. return _cpConsume;
  744. }
  745. /**
  746. * @return Returns the effectRange.
  747. */
  748. public final int getEffectRange()
  749. {
  750. return _effectRange;
  751. }
  752. /**
  753. * @return Returns the hpConsume.
  754. */
  755. public final int getHpConsume()
  756. {
  757. return _hpConsume;
  758. }
  759. /**
  760. * @return Returns the id.
  761. */
  762. public final int getId()
  763. {
  764. return _id;
  765. }
  766. /**
  767. * @return Returns the boolean _isDebuff.
  768. */
  769. public final boolean isDebuff()
  770. {
  771. return _isDebuff;
  772. }
  773. public int getDisplayId()
  774. {
  775. return _displayId;
  776. }
  777. public void setDisplayId(int id)
  778. {
  779. _displayId = id;
  780. }
  781. public int getTriggeredId()
  782. {
  783. return _triggeredId;
  784. }
  785. public int getTriggeredLevel()
  786. {
  787. return _triggeredLevel;
  788. }
  789. public boolean triggerAnotherSkill()
  790. {
  791. return _triggeredId > 1;
  792. }
  793. /**
  794. * Return the skill type (ex : BLEED, SLEEP, WATER...).
  795. * @return
  796. */
  797. public final Stats getStat()
  798. {
  799. return _stat;
  800. }
  801. /**
  802. * Return skill saveVs base stat (STR, INT ...).
  803. * @return
  804. */
  805. public final BaseStats getSaveVs()
  806. {
  807. return _saveVs;
  808. }
  809. /**
  810. * @return Returns the _targetConsumeId.
  811. */
  812. public final int getTargetConsumeId()
  813. {
  814. return _targetConsumeId;
  815. }
  816. /**
  817. * @return Returns the targetConsume.
  818. */
  819. public final int getTargetConsume()
  820. {
  821. return _targetConsume;
  822. }
  823. /**
  824. * @return Returns the itemConsume.
  825. */
  826. public final int getItemConsume()
  827. {
  828. return _itemConsume;
  829. }
  830. /**
  831. * @return Returns the itemConsumeId.
  832. */
  833. public final int getItemConsumeId()
  834. {
  835. return _itemConsumeId;
  836. }
  837. /**
  838. * @return Returns the level.
  839. */
  840. public final int getLevel()
  841. {
  842. return _level;
  843. }
  844. /**
  845. * @return Returns the magic.
  846. */
  847. public final boolean isMagic()
  848. {
  849. return _magic;
  850. }
  851. /**
  852. * @return Returns true to set static reuse.
  853. */
  854. public final boolean isStaticReuse()
  855. {
  856. return _staticReuse;
  857. }
  858. /**
  859. * @return Returns true to set static hittime.
  860. */
  861. public final boolean isStaticHitTime()
  862. {
  863. return _staticHitTime;
  864. }
  865. public final boolean isStaticDamage()
  866. {
  867. return _staticDamage;
  868. }
  869. /**
  870. * @return Returns the mpConsume.
  871. */
  872. public final int getMpConsume()
  873. {
  874. return _mpConsume;
  875. }
  876. /**
  877. * @return Returns the mpInitialConsume.
  878. */
  879. public final int getMpInitialConsume()
  880. {
  881. return _mpInitialConsume;
  882. }
  883. /**
  884. * @return Returns the name.
  885. */
  886. public final String getName()
  887. {
  888. return _name;
  889. }
  890. /**
  891. * @return Returns the reuseDelay.
  892. */
  893. public final int getReuseDelay()
  894. {
  895. return _reuseDelay;
  896. }
  897. public final int getReuseHashCode()
  898. {
  899. return _reuseHashCode;
  900. }
  901. public final int getEquipDelay()
  902. {
  903. return _equipDelay;
  904. }
  905. public final int getHitTime()
  906. {
  907. return _hitTime;
  908. }
  909. public final int getHitCounts()
  910. {
  911. return _hitTimings.length;
  912. }
  913. public final int[] getHitTimings()
  914. {
  915. return _hitTimings;
  916. }
  917. /**
  918. * @return Returns the coolTime.
  919. */
  920. public final int getCoolTime()
  921. {
  922. return _coolTime;
  923. }
  924. public final int getSkillRadius()
  925. {
  926. return _skillRadius;
  927. }
  928. public final boolean isActive()
  929. {
  930. return _operateType == SkillOpType.OP_ACTIVE;
  931. }
  932. public final boolean isPassive()
  933. {
  934. return _operateType == SkillOpType.OP_PASSIVE;
  935. }
  936. public final boolean isToggle()
  937. {
  938. return _operateType == SkillOpType.OP_TOGGLE;
  939. }
  940. public final boolean isChance()
  941. {
  942. return _chanceCondition != null && isPassive();
  943. }
  944. public final boolean isTriggeredSkill()
  945. {
  946. return _isTriggeredSkill;
  947. }
  948. public final boolean isDance()
  949. {
  950. return _isDance;
  951. }
  952. public final int getNextDanceMpCost()
  953. {
  954. return _nextDanceCost;
  955. }
  956. public final float getSSBoost()
  957. {
  958. return _sSBoost;
  959. }
  960. public final int getAggroPoints()
  961. {
  962. return _aggroPoints;
  963. }
  964. public final boolean useSoulShot()
  965. {
  966. switch (getSkillType())
  967. {
  968. case PDAM:
  969. case CHARGEDAM:
  970. case BLOW:
  971. return true;
  972. default:
  973. return false;
  974. }
  975. }
  976. public final boolean useSpiritShot()
  977. {
  978. return isMagic();
  979. }
  980. public final boolean useFishShot()
  981. {
  982. return ((getSkillType() == L2SkillType.PUMPING) || (getSkillType() == L2SkillType.REELING) );
  983. }
  984. public final int getWeaponsAllowed()
  985. {
  986. return _weaponsAllowed;
  987. }
  988. public int getMinPledgeClass() { return _minPledgeClass; }
  989. public final boolean isPvpSkill()
  990. {
  991. switch (_skillType)
  992. {
  993. case DOT:
  994. case BLEED:
  995. case CONFUSION:
  996. case POISON:
  997. case DEBUFF:
  998. case AGGDEBUFF:
  999. case STUN:
  1000. case ROOT:
  1001. case FEAR:
  1002. case SLEEP:
  1003. case MDOT:
  1004. case MUTE:
  1005. case PARALYZE:
  1006. case CANCEL:
  1007. case BETRAY:
  1008. case DISARM:
  1009. case AGGDAMAGE:
  1010. case STEAL_BUFF:
  1011. case AGGREDUCE_CHAR:
  1012. case MANADAM:
  1013. return true;
  1014. default:
  1015. return false;
  1016. }
  1017. }
  1018. public final boolean isOffensive()
  1019. {
  1020. return _isOffensive;
  1021. }
  1022. public final boolean isNeutral()
  1023. {
  1024. return _isNeutral;
  1025. }
  1026. public final boolean isHeroSkill()
  1027. {
  1028. return _isHeroSkill;
  1029. }
  1030. public final boolean isGMSkill()
  1031. {
  1032. return _isGMSkill;
  1033. }
  1034. public final int getNumCharges()
  1035. {
  1036. return _numCharges;
  1037. }
  1038. public final int getNumSouls()
  1039. {
  1040. return _numSouls;
  1041. }
  1042. public final int getMaxSoulConsumeCount()
  1043. {
  1044. return _soulMaxConsume;
  1045. }
  1046. public final int getSoulConsumeCount()
  1047. {
  1048. return _soulConsume;
  1049. }
  1050. public final int getExpNeeded()
  1051. {
  1052. return _expNeeded;
  1053. }
  1054. public final int getCritChance()
  1055. {
  1056. return _critChance;
  1057. }
  1058. public final int getTransformId()
  1059. {
  1060. return _transformId;
  1061. }
  1062. public final int getTransformDuration()
  1063. {
  1064. return _transformDuration;
  1065. }
  1066. public final int getBaseCritRate()
  1067. {
  1068. return _baseCritRate;
  1069. }
  1070. public final int getLethalChance1()
  1071. {
  1072. return _lethalEffect1;
  1073. }
  1074. public final int getLethalChance2()
  1075. {
  1076. return _lethalEffect2;
  1077. }
  1078. public final boolean getDmgDirectlyToHP()
  1079. {
  1080. return _directHpDmg;
  1081. }
  1082. public final String getFlyType()
  1083. {
  1084. return _flyType;
  1085. }
  1086. public final int getFlyRadius()
  1087. {
  1088. return _flyRadius;
  1089. }
  1090. public final float getFlyCourse()
  1091. {
  1092. return _flyCourse;
  1093. }
  1094. public final boolean isSkillTypeOffensive()
  1095. {
  1096. switch (_skillType)
  1097. {
  1098. case PDAM:
  1099. case MDAM:
  1100. case CPDAM:
  1101. case DOT:
  1102. case CPDAMPERCENT:
  1103. case BLEED:
  1104. case POISON:
  1105. case AGGDAMAGE:
  1106. case DEBUFF:
  1107. case AGGDEBUFF:
  1108. case STUN:
  1109. case ROOT:
  1110. case CONFUSION:
  1111. case ERASE:
  1112. case BLOW:
  1113. case FATAL:
  1114. case FEAR:
  1115. case DRAIN:
  1116. case SLEEP:
  1117. case CHARGEDAM:
  1118. case CONFUSE_MOB_ONLY:
  1119. case DEATHLINK:
  1120. case DETECT_WEAKNESS:
  1121. case MANADAM:
  1122. case MDOT:
  1123. case MUTE:
  1124. case SOULSHOT:
  1125. case SPIRITSHOT:
  1126. case SPOIL:
  1127. case SWEEP:
  1128. case PARALYZE:
  1129. case DRAIN_SOUL:
  1130. case AGGREDUCE:
  1131. case CANCEL:
  1132. case AGGREMOVE:
  1133. case AGGREDUCE_CHAR:
  1134. case BETRAY:
  1135. case DELUXE_KEY_UNLOCK:
  1136. case SOW:
  1137. case HARVEST:
  1138. case DISARM:
  1139. case STEAL_BUFF:
  1140. case INSTANT_JUMP:
  1141. return true;
  1142. default:
  1143. return this.isDebuff();
  1144. }
  1145. }
  1146. public final boolean is7Signs()
  1147. {
  1148. if (_id > 4360 && _id < 4367)
  1149. return true;
  1150. return false;
  1151. }
  1152. public final boolean isStayAfterDeath()
  1153. {
  1154. return _stayAfterDeath;
  1155. }
  1156. public final boolean isStayOnSubclassChange()
  1157. {
  1158. return _stayOnSubclassChange;
  1159. }
  1160. // int weapons[] = {L2Weapon.WEAPON_TYPE_ETC, L2Weapon.WEAPON_TYPE_BOW,
  1161. // L2Weapon.WEAPON_TYPE_POLE, L2Weapon.WEAPON_TYPE_DUALFIST,
  1162. // L2Weapon.WEAPON_TYPE_DUAL, L2Weapon.WEAPON_TYPE_BLUNT,
  1163. // L2Weapon.WEAPON_TYPE_SWORD, L2Weapon.WEAPON_TYPE_DAGGER};
  1164. public final boolean getWeaponDependancy(L2Character activeChar)
  1165. {
  1166. if(getWeaponDependancy(activeChar, false))
  1167. {
  1168. return true;
  1169. }
  1170. final SystemMessage message = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  1171. message.addSkillName(this);
  1172. activeChar.sendPacket(message);
  1173. return false;
  1174. }
  1175. public final boolean getWeaponDependancy(L2Character activeChar,boolean chance)
  1176. {
  1177. int weaponsAllowed = getWeaponsAllowed();
  1178. //check to see if skill has a weapon dependency.
  1179. if (weaponsAllowed == 0)
  1180. return true;
  1181. int mask = 0;
  1182. if (activeChar.getActiveWeaponItem() != null)
  1183. mask |= activeChar.getActiveWeaponItem().getItemType().mask();
  1184. if (activeChar.getSecondaryWeaponItem() != null && activeChar.getSecondaryWeaponItem() instanceof L2Armor)
  1185. mask |= ((L2ArmorType) activeChar.getSecondaryWeaponItem().getItemType()).mask();
  1186. if ((mask & weaponsAllowed) != 0)
  1187. return true;
  1188. return false;
  1189. }
  1190. public boolean checkCondition(L2Character activeChar, L2Object target, boolean itemOrWeapon)
  1191. {
  1192. if (activeChar.isGM() && !Config.GM_SKILL_RESTRICTION)
  1193. return true;
  1194. if ((getCondition() & L2Skill.COND_SHIELD) != 0)
  1195. {
  1196. /*
  1197. L2Armor armorPiece;
  1198. L2ItemInstance dummy;
  1199. dummy = activeChar.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  1200. armorPiece = (L2Armor) dummy.getItem();
  1201. */
  1202. //TODO add checks for shield here.
  1203. }
  1204. List<Condition> preCondition = _preCondition;
  1205. if(itemOrWeapon) preCondition = _itemPreCondition;
  1206. if (preCondition == null || preCondition.isEmpty()) return true;
  1207. for(Condition cond : preCondition)
  1208. {
  1209. Env env = new Env();
  1210. env.player = activeChar;
  1211. if (target instanceof L2Character) // TODO: object or char?
  1212. env.target = (L2Character)target;
  1213. env.skill = this;
  1214. if (!cond.test(env))
  1215. {
  1216. String msg = cond.getMessage();
  1217. int msgId = cond.getMessageId();
  1218. if (msgId != 0)
  1219. {
  1220. SystemMessage sm = SystemMessage.getSystemMessage(msgId);
  1221. if (cond.isAddName())
  1222. sm.addSkillName(_id);
  1223. activeChar.sendPacket(sm);
  1224. }
  1225. else if (msg != null)
  1226. {
  1227. activeChar.sendMessage(msg);
  1228. }
  1229. return false;
  1230. }
  1231. }
  1232. return true;
  1233. }
  1234. public final L2Object[] getTargetList(L2Character activeChar, boolean onlyFirst)
  1235. {
  1236. // Init to null the target of the skill
  1237. L2Character target = null;
  1238. // Get the L2Objcet targeted by the user of the skill at this moment
  1239. L2Object objTarget = activeChar.getTarget();
  1240. // If the L2Object targeted is a L2Character, it becomes the L2Character target
  1241. if (objTarget instanceof L2Character)
  1242. {
  1243. target = (L2Character) objTarget;
  1244. }
  1245. return getTargetList(activeChar, onlyFirst, target);
  1246. }
  1247. /**
  1248. * Return all targets of the skill in a table in function a the skill type.<BR><BR>
  1249. *
  1250. * <B><U> Values of skill type</U> :</B><BR><BR>
  1251. * <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>
  1252. * <li>SELF</li>
  1253. * <li>HOLY, UNDEAD</li>
  1254. * <li>PET</li>
  1255. * <li>AURA, AURA_CLOSE</li>
  1256. * <li>AREA</li>
  1257. * <li>MULTIFACE</li>
  1258. * <li>PARTY, CLAN</li>
  1259. * <li>CORPSE_PLAYER, CORPSE_MOB, CORPSE_CLAN</li>
  1260. * <li>UNLOCKABLE</li>
  1261. * <li>ITEM</li><BR><BR>
  1262. *
  1263. * @param activeChar The L2Character who use the skill
  1264. * @param onlyFirst
  1265. * @param target
  1266. * @return
  1267. *
  1268. */
  1269. public final L2Object[] getTargetList(L2Character activeChar, boolean onlyFirst, L2Character target)
  1270. {
  1271. List<L2Character> targetList = new FastList<L2Character>();
  1272. // Get the target type of the skill
  1273. // (ex : ONE, SELF, HOLY, PET, AURA, AURA_CLOSE, AREA, MULTIFACE, PARTY, CLAN, CORPSE_PLAYER, CORPSE_MOB, CORPSE_CLAN, UNLOCKABLE, ITEM, UNDEAD)
  1274. SkillTargetType targetType = getTargetType();
  1275. // Get the type of the skill
  1276. // (ex : PDAM, MDAM, DOT, BLEED, POISON, HEAL, HOT, MANAHEAL, MANARECHARGE, AGGDAMAGE, BUFF, DEBUFF, STUN, ROOT, RESURRECT, PASSIVE...)
  1277. L2SkillType skillType = getSkillType();
  1278. switch (targetType)
  1279. {
  1280. // The skill can only be used on the L2Character targeted, or on the caster itself
  1281. case TARGET_ONE:
  1282. {
  1283. boolean canTargetSelf = false;
  1284. switch (skillType)
  1285. {
  1286. case BUFF:
  1287. case HEAL:
  1288. case HOT:
  1289. case HEAL_PERCENT:
  1290. case MANARECHARGE:
  1291. case MANA_BY_LEVEL:
  1292. case MANAHEAL:
  1293. case NEGATE:
  1294. case CANCEL_DEBUFF:
  1295. case COMBATPOINTHEAL:
  1296. case BALANCE_LIFE:
  1297. case HPMPCPHEAL_PERCENT:
  1298. case HPMPHEAL_PERCENT:
  1299. case HPCPHEAL_PERCENT:
  1300. canTargetSelf = true;
  1301. break;
  1302. }
  1303. // Check for null target or any other invalid target
  1304. if (target == null || target.isDead() || (target == activeChar && !canTargetSelf))
  1305. {
  1306. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1307. return _emptyTargetList;
  1308. }
  1309. // If a target is found, return it in a table else send a system message TARGET_IS_INCORRECT
  1310. return new L2Character[] {target};
  1311. }
  1312. case TARGET_SELF:
  1313. case TARGET_GROUND:
  1314. {
  1315. return new L2Character[] {activeChar};
  1316. }
  1317. case TARGET_HOLY:
  1318. {
  1319. if (activeChar instanceof L2PcInstance)
  1320. {
  1321. if (target instanceof L2ArtefactInstance)
  1322. return new L2Character[] {target};
  1323. }
  1324. return _emptyTargetList;
  1325. }
  1326. case TARGET_FLAGPOLE:
  1327. {
  1328. return new L2Character[] {activeChar};
  1329. }
  1330. case TARGET_PET:
  1331. {
  1332. target = activeChar.getPet();
  1333. if (target != null && !target.isDead()) return new L2Character[] {target};
  1334. return _emptyTargetList;
  1335. }
  1336. case TARGET_SUMMON:
  1337. {
  1338. target = activeChar.getPet();
  1339. if (target != null && !target.isDead() && target instanceof L2SummonInstance) return new L2Character[] {target};
  1340. return _emptyTargetList;
  1341. }
  1342. case TARGET_OWNER_PET:
  1343. {
  1344. if (activeChar instanceof L2Summon)
  1345. {
  1346. target = ((L2Summon)activeChar).getOwner();
  1347. if (target != null && !target.isDead())
  1348. return new L2Character[]{target};
  1349. }
  1350. return _emptyTargetList;
  1351. }
  1352. case TARGET_CORPSE_PET:
  1353. {
  1354. if (activeChar instanceof L2PcInstance)
  1355. {
  1356. target = activeChar.getPet();
  1357. if (target != null && target.isDead())
  1358. return new L2Character[]{target};
  1359. }
  1360. return _emptyTargetList;
  1361. }
  1362. case TARGET_AURA:
  1363. case TARGET_FRONT_AURA:
  1364. case TARGET_BEHIND_AURA:
  1365. {
  1366. final boolean srcInArena = (activeChar.isInsideZone(L2Character.ZONE_PVP) && !activeChar.isInsideZone(L2Character.ZONE_SIEGE));
  1367. final L2PcInstance sourcePlayer = activeChar.getActingPlayer();
  1368. // Go through the L2Character _knownList
  1369. final Collection<L2Character> objs = activeChar.getKnownList().getKnownCharactersInRadius(getSkillRadius());
  1370. if (getSkillType() == L2SkillType.DUMMY)
  1371. {
  1372. if (onlyFirst)
  1373. return new L2Character[] { activeChar };
  1374. targetList.add(activeChar);
  1375. for (L2Character obj : objs)
  1376. {
  1377. if (!(obj == activeChar
  1378. || obj == sourcePlayer
  1379. || obj instanceof L2Npc
  1380. || obj instanceof L2Attackable))
  1381. continue;
  1382. targetList.add(obj);
  1383. }
  1384. }
  1385. else
  1386. {
  1387. for (L2Character obj : objs)
  1388. {
  1389. if (obj instanceof L2Attackable || obj instanceof L2Playable)
  1390. {
  1391. switch (targetType)
  1392. {
  1393. case TARGET_FRONT_AURA:
  1394. if (!obj.isInFrontOf(activeChar))
  1395. continue;
  1396. break;
  1397. case TARGET_BEHIND_AURA:
  1398. if(!obj.isBehind(activeChar))
  1399. continue;
  1400. break;
  1401. }
  1402. if (!checkForAreaOffensiveSkills(activeChar, obj, this, srcInArena))
  1403. continue;
  1404. if (onlyFirst)
  1405. return new L2Character[] { obj };
  1406. targetList.add(obj);
  1407. }
  1408. }
  1409. }
  1410. return targetList.toArray(new L2Character[targetList.size()]);
  1411. }
  1412. case TARGET_AREA_SUMMON:
  1413. {
  1414. target = activeChar.getPet();
  1415. if (target == null || !(target instanceof L2SummonInstance) || target.isDead())
  1416. return _emptyTargetList;
  1417. if(onlyFirst)
  1418. return new L2Character[]{target};
  1419. final boolean srcInArena = (activeChar.isInsideZone(L2Character.ZONE_PVP) && !activeChar.isInsideZone(L2Character.ZONE_SIEGE));
  1420. final Collection<L2Character> objs = target.getKnownList().getKnownCharacters();
  1421. final int radius = getSkillRadius();
  1422. for (L2Character obj : objs)
  1423. {
  1424. if (obj == null || obj == target || obj == activeChar)
  1425. continue;
  1426. if (!Util.checkIfInRange(radius, target, obj, true))
  1427. continue;
  1428. if (!(obj instanceof L2Attackable || obj instanceof L2Playable))
  1429. continue;
  1430. if (!checkForAreaOffensiveSkills(activeChar, obj, this, srcInArena))
  1431. continue;
  1432. targetList.add(obj);
  1433. }
  1434. if (targetList.isEmpty())
  1435. return _emptyTargetList;
  1436. return targetList.toArray(new L2Character[targetList.size()]);
  1437. }
  1438. case TARGET_AREA:
  1439. case TARGET_FRONT_AREA:
  1440. case TARGET_BEHIND_AREA:
  1441. {
  1442. if (((target == null || target == activeChar || target.isAlikeDead()) && getCastRange() >= 0) ||
  1443. (!(target instanceof L2Attackable || target instanceof L2Playable)))
  1444. {
  1445. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1446. return _emptyTargetList;
  1447. }
  1448. final L2Character origin;
  1449. final boolean srcInArena = (activeChar.isInsideZone(L2Character.ZONE_PVP) && !activeChar.isInsideZone(L2Character.ZONE_SIEGE));
  1450. final int radius = getSkillRadius();
  1451. if (getCastRange() >= 0)
  1452. {
  1453. if (!checkForAreaOffensiveSkills(activeChar, target, this, srcInArena))
  1454. return _emptyTargetList;
  1455. if(onlyFirst)
  1456. return new L2Character[]{target};
  1457. origin = target;
  1458. targetList.add(origin); // Add target to target list
  1459. }
  1460. else
  1461. origin = activeChar;
  1462. final Collection<L2Character> objs = activeChar.getKnownList().getKnownCharacters();
  1463. {
  1464. for (L2Character obj : objs)
  1465. {
  1466. if (!(obj instanceof L2Attackable
  1467. || obj instanceof L2Playable))
  1468. continue;
  1469. if (obj == origin)
  1470. continue;
  1471. if (Util.checkIfInRange(radius, origin, obj, true))
  1472. {
  1473. switch (targetType)
  1474. {
  1475. case TARGET_FRONT_AREA:
  1476. if (!obj.isInFrontOf(activeChar))
  1477. continue;
  1478. break;
  1479. case TARGET_BEHIND_AREA:
  1480. if (!obj.isBehind(activeChar))
  1481. continue;
  1482. break;
  1483. }
  1484. if (!checkForAreaOffensiveSkills(activeChar, obj, this, srcInArena))
  1485. continue;
  1486. targetList.add(obj);
  1487. }
  1488. }
  1489. }
  1490. if (targetList.isEmpty())
  1491. return _emptyTargetList;
  1492. return targetList.toArray(new L2Character[targetList.size()]);
  1493. }
  1494. case TARGET_PARTY:
  1495. {
  1496. if (onlyFirst)
  1497. return new L2Character[]{activeChar};
  1498. targetList.add(activeChar);
  1499. final int radius = getSkillRadius();
  1500. L2PcInstance player = activeChar.getActingPlayer();
  1501. if (activeChar instanceof L2Summon)
  1502. {
  1503. if (addCharacter(activeChar, player, radius, false))
  1504. targetList.add(player);
  1505. }
  1506. else if (activeChar instanceof L2PcInstance)
  1507. {
  1508. if (addSummon(activeChar, player, radius, false))
  1509. targetList.add(player.getPet());
  1510. }
  1511. if (activeChar.isInParty())
  1512. {
  1513. // Get a list of Party Members
  1514. for(L2PcInstance partyMember : activeChar.getParty().getPartyMembers())
  1515. {
  1516. if (partyMember == null || partyMember == player)
  1517. continue;
  1518. if (addCharacter(activeChar, partyMember, radius, false))
  1519. targetList.add(partyMember);
  1520. if (addSummon(activeChar, partyMember, radius, false))
  1521. targetList.add(partyMember.getPet());
  1522. }
  1523. }
  1524. return targetList.toArray(new L2Character[targetList.size()]);
  1525. }
  1526. case TARGET_PARTY_MEMBER:
  1527. {
  1528. if ((target != null
  1529. && target == activeChar)
  1530. || (target != null
  1531. && activeChar.isInParty()
  1532. && target.isInParty()
  1533. && activeChar.getParty().getPartyLeaderOID() == target.getParty().getPartyLeaderOID())
  1534. || (target != null
  1535. && activeChar instanceof L2PcInstance
  1536. && target instanceof L2Summon
  1537. && activeChar.getPet() == target)
  1538. || (target != null
  1539. && activeChar instanceof L2Summon
  1540. && target instanceof L2PcInstance
  1541. && activeChar == target.getPet()))
  1542. {
  1543. if (!target.isDead())
  1544. {
  1545. // If a target is found, return it in a table else send a system message TARGET_IS_INCORRECT
  1546. return new L2Character[]{target};
  1547. }
  1548. }
  1549. else
  1550. {
  1551. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1552. }
  1553. return _emptyTargetList;
  1554. }
  1555. case TARGET_PARTY_OTHER:
  1556. {
  1557. if (target != null && target != activeChar
  1558. && activeChar.isInParty() && target.isInParty()
  1559. && activeChar.getParty().getPartyLeaderOID() == target.getParty().getPartyLeaderOID())
  1560. {
  1561. if (!target.isDead())
  1562. {
  1563. if (target instanceof L2PcInstance)
  1564. {
  1565. switch (getId())
  1566. {
  1567. // FORCE BUFFS may cancel here but there should be a proper condition
  1568. case 426:
  1569. if (!((L2PcInstance)target).isMageClass())
  1570. return new L2Character[]{target};
  1571. return _emptyTargetList;
  1572. case 427:
  1573. if (((L2PcInstance)target).isMageClass())
  1574. return new L2Character[]{target};
  1575. return _emptyTargetList;
  1576. }
  1577. }
  1578. return new L2Character[]{target};
  1579. }
  1580. }
  1581. else
  1582. {
  1583. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1584. }
  1585. return _emptyTargetList;
  1586. }
  1587. case TARGET_CORPSE_ALLY:
  1588. case TARGET_ALLY:
  1589. {
  1590. if (activeChar instanceof L2Playable)
  1591. {
  1592. final L2PcInstance player = activeChar.getActingPlayer();
  1593. if (player == null)
  1594. return _emptyTargetList;
  1595. if (player.isInOlympiadMode())
  1596. return new L2Character[] {player};
  1597. final boolean isCorpseType = targetType == SkillTargetType.TARGET_CORPSE_ALLY;
  1598. if (!isCorpseType)
  1599. {
  1600. if (onlyFirst)
  1601. return new L2Character[] {player};
  1602. targetList.add(player);
  1603. }
  1604. final int radius = getSkillRadius();
  1605. if (addSummon(activeChar, player, radius, isCorpseType))
  1606. targetList.add(player.getPet());
  1607. if (player.getClan() != null)
  1608. {
  1609. // Get all visible objects in a spherical area near the L2Character
  1610. final Collection<L2PcInstance> objs = activeChar.getKnownList().getKnownPlayersInRadius(radius);
  1611. for (L2PcInstance obj : objs)
  1612. {
  1613. if (obj == null)
  1614. continue;
  1615. if ((obj.getAllyId() == 0 || obj.getAllyId() != player.getAllyId())
  1616. && (obj.getClan() == null || obj.getClanId() != player.getClanId()))
  1617. continue;
  1618. if (player.isInDuel())
  1619. {
  1620. if (player.getDuelId() != obj.getDuelId())
  1621. continue;
  1622. if (player.isInParty() && obj.isInParty() && player.getParty().getPartyLeaderOID() != obj.getParty().getPartyLeaderOID())
  1623. continue;
  1624. }
  1625. // Don't add this target if this is a Pc->Pc pvp
  1626. // casting and pvp condition not met
  1627. if (!player.checkPvpSkill(obj, this))
  1628. continue;
  1629. if (!TvTEvent.checkForTvTSkill(player, obj, this))
  1630. continue;
  1631. if (!onlyFirst && addSummon(activeChar, obj, radius, isCorpseType))
  1632. targetList.add(obj.getPet());
  1633. if (!addCharacter(activeChar, obj, radius, isCorpseType))
  1634. continue;
  1635. if (isCorpseType)
  1636. {
  1637. // Siege battlefield resurrect has been made possible for participants
  1638. if (getSkillType() == L2SkillType.RESURRECT)
  1639. {
  1640. if (obj.isInsideZone(L2Character.ZONE_SIEGE) && !obj.isInSiege())
  1641. continue;
  1642. }
  1643. }
  1644. if (onlyFirst)
  1645. return new L2Character[] { obj };
  1646. targetList.add(obj);
  1647. }
  1648. }
  1649. }
  1650. return targetList.toArray(new L2Character[targetList.size()]);
  1651. }
  1652. case TARGET_CORPSE_CLAN:
  1653. case TARGET_CLAN:
  1654. {
  1655. if (activeChar instanceof L2Playable)
  1656. {
  1657. final L2PcInstance player = activeChar.getActingPlayer();
  1658. if (player == null)
  1659. return _emptyTargetList;
  1660. if (player.isInOlympiadMode())
  1661. return new L2Character[] {player};
  1662. final boolean isCorpseType = targetType == SkillTargetType.TARGET_CORPSE_CLAN;
  1663. if (!isCorpseType)
  1664. {
  1665. if (onlyFirst)
  1666. return new L2Character[] {player};
  1667. targetList.add(player);
  1668. }
  1669. final int radius = getSkillRadius();
  1670. final L2Clan clan = player.getClan();
  1671. if (addSummon(activeChar, player, radius, isCorpseType))
  1672. targetList.add(player.getPet());
  1673. if (clan != null)
  1674. {
  1675. L2PcInstance obj;
  1676. // Get Clan Members
  1677. for (L2ClanMember member : clan.getMembers())
  1678. {
  1679. obj = member.getPlayerInstance();
  1680. if (obj == null || obj == player)
  1681. continue;
  1682. if (player.isInDuel())
  1683. {
  1684. if (player.getDuelId() != obj.getDuelId())
  1685. continue;
  1686. if (player.isInParty() && obj.isInParty() && player.getParty().getPartyLeaderOID() != obj.getParty().getPartyLeaderOID())
  1687. continue;
  1688. }
  1689. // Don't add this target if this is a Pc->Pc pvp casting and pvp condition not met
  1690. if (!player.checkPvpSkill(obj, this))
  1691. continue;
  1692. if (!TvTEvent.checkForTvTSkill(player, obj, this))
  1693. continue;
  1694. if (!onlyFirst && addSummon(activeChar, obj, radius, isCorpseType))
  1695. targetList.add(obj.getPet());
  1696. if (!addCharacter(activeChar, obj, radius, isCorpseType))
  1697. continue;
  1698. if (isCorpseType)
  1699. {
  1700. if (getSkillType() == L2SkillType.RESURRECT)
  1701. {
  1702. // check target is not in a active siege zone
  1703. if (obj.isInsideZone(L2Character.ZONE_SIEGE) && !obj.isInSiege())
  1704. continue;
  1705. }
  1706. }
  1707. if (onlyFirst)
  1708. return new L2Character[] {obj};
  1709. targetList.add(obj);
  1710. }
  1711. }
  1712. }
  1713. else if (activeChar instanceof L2Npc)
  1714. {
  1715. // for buff purposes, returns friendly mobs nearby and mob itself
  1716. final L2Npc npc = (L2Npc) activeChar;
  1717. if (npc.getFactionId() == null || npc.getFactionId().isEmpty())
  1718. {
  1719. return new L2Character[]{activeChar};
  1720. }
  1721. targetList.add(activeChar);
  1722. final Collection<L2Object> objs = activeChar.getKnownList().getKnownObjects().values();
  1723. for (L2Object newTarget : objs)
  1724. {
  1725. if (newTarget instanceof L2Npc
  1726. && npc.getFactionId().equals(((L2Npc) newTarget).getFactionId()))
  1727. {
  1728. if (!Util.checkIfInRange(getCastRange(), activeChar, newTarget, true))
  1729. continue;
  1730. targetList.add((L2Npc) newTarget);
  1731. }
  1732. }
  1733. }
  1734. return targetList.toArray(new L2Character[targetList.size()]);
  1735. }
  1736. case TARGET_PARTY_CLAN:
  1737. {
  1738. if (onlyFirst)
  1739. return new L2Character[]{activeChar};
  1740. final L2PcInstance player = activeChar.getActingPlayer();
  1741. if (player == null)
  1742. return _emptyTargetList;
  1743. targetList.add(player);
  1744. final int radius = getSkillRadius();
  1745. final boolean hasClan = player.getClan() != null;
  1746. final boolean hasParty = player.isInParty();
  1747. if (addSummon(activeChar, player, radius, false))
  1748. targetList.add(player.getPet());
  1749. // if player in clan and not in party
  1750. if (!(hasClan || hasParty))
  1751. return targetList.toArray(new L2Character[targetList.size()]);
  1752. // Get all visible objects in a spherical area near the L2Character
  1753. final Collection<L2PcInstance> objs = activeChar.getKnownList().getKnownPlayersInRadius(radius);
  1754. for (L2PcInstance obj : objs)
  1755. {
  1756. if (obj == null)
  1757. continue;
  1758. // olympiad mode - adding only own side
  1759. if (player.isInOlympiadMode())
  1760. {
  1761. if (!obj.isInOlympiadMode())
  1762. continue;
  1763. if (player.getOlympiadGameId() != obj.getOlympiadGameId())
  1764. continue;
  1765. if (player.getOlympiadSide() != obj.getOlympiadSide())
  1766. continue;
  1767. }
  1768. if (player.isInDuel())
  1769. {
  1770. if (player.getDuelId() != obj.getDuelId())
  1771. continue;
  1772. if (hasParty && obj.isInParty() && player.getParty().getPartyLeaderOID() != obj.getParty().getPartyLeaderOID())
  1773. continue;
  1774. }
  1775. if (!((hasClan && obj.getClanId() == player.getClanId())
  1776. || (hasParty && obj.isInParty() && player.getParty().getPartyLeaderOID() == obj.getParty().getPartyLeaderOID())))
  1777. continue;
  1778. // Don't add this target if this is a Pc->Pc pvp
  1779. // casting and pvp condition not met
  1780. if (!player.checkPvpSkill(obj, this))
  1781. continue;
  1782. if (!TvTEvent.checkForTvTSkill(player, obj, this))
  1783. continue;
  1784. if (!onlyFirst && addSummon(activeChar, obj, radius, false))
  1785. targetList.add(obj.getPet());
  1786. if (!addCharacter(activeChar, obj, radius, false))
  1787. continue;
  1788. if (onlyFirst)
  1789. return new L2Character[] { obj };
  1790. targetList.add(obj);
  1791. }
  1792. return targetList.toArray(new L2Character[targetList.size()]);
  1793. }
  1794. case TARGET_CORPSE_PLAYER:
  1795. {
  1796. if (target != null && target.isDead())
  1797. {
  1798. final L2PcInstance player;
  1799. if (activeChar instanceof L2PcInstance)
  1800. player = (L2PcInstance) activeChar;
  1801. else
  1802. player = null;
  1803. final L2PcInstance targetPlayer;
  1804. if (target instanceof L2PcInstance)
  1805. targetPlayer = (L2PcInstance) target;
  1806. else
  1807. targetPlayer = null;
  1808. final L2PetInstance targetPet;
  1809. if (target instanceof L2PetInstance)
  1810. targetPet = (L2PetInstance) target;
  1811. else
  1812. targetPet = null;
  1813. if (player != null && (targetPlayer != null || targetPet != null))
  1814. {
  1815. boolean condGood = true;
  1816. if (getSkillType() == L2SkillType.RESURRECT)
  1817. {
  1818. if (targetPlayer != null)
  1819. {
  1820. // check target is not in a active siege zone
  1821. if (targetPlayer.isInsideZone(L2Character.ZONE_SIEGE) && !targetPlayer.isInSiege())
  1822. {
  1823. condGood = false;
  1824. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CANNOT_BE_RESURRECTED_DURING_SIEGE));
  1825. }
  1826. if (targetPlayer.isFestivalParticipant()) // Check to see if the current player target is in a festival.
  1827. {
  1828. condGood = false;
  1829. activeChar.sendMessage("You may not resurrect participants in a festival.");
  1830. }
  1831. if (targetPlayer.isReviveRequested())
  1832. {
  1833. if (targetPlayer.isRevivingPet())
  1834. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.MASTER_CANNOT_RES)); // While a pet is attempting to resurrect, it cannot help in resurrecting its master.
  1835. else
  1836. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.RES_HAS_ALREADY_BEEN_PROPOSED)); // Resurrection is already been proposed.
  1837. condGood = false;
  1838. }
  1839. }
  1840. else if (targetPet != null)
  1841. {
  1842. if (targetPet.getOwner() != player)
  1843. {
  1844. if (targetPet.getOwner().isReviveRequested())
  1845. {
  1846. if (targetPet.getOwner().isRevivingPet())
  1847. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.RES_HAS_ALREADY_BEEN_PROPOSED)); // Resurrection is already been proposed.
  1848. else
  1849. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CANNOT_RES_PET2)); // A pet cannot be resurrected while it's owner is in the process of resurrecting.
  1850. condGood = false;
  1851. }
  1852. }
  1853. }
  1854. }
  1855. if (condGood)
  1856. {
  1857. if (!onlyFirst)
  1858. {
  1859. targetList.add(target);
  1860. return targetList.toArray(new L2Object[targetList.size()]);
  1861. }
  1862. return new L2Character[] { target };
  1863. }
  1864. }
  1865. }
  1866. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1867. return _emptyTargetList;
  1868. }
  1869. case TARGET_CORPSE_MOB:
  1870. {
  1871. final boolean isSummon = target instanceof L2SummonInstance;
  1872. if (!(isSummon || target instanceof L2Attackable) || !target.isDead())
  1873. {
  1874. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1875. return _emptyTargetList;
  1876. }
  1877. // Corpse mob only available for half time
  1878. switch (getSkillType())
  1879. {
  1880. case SUMMON:
  1881. {
  1882. if (isSummon && ((L2SummonInstance)target).getOwner() != null
  1883. && ((L2SummonInstance)target).getOwner().getObjectId() == activeChar.getObjectId())
  1884. return _emptyTargetList;
  1885. }
  1886. case DRAIN:
  1887. {
  1888. if (((L2Attackable) target).checkCorpseTime(activeChar.getActingPlayer(), (Config.NPC_DECAY_TIME / 2), true))
  1889. {
  1890. return _emptyTargetList;
  1891. }
  1892. }
  1893. }
  1894. if (!onlyFirst)
  1895. {
  1896. targetList.add(target);
  1897. return targetList.toArray(new L2Object[targetList.size()]);
  1898. }
  1899. return new L2Character[] { target };
  1900. }
  1901. case TARGET_AREA_CORPSE_MOB:
  1902. {
  1903. if ((!(target instanceof L2Attackable)) || !target.isDead())
  1904. {
  1905. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1906. return _emptyTargetList;
  1907. }
  1908. if (onlyFirst)
  1909. return new L2Character[] {target};
  1910. targetList.add(target);
  1911. final boolean srcInArena = (activeChar.isInsideZone(L2Character.ZONE_PVP) && !activeChar.isInsideZone(L2Character.ZONE_SIEGE));
  1912. final int radius = getSkillRadius();
  1913. final Collection<L2Character> objs = activeChar.getKnownList().getKnownCharacters();
  1914. for (L2Character obj : objs)
  1915. {
  1916. if (!(obj instanceof L2Attackable || obj instanceof L2Playable)
  1917. || !Util.checkIfInRange(radius, target, obj, true))
  1918. continue;
  1919. if (!checkForAreaOffensiveSkills(activeChar, obj, this, srcInArena))
  1920. continue;
  1921. targetList.add(obj);
  1922. }
  1923. if (targetList.isEmpty())
  1924. return _emptyTargetList;
  1925. return targetList.toArray(new L2Character[targetList.size()]);
  1926. }
  1927. case TARGET_AURA_CORPSE_MOB:
  1928. {
  1929. for (L2Character character : activeChar.getKnownList().getKnownCharactersInRadius(getSkillRadius()))
  1930. {
  1931. if ((character instanceof L2Attackable) && character.isDead())
  1932. {
  1933. targetList.add(character);
  1934. }
  1935. }
  1936. return (targetList.isEmpty() ? _emptyTargetList : targetList.toArray(new L2Character[targetList.size()]));
  1937. }
  1938. case TARGET_UNLOCKABLE:
  1939. {
  1940. if (!(target instanceof L2DoorInstance) && !(target instanceof L2ChestInstance))
  1941. {
  1942. //activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessage.TARGET_IS_INCORRECT));
  1943. return _emptyTargetList;
  1944. }
  1945. if (!onlyFirst)
  1946. {
  1947. targetList.add(target);
  1948. return targetList.toArray(new L2Object[targetList.size()]);
  1949. }
  1950. return new L2Character[] { target };
  1951. }
  1952. case TARGET_UNDEAD:
  1953. {
  1954. if (target instanceof L2Npc || target instanceof L2SummonInstance)
  1955. {
  1956. if (!target.isUndead() || target.isDead())
  1957. {
  1958. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1959. }
  1960. else
  1961. {
  1962. if (!onlyFirst)
  1963. targetList.add(target);
  1964. else
  1965. return new L2Character[] {target};
  1966. return targetList.toArray(new L2Object[targetList.size()]);
  1967. }
  1968. }
  1969. else
  1970. {
  1971. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  1972. }
  1973. return _emptyTargetList;
  1974. }
  1975. case TARGET_AREA_UNDEAD:
  1976. {
  1977. final L2Character cha;
  1978. final int radius = getSkillRadius();
  1979. if (getCastRange() >= 0 && (target instanceof L2Npc || target instanceof L2SummonInstance)
  1980. && target.isUndead() && !target.isAlikeDead())
  1981. {
  1982. cha = target;
  1983. if (!onlyFirst)
  1984. targetList.add(cha); // Add target to target list
  1985. else
  1986. return new L2Character[] {cha};
  1987. }
  1988. else cha = activeChar;
  1989. final Collection<L2Character> objs = activeChar.getKnownList().getKnownCharacters();
  1990. for (L2Character obj : objs)
  1991. {
  1992. if (!Util.checkIfInRange(radius, cha, obj, true))
  1993. continue;
  1994. else if (obj instanceof L2Npc)
  1995. target = obj;
  1996. else if (obj instanceof L2SummonInstance)
  1997. target = obj;
  1998. else
  1999. continue;
  2000. if (!target.isAlikeDead())
  2001. {
  2002. if (!target.isUndead())
  2003. continue;
  2004. if (geoEnabled && !GeoData.getInstance().canSeeTarget(activeChar, target))
  2005. continue;
  2006. if (!onlyFirst)
  2007. targetList.add(obj);
  2008. else
  2009. return new L2Character[] { obj };
  2010. }
  2011. }
  2012. if (targetList.isEmpty()) return _emptyTargetList;
  2013. return targetList.toArray(new L2Character[targetList.size()]);
  2014. }
  2015. case TARGET_ENEMY_SUMMON:
  2016. {
  2017. if(target instanceof L2Summon)
  2018. {
  2019. L2Summon targetSummon = (L2Summon)target;
  2020. if (activeChar instanceof L2PcInstance && activeChar.getPet() != targetSummon && !targetSummon.isDead()
  2021. && (targetSummon.getOwner().getPvpFlag() != 0 || targetSummon.getOwner().getKarma() > 0)
  2022. || (targetSummon.getOwner().isInsideZone(L2Character.ZONE_PVP) && ((L2PcInstance)activeChar).isInsideZone(L2Character.ZONE_PVP))
  2023. || (targetSummon.getOwner().isInDuel() && ((L2PcInstance)activeChar).isInDuel() && targetSummon.getOwner().getDuelId() == ((L2PcInstance)activeChar).getDuelId()))
  2024. return new L2Character[]{targetSummon};
  2025. }
  2026. return _emptyTargetList;
  2027. }
  2028. case TARGET_PARTY_NOTME:
  2029. {
  2030. //target all party members except yourself
  2031. if (onlyFirst)
  2032. return new L2Character[] { activeChar };
  2033. L2PcInstance player = null;
  2034. if (activeChar instanceof L2Summon)
  2035. {
  2036. player = ((L2Summon) activeChar).getOwner();
  2037. targetList.add(player);
  2038. }
  2039. else if (activeChar instanceof L2PcInstance)
  2040. {
  2041. player = (L2PcInstance) activeChar;
  2042. if (activeChar.getPet() != null)
  2043. targetList.add(activeChar.getPet());
  2044. }
  2045. if (activeChar.getParty() != null)
  2046. {
  2047. List<L2PcInstance> partyList = activeChar.getParty().getPartyMembers();
  2048. for (L2PcInstance partyMember : partyList)
  2049. {
  2050. if (partyMember == null)
  2051. continue;
  2052. else if (partyMember == player)
  2053. continue;
  2054. else if (!partyMember.isDead() && Util.checkIfInRange(getSkillRadius(), activeChar, partyMember, true))
  2055. {
  2056. targetList.add(partyMember);
  2057. if (partyMember.getPet() != null && !partyMember.getPet().isDead())
  2058. {
  2059. targetList.add(partyMember.getPet());
  2060. }
  2061. }
  2062. }
  2063. }
  2064. return targetList.toArray(new L2Character[targetList.size()]);
  2065. }
  2066. // npc only for now - untested
  2067. case TARGET_CLAN_MEMBER:
  2068. {
  2069. if (activeChar instanceof L2Npc)
  2070. {
  2071. // for buff purposes, returns friendly mobs nearby and mob itself
  2072. final L2Npc npc = (L2Npc) activeChar;
  2073. if (npc.getFactionId() == null || npc.getFactionId().isEmpty())
  2074. {
  2075. return new L2Character[]{activeChar};
  2076. }
  2077. final Collection<L2Object> objs = activeChar.getKnownList().getKnownObjects().values();
  2078. for (L2Object newTarget : objs)
  2079. {
  2080. if (newTarget instanceof L2Npc
  2081. && npc.getFactionId().equals(((L2Npc) newTarget).getFactionId()))
  2082. {
  2083. if (!Util.checkIfInRange(getCastRange(), activeChar, newTarget, true))
  2084. continue;
  2085. if (((L2Npc) newTarget).getFirstEffect(this) != null)
  2086. continue;
  2087. targetList.add((L2Npc) newTarget);
  2088. break; // found
  2089. }
  2090. }
  2091. if (targetList.isEmpty())
  2092. targetList.add(npc);
  2093. }
  2094. else
  2095. return _emptyTargetList;
  2096. return targetList.toArray(new L2Character[targetList.size()]);
  2097. }
  2098. default:
  2099. {
  2100. activeChar.sendMessage("Target type of skill is not currently handled");
  2101. return _emptyTargetList;
  2102. }
  2103. }//end switch
  2104. }
  2105. public final L2Object[] getTargetList(L2Character activeChar)
  2106. {
  2107. return getTargetList(activeChar, false);
  2108. }
  2109. public final L2Object getFirstOfTargetList(L2Character activeChar)
  2110. {
  2111. L2Object[] targets;
  2112. targets = getTargetList(activeChar, true);
  2113. if (targets.length == 0)
  2114. return null;
  2115. return targets[0];
  2116. }
  2117. /*
  2118. * Check if should be target added to the target list
  2119. * false if target is dead, target same as caster,
  2120. * target inside peace zone, target in the same party with caster,
  2121. * caster can see target
  2122. * Additional checks if not in PvP zones (arena, siege):
  2123. * target in not the same clan and alliance with caster,
  2124. * and usual skill PvP check.
  2125. * If TvT event is active - performing additional checks.
  2126. *
  2127. * Caution: distance is not checked.
  2128. */
  2129. public static final boolean checkForAreaOffensiveSkills(L2Character caster, L2Character target, L2Skill skill, boolean sourceInArena)
  2130. {
  2131. if (target == null || target.isDead() || target == caster)
  2132. return false;
  2133. final L2PcInstance player = caster.getActingPlayer();
  2134. final L2PcInstance targetPlayer = target.getActingPlayer();
  2135. if (player != null)
  2136. {
  2137. if (targetPlayer != null)
  2138. {
  2139. if (targetPlayer == caster || targetPlayer == player)
  2140. return false;
  2141. if (targetPlayer.inObserverMode())
  2142. return false;
  2143. if (skill.isOffensive() && player.getSiegeState() > 0 && player.isInsideZone(L2Character.ZONE_SIEGE)
  2144. && player.getSiegeState() == targetPlayer.getSiegeState()
  2145. && player.getSiegeSide() == targetPlayer.getSiegeSide())
  2146. return false;
  2147. if (skill.isOffensive() && target.isInsideZone(L2Character.ZONE_PEACE))
  2148. return false;
  2149. if (player.isInParty() && targetPlayer.isInParty())
  2150. {
  2151. // Same party
  2152. if (player.getParty().getPartyLeaderOID() == targetPlayer.getParty().getPartyLeaderOID())
  2153. return false;
  2154. // Same commandchannel
  2155. if (player.getParty().getCommandChannel() != null
  2156. && player.getParty().getCommandChannel() == targetPlayer.getParty().getCommandChannel())
  2157. return false;
  2158. }
  2159. if (!TvTEvent.checkForTvTSkill(player, targetPlayer, skill))
  2160. return false;
  2161. if (!sourceInArena && !(targetPlayer.isInsideZone(L2Character.ZONE_PVP) && !targetPlayer.isInsideZone(L2Character.ZONE_SIEGE)))
  2162. {
  2163. if (player.getAllyId() != 0 && player.getAllyId() == targetPlayer.getAllyId())
  2164. return false;
  2165. if (player.getClanId() != 0 && player.getClanId() == targetPlayer.getClanId())
  2166. return false;
  2167. if (!player.checkPvpSkill(targetPlayer, skill, (caster instanceof L2Summon)))
  2168. return false;
  2169. }
  2170. }
  2171. }
  2172. else
  2173. {
  2174. // target is mob
  2175. if (targetPlayer == null && target instanceof L2Attackable && caster instanceof L2Attackable)
  2176. {
  2177. String casterEnemyClan = ((L2Attackable)caster).getEnemyClan();
  2178. if (casterEnemyClan == null || casterEnemyClan.isEmpty())
  2179. return false;
  2180. String targetClan = ((L2Attackable)target).getClan();
  2181. if (targetClan == null || targetClan.isEmpty())
  2182. return false;
  2183. if (!casterEnemyClan.equals(targetClan))
  2184. return false;
  2185. }
  2186. }
  2187. if (geoEnabled && !GeoData.getInstance().canSeeTarget(caster, target))
  2188. return false;
  2189. return true;
  2190. }
  2191. public static final boolean addSummon(L2Character caster, L2PcInstance owner, int radius, boolean isDead)
  2192. {
  2193. final L2Summon summon = owner.getPet();
  2194. if (summon == null)
  2195. return false;
  2196. return addCharacter(caster, summon, radius, isDead);
  2197. }
  2198. public static final boolean addCharacter(L2Character caster, L2Character target, int radius, boolean isDead)
  2199. {
  2200. if (isDead != target.isDead())
  2201. return false;
  2202. if (radius > 0 && !Util.checkIfInRange(radius, caster, target, true))
  2203. return false;
  2204. return true;
  2205. }
  2206. public final Func[] getStatFuncs(L2Effect effect, L2Character player)
  2207. {
  2208. if (_funcTemplates == null)
  2209. return _emptyFunctionSet;
  2210. if (!(player instanceof L2Playable) && !(player instanceof L2Attackable))
  2211. return _emptyFunctionSet;
  2212. ArrayList<Func> funcs = new ArrayList<Func>(_funcTemplates.length);
  2213. Env env = new Env();
  2214. env.player = player;
  2215. env.skill = this;
  2216. Func f;
  2217. for (FuncTemplate t : _funcTemplates)
  2218. {
  2219. f = t.getFunc(env, this); // skill is owner
  2220. if (f != null)
  2221. funcs.add(f);
  2222. }
  2223. if (funcs.isEmpty())
  2224. return _emptyFunctionSet;
  2225. return funcs.toArray(new Func[funcs.size()]);
  2226. }
  2227. public boolean hasEffects()
  2228. {
  2229. return (_effectTemplates != null && _effectTemplates.length > 0);
  2230. }
  2231. public EffectTemplate[] getEffectTemplates()
  2232. {
  2233. return _effectTemplates;
  2234. }
  2235. public EffectTemplate[] getEffectTemplatesPassive()
  2236. {
  2237. return _effectTemplatesPassive;
  2238. }
  2239. public boolean hasSelfEffects()
  2240. {
  2241. return (_effectTemplatesSelf != null && _effectTemplatesSelf.length > 0);
  2242. }
  2243. public boolean hasPassiveEffects()
  2244. {
  2245. return (_effectTemplatesPassive != null && _effectTemplatesPassive.length > 0);
  2246. }
  2247. /**
  2248. * Env is used to pass parameters for secondary effects (shield and ss/bss/bsss)
  2249. * @param effector
  2250. * @param effected
  2251. * @param env
  2252. * @return an array with the effects that have been added to effector
  2253. */
  2254. public final L2Effect[] getEffects(L2Character effector, L2Character effected, Env env)
  2255. {
  2256. if (!hasEffects() || isPassive())
  2257. return _emptyEffectSet;
  2258. // doors and siege flags cannot receive any effects
  2259. if (effected instanceof L2DoorInstance ||effected instanceof L2SiegeFlagInstance )
  2260. return _emptyEffectSet;
  2261. if (effector != effected)
  2262. {
  2263. if (isOffensive() || isDebuff())
  2264. {
  2265. if (effected.isInvul())
  2266. return _emptyEffectSet;
  2267. if (effector instanceof L2PcInstance && ((L2PcInstance)effector).isGM())
  2268. {
  2269. if (!((L2PcInstance)effector).getAccessLevel().canGiveDamage())
  2270. return _emptyEffectSet;
  2271. }
  2272. }
  2273. }
  2274. ArrayList<L2Effect> effects = new ArrayList<L2Effect>(_effectTemplates.length);
  2275. if (env == null)
  2276. env = new Env();
  2277. env.skillMastery = Formulas.calcSkillMastery(effector, this);
  2278. env.player = effector;
  2279. env.target = effected;
  2280. env.skill = this;
  2281. for (EffectTemplate et : _effectTemplates)
  2282. {
  2283. boolean success = true;
  2284. if (et.effectPower > -1)
  2285. success = Formulas.calcEffectSuccess(effector, effected, et, this, env.shld, env.ss, env.sps, env.bss);
  2286. if (success)
  2287. {
  2288. L2Effect e = et.getEffect(env);
  2289. if (e != null)
  2290. {
  2291. e.scheduleEffect();
  2292. effects.add(e);
  2293. }
  2294. }
  2295. // display fail message only for effects with icons
  2296. else if (et.icon && effector instanceof L2PcInstance)
  2297. {
  2298. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  2299. sm.addCharName(effected);
  2300. sm.addSkillName(this);
  2301. ((L2PcInstance)effector).sendPacket(sm);
  2302. }
  2303. }
  2304. if (effects.isEmpty()) return _emptyEffectSet;
  2305. return effects.toArray(new L2Effect[effects.size()]);
  2306. }
  2307. /**
  2308. * Warning: this method doesn't consider modifier (shield, ss, sps, bss) for secondary effects
  2309. * @param effector
  2310. * @param effected
  2311. * @return
  2312. */
  2313. public final L2Effect[] getEffects(L2Character effector, L2Character effected)
  2314. {
  2315. return getEffects(effector, effected, null);
  2316. }
  2317. /**
  2318. * This method has suffered some changes in CT2.2 ->CT2.3<br>
  2319. * Effect engine is now supporting secondary effects with independent
  2320. * success/fail calculus from effect skill. Env parameter has been added to
  2321. * pass parameters like soulshot, spiritshots, blessed spiritshots or shield deffence.
  2322. * Some other optimizations have been done
  2323. * <br><br>
  2324. * This new feature works following next rules:
  2325. * <li> To enable feature, effectPower must be over -1 (check DocumentSkill#attachEffect for further information)</li>
  2326. * <li> If main skill fails, secondary effect always fail</li>
  2327. * @param effector
  2328. * @param effected
  2329. * @param env
  2330. * @return
  2331. */
  2332. public final L2Effect[] getEffects(L2CubicInstance effector, L2Character effected, Env env)
  2333. {
  2334. if (!hasEffects() || isPassive())
  2335. return _emptyEffectSet;
  2336. if (effector.getOwner() != effected)
  2337. {
  2338. if (isDebuff() || isOffensive())
  2339. {
  2340. if (effected.isInvul())
  2341. return _emptyEffectSet;
  2342. if (effector.getOwner().isGM() &&
  2343. !effector.getOwner().getAccessLevel().canGiveDamage())
  2344. {
  2345. return _emptyEffectSet;
  2346. }
  2347. }
  2348. }
  2349. ArrayList<L2Effect> effects = new ArrayList<L2Effect>(_effectTemplates.length);
  2350. if (env == null)
  2351. env = new Env();
  2352. env.player = effector.getOwner();
  2353. env.cubic = effector;
  2354. env.target = effected;
  2355. env.skill = this;
  2356. for (EffectTemplate et : _effectTemplates)
  2357. {
  2358. boolean success = true;
  2359. if (et.effectPower > -1)
  2360. success = Formulas.calcEffectSuccess(effector.getOwner(), effected, et, this, env.shld, env.ss, env.sps, env.bss);
  2361. if (success)
  2362. {
  2363. L2Effect e = et.getEffect(env);
  2364. if (e != null)
  2365. {
  2366. e.scheduleEffect();
  2367. effects.add(e);
  2368. }
  2369. }
  2370. }
  2371. if (effects.isEmpty()) return _emptyEffectSet;
  2372. return effects.toArray(new L2Effect[effects.size()]);
  2373. }
  2374. public final L2Effect[] getEffectsSelf(L2Character effector)
  2375. {
  2376. if (!hasSelfEffects() || isPassive())
  2377. return _emptyEffectSet;
  2378. List<L2Effect> effects = new ArrayList<L2Effect>(_effectTemplatesSelf.length);
  2379. for (EffectTemplate et : _effectTemplatesSelf)
  2380. {
  2381. Env env = new Env();
  2382. env.player = effector;
  2383. env.target = effector;
  2384. env.skill = this;
  2385. L2Effect e = et.getEffect(env);
  2386. if (e != null)
  2387. {
  2388. e.setSelfEffect();
  2389. e.scheduleEffect();
  2390. effects.add(e);
  2391. }
  2392. }
  2393. if (effects.isEmpty()) return _emptyEffectSet;
  2394. return effects.toArray(new L2Effect[effects.size()]);
  2395. }
  2396. public final L2Effect[] getEffectsPassive(L2Character effector)
  2397. {
  2398. if (!hasPassiveEffects())
  2399. return _emptyEffectSet;
  2400. List<L2Effect> effects = new ArrayList<L2Effect>(_effectTemplatesPassive.length);
  2401. for (EffectTemplate et : _effectTemplatesPassive)
  2402. {
  2403. Env env = new Env();
  2404. env.player = effector;
  2405. env.target = effector;
  2406. env.skill = this;
  2407. L2Effect e = et.getEffect(env);
  2408. if (e != null)
  2409. {
  2410. e.setPassiveEffect();
  2411. e.scheduleEffect();
  2412. effects.add(e);
  2413. }
  2414. }
  2415. if (effects.isEmpty()) return _emptyEffectSet;
  2416. return effects.toArray(new L2Effect[effects.size()]);
  2417. }
  2418. public final void attach(FuncTemplate f)
  2419. {
  2420. if (_funcTemplates == null)
  2421. {
  2422. _funcTemplates = new FuncTemplate[] {f};
  2423. }
  2424. else
  2425. {
  2426. int len = _funcTemplates.length;
  2427. FuncTemplate[] tmp = new FuncTemplate[len + 1];
  2428. System.arraycopy(_funcTemplates, 0, tmp, 0, len);
  2429. tmp[len] = f;
  2430. _funcTemplates = tmp;
  2431. }
  2432. }
  2433. public final void attach(EffectTemplate effect)
  2434. {
  2435. if (_effectTemplates == null)
  2436. {
  2437. _effectTemplates = new EffectTemplate[] {effect};
  2438. }
  2439. else
  2440. {
  2441. int len = _effectTemplates.length;
  2442. EffectTemplate[] tmp = new EffectTemplate[len + 1];
  2443. System.arraycopy(_effectTemplates, 0, tmp, 0, len);
  2444. tmp[len] = effect;
  2445. _effectTemplates = tmp;
  2446. }
  2447. }
  2448. public final void attachSelf(EffectTemplate effect)
  2449. {
  2450. if (_effectTemplatesSelf == null)
  2451. {
  2452. _effectTemplatesSelf = new EffectTemplate[] {effect};
  2453. }
  2454. else
  2455. {
  2456. int len = _effectTemplatesSelf.length;
  2457. EffectTemplate[] tmp = new EffectTemplate[len + 1];
  2458. System.arraycopy(_effectTemplatesSelf, 0, tmp, 0, len);
  2459. tmp[len] = effect;
  2460. _effectTemplatesSelf = tmp;
  2461. }
  2462. }
  2463. public final void attachPassive(EffectTemplate effect)
  2464. {
  2465. if (_effectTemplatesPassive == null)
  2466. {
  2467. _effectTemplatesPassive = new EffectTemplate[] {effect};
  2468. }
  2469. else
  2470. {
  2471. int len = _effectTemplatesPassive.length;
  2472. EffectTemplate[] tmp = new EffectTemplate[len + 1];
  2473. System.arraycopy(_effectTemplatesPassive, 0, tmp, 0, len);
  2474. tmp[len] = effect;
  2475. _effectTemplatesPassive = tmp;
  2476. }
  2477. }
  2478. public final void attach(Condition c, boolean itemOrWeapon)
  2479. {
  2480. if (itemOrWeapon)
  2481. {
  2482. if (_itemPreCondition == null)
  2483. _itemPreCondition = new FastList<Condition>();
  2484. _itemPreCondition.add(c);
  2485. }
  2486. else
  2487. {
  2488. if (_preCondition == null)
  2489. _preCondition = new FastList<Condition>();
  2490. _preCondition.add(c);
  2491. }
  2492. }
  2493. @Override
  2494. public String toString()
  2495. {
  2496. return "" + _name + "[id=" + _id + ",lvl=" + _level + "]";
  2497. }
  2498. /**
  2499. * @return pet food
  2500. */
  2501. public int getFeed()
  2502. {
  2503. return _feed;
  2504. }
  2505. /**
  2506. * used for tracking item id in case that item consume cannot be used
  2507. * @return reference item id
  2508. */
  2509. public int getReferenceItemId()
  2510. {
  2511. return _refId;
  2512. }
  2513. public final int getMaxCharges()
  2514. {
  2515. return _maxCharges;
  2516. }
  2517. public int getAfterEffectId()
  2518. {
  2519. return _afterEffectId;
  2520. }
  2521. public int getAfterEffectLvl()
  2522. {
  2523. return _afterEffectLvl;
  2524. }
  2525. @Override
  2526. public boolean triggersChanceSkill()
  2527. {
  2528. return _triggeredId > 0 && isChance();
  2529. }
  2530. @Override
  2531. public int getTriggeredChanceId()
  2532. {
  2533. return _triggeredId;
  2534. }
  2535. @Override
  2536. public int getTriggeredChanceLevel()
  2537. {
  2538. return _triggeredLevel;
  2539. }
  2540. @Override
  2541. public ChanceCondition getTriggeredChanceCondition()
  2542. {
  2543. return _chanceCondition;
  2544. }
  2545. public String getAttributeName()
  2546. {
  2547. return _attribute;
  2548. }
  2549. /**
  2550. * @return the _blowChance
  2551. */
  2552. public int getBlowChance()
  2553. {
  2554. return _blowChance;
  2555. }
  2556. public boolean ignoreShield()
  2557. {
  2558. return _ignoreShield;
  2559. }
  2560. public boolean canBeReflected()
  2561. {
  2562. return _canBeReflected;
  2563. }
  2564. public boolean canBeDispeled()
  2565. {
  2566. return _canBeDispeled;
  2567. }
  2568. public boolean isClanSkill()
  2569. {
  2570. return _isClanSkill;
  2571. }
  2572. public boolean isExcludedFromCheck()
  2573. {
  2574. return _excludedFromCheck;
  2575. }
  2576. public float getDependOnTargetBuff()
  2577. {
  2578. return _dependOnTargetBuff;
  2579. }
  2580. public boolean isSimultaneousCast()
  2581. {
  2582. return _simultaneousCast;
  2583. }
  2584. /**
  2585. * @param skillId
  2586. * @param skillLvl
  2587. * @param values
  2588. * @return L2ExtractableSkill
  2589. * @author Zoey76
  2590. */
  2591. private L2ExtractableSkill parseExtractableSkill(int skillId, int skillLvl, String values)
  2592. {
  2593. String[] lineSplit = values.split(";");
  2594. final FastList<L2ExtractableProductItem> product_temp = new FastList<L2ExtractableProductItem>();
  2595. for (int i = 0; i <= (lineSplit.length-1); i++)
  2596. {
  2597. final String[] lineSplit2 = lineSplit[i].split(",");
  2598. if (lineSplit2.length < 3)
  2599. _log.warning("Extractable skills data: Error in Skill Id: " + skillId + " Level: " + skillLvl + " -> wrong seperator!");
  2600. int[] production = null;
  2601. int[] amount = null;
  2602. double chance = 0;
  2603. int prodId = 0;
  2604. int quantity = 0;
  2605. try
  2606. {
  2607. int k =0;
  2608. production = new int[(lineSplit2.length-1)/2];
  2609. amount = new int[(lineSplit2.length-1)/2];
  2610. for (int j = 0; j < (lineSplit2.length-1); j++)
  2611. {
  2612. prodId = Integer.parseInt(lineSplit2[j]);
  2613. quantity = Integer.parseInt(lineSplit2[j+=1]);
  2614. if ((prodId <= 0) || (quantity <= 0))
  2615. _log.warning("Extractable skills data: Error in Skill Id: " + skillId + " Level: " + skillLvl + " wrong production Id: " + prodId + " or wrond quantity: " + quantity + "!");
  2616. production[k] = prodId;
  2617. amount[k] = quantity;
  2618. k++;
  2619. }
  2620. chance = Double.parseDouble(lineSplit2[lineSplit2.length-1]);
  2621. }
  2622. catch (Exception e)
  2623. {
  2624. _log.warning("Extractable skills data: Error in Skill Id: " + skillId + " Level: " + skillLvl + " -> incomplete/invalid production data or wrong seperator!");
  2625. }
  2626. product_temp.add(new L2ExtractableProductItem(production, amount, chance));
  2627. }
  2628. if (product_temp.size()== 0)
  2629. _log.warning("Extractable skills data: Error in Skill Id: " + skillId + " Level: " + skillLvl + " -> There are no production items!");
  2630. return new L2ExtractableSkill(SkillTable.getSkillHashCode(this), product_temp);
  2631. }
  2632. public L2ExtractableSkill getExtractableSkill()
  2633. {
  2634. return _extractableItems;
  2635. }
  2636. }