L2Skill.java 81 KB

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