L2Skill.java 80 KB

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