L2Item.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  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 net.sf.l2j.gameserver.templates.item;
  16. import java.util.List;
  17. import javolution.util.FastList;
  18. import net.sf.l2j.Config;
  19. import net.sf.l2j.gameserver.model.L2Effect;
  20. import net.sf.l2j.gameserver.model.L2ItemInstance;
  21. import net.sf.l2j.gameserver.model.L2Object;
  22. import net.sf.l2j.gameserver.model.L2Skill;
  23. import net.sf.l2j.gameserver.model.actor.L2Character;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2SummonInstance;
  25. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  26. import net.sf.l2j.gameserver.network.SystemMessageId;
  27. import net.sf.l2j.gameserver.skills.Env;
  28. import net.sf.l2j.gameserver.skills.conditions.Condition;
  29. import net.sf.l2j.gameserver.skills.funcs.Func;
  30. import net.sf.l2j.gameserver.skills.funcs.FuncTemplate;
  31. import net.sf.l2j.gameserver.templates.StatsSet;
  32. import net.sf.l2j.gameserver.templates.effects.EffectTemplate;
  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. @SuppressWarnings("unchecked")
  151. protected final Enum _type;
  152. protected FuncTemplate[] _funcTemplates;
  153. protected EffectTemplate[] _effectTemplates;
  154. protected L2Skill[] _skills;
  155. protected List <Condition> _preConditions = new FastList<Condition>();
  156. private static final Func[] _emptyFunctionSet = new Func[0];
  157. protected static final L2Effect[] _emptyEffectSet = new L2Effect[0];
  158. /**
  159. * Constructor of the L2Item that fill class variables.<BR><BR>
  160. * <U><I>Variables filled :</I></U><BR>
  161. * <LI>type</LI>
  162. * <LI>_itemId</LI>
  163. * <LI>_name</LI>
  164. * <LI>_type1 & _type2</LI>
  165. * <LI>_weight</LI>
  166. * <LI>_crystallizable</LI>
  167. * <LI>_stackable</LI>
  168. * <LI>_materialType & _crystalType & _crystlaCount</LI>
  169. * <LI>_duration</LI>
  170. * <LI>_bodypart</LI>
  171. * <LI>_referencePrice</LI>
  172. * <LI>_sellable</LI>
  173. * @param type : Enum designating the type of the item
  174. * @param set : StatsSet corresponding to a set of couples (key,value) for description of the item
  175. */
  176. protected L2Item(Enum<?> type, StatsSet set)
  177. {
  178. _type = type;
  179. _itemId = set.getInteger("item_id");
  180. _name = set.getString("name");
  181. _type1 = set.getInteger("type1"); // needed for item list (inventory)
  182. _type2 = set.getInteger("type2"); // different lists for armor, weapon, etc
  183. _weight = set.getInteger("weight");
  184. _crystallizable = set.getBool("crystallizable");
  185. _stackable = set.getBool("stackable", false);
  186. _materialType = set.getInteger("material");
  187. _crystalType = set.getInteger("crystal_type", CRYSTAL_NONE); // default to none-grade
  188. _duration = set.getInteger("duration");
  189. _time = set.getInteger("time");
  190. _bodyPart = set.getInteger("bodypart");
  191. _referencePrice = set.getInteger("price");
  192. _crystalCount = set.getInteger("crystal_count", 0);
  193. _sellable = set.getBool("sellable", true);
  194. _dropable = set.getBool("dropable", true);
  195. _destroyable = set.getBool("destroyable", true);
  196. _tradeable = set.getBool("tradeable", true);
  197. }
  198. /**
  199. * Returns the itemType.
  200. * @return Enum
  201. */
  202. @SuppressWarnings("unchecked")
  203. public Enum getItemType()
  204. {
  205. return _type;
  206. }
  207. /**
  208. * Returns the duration of the item
  209. * @return int
  210. */
  211. public final int getDuration()
  212. {
  213. return _duration;
  214. }
  215. /**
  216. * Returns the time of the item
  217. * @return int
  218. */
  219. public final int getTime()
  220. {
  221. return _time;
  222. }
  223. /**
  224. * Returns the ID of the iden
  225. * @return int
  226. */
  227. public final int getItemId()
  228. {
  229. return _itemId;
  230. }
  231. public abstract int getItemMask();
  232. /**
  233. * Return the type of material of the item
  234. * @return int
  235. */
  236. public final int getMaterialType()
  237. {
  238. return _materialType;
  239. }
  240. /**
  241. * Returns the type 2 of the item
  242. * @return int
  243. */
  244. public final int getType2()
  245. {
  246. return _type2;
  247. }
  248. /**
  249. * Returns the weight of the item
  250. * @return int
  251. */
  252. public final int getWeight()
  253. {
  254. return _weight;
  255. }
  256. /**
  257. * Returns if the item is crystallizable
  258. * @return boolean
  259. */
  260. public final boolean isCrystallizable()
  261. {
  262. return _crystallizable;
  263. }
  264. /**
  265. * Return the type of crystal if item is crystallizable
  266. * @return int
  267. */
  268. public final int getCrystalType()
  269. {
  270. return _crystalType;
  271. }
  272. /**
  273. * Return the type of crystal if item is crystallizable
  274. * @return int
  275. */
  276. public final int getCrystalItemId()
  277. {
  278. return crystalItemId[_crystalType];
  279. }
  280. /**
  281. * Returns the grade of the item.<BR><BR>
  282. * <U><I>Concept :</I></U><BR>
  283. * In fact, this fucntion returns the type of crystal of the item.
  284. * @return int
  285. */
  286. public final int getItemGrade()
  287. {
  288. return getCrystalType();
  289. }
  290. /**
  291. * Returns the quantity of crystals for crystallization
  292. * @return int
  293. */
  294. public final int getCrystalCount()
  295. {
  296. return _crystalCount;
  297. }
  298. /**
  299. * Returns the quantity of crystals for crystallization on specific enchant level
  300. * @return int
  301. */
  302. public final int getCrystalCount(int enchantLevel)
  303. {
  304. if (enchantLevel > 3)
  305. switch (_type2)
  306. {
  307. case TYPE2_SHIELD_ARMOR:
  308. case TYPE2_ACCESSORY:
  309. return _crystalCount + crystalEnchantBonusArmor[getCrystalType()] * (3 * enchantLevel - 6);
  310. case TYPE2_WEAPON:
  311. return _crystalCount + crystalEnchantBonusWeapon[getCrystalType()] * (2 * enchantLevel - 3);
  312. default:
  313. return _crystalCount;
  314. }
  315. else if (enchantLevel > 0)
  316. switch (_type2)
  317. {
  318. case TYPE2_SHIELD_ARMOR:
  319. case TYPE2_ACCESSORY:
  320. return _crystalCount + crystalEnchantBonusArmor[getCrystalType()] * enchantLevel;
  321. case TYPE2_WEAPON:
  322. return _crystalCount + crystalEnchantBonusWeapon[getCrystalType()] * enchantLevel;
  323. default:
  324. return _crystalCount;
  325. }
  326. else
  327. return _crystalCount;
  328. }
  329. /**
  330. * Returns the name of the item
  331. * @return String
  332. */
  333. public final String getName()
  334. {
  335. return _name;
  336. }
  337. /**
  338. * Return the part of the body used with the item.
  339. * @return int
  340. */
  341. public final int getBodyPart()
  342. {
  343. return _bodyPart;
  344. }
  345. /**
  346. * Returns the type 1 of the item
  347. * @return int
  348. */
  349. public final int getType1()
  350. {
  351. return _type1;
  352. }
  353. /**
  354. * Returns if the item is stackable
  355. * @return boolean
  356. */
  357. public final boolean isStackable()
  358. {
  359. return _stackable;
  360. }
  361. /**
  362. * Returns if the item is consumable
  363. * @return boolean
  364. */
  365. public boolean isConsumable()
  366. {
  367. return false;
  368. }
  369. public boolean isEquipable()
  370. {
  371. return this.getBodyPart() != 0 && !(this.getItemType() instanceof L2EtcItemType);
  372. }
  373. /**
  374. * Returns the price of reference of the item
  375. * @return int
  376. */
  377. public final int getReferencePrice()
  378. {
  379. return (isConsumable() ? (int)(_referencePrice * Config.RATE_CONSUMABLE_COST) : _referencePrice);
  380. }
  381. /**
  382. * Returns if the item can be sold
  383. * @return boolean
  384. */
  385. public final boolean isSellable()
  386. {
  387. return _sellable;
  388. }
  389. /**
  390. * Returns if the item can dropped
  391. * @return boolean
  392. */
  393. public final boolean isDropable()
  394. {
  395. return _dropable;
  396. }
  397. /**
  398. * Returns if the item can destroy
  399. * @return boolean
  400. */
  401. public final boolean isDestroyable()
  402. {
  403. return _destroyable;
  404. }
  405. /**
  406. * Returns if the item can add to trade
  407. * @return boolean
  408. */
  409. public final boolean isTradeable()
  410. {
  411. return _tradeable;
  412. }
  413. /**
  414. * Returns if item is for hatchling
  415. * @return boolean
  416. */
  417. public boolean isForHatchling()
  418. {
  419. return (_type2 == TYPE2_PET_HATCHLING);
  420. }
  421. /**
  422. * Returns if item is for strider
  423. * @return boolean
  424. */
  425. public boolean isForStrider()
  426. {
  427. return (_type2 == TYPE2_PET_STRIDER);
  428. }
  429. /**
  430. * Returns if item is for wolf
  431. * @return boolean
  432. */
  433. public boolean isForWolf()
  434. {
  435. return (_type2 == TYPE2_PET_WOLF);
  436. }
  437. /**
  438. * Returns if item is for Great wolf
  439. * @return boolean
  440. */
  441. public boolean isForEvolvedWolf()
  442. {
  443. return (_type2 == TYPE2_PET_EVOLVEDWOLF);
  444. }
  445. /**
  446. * Returns if item is for wolf
  447. * @return boolean
  448. */
  449. public boolean isForBabyPet()
  450. {
  451. return (_type2 == TYPE2_PET_BABY);
  452. }
  453. /**
  454. * Returns array of Func objects containing the list of functions used by the item
  455. * @param instance : L2ItemInstance pointing out the item
  456. * @param player : L2Character pointing out the player
  457. * @return Func[] : array of functions
  458. */
  459. public Func[] getStatFuncs(L2ItemInstance instance, L2Character player)
  460. {
  461. if (_funcTemplates == null)
  462. return _emptyFunctionSet;
  463. List<Func> funcs = new FastList<Func>();
  464. for (FuncTemplate t : _funcTemplates)
  465. {
  466. Env env = new Env();
  467. env.player = player;
  468. env.target = player;
  469. env.item = instance;
  470. Func f = t.getFunc(env, this); // skill is owner
  471. if (f != null)
  472. funcs.add(f);
  473. }
  474. if (funcs.isEmpty())
  475. return _emptyFunctionSet;
  476. return funcs.toArray(new Func[funcs.size()]);
  477. }
  478. /**
  479. * Returns the effects associated with the item.
  480. * @param instance : L2ItemInstance pointing out the item
  481. * @param player : L2Character pointing out the player
  482. * @return L2Effect[] : array of effects generated by the item
  483. */
  484. public L2Effect[] getEffects(L2ItemInstance instance, L2Character player)
  485. {
  486. if (_effectTemplates == null)
  487. return _emptyEffectSet;
  488. List<L2Effect> effects = new FastList<L2Effect>();
  489. for (EffectTemplate et : _effectTemplates)
  490. {
  491. Env env = new Env();
  492. env.player = player;
  493. env.target = player;
  494. env.item = instance;
  495. L2Effect e = et.getEffect(env);
  496. if (e != null)
  497. {
  498. e.scheduleEffect();
  499. effects.add(e);
  500. }
  501. }
  502. if (effects.isEmpty())
  503. return _emptyEffectSet;
  504. return effects.toArray(new L2Effect[effects.size()]);
  505. }
  506. /**
  507. * Returns effects of skills associated with the item.
  508. * @param caster : L2Character pointing out the caster
  509. * @param target : L2Character pointing out the target
  510. * @return L2Effect[] : array of effects generated by the skill
  511. public L2Effect[] getSkillEffects(L2Character caster, L2Character target)
  512. {
  513. if (_skills == null)
  514. return _emptyEffectSet;
  515. List<L2Effect> effects = new FastList<L2Effect>();
  516. for (L2Skill skill : _skills)
  517. {
  518. if (!skill.checkCondition(caster, target, true))
  519. continue; // Skill condition not met
  520. if (target.getFirstEffect(skill.getId()) != null)
  521. target.removeEffect(target.getFirstEffect(skill.getId()));
  522. for (L2Effect e : skill.getEffects(caster, target))
  523. effects.add(e);
  524. }
  525. if (effects.isEmpty())
  526. return _emptyEffectSet;
  527. return effects.toArray(new L2Effect[effects.size()]);
  528. }
  529. */
  530. /**
  531. * Add the FuncTemplate f to the list of functions used with the item
  532. * @param f : FuncTemplate to add
  533. */
  534. public void attach(FuncTemplate f)
  535. {
  536. // If _functTemplates is empty, create it and add the FuncTemplate f in it
  537. if (_funcTemplates == null)
  538. {
  539. _funcTemplates = new FuncTemplate[]
  540. {
  541. f
  542. };
  543. }
  544. else
  545. {
  546. int len = _funcTemplates.length;
  547. FuncTemplate[] tmp = new FuncTemplate[len + 1];
  548. // Definition : arraycopy(array source, begins copy at this position of source, array destination, begins copy at this position in dest,
  549. // number of components to be copied)
  550. System.arraycopy(_funcTemplates, 0, tmp, 0, len);
  551. tmp[len] = f;
  552. _funcTemplates = tmp;
  553. }
  554. }
  555. /**
  556. * Add the EffectTemplate effect to the list of effects generated by the item
  557. * @param effect : EffectTemplate
  558. */
  559. public void attach(EffectTemplate effect)
  560. {
  561. if (_effectTemplates == null)
  562. {
  563. _effectTemplates = new EffectTemplate[]
  564. {
  565. effect
  566. };
  567. }
  568. else
  569. {
  570. int len = _effectTemplates.length;
  571. EffectTemplate[] tmp = new EffectTemplate[len + 1];
  572. // Definition : arraycopy(array source, begins copy at this position of source, array destination, begins copy at this position in dest,
  573. // number of components to be copied)
  574. System.arraycopy(_effectTemplates, 0, tmp, 0, len);
  575. tmp[len] = effect;
  576. _effectTemplates = tmp;
  577. }
  578. }
  579. /**
  580. * Add the L2Skill skill to the list of skills generated by the item
  581. * @param skill : L2Skill
  582. */
  583. public void attach(L2Skill skill)
  584. {
  585. if (_skills == null)
  586. {
  587. _skills = new L2Skill[]
  588. {
  589. skill
  590. };
  591. }
  592. else
  593. {
  594. int len = _skills.length;
  595. L2Skill[] tmp = new L2Skill[len + 1];
  596. // Definition : arraycopy(array source, begins copy at this position of source, array destination, begins copy at this position in dest,
  597. // number of components to be copied)
  598. System.arraycopy(_skills, 0, tmp, 0, len);
  599. tmp[len] = skill;
  600. _skills = tmp;
  601. }
  602. }
  603. public final void attach(Condition c)
  604. {
  605. if (!_preConditions.contains(c))
  606. _preConditions.add(c);
  607. }
  608. public final L2Skill[] getItemSkills()
  609. {
  610. return _skills;
  611. }
  612. public boolean checkCondition(L2Character activeChar, L2Object target)
  613. {
  614. if (activeChar.isGM() && !Config.GM_ITEM_RESTRICTION)
  615. return true;
  616. for (Condition preCondition : _preConditions)
  617. {
  618. if (preCondition == null) return true;
  619. Env env = new Env();
  620. env.player = activeChar;
  621. if (target instanceof L2Character) // TODO: object or char?
  622. env.target = (L2Character)target;
  623. if (!preCondition.test(env))
  624. {
  625. if (activeChar instanceof L2SummonInstance)
  626. {
  627. ((L2SummonInstance)activeChar).getOwner().sendPacket(new SystemMessage(SystemMessageId.PET_CANNOT_USE_ITEM));
  628. return false;
  629. }
  630. String msg = preCondition.getMessage();
  631. int msgId = preCondition.getMessageId();
  632. if (msg != null)
  633. {
  634. activeChar.sendMessage(msg);
  635. }
  636. else if (msgId !=0)
  637. {
  638. SystemMessage sm = new SystemMessage(msgId);
  639. if (preCondition.isAddName())
  640. sm.addItemName(_itemId);
  641. activeChar.sendPacket(sm);
  642. }
  643. return false;
  644. }
  645. }
  646. return true;
  647. }
  648. /**
  649. * Returns the name of the item
  650. * @return String
  651. */
  652. @Override
  653. public String toString()
  654. {
  655. return _name;
  656. }
  657. }