L2Item.java 27 KB

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