L2Skill.java 81 KB

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