L2Skill.java 81 KB

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