L2Skill.java 80 KB

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