L2Skill.java 80 KB

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