L2Skill.java 84 KB

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