L2Item.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  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.templates.item;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import java.util.logging.Logger;
  19. import javolution.util.FastList;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.datatables.ItemTable;
  22. import com.l2jserver.gameserver.model.Elementals;
  23. import com.l2jserver.gameserver.model.L2Effect;
  24. import com.l2jserver.gameserver.model.L2ItemInstance;
  25. import com.l2jserver.gameserver.model.L2Object;
  26. import com.l2jserver.gameserver.model.actor.L2Character;
  27. import com.l2jserver.gameserver.model.actor.L2Summon;
  28. import com.l2jserver.gameserver.network.SystemMessageId;
  29. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  30. import com.l2jserver.gameserver.skills.Env;
  31. import com.l2jserver.gameserver.skills.SkillHolder;
  32. import com.l2jserver.gameserver.skills.conditions.Condition;
  33. import com.l2jserver.gameserver.skills.conditions.ConditionPetType;
  34. import com.l2jserver.gameserver.skills.funcs.Func;
  35. import com.l2jserver.gameserver.skills.funcs.FuncTemplate;
  36. import com.l2jserver.gameserver.templates.StatsSet;
  37. import com.l2jserver.gameserver.templates.effects.EffectTemplate;
  38. /**
  39. * This class contains all informations concerning the item (weapon, armor, etc).<BR>
  40. * Mother class of :
  41. * <LI>L2Armor</LI>
  42. * <LI>L2EtcItem</LI>
  43. * <LI>L2Weapon</LI>
  44. * @version $Revision: 1.7.2.2.2.5 $ $Date: 2005/04/06 18:25:18 $
  45. */
  46. public abstract class L2Item
  47. {
  48. public static final int TYPE1_WEAPON_RING_EARRING_NECKLACE = 0;
  49. public static final int TYPE1_SHIELD_ARMOR = 1;
  50. public static final int TYPE1_ITEM_QUESTITEM_ADENA = 4;
  51. public static final int TYPE2_WEAPON = 0;
  52. public static final int TYPE2_SHIELD_ARMOR = 1;
  53. public static final int TYPE2_ACCESSORY = 2;
  54. public static final int TYPE2_QUEST = 3;
  55. public static final int TYPE2_MONEY = 4;
  56. public static final int TYPE2_OTHER = 5;
  57. public static final int WOLF = 0x1;
  58. public static final int HATCHLING = 0x2;
  59. public static final int STRIDER = 0x4;
  60. public static final int BABY = 0x8;
  61. public static final int IMPROVED_BABY = 0x10;
  62. public static final int GROWN_WOLF = 0x20;
  63. public static final int ALL_WOLF = 0x21;
  64. public static final int ALL_PET = 0x3F;
  65. public static final int SLOT_NONE = 0x0000;
  66. public static final int SLOT_UNDERWEAR = 0x0001;
  67. public static final int SLOT_R_EAR = 0x0002;
  68. public static final int SLOT_L_EAR = 0x0004;
  69. public static final int SLOT_LR_EAR = 0x00006;
  70. public static final int SLOT_NECK = 0x0008;
  71. public static final int SLOT_R_FINGER = 0x0010;
  72. public static final int SLOT_L_FINGER = 0x0020;
  73. public static final int SLOT_LR_FINGER = 0x0030;
  74. public static final int SLOT_HEAD = 0x0040;
  75. public static final int SLOT_R_HAND = 0x0080;
  76. public static final int SLOT_L_HAND = 0x0100;
  77. public static final int SLOT_GLOVES = 0x0200;
  78. public static final int SLOT_CHEST = 0x0400;
  79. public static final int SLOT_LEGS = 0x0800;
  80. public static final int SLOT_FEET = 0x1000;
  81. public static final int SLOT_BACK = 0x2000;
  82. public static final int SLOT_LR_HAND = 0x4000;
  83. public static final int SLOT_FULL_ARMOR = 0x8000;
  84. public static final int SLOT_HAIR = 0x010000;
  85. public static final int SLOT_ALLDRESS = 0x020000;
  86. public static final int SLOT_HAIR2 = 0x040000;
  87. public static final int SLOT_HAIRALL = 0x080000;
  88. public static final int SLOT_R_BRACELET = 0x100000;
  89. public static final int SLOT_L_BRACELET = 0x200000;
  90. public static final int SLOT_DECO = 0x400000;
  91. public static final int SLOT_BELT = 0x10000000;
  92. public static final int SLOT_WOLF = -100;
  93. public static final int SLOT_HATCHLING = -101;
  94. public static final int SLOT_STRIDER = -102;
  95. public static final int SLOT_BABYPET = -103;
  96. public static final int SLOT_GREATWOLF = -104;
  97. public static final int SLOT_MULTI_ALLWEAPON = SLOT_LR_HAND | SLOT_R_HAND;
  98. public static final int MATERIAL_STEEL = 0x00; // ??
  99. public static final int MATERIAL_FINE_STEEL = 0x01; // ??
  100. public static final int MATERIAL_BLOOD_STEEL = 0x02; // ??
  101. public static final int MATERIAL_BRONZE = 0x03; // ??
  102. public static final int MATERIAL_SILVER = 0x04; // ??
  103. public static final int MATERIAL_GOLD = 0x05; // ??
  104. public static final int MATERIAL_MITHRIL = 0x06; // ??
  105. public static final int MATERIAL_ORIHARUKON = 0x07; // ??
  106. public static final int MATERIAL_PAPER = 0x08; // ??
  107. public static final int MATERIAL_WOOD = 0x09; // ??
  108. public static final int MATERIAL_CLOTH = 0x0a; // ??
  109. public static final int MATERIAL_LEATHER = 0x0b; // ??
  110. public static final int MATERIAL_BONE = 0x0c; // ??
  111. public static final int MATERIAL_HORN = 0x0d; // ??
  112. public static final int MATERIAL_DAMASCUS = 0x0e; // ??
  113. public static final int MATERIAL_ADAMANTAITE = 0x0f; // ??
  114. public static final int MATERIAL_CHRYSOLITE = 0x10; // ??
  115. public static final int MATERIAL_CRYSTAL = 0x11; // ??
  116. public static final int MATERIAL_LIQUID = 0x12; // ??
  117. public static final int MATERIAL_SCALE_OF_DRAGON = 0x13; // ??
  118. public static final int MATERIAL_DYESTUFF = 0x14; // ??
  119. public static final int MATERIAL_COBWEB = 0x15; // ??
  120. public static final int MATERIAL_SEED = 0x16; // ??
  121. public static final int MATERIAL_FISH = 0x17; // ??
  122. public static final int MATERIAL_RUNE_XP = 0x18; // ??
  123. public static final int MATERIAL_RUNE_SP = 0x19; // ??
  124. public static final int MATERIAL_RUNE_PENALTY = 0x20; // ??
  125. public static final int CRYSTAL_NONE = 0x00; // ??
  126. public static final int CRYSTAL_D = 0x01; // ??
  127. public static final int CRYSTAL_C = 0x02; // ??
  128. public static final int CRYSTAL_B = 0x03; // ??
  129. public static final int CRYSTAL_A = 0x04; // ??
  130. public static final int CRYSTAL_S = 0x05; // ??
  131. public static final int CRYSTAL_S80 = 0x06; // ??
  132. public static final int CRYSTAL_S84 = 0x07; // ??
  133. private static final int[] crystalItemId =
  134. {
  135. 0, 1458, 1459, 1460, 1461, 1462, 1462, 1462
  136. };
  137. private static final int[] crystalEnchantBonusArmor =
  138. {
  139. 0, 11, 6, 11, 19, 25, 25, 25
  140. };
  141. private static final int[] crystalEnchantBonusWeapon =
  142. {
  143. 0, 90, 45, 67, 144, 250, 250, 250
  144. };
  145. private final int _itemId;
  146. private final String _name;
  147. private final String _icon;
  148. private final int _weight;
  149. private final boolean _stackable;
  150. private final int _materialType;
  151. private final int _crystalType; // default to none-grade
  152. private final int _duration;
  153. private final int _time;
  154. private final int _bodyPart;
  155. private final int _referencePrice;
  156. private final int _crystalCount;
  157. private final boolean _sellable;
  158. private final boolean _dropable;
  159. private final boolean _destroyable;
  160. private final boolean _tradeable;
  161. private final boolean _depositable;
  162. private final boolean _questItem;
  163. private final boolean _common;
  164. private final boolean _heroItem;
  165. private final boolean _pvpItem;
  166. private final boolean _ex_immediate_effect;
  167. private final L2ActionType _defaultAction;
  168. protected int _type1; // needed for item list (inventory)
  169. protected int _type2; // different lists for armor, weapon, etc
  170. protected Elementals[] _elementals = null;
  171. protected FuncTemplate[] _funcTemplates;
  172. protected EffectTemplate[] _effectTemplates;
  173. protected List <Condition> _preConditions;
  174. protected static final Func[] _emptyFunctionSet = new Func[0];
  175. protected static final L2Effect[] _emptyEffectSet = new L2Effect[0];
  176. protected static final Logger _log = Logger.getLogger(L2Item.class.getName());
  177. /**
  178. * Constructor of the L2Item that fill class variables.<BR><BR>
  179. * @param set : StatsSet corresponding to a set of couples (key,value) for description of the item
  180. */
  181. protected L2Item(StatsSet set)
  182. {
  183. _itemId = set.getInteger("item_id");
  184. _name = set.getString("name");
  185. _icon = set.getString("icon", null);
  186. _weight = set.getInteger("weight", 0);
  187. _materialType = ItemTable._materials.get(set.getString("material", "steel")); // default is steel, yeah and what?
  188. _duration = set.getInteger("duration", -1);
  189. _time = set.getInteger("time", -1);
  190. _bodyPart = ItemTable._slots.get(set.getString("bodypart", "none"));
  191. _referencePrice = set.getInteger("price", 0);
  192. _crystalType = ItemTable._crystalTypes.get(set.getString("crystal_type", "none")); // default to none-grade
  193. _crystalCount = set.getInteger("crystal_count", 0);
  194. _stackable = set.getBool("is_stackable", false);
  195. _sellable = set.getBool("is_sellable", true);
  196. _dropable = set.getBool("is_dropable", true);
  197. _destroyable = set.getBool("is_destroyable", true);
  198. _tradeable = set.getBool("is_tradable", true);
  199. _depositable = set.getBool("is_depositable", true);
  200. _questItem = set.getBool("is_questitem", false);
  201. //_immediate_effect - herb
  202. _ex_immediate_effect = set.getInteger("ex_immediate_effect", 0) > 0;
  203. //used for custom type select
  204. _defaultAction = set.getEnum("default_action", L2ActionType.class, L2ActionType.none);
  205. //TODO cleanup + finish
  206. String equip_condition = set.getString("equip_condition", null);
  207. if (equip_condition != null)
  208. {
  209. //pet conditions
  210. if (equip_condition.contains("all_wolf_group"))
  211. attach(new ConditionPetType(ALL_WOLF));
  212. else if (equip_condition.contains("hatchling_group"))
  213. attach(new ConditionPetType(HATCHLING));
  214. else if (equip_condition.contains("strider"))
  215. attach(new ConditionPetType(STRIDER));
  216. else if (equip_condition.contains("baby_pet_group"))
  217. attach(new ConditionPetType(BABY));
  218. else if (equip_condition.contains("grown_up_wolf_group"))
  219. attach(new ConditionPetType(GROWN_WOLF));
  220. else if (equip_condition.contains("item_equip_pet_group"))
  221. attach(new ConditionPetType(ALL_PET));
  222. }
  223. _common = (_itemId >= 12006 && _itemId <= 12361) || (_itemId >= 11605 && _itemId <= 12308);
  224. _heroItem = (_itemId >= 6611 && _itemId <= 6621) || (_itemId >= 9388 && _itemId <= 9390) || _itemId == 6842;
  225. _pvpItem = (_itemId >= 10667 && _itemId <= 10792) || (_itemId >= 10793 && _itemId <= 10835) || (_itemId >= 12852 && _itemId <= 12977) || (_itemId >= 14363 && _itemId <= 14519) || (_itemId >= 14520 && _itemId <= 14525) || _itemId == 14528 || _itemId == 14529 || _itemId == 14558 || (_itemId >=15913 && _itemId <= 16024) || (_itemId >=16134 && _itemId <= 16147) || _itemId == 16149 || _itemId == 16151 || _itemId == 16153 || _itemId == 16155 || _itemId == 16157 || _itemId == 16159 || (_itemId >=16168 && _itemId <= 16176) || (_itemId >=16179 && _itemId <= 16220);
  226. }
  227. /**
  228. * Returns the itemType.
  229. * @return Enum
  230. */
  231. public abstract L2ItemType getItemType();
  232. /**
  233. * Returns the duration of the item
  234. * @return int
  235. */
  236. public final int getDuration()
  237. {
  238. return _duration;
  239. }
  240. /**
  241. * Returns the time of the item
  242. * @return int
  243. */
  244. public final int getTime()
  245. {
  246. return _time;
  247. }
  248. /**
  249. * Returns the ID of the iden
  250. * @return int
  251. */
  252. public final int getItemId()
  253. {
  254. return _itemId;
  255. }
  256. public abstract int getItemMask();
  257. /**
  258. * Return the type of material of the item
  259. * @return int
  260. */
  261. public final int getMaterialType()
  262. {
  263. return _materialType;
  264. }
  265. /**
  266. * Returns the type 2 of the item
  267. * @return int
  268. */
  269. public final int getType2()
  270. {
  271. return _type2;
  272. }
  273. /**
  274. * Returns the weight of the item
  275. * @return int
  276. */
  277. public final int getWeight()
  278. {
  279. return _weight;
  280. }
  281. /**
  282. * Returns if the item is crystallizable
  283. * @return boolean
  284. */
  285. public final boolean isCrystallizable()
  286. {
  287. return _crystalType != L2Item.CRYSTAL_NONE && _crystalCount > 0;
  288. }
  289. /**
  290. * Return the type of crystal if item is crystallizable
  291. * @return int
  292. */
  293. public final int getCrystalType()
  294. {
  295. return _crystalType;
  296. }
  297. /**
  298. * Return the type of crystal if item is crystallizable
  299. * @return int
  300. */
  301. public final int getCrystalItemId()
  302. {
  303. return crystalItemId[_crystalType];
  304. }
  305. /**
  306. * Returns the grade of the item.<BR><BR>
  307. * <U><I>Concept :</I></U><BR>
  308. * In fact, this fucntion returns the type of crystal of the item.
  309. * @return int
  310. */
  311. public final int getItemGrade()
  312. {
  313. return getCrystalType();
  314. }
  315. /**
  316. * Returns the grade of the item.<BR><BR>
  317. * For grades S80 and S84 return S
  318. * @return int
  319. */
  320. public final int getItemGradeSPlus()
  321. {
  322. switch (getItemGrade())
  323. {
  324. case CRYSTAL_S80:
  325. case CRYSTAL_S84:
  326. return CRYSTAL_S;
  327. default:
  328. return getItemGrade();
  329. }
  330. }
  331. /**
  332. * Returns the quantity of crystals for crystallization
  333. * @return int
  334. */
  335. public final int getCrystalCount()
  336. {
  337. return _crystalCount;
  338. }
  339. /**
  340. * Returns the quantity of crystals for crystallization on specific enchant level
  341. * @return int
  342. */
  343. public final int getCrystalCount(int enchantLevel)
  344. {
  345. if (enchantLevel > 3)
  346. switch (_type2)
  347. {
  348. case TYPE2_SHIELD_ARMOR:
  349. case TYPE2_ACCESSORY:
  350. return _crystalCount + crystalEnchantBonusArmor[getCrystalType()] * (3 * enchantLevel - 6);
  351. case TYPE2_WEAPON:
  352. return _crystalCount + crystalEnchantBonusWeapon[getCrystalType()] * (2 * enchantLevel - 3);
  353. default:
  354. return _crystalCount;
  355. }
  356. else if (enchantLevel > 0)
  357. switch (_type2)
  358. {
  359. case TYPE2_SHIELD_ARMOR:
  360. case TYPE2_ACCESSORY:
  361. return _crystalCount + crystalEnchantBonusArmor[getCrystalType()] * enchantLevel;
  362. case TYPE2_WEAPON:
  363. return _crystalCount + crystalEnchantBonusWeapon[getCrystalType()] * enchantLevel;
  364. default:
  365. return _crystalCount;
  366. }
  367. else
  368. return _crystalCount;
  369. }
  370. /**
  371. * Returns the name of the item
  372. * @return String
  373. */
  374. public final String getName()
  375. {
  376. return _name;
  377. }
  378. /**
  379. * Returns the base elemental of the item
  380. * @return Elementals
  381. */
  382. public final Elementals[] getElementals()
  383. {
  384. return _elementals;
  385. }
  386. public Elementals getElemental(byte attribute)
  387. {
  388. for (Elementals elm : _elementals)
  389. {
  390. if (elm.getElement() == attribute)
  391. return elm;
  392. }
  393. return null;
  394. }
  395. /**
  396. * Sets the base elemental of the item
  397. */
  398. public void setElementals(Elementals element)
  399. {
  400. if (_elementals == null)
  401. {
  402. _elementals = new Elementals[1];
  403. _elementals[0] = element;
  404. }
  405. else
  406. {
  407. Elementals elm = getElemental(element.getElement());
  408. if (elm != null)
  409. {
  410. elm.setValue(element.getValue());
  411. }
  412. else
  413. {
  414. elm = element;
  415. Elementals[] array = new Elementals[_elementals.length + 1];
  416. System.arraycopy(_elementals, 0, array, 0, _elementals.length);
  417. array[_elementals.length] = elm;
  418. _elementals = array;
  419. }
  420. }
  421. }
  422. /**
  423. * Return the part of the body used with the item.
  424. * @return int
  425. */
  426. public final int getBodyPart()
  427. {
  428. return _bodyPart;
  429. }
  430. /**
  431. * Returns the type 1 of the item
  432. * @return int
  433. */
  434. public final int getType1()
  435. {
  436. return _type1;
  437. }
  438. /**
  439. * Returns if the item is stackable
  440. * @return boolean
  441. */
  442. public final boolean isStackable()
  443. {
  444. return _stackable;
  445. }
  446. /**
  447. * Returns if the item is consumable
  448. * @return boolean
  449. */
  450. public boolean isConsumable()
  451. {
  452. return false;
  453. }
  454. public boolean isEquipable()
  455. {
  456. return this.getBodyPart() != 0 && !(this.getItemType() instanceof L2EtcItemType);
  457. }
  458. /**
  459. * Returns the price of reference of the item
  460. * @return int
  461. */
  462. public final int getReferencePrice()
  463. {
  464. return (isConsumable() ? (int)(_referencePrice * Config.RATE_CONSUMABLE_COST) : _referencePrice);
  465. }
  466. /**
  467. * Returns if the item can be sold
  468. * @return boolean
  469. */
  470. public final boolean isSellable()
  471. {
  472. return _sellable;
  473. }
  474. /**
  475. * Returns if the item can dropped
  476. * @return boolean
  477. */
  478. public final boolean isDropable()
  479. {
  480. return _dropable;
  481. }
  482. /**
  483. * Returns if the item can destroy
  484. * @return boolean
  485. */
  486. public final boolean isDestroyable()
  487. {
  488. return _destroyable;
  489. }
  490. /**
  491. * Returns if the item can add to trade
  492. * @return boolean
  493. */
  494. public final boolean isTradeable()
  495. {
  496. return _tradeable;
  497. }
  498. /**
  499. * Returns if the item can be put into warehouse
  500. * @return boolean
  501. */
  502. public final boolean isDepositable()
  503. {
  504. return _depositable;
  505. }
  506. /**
  507. * Returns if item is common
  508. * @return boolean
  509. */
  510. public final boolean isCommon()
  511. {
  512. return _common;
  513. }
  514. /**
  515. * Returns if item is hero-only
  516. * @return
  517. */
  518. public final boolean isHeroItem()
  519. {
  520. return _heroItem;
  521. }
  522. /**
  523. * Returns if item is pvp
  524. * @return
  525. */
  526. public final boolean isPvpItem()
  527. {
  528. return _pvpItem;
  529. }
  530. /**
  531. * Returns array of Func objects containing the list of functions used by the item
  532. * @param instance : L2ItemInstance pointing out the item
  533. * @param player : L2Character pointing out the player
  534. * @return Func[] : array of functions
  535. */
  536. public Func[] getStatFuncs(L2ItemInstance instance, L2Character player)
  537. {
  538. if (_funcTemplates == null || _funcTemplates.length == 0)
  539. return _emptyFunctionSet;
  540. ArrayList<Func> funcs = new ArrayList<Func>(_funcTemplates.length);
  541. Env env = new Env();
  542. env.player = player;
  543. env.target = player;
  544. env.item = instance;
  545. Func f;
  546. for (FuncTemplate t : _funcTemplates)
  547. {
  548. f = t.getFunc(env, this); // skill is owner
  549. if (f != null)
  550. funcs.add(f);
  551. }
  552. if (funcs.isEmpty())
  553. return _emptyFunctionSet;
  554. return funcs.toArray(new Func[funcs.size()]);
  555. }
  556. /**
  557. * Returns the effects associated with the item.
  558. * @param instance : L2ItemInstance pointing out the item
  559. * @param player : L2Character pointing out the player
  560. * @return L2Effect[] : array of effects generated by the item
  561. */
  562. public L2Effect[] getEffects(L2ItemInstance instance, L2Character player)
  563. {
  564. if (_effectTemplates == null || _effectTemplates.length == 0)
  565. return _emptyEffectSet;
  566. FastList<L2Effect> effects = FastList.newInstance();
  567. Env env = new Env();
  568. env.player = player;
  569. env.target = player;
  570. env.item = instance;
  571. L2Effect e;
  572. for (EffectTemplate et : _effectTemplates)
  573. {
  574. e = et.getEffect(env);
  575. if (e != null)
  576. {
  577. e.scheduleEffect();
  578. effects.add(e);
  579. }
  580. }
  581. if (effects.isEmpty())
  582. return _emptyEffectSet;
  583. L2Effect[] result = effects.toArray(new L2Effect[effects.size()]);
  584. FastList.recycle(effects);
  585. return result;
  586. }
  587. /**
  588. * Returns effects of skills associated with the item.
  589. * @param caster : L2Character pointing out the caster
  590. * @param target : L2Character pointing out the target
  591. * @return L2Effect[] : array of effects generated by the skill
  592. public L2Effect[] getSkillEffects(L2Character caster, L2Character target)
  593. {
  594. if (_skills == null)
  595. return _emptyEffectSet;
  596. List<L2Effect> effects = new FastList<L2Effect>();
  597. for (L2Skill skill : _skills)
  598. {
  599. if (!skill.checkCondition(caster, target, true))
  600. continue; // Skill condition not met
  601. if (target.getFirstEffect(skill.getId()) != null)
  602. target.removeEffect(target.getFirstEffect(skill.getId()));
  603. for (L2Effect e : skill.getEffects(caster, target))
  604. effects.add(e);
  605. }
  606. if (effects.isEmpty())
  607. return _emptyEffectSet;
  608. return effects.toArray(new L2Effect[effects.size()]);
  609. }
  610. */
  611. /**
  612. * Add the FuncTemplate f to the list of functions used with the item
  613. * @param f : FuncTemplate to add
  614. */
  615. public void attach(FuncTemplate f)
  616. {
  617. switch(f.stat)
  618. {
  619. case FIRE_RES:
  620. case FIRE_POWER:
  621. setElementals(new Elementals(Elementals.FIRE, (int) f.lambda.calc(null)));
  622. break;
  623. case WATER_RES:
  624. case WATER_POWER:
  625. setElementals(new Elementals(Elementals.WATER, (int) f.lambda.calc(null)));
  626. break;
  627. case WIND_RES:
  628. case WIND_POWER:
  629. setElementals(new Elementals(Elementals.WIND, (int) f.lambda.calc(null)));
  630. break;
  631. case EARTH_RES:
  632. case EARTH_POWER:
  633. setElementals(new Elementals(Elementals.EARTH, (int) f.lambda.calc(null)));
  634. break;
  635. case HOLY_RES:
  636. case HOLY_POWER:
  637. setElementals(new Elementals(Elementals.HOLY, (int) f.lambda.calc(null)));
  638. break;
  639. case DARK_RES:
  640. case DARK_POWER:
  641. setElementals(new Elementals(Elementals.DARK, (int) f.lambda.calc(null)));
  642. break;
  643. }
  644. // If _functTemplates is empty, create it and add the FuncTemplate f in it
  645. if (_funcTemplates == null)
  646. {
  647. _funcTemplates = new FuncTemplate[]
  648. {
  649. f
  650. };
  651. }
  652. else
  653. {
  654. int len = _funcTemplates.length;
  655. FuncTemplate[] tmp = new FuncTemplate[len + 1];
  656. // Definition : arraycopy(array source, begins copy at this position of source, array destination, begins copy at this position in dest,
  657. // number of components to be copied)
  658. System.arraycopy(_funcTemplates, 0, tmp, 0, len);
  659. tmp[len] = f;
  660. _funcTemplates = tmp;
  661. }
  662. }
  663. /**
  664. * Add the EffectTemplate effect to the list of effects generated by the item
  665. * @param effect : EffectTemplate
  666. */
  667. public void attach(EffectTemplate effect)
  668. {
  669. if (_effectTemplates == null)
  670. {
  671. _effectTemplates = new EffectTemplate[]
  672. {
  673. effect
  674. };
  675. }
  676. else
  677. {
  678. int len = _effectTemplates.length;
  679. EffectTemplate[] tmp = new EffectTemplate[len + 1];
  680. // Definition : arraycopy(array source, begins copy at this position of source, array destination, begins copy at this position in dest,
  681. // number of components to be copied)
  682. System.arraycopy(_effectTemplates, 0, tmp, 0, len);
  683. tmp[len] = effect;
  684. _effectTemplates = tmp;
  685. }
  686. }
  687. public final void attach(Condition c)
  688. {
  689. if (_preConditions == null)
  690. _preConditions = new FastList<Condition>();
  691. if (!_preConditions.contains(c))
  692. _preConditions.add(c);
  693. }
  694. public abstract SkillHolder[] getSkills();
  695. public boolean checkCondition(L2Character activeChar, L2Object target, boolean sendMessage)
  696. {
  697. if (activeChar.isGM() && !Config.GM_ITEM_RESTRICTION)
  698. return true;
  699. if (_preConditions == null)
  700. return true;
  701. Env env = new Env();
  702. env.player = activeChar;
  703. if (target instanceof L2Character)
  704. env.target = (L2Character)target;
  705. for (Condition preCondition : _preConditions)
  706. {
  707. if (preCondition == null)
  708. continue;
  709. if (!preCondition.test(env))
  710. {
  711. if (activeChar instanceof L2Summon)
  712. {
  713. activeChar.getActingPlayer().sendPacket(SystemMessage.getSystemMessage(SystemMessageId.PET_CANNOT_USE_ITEM));
  714. return false;
  715. }
  716. if (sendMessage)
  717. {
  718. String msg = preCondition.getMessage();
  719. int msgId = preCondition.getMessageId();
  720. if (msg != null)
  721. {
  722. activeChar.sendMessage(msg);
  723. }
  724. else if (msgId !=0)
  725. {
  726. SystemMessage sm = SystemMessage.getSystemMessage(msgId);
  727. if (preCondition.isAddName())
  728. sm.addItemName(_itemId);
  729. activeChar.getActingPlayer().sendPacket(sm);
  730. }
  731. }
  732. return false;
  733. }
  734. }
  735. return true;
  736. }
  737. public boolean isConditionAttached()
  738. {
  739. return _preConditions != null && !_preConditions.isEmpty();
  740. }
  741. public boolean isQuestItem()
  742. {
  743. return _questItem;
  744. }
  745. /**
  746. * Returns the name of the item
  747. * @return String
  748. */
  749. @Override
  750. public String toString()
  751. {
  752. return _name+"("+_itemId+")";
  753. }
  754. /**
  755. * @return the _ex_immediate_effect
  756. */
  757. public boolean is_ex_immediate_effect()
  758. {
  759. return _ex_immediate_effect;
  760. }
  761. /**
  762. * @return the _default_action
  763. */
  764. public L2ActionType getDefaultAction()
  765. {
  766. return _defaultAction;
  767. }
  768. /**
  769. * Get the icon link in client files.<BR> Usable in HTML windows.
  770. * @return the _icon
  771. */
  772. public String getIcon()
  773. {
  774. return _icon;
  775. }
  776. }