L2Skill.java 82 KB

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