L2Skill.java 85 KB

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