L2Skill.java 83 KB

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