L2Item.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  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 grade of the item.<BR><BR>
  292. * For grades S80 and S84 return S
  293. * @return int
  294. */
  295. public final int getItemGradeSPlus()
  296. {
  297. switch (getItemGrade())
  298. {
  299. case CRYSTAL_S80:
  300. case CRYSTAL_S84:
  301. return CRYSTAL_S;
  302. default:
  303. return getItemGrade();
  304. }
  305. }
  306. /**
  307. * Returns the quantity of crystals for crystallization
  308. * @return int
  309. */
  310. public final int getCrystalCount()
  311. {
  312. return _crystalCount;
  313. }
  314. /**
  315. * Returns the quantity of crystals for crystallization on specific enchant level
  316. * @return int
  317. */
  318. public final int getCrystalCount(int enchantLevel)
  319. {
  320. if (enchantLevel > 3)
  321. switch (_type2)
  322. {
  323. case TYPE2_SHIELD_ARMOR:
  324. case TYPE2_ACCESSORY:
  325. return _crystalCount + crystalEnchantBonusArmor[getCrystalType()] * (3 * enchantLevel - 6);
  326. case TYPE2_WEAPON:
  327. return _crystalCount + crystalEnchantBonusWeapon[getCrystalType()] * (2 * enchantLevel - 3);
  328. default:
  329. return _crystalCount;
  330. }
  331. else if (enchantLevel > 0)
  332. switch (_type2)
  333. {
  334. case TYPE2_SHIELD_ARMOR:
  335. case TYPE2_ACCESSORY:
  336. return _crystalCount + crystalEnchantBonusArmor[getCrystalType()] * enchantLevel;
  337. case TYPE2_WEAPON:
  338. return _crystalCount + crystalEnchantBonusWeapon[getCrystalType()] * enchantLevel;
  339. default:
  340. return _crystalCount;
  341. }
  342. else
  343. return _crystalCount;
  344. }
  345. /**
  346. * Returns the name of the item
  347. * @return String
  348. */
  349. public final String getName()
  350. {
  351. return _name;
  352. }
  353. /**
  354. * Return the part of the body used with the item.
  355. * @return int
  356. */
  357. public final int getBodyPart()
  358. {
  359. return _bodyPart;
  360. }
  361. /**
  362. * Returns the type 1 of the item
  363. * @return int
  364. */
  365. public final int getType1()
  366. {
  367. return _type1;
  368. }
  369. /**
  370. * Returns if the item is stackable
  371. * @return boolean
  372. */
  373. public final boolean isStackable()
  374. {
  375. return _stackable;
  376. }
  377. /**
  378. * Returns if the item is consumable
  379. * @return boolean
  380. */
  381. public boolean isConsumable()
  382. {
  383. return false;
  384. }
  385. public boolean isEquipable()
  386. {
  387. return this.getBodyPart() != 0 && !(this.getItemType() instanceof L2EtcItemType);
  388. }
  389. /**
  390. * Returns the price of reference of the item
  391. * @return int
  392. */
  393. public final int getReferencePrice()
  394. {
  395. return (isConsumable() ? (int)(_referencePrice * Config.RATE_CONSUMABLE_COST) : _referencePrice);
  396. }
  397. /**
  398. * Returns if the item can be sold
  399. * @return boolean
  400. */
  401. public final boolean isSellable()
  402. {
  403. return _sellable;
  404. }
  405. /**
  406. * Returns if the item can dropped
  407. * @return boolean
  408. */
  409. public final boolean isDropable()
  410. {
  411. return _dropable;
  412. }
  413. /**
  414. * Returns if the item can destroy
  415. * @return boolean
  416. */
  417. public final boolean isDestroyable()
  418. {
  419. return _destroyable;
  420. }
  421. /**
  422. * Returns if the item can add to trade
  423. * @return boolean
  424. */
  425. public final boolean isTradeable()
  426. {
  427. return _tradeable;
  428. }
  429. /**
  430. * Returns if item is for hatchling
  431. * @return boolean
  432. */
  433. public boolean isForHatchling()
  434. {
  435. return (_type2 == TYPE2_PET_HATCHLING);
  436. }
  437. /**
  438. * Returns if item is for strider
  439. * @return boolean
  440. */
  441. public boolean isForStrider()
  442. {
  443. return (_type2 == TYPE2_PET_STRIDER);
  444. }
  445. /**
  446. * Returns if item is for wolf
  447. * @return boolean
  448. */
  449. public boolean isForWolf()
  450. {
  451. return (_type2 == TYPE2_PET_WOLF);
  452. }
  453. /**
  454. * Returns if item is for Great wolf
  455. * @return boolean
  456. */
  457. public boolean isForEvolvedWolf()
  458. {
  459. return (_type2 == TYPE2_PET_EVOLVEDWOLF);
  460. }
  461. /**
  462. * Returns if item is for wolf
  463. * @return boolean
  464. */
  465. public boolean isForBabyPet()
  466. {
  467. return (_type2 == TYPE2_PET_BABY);
  468. }
  469. /**
  470. * Returns array of Func objects containing the list of functions used by the item
  471. * @param instance : L2ItemInstance pointing out the item
  472. * @param player : L2Character pointing out the player
  473. * @return Func[] : array of functions
  474. */
  475. public Func[] getStatFuncs(L2ItemInstance instance, L2Character player)
  476. {
  477. if (_funcTemplates == null)
  478. return _emptyFunctionSet;
  479. List<Func> funcs = new FastList<Func>();
  480. for (FuncTemplate t : _funcTemplates)
  481. {
  482. Env env = new Env();
  483. env.player = player;
  484. env.target = player;
  485. env.item = instance;
  486. Func f = t.getFunc(env, this); // skill is owner
  487. if (f != null)
  488. funcs.add(f);
  489. }
  490. if (funcs.isEmpty())
  491. return _emptyFunctionSet;
  492. return funcs.toArray(new Func[funcs.size()]);
  493. }
  494. /**
  495. * Returns the effects associated with the item.
  496. * @param instance : L2ItemInstance pointing out the item
  497. * @param player : L2Character pointing out the player
  498. * @return L2Effect[] : array of effects generated by the item
  499. */
  500. public L2Effect[] getEffects(L2ItemInstance instance, L2Character player)
  501. {
  502. if (_effectTemplates == null)
  503. return _emptyEffectSet;
  504. List<L2Effect> effects = new FastList<L2Effect>();
  505. for (EffectTemplate et : _effectTemplates)
  506. {
  507. Env env = new Env();
  508. env.player = player;
  509. env.target = player;
  510. env.item = instance;
  511. L2Effect e = et.getEffect(env);
  512. if (e != null)
  513. {
  514. e.scheduleEffect();
  515. effects.add(e);
  516. }
  517. }
  518. if (effects.isEmpty())
  519. return _emptyEffectSet;
  520. return effects.toArray(new L2Effect[effects.size()]);
  521. }
  522. /**
  523. * Returns effects of skills associated with the item.
  524. * @param caster : L2Character pointing out the caster
  525. * @param target : L2Character pointing out the target
  526. * @return L2Effect[] : array of effects generated by the skill
  527. public L2Effect[] getSkillEffects(L2Character caster, L2Character target)
  528. {
  529. if (_skills == null)
  530. return _emptyEffectSet;
  531. List<L2Effect> effects = new FastList<L2Effect>();
  532. for (L2Skill skill : _skills)
  533. {
  534. if (!skill.checkCondition(caster, target, true))
  535. continue; // Skill condition not met
  536. if (target.getFirstEffect(skill.getId()) != null)
  537. target.removeEffect(target.getFirstEffect(skill.getId()));
  538. for (L2Effect e : skill.getEffects(caster, target))
  539. effects.add(e);
  540. }
  541. if (effects.isEmpty())
  542. return _emptyEffectSet;
  543. return effects.toArray(new L2Effect[effects.size()]);
  544. }
  545. */
  546. /**
  547. * Add the FuncTemplate f to the list of functions used with the item
  548. * @param f : FuncTemplate to add
  549. */
  550. public void attach(FuncTemplate f)
  551. {
  552. // If _functTemplates is empty, create it and add the FuncTemplate f in it
  553. if (_funcTemplates == null)
  554. {
  555. _funcTemplates = new FuncTemplate[]
  556. {
  557. f
  558. };
  559. }
  560. else
  561. {
  562. int len = _funcTemplates.length;
  563. FuncTemplate[] tmp = new FuncTemplate[len + 1];
  564. // Definition : arraycopy(array source, begins copy at this position of source, array destination, begins copy at this position in dest,
  565. // number of components to be copied)
  566. System.arraycopy(_funcTemplates, 0, tmp, 0, len);
  567. tmp[len] = f;
  568. _funcTemplates = tmp;
  569. }
  570. }
  571. /**
  572. * Add the EffectTemplate effect to the list of effects generated by the item
  573. * @param effect : EffectTemplate
  574. */
  575. public void attach(EffectTemplate effect)
  576. {
  577. if (_effectTemplates == null)
  578. {
  579. _effectTemplates = new EffectTemplate[]
  580. {
  581. effect
  582. };
  583. }
  584. else
  585. {
  586. int len = _effectTemplates.length;
  587. EffectTemplate[] tmp = new EffectTemplate[len + 1];
  588. // Definition : arraycopy(array source, begins copy at this position of source, array destination, begins copy at this position in dest,
  589. // number of components to be copied)
  590. System.arraycopy(_effectTemplates, 0, tmp, 0, len);
  591. tmp[len] = effect;
  592. _effectTemplates = tmp;
  593. }
  594. }
  595. /**
  596. * Add the L2Skill skill to the list of skills generated by the item
  597. * @param skill : L2Skill
  598. */
  599. public void attach(L2Skill skill)
  600. {
  601. if (_skills == null)
  602. {
  603. _skills = new L2Skill[]
  604. {
  605. skill
  606. };
  607. }
  608. else
  609. {
  610. int len = _skills.length;
  611. L2Skill[] tmp = new L2Skill[len + 1];
  612. // Definition : arraycopy(array source, begins copy at this position of source, array destination, begins copy at this position in dest,
  613. // number of components to be copied)
  614. System.arraycopy(_skills, 0, tmp, 0, len);
  615. tmp[len] = skill;
  616. _skills = tmp;
  617. }
  618. }
  619. public final void attach(Condition c)
  620. {
  621. if (!_preConditions.contains(c))
  622. _preConditions.add(c);
  623. }
  624. public final L2Skill[] getItemSkills()
  625. {
  626. return _skills;
  627. }
  628. public boolean checkCondition(L2Character activeChar, L2Object target)
  629. {
  630. if (activeChar.isGM() && !Config.GM_ITEM_RESTRICTION)
  631. return true;
  632. for (Condition preCondition : _preConditions)
  633. {
  634. if (preCondition == null) return true;
  635. Env env = new Env();
  636. env.player = activeChar;
  637. if (target instanceof L2Character) // TODO: object or char?
  638. env.target = (L2Character)target;
  639. if (!preCondition.test(env))
  640. {
  641. if (activeChar instanceof L2SummonInstance)
  642. {
  643. ((L2SummonInstance)activeChar).getOwner().sendPacket(new SystemMessage(SystemMessageId.PET_CANNOT_USE_ITEM));
  644. return false;
  645. }
  646. String msg = preCondition.getMessage();
  647. int msgId = preCondition.getMessageId();
  648. if (msg != null)
  649. {
  650. activeChar.sendMessage(msg);
  651. }
  652. else if (msgId !=0)
  653. {
  654. SystemMessage sm = new SystemMessage(msgId);
  655. if (preCondition.isAddName())
  656. sm.addItemName(_itemId);
  657. activeChar.sendPacket(sm);
  658. }
  659. return false;
  660. }
  661. }
  662. return true;
  663. }
  664. /**
  665. * Returns the name of the item
  666. * @return String
  667. */
  668. @Override
  669. public String toString()
  670. {
  671. return _name;
  672. }
  673. }