L2Skill.java 82 KB

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