L2Item.java 23 KB

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