L2Item.java 27 KB

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