L2Item.java 23 KB

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