L2Item.java 21 KB

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