L2Item.java 24 KB

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