L2Item.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.model.items;
  20. import java.util.ArrayList;
  21. import java.util.Arrays;
  22. import java.util.Collections;
  23. import java.util.List;
  24. import java.util.logging.Logger;
  25. import com.l2jserver.Config;
  26. import com.l2jserver.gameserver.datatables.ItemTable;
  27. import com.l2jserver.gameserver.model.Elementals;
  28. import com.l2jserver.gameserver.model.L2Object;
  29. import com.l2jserver.gameserver.model.PcCondOverride;
  30. import com.l2jserver.gameserver.model.StatsSet;
  31. import com.l2jserver.gameserver.model.actor.L2Character;
  32. import com.l2jserver.gameserver.model.actor.L2Summon;
  33. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  34. import com.l2jserver.gameserver.model.conditions.Condition;
  35. import com.l2jserver.gameserver.model.events.ListenersContainer;
  36. import com.l2jserver.gameserver.model.holders.SkillHolder;
  37. import com.l2jserver.gameserver.model.interfaces.IIdentifiable;
  38. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  39. import com.l2jserver.gameserver.model.items.type.ActionType;
  40. import com.l2jserver.gameserver.model.items.type.CrystalType;
  41. import com.l2jserver.gameserver.model.items.type.EtcItemType;
  42. import com.l2jserver.gameserver.model.items.type.ItemType;
  43. import com.l2jserver.gameserver.model.items.type.MaterialType;
  44. import com.l2jserver.gameserver.model.skills.Skill;
  45. import com.l2jserver.gameserver.model.stats.functions.AbstractFunction;
  46. import com.l2jserver.gameserver.model.stats.functions.FuncTemplate;
  47. import com.l2jserver.gameserver.network.SystemMessageId;
  48. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  49. import com.l2jserver.util.StringUtil;
  50. /**
  51. * This class contains all informations concerning the item (weapon, armor, etc).<BR>
  52. * Mother class of :
  53. * <ul>
  54. * <li>L2Armor</li>
  55. * <li>L2EtcItem</li>
  56. * <li>L2Weapon</li>
  57. * </ul>
  58. */
  59. public abstract class L2Item extends ListenersContainer implements IIdentifiable
  60. {
  61. protected static final Logger _log = Logger.getLogger(L2Item.class.getName());
  62. public static final int TYPE1_WEAPON_RING_EARRING_NECKLACE = 0;
  63. public static final int TYPE1_SHIELD_ARMOR = 1;
  64. public static final int TYPE1_ITEM_QUESTITEM_ADENA = 4;
  65. public static final int TYPE2_WEAPON = 0;
  66. public static final int TYPE2_SHIELD_ARMOR = 1;
  67. public static final int TYPE2_ACCESSORY = 2;
  68. public static final int TYPE2_QUEST = 3;
  69. public static final int TYPE2_MONEY = 4;
  70. public static final int TYPE2_OTHER = 5;
  71. public static final int SLOT_NONE = 0x0000;
  72. public static final int SLOT_UNDERWEAR = 0x0001;
  73. public static final int SLOT_R_EAR = 0x0002;
  74. public static final int SLOT_L_EAR = 0x0004;
  75. public static final int SLOT_LR_EAR = 0x00006;
  76. public static final int SLOT_NECK = 0x0008;
  77. public static final int SLOT_R_FINGER = 0x0010;
  78. public static final int SLOT_L_FINGER = 0x0020;
  79. public static final int SLOT_LR_FINGER = 0x0030;
  80. public static final int SLOT_HEAD = 0x0040;
  81. public static final int SLOT_R_HAND = 0x0080;
  82. public static final int SLOT_L_HAND = 0x0100;
  83. public static final int SLOT_GLOVES = 0x0200;
  84. public static final int SLOT_CHEST = 0x0400;
  85. public static final int SLOT_LEGS = 0x0800;
  86. public static final int SLOT_FEET = 0x1000;
  87. public static final int SLOT_BACK = 0x2000;
  88. public static final int SLOT_LR_HAND = 0x4000;
  89. public static final int SLOT_FULL_ARMOR = 0x8000;
  90. public static final int SLOT_HAIR = 0x010000;
  91. public static final int SLOT_ALLDRESS = 0x020000;
  92. public static final int SLOT_HAIR2 = 0x040000;
  93. public static final int SLOT_HAIRALL = 0x080000;
  94. public static final int SLOT_R_BRACELET = 0x100000;
  95. public static final int SLOT_L_BRACELET = 0x200000;
  96. public static final int SLOT_DECO = 0x400000;
  97. public static final int SLOT_BELT = 0x10000000;
  98. public static final int SLOT_WOLF = -100;
  99. public static final int SLOT_HATCHLING = -101;
  100. public static final int SLOT_STRIDER = -102;
  101. public static final int SLOT_BABYPET = -103;
  102. public static final int SLOT_GREATWOLF = -104;
  103. public static final int SLOT_MULTI_ALLWEAPON = SLOT_LR_HAND | SLOT_R_HAND;
  104. private final int _itemId;
  105. private final int _displayId;
  106. private final String _name;
  107. private final String _icon;
  108. private final int _weight;
  109. private final boolean _stackable;
  110. private final MaterialType _materialType;
  111. private final CrystalType _crystalType;
  112. private final int _equipReuseDelay;
  113. private final int _duration;
  114. private final int _time;
  115. private final int _autoDestroyTime;
  116. private final int _bodyPart;
  117. private final int _referencePrice;
  118. private final int _crystalCount;
  119. private final boolean _sellable;
  120. private final boolean _dropable;
  121. private final boolean _destroyable;
  122. private final boolean _tradeable;
  123. private final boolean _depositable;
  124. private final int _enchantable;
  125. private final boolean _elementable;
  126. private final boolean _questItem;
  127. private final boolean _freightable;
  128. private final boolean _allow_self_resurrection;
  129. private final boolean _is_oly_restricted;
  130. private final boolean _for_npc;
  131. private final boolean _common;
  132. private final boolean _heroItem;
  133. private final boolean _pvpItem;
  134. private final boolean _immediate_effect;
  135. private final boolean _ex_immediate_effect;
  136. private final int _defaultEnchantLevel;
  137. private final ActionType _defaultAction;
  138. protected int _type1; // needed for item list (inventory)
  139. protected int _type2; // different lists for armor, weapon, etc
  140. protected Elementals[] _elementals = null;
  141. protected List<FuncTemplate> _funcTemplates;
  142. protected List<Condition> _preConditions;
  143. private SkillHolder[] _skillHolder;
  144. private SkillHolder _unequipSkill = null;
  145. private final int _useSkillDisTime;
  146. private final int _reuseDelay;
  147. private final int _sharedReuseGroup;
  148. /**
  149. * Constructor of the L2Item that fill class variables.<BR>
  150. * <BR>
  151. * @param set : StatsSet corresponding to a set of couples (key,value) for description of the item
  152. */
  153. protected L2Item(StatsSet set)
  154. {
  155. _itemId = set.getInt("item_id");
  156. _displayId = set.getInt("displayId", _itemId);
  157. _name = set.getString("name");
  158. _icon = set.getString("icon", null);
  159. _weight = set.getInt("weight", 0);
  160. _materialType = set.getEnum("material", MaterialType.class, MaterialType.STEEL);
  161. _equipReuseDelay = set.getInt("equip_reuse_delay", 0) * 1000;
  162. _duration = set.getInt("duration", -1);
  163. _time = set.getInt("time", -1);
  164. _autoDestroyTime = set.getInt("auto_destroy_time", -1) * 1000;
  165. _bodyPart = ItemTable.SLOTS.get(set.getString("bodypart", "none"));
  166. _referencePrice = set.getInt("price", 0);
  167. _crystalType = set.getEnum("crystal_type", CrystalType.class, CrystalType.NONE);
  168. _crystalCount = set.getInt("crystal_count", 0);
  169. _stackable = set.getBoolean("is_stackable", false);
  170. _sellable = set.getBoolean("is_sellable", true);
  171. _dropable = set.getBoolean("is_dropable", true);
  172. _destroyable = set.getBoolean("is_destroyable", true);
  173. _tradeable = set.getBoolean("is_tradable", true);
  174. _depositable = set.getBoolean("is_depositable", true);
  175. _elementable = set.getBoolean("element_enabled", false);
  176. _enchantable = set.getInt("enchant_enabled", 0);
  177. _questItem = set.getBoolean("is_questitem", false);
  178. _freightable = set.getBoolean("is_freightable", false);
  179. _allow_self_resurrection = set.getBoolean("allow_self_resurrection", false);
  180. _is_oly_restricted = set.getBoolean("is_oly_restricted", false);
  181. _for_npc = set.getBoolean("for_npc", false);
  182. _immediate_effect = set.getBoolean("immediate_effect", false);
  183. _ex_immediate_effect = set.getBoolean("ex_immediate_effect", false);
  184. _defaultAction = set.getEnum("default_action", ActionType.class, ActionType.NONE);
  185. _useSkillDisTime = set.getInt("useSkillDisTime", 0);
  186. _defaultEnchantLevel = set.getInt("enchanted", 0);
  187. _reuseDelay = set.getInt("reuse_delay", 0);
  188. _sharedReuseGroup = set.getInt("shared_reuse_group", 0);
  189. String skills = set.getString("item_skill", null);
  190. if (skills != null)
  191. {
  192. String[] skillsSplit = skills.split(";");
  193. _skillHolder = new SkillHolder[skillsSplit.length];
  194. int used = 0;
  195. for (String element : skillsSplit)
  196. {
  197. try
  198. {
  199. String[] skillSplit = element.split("-");
  200. int id = Integer.parseInt(skillSplit[0]);
  201. int level = Integer.parseInt(skillSplit[1]);
  202. if (id == 0)
  203. {
  204. _log.info(StringUtil.concat("Ignoring item_skill(", element, ") for item ", toString(), ". Skill id is 0!"));
  205. continue;
  206. }
  207. if (level == 0)
  208. {
  209. _log.info(StringUtil.concat("Ignoring item_skill(", element, ") for item ", toString(), ". Skill level is 0!"));
  210. continue;
  211. }
  212. _skillHolder[used] = new SkillHolder(id, level);
  213. ++used;
  214. }
  215. catch (Exception e)
  216. {
  217. _log.warning(StringUtil.concat("Failed to parse item_skill(", element, ") for item ", toString(), "! Format: SkillId0-SkillLevel0[;SkillIdN-SkillLevelN]"));
  218. }
  219. }
  220. // this is only loading? just don't leave a null or use a collection?
  221. if (used != _skillHolder.length)
  222. {
  223. SkillHolder[] skillHolder = new SkillHolder[used];
  224. System.arraycopy(_skillHolder, 0, skillHolder, 0, used);
  225. _skillHolder = skillHolder;
  226. }
  227. }
  228. skills = set.getString("unequip_skill", null);
  229. if (skills != null)
  230. {
  231. String[] info = skills.split("-");
  232. if ((info != null) && (info.length == 2))
  233. {
  234. int id = 0;
  235. int level = 0;
  236. try
  237. {
  238. id = Integer.parseInt(info[0]);
  239. level = Integer.parseInt(info[1]);
  240. }
  241. catch (Exception nfe)
  242. {
  243. // Incorrect syntax, don't add new skill
  244. _log.info(StringUtil.concat("Couldnt parse ", skills, " in weapon unequip skills! item ", toString()));
  245. }
  246. if ((id > 0) && (level > 0))
  247. {
  248. _unequipSkill = new SkillHolder(id, level);
  249. }
  250. }
  251. }
  252. _common = ((_itemId >= 11605) && (_itemId <= 12361));
  253. _heroItem = ((_itemId >= 6611) && (_itemId <= 6621)) || ((_itemId >= 9388) && (_itemId <= 9390)) || (_itemId == 6842);
  254. _pvpItem = ((_itemId >= 10667) && (_itemId <= 10835)) || ((_itemId >= 12852) && (_itemId <= 12977)) || ((_itemId >= 14363) && (_itemId <= 14525)) || (_itemId == 14528) || (_itemId == 14529) || (_itemId == 14558) || ((_itemId >= 15913) && (_itemId <= 16024)) || ((_itemId >= 16134) && (_itemId <= 16147)) || (_itemId == 16149) || (_itemId == 16151) || (_itemId == 16153) || (_itemId == 16155) || (_itemId == 16157) || (_itemId == 16159) || ((_itemId >= 16168) && (_itemId <= 16176)) || ((_itemId >= 16179) && (_itemId <= 16220));
  255. }
  256. /**
  257. * Returns the itemType.
  258. * @return Enum
  259. */
  260. public abstract ItemType getItemType();
  261. /**
  262. * Verifies if the item is a magic weapon.
  263. * @return {@code true} if the weapon is magic, {@code false} otherwise
  264. */
  265. public boolean isMagicWeapon()
  266. {
  267. return false;
  268. }
  269. /**
  270. * @return the _equipReuseDelay
  271. */
  272. public int getEquipReuseDelay()
  273. {
  274. return _equipReuseDelay;
  275. }
  276. /**
  277. * Returns the duration of the item
  278. * @return int
  279. */
  280. public final int getDuration()
  281. {
  282. return _duration;
  283. }
  284. /**
  285. * Returns the time of the item
  286. * @return int
  287. */
  288. public final int getTime()
  289. {
  290. return _time;
  291. }
  292. /**
  293. * @return the auto destroy time of the item in seconds: 0 or less - default
  294. */
  295. public final int getAutoDestroyTime()
  296. {
  297. return _autoDestroyTime;
  298. }
  299. /**
  300. * Returns the ID of the item
  301. * @return int
  302. */
  303. @Override
  304. public final int getId()
  305. {
  306. return _itemId;
  307. }
  308. /**
  309. * Returns the ID of the item
  310. * @return int
  311. */
  312. public final int getDisplayId()
  313. {
  314. return _displayId;
  315. }
  316. public abstract int getItemMask();
  317. /**
  318. * Return the type of material of the item
  319. * @return MaterialType
  320. */
  321. public final MaterialType getMaterialType()
  322. {
  323. return _materialType;
  324. }
  325. /**
  326. * Returns the type 2 of the item
  327. * @return int
  328. */
  329. public final int getType2()
  330. {
  331. return _type2;
  332. }
  333. /**
  334. * Returns the weight of the item
  335. * @return int
  336. */
  337. public final int getWeight()
  338. {
  339. return _weight;
  340. }
  341. /**
  342. * Returns if the item is crystallizable
  343. * @return boolean
  344. */
  345. public final boolean isCrystallizable()
  346. {
  347. return (_crystalType != CrystalType.NONE) && (_crystalCount > 0);
  348. }
  349. /**
  350. * Return the type of crystal if item is crystallizable
  351. * @return CrystalType
  352. */
  353. public final CrystalType getCrystalType()
  354. {
  355. return _crystalType;
  356. }
  357. /**
  358. * Return the ID of crystal if item is crystallizable
  359. * @return int
  360. */
  361. public final int getCrystalItemId()
  362. {
  363. return _crystalType.getCrystalId();
  364. }
  365. /**
  366. * Returns the grade of the item.<BR>
  367. * <BR>
  368. * <U><I>Concept :</I></U><BR>
  369. * In fact, this function returns the type of crystal of the item.
  370. * @return CrystalType
  371. */
  372. public final CrystalType getItemGrade()
  373. {
  374. return getCrystalType();
  375. }
  376. /**
  377. * For grades S80 and S84 return S
  378. * @return the grade of the item.
  379. */
  380. public final CrystalType getItemGradeSPlus()
  381. {
  382. switch (getItemGrade())
  383. {
  384. case S80:
  385. case S84:
  386. return CrystalType.S;
  387. default:
  388. return getItemGrade();
  389. }
  390. }
  391. /**
  392. * @return the quantity of crystals for crystallization.
  393. */
  394. public final int getCrystalCount()
  395. {
  396. return _crystalCount;
  397. }
  398. /**
  399. * @param enchantLevel
  400. * @return the quantity of crystals for crystallization on specific enchant level
  401. */
  402. public final int getCrystalCount(int enchantLevel)
  403. {
  404. if (enchantLevel > 3)
  405. {
  406. switch (_type2)
  407. {
  408. case TYPE2_SHIELD_ARMOR:
  409. case TYPE2_ACCESSORY:
  410. return _crystalCount + (getCrystalType().getCrystalEnchantBonusArmor() * ((3 * enchantLevel) - 6));
  411. case TYPE2_WEAPON:
  412. return _crystalCount + (getCrystalType().getCrystalEnchantBonusWeapon() * ((2 * enchantLevel) - 3));
  413. default:
  414. return _crystalCount;
  415. }
  416. }
  417. else if (enchantLevel > 0)
  418. {
  419. switch (_type2)
  420. {
  421. case TYPE2_SHIELD_ARMOR:
  422. case TYPE2_ACCESSORY:
  423. return _crystalCount + (getCrystalType().getCrystalEnchantBonusArmor() * enchantLevel);
  424. case TYPE2_WEAPON:
  425. return _crystalCount + (getCrystalType().getCrystalEnchantBonusWeapon() * enchantLevel);
  426. default:
  427. return _crystalCount;
  428. }
  429. }
  430. else
  431. {
  432. return _crystalCount;
  433. }
  434. }
  435. /**
  436. * @return the name of the item.
  437. */
  438. public final String getName()
  439. {
  440. return _name;
  441. }
  442. /**
  443. * @return the base elemental of the item.
  444. */
  445. public final Elementals[] getElementals()
  446. {
  447. return _elementals;
  448. }
  449. public Elementals getElemental(byte attribute)
  450. {
  451. for (Elementals elm : _elementals)
  452. {
  453. if (elm.getElement() == attribute)
  454. {
  455. return elm;
  456. }
  457. }
  458. return null;
  459. }
  460. /**
  461. * Sets the base elemental of the item.
  462. * @param element the element to set.
  463. */
  464. public void setElementals(Elementals element)
  465. {
  466. if (_elementals == null)
  467. {
  468. _elementals = new Elementals[1];
  469. _elementals[0] = element;
  470. }
  471. else
  472. {
  473. Elementals elm = getElemental(element.getElement());
  474. if (elm != null)
  475. {
  476. elm.setValue(element.getValue());
  477. }
  478. else
  479. {
  480. elm = element;
  481. Elementals[] array = new Elementals[_elementals.length + 1];
  482. System.arraycopy(_elementals, 0, array, 0, _elementals.length);
  483. array[_elementals.length] = elm;
  484. _elementals = array;
  485. }
  486. }
  487. }
  488. /**
  489. * @return the part of the body used with the item.
  490. */
  491. public final int getBodyPart()
  492. {
  493. return _bodyPart;
  494. }
  495. /**
  496. * @return the type 1 of the item.
  497. */
  498. public final int getType1()
  499. {
  500. return _type1;
  501. }
  502. /**
  503. * @return {@code true} if the item is stackable, {@code false} otherwise.
  504. */
  505. public final boolean isStackable()
  506. {
  507. return _stackable;
  508. }
  509. /**
  510. * @return {@code true} if the item can be equipped, {@code false} otherwise.
  511. */
  512. public boolean isEquipable()
  513. {
  514. return (getBodyPart() != 0) && !(getItemType() instanceof EtcItemType);
  515. }
  516. /**
  517. * @return the price of reference of the item.
  518. */
  519. public final int getReferencePrice()
  520. {
  521. return _referencePrice;
  522. }
  523. /**
  524. * @return {@code true} if the item can be sold, {@code false} otherwise.
  525. */
  526. public final boolean isSellable()
  527. {
  528. return _sellable;
  529. }
  530. /**
  531. * @return {@code true} if the item can be dropped, {@code false} otherwise.
  532. */
  533. public final boolean isDropable()
  534. {
  535. return _dropable;
  536. }
  537. /**
  538. * @return {@code true} if the item can be destroyed, {@code false} otherwise.
  539. */
  540. public final boolean isDestroyable()
  541. {
  542. return _destroyable;
  543. }
  544. /**
  545. * @return {@code true} if the item can be traded, {@code false} otherwise.
  546. */
  547. public final boolean isTradeable()
  548. {
  549. return _tradeable;
  550. }
  551. /**
  552. * @return {@code true} if the item can be put into warehouse, {@code false} otherwise.
  553. */
  554. public final boolean isDepositable()
  555. {
  556. return _depositable;
  557. }
  558. /**
  559. * This method also check the enchant blacklist.
  560. * @return {@code true} if the item can be enchanted, {@code false} otherwise.
  561. */
  562. public final int isEnchantable()
  563. {
  564. return Arrays.binarySearch(Config.ENCHANT_BLACKLIST, getId()) < 0 ? _enchantable : 0;
  565. }
  566. /**
  567. * @return {@code true} if the item can be elemented, {@code false} otherwise.
  568. */
  569. public final boolean isElementable()
  570. {
  571. return _elementable;
  572. }
  573. /**
  574. * Returns if item is common
  575. * @return boolean
  576. */
  577. public final boolean isCommon()
  578. {
  579. return _common;
  580. }
  581. /**
  582. * Returns if item is hero-only
  583. * @return
  584. */
  585. public final boolean isHeroItem()
  586. {
  587. return _heroItem;
  588. }
  589. /**
  590. * Returns if item is pvp
  591. * @return
  592. */
  593. public final boolean isPvpItem()
  594. {
  595. return _pvpItem;
  596. }
  597. public boolean isPotion()
  598. {
  599. return (getItemType() == EtcItemType.POTION);
  600. }
  601. public boolean isElixir()
  602. {
  603. return (getItemType() == EtcItemType.ELIXIR);
  604. }
  605. public boolean isScroll()
  606. {
  607. return (getItemType() == EtcItemType.SCROLL);
  608. }
  609. /**
  610. * Get the functions used by this item.
  611. * @param item : L2ItemInstance pointing out the item
  612. * @param player : L2Character pointing out the player
  613. * @return the list of functions
  614. */
  615. public final List<AbstractFunction> getStatFuncs(L2ItemInstance item, L2Character player)
  616. {
  617. if ((_funcTemplates == null) || _funcTemplates.isEmpty())
  618. {
  619. return Collections.<AbstractFunction> emptyList();
  620. }
  621. final List<AbstractFunction> funcs = new ArrayList<>(_funcTemplates.size());
  622. for (FuncTemplate t : _funcTemplates)
  623. {
  624. AbstractFunction f = t.getFunc(player, player, item, item);
  625. if (f != null)
  626. {
  627. funcs.add(f);
  628. }
  629. }
  630. return funcs;
  631. }
  632. /**
  633. * Add the FuncTemplate f to the list of functions used with the item
  634. * @param f : FuncTemplate to add
  635. */
  636. public void attach(FuncTemplate f)
  637. {
  638. switch (f.getStat())
  639. {
  640. case FIRE_RES:
  641. case FIRE_POWER:
  642. setElementals(new Elementals(Elementals.FIRE, (int) f.getValue()));
  643. break;
  644. case WATER_RES:
  645. case WATER_POWER:
  646. setElementals(new Elementals(Elementals.WATER, (int) f.getValue()));
  647. break;
  648. case WIND_RES:
  649. case WIND_POWER:
  650. setElementals(new Elementals(Elementals.WIND, (int) f.getValue()));
  651. break;
  652. case EARTH_RES:
  653. case EARTH_POWER:
  654. setElementals(new Elementals(Elementals.EARTH, (int) f.getValue()));
  655. break;
  656. case HOLY_RES:
  657. case HOLY_POWER:
  658. setElementals(new Elementals(Elementals.HOLY, (int) f.getValue()));
  659. break;
  660. case DARK_RES:
  661. case DARK_POWER:
  662. setElementals(new Elementals(Elementals.DARK, (int) f.getValue()));
  663. break;
  664. }
  665. if (_funcTemplates == null)
  666. {
  667. _funcTemplates = new ArrayList<>(1);
  668. }
  669. _funcTemplates.add(f);
  670. }
  671. public final void attach(Condition c)
  672. {
  673. if (_preConditions == null)
  674. {
  675. _preConditions = new ArrayList<>(1);
  676. }
  677. if (!_preConditions.contains(c))
  678. {
  679. _preConditions.add(c);
  680. }
  681. }
  682. public boolean hasSkills()
  683. {
  684. return _skillHolder != null;
  685. }
  686. /**
  687. * Method to retrieve skills linked to this item armor and weapon: passive skills etcitem: skills used on item use <-- ???
  688. * @return Skills linked to this item as SkillHolder[]
  689. */
  690. public final SkillHolder[] getSkills()
  691. {
  692. return _skillHolder;
  693. }
  694. /**
  695. * @return skill that activates, when player unequip this weapon or armor
  696. */
  697. public final Skill getUnequipSkill()
  698. {
  699. return _unequipSkill == null ? null : _unequipSkill.getSkill();
  700. }
  701. public boolean checkCondition(L2Character activeChar, L2Object object, boolean sendMessage)
  702. {
  703. if (activeChar.canOverrideCond(PcCondOverride.ITEM_CONDITIONS) && !Config.GM_ITEM_RESTRICTION)
  704. {
  705. return true;
  706. }
  707. // Don't allow hero equipment and restricted items during Olympiad
  708. if ((isOlyRestrictedItem() || isHeroItem()) && ((activeChar instanceof L2PcInstance) && activeChar.getActingPlayer().isInOlympiadMode()))
  709. {
  710. if (isEquipable())
  711. {
  712. activeChar.sendPacket(SystemMessageId.THIS_ITEM_CANT_BE_EQUIPPED_FOR_THE_OLYMPIAD_EVENT);
  713. }
  714. else
  715. {
  716. activeChar.sendPacket(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
  717. }
  718. return false;
  719. }
  720. if (!isConditionAttached())
  721. {
  722. return true;
  723. }
  724. final L2Character target = (object instanceof L2Character) ? (L2Character) object : null;
  725. for (Condition preCondition : _preConditions)
  726. {
  727. if (preCondition == null)
  728. {
  729. continue;
  730. }
  731. if (!preCondition.test(activeChar, target, null, null))
  732. {
  733. if (activeChar instanceof L2Summon)
  734. {
  735. activeChar.sendPacket(SystemMessageId.PET_CANNOT_USE_ITEM);
  736. return false;
  737. }
  738. if (sendMessage)
  739. {
  740. String msg = preCondition.getMessage();
  741. int msgId = preCondition.getMessageId();
  742. if (msg != null)
  743. {
  744. activeChar.sendMessage(msg);
  745. }
  746. else if (msgId != 0)
  747. {
  748. SystemMessage sm = SystemMessage.getSystemMessage(msgId);
  749. if (preCondition.isAddName())
  750. {
  751. sm.addItemName(_itemId);
  752. }
  753. activeChar.sendPacket(sm);
  754. }
  755. }
  756. return false;
  757. }
  758. }
  759. return true;
  760. }
  761. public boolean isConditionAttached()
  762. {
  763. return (_preConditions != null) && !_preConditions.isEmpty();
  764. }
  765. public boolean isQuestItem()
  766. {
  767. return _questItem;
  768. }
  769. public boolean isFreightable()
  770. {
  771. return _freightable;
  772. }
  773. public boolean isAllowSelfResurrection()
  774. {
  775. return _allow_self_resurrection;
  776. }
  777. public boolean isOlyRestrictedItem()
  778. {
  779. return _is_oly_restricted || Config.LIST_OLY_RESTRICTED_ITEMS.contains(_itemId);
  780. }
  781. public boolean isForNpc()
  782. {
  783. return _for_npc;
  784. }
  785. /**
  786. * Returns the name of the item followed by the item ID.
  787. * @return the name and the ID of the item
  788. */
  789. @Override
  790. public String toString()
  791. {
  792. return _name + "(" + _itemId + ")";
  793. }
  794. /**
  795. * Verifies if the item has effects immediately.<br>
  796. * <i>Used for herbs mostly.</i>
  797. * @return {@code true} if the item applies effects immediately, {@code false} otherwise
  798. */
  799. public boolean hasExImmediateEffect()
  800. {
  801. return _ex_immediate_effect;
  802. }
  803. /**
  804. * Verifies if the item has effects immediately.
  805. * @return {@code true} if the item applies effects immediately, {@code false} otherwise
  806. */
  807. public boolean hasImmediateEffect()
  808. {
  809. return _immediate_effect;
  810. }
  811. /**
  812. * @return the _default_action
  813. */
  814. public ActionType getDefaultAction()
  815. {
  816. return _defaultAction;
  817. }
  818. public int useSkillDisTime()
  819. {
  820. return _useSkillDisTime;
  821. }
  822. /**
  823. * Gets the item reuse delay time in seconds.
  824. * @return the reuse delay time
  825. */
  826. public int getReuseDelay()
  827. {
  828. return _reuseDelay;
  829. }
  830. /**
  831. * Gets the shared reuse group.<br>
  832. * Items with the same reuse group will render reuse delay upon those items when used.
  833. * @return the shared reuse group
  834. */
  835. public int getSharedReuseGroup()
  836. {
  837. return _sharedReuseGroup;
  838. }
  839. /**
  840. * Usable in HTML windows.
  841. * @return the icon link in client files
  842. */
  843. public String getIcon()
  844. {
  845. return _icon;
  846. }
  847. public int getDefaultEnchantLevel()
  848. {
  849. return _defaultEnchantLevel;
  850. }
  851. public boolean isPetItem()
  852. {
  853. return getItemType() == EtcItemType.PET_COLLAR;
  854. }
  855. public Skill getEnchant4Skill()
  856. {
  857. return null;
  858. }
  859. }