L2Skill.java 84 KB

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