L2Skill.java 80 KB

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