L2Item.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.model.items;
  16. import java.util.ArrayList;
  17. import java.util.Arrays;
  18. import java.util.List;
  19. import java.util.logging.Level;
  20. import java.util.logging.Logger;
  21. import javolution.util.FastList;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.datatables.ItemTable;
  24. import com.l2jserver.gameserver.model.Elementals;
  25. import com.l2jserver.gameserver.model.L2Object;
  26. import com.l2jserver.gameserver.model.StatsSet;
  27. import com.l2jserver.gameserver.model.actor.L2Character;
  28. import com.l2jserver.gameserver.model.actor.L2Summon;
  29. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  30. import com.l2jserver.gameserver.model.conditions.Condition;
  31. import com.l2jserver.gameserver.model.conditions.ConditionLogicOr;
  32. import com.l2jserver.gameserver.model.conditions.ConditionPetType;
  33. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  34. import com.l2jserver.gameserver.model.effects.L2Effect;
  35. import com.l2jserver.gameserver.model.holders.SkillHolder;
  36. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  37. import com.l2jserver.gameserver.model.items.type.L2ActionType;
  38. import com.l2jserver.gameserver.model.items.type.L2EtcItemType;
  39. import com.l2jserver.gameserver.model.items.type.L2ItemType;
  40. import com.l2jserver.gameserver.model.quest.Quest;
  41. import com.l2jserver.gameserver.model.skills.funcs.Func;
  42. import com.l2jserver.gameserver.model.skills.funcs.FuncTemplate;
  43. import com.l2jserver.gameserver.model.stats.Env;
  44. import com.l2jserver.gameserver.network.SystemMessageId;
  45. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  46. import com.l2jserver.util.StringUtil;
  47. /**
  48. * This class contains all informations concerning the item (weapon, armor, etc).<BR>
  49. * Mother class of :
  50. * <LI>L2Armor</LI>
  51. * <LI>L2EtcItem</LI>
  52. * <LI>L2Weapon</LI>
  53. * @version $Revision: 1.7.2.2.2.5 $ $Date: 2005/04/06 18:25:18 $
  54. */
  55. public abstract class L2Item
  56. {
  57. protected static final Logger _log = Logger.getLogger(L2Item.class.getName());
  58. public static final int TYPE1_WEAPON_RING_EARRING_NECKLACE = 0;
  59. public static final int TYPE1_SHIELD_ARMOR = 1;
  60. public static final int TYPE1_ITEM_QUESTITEM_ADENA = 4;
  61. public static final int TYPE2_WEAPON = 0;
  62. public static final int TYPE2_SHIELD_ARMOR = 1;
  63. public static final int TYPE2_ACCESSORY = 2;
  64. public static final int TYPE2_QUEST = 3;
  65. public static final int TYPE2_MONEY = 4;
  66. public static final int TYPE2_OTHER = 5;
  67. public static final int WOLF = 0x1;
  68. public static final int HATCHLING = 0x2;
  69. public static final int STRIDER = 0x4;
  70. public static final int BABY = 0x8;
  71. public static final int IMPROVED_BABY = 0x10;
  72. public static final int GROWN_WOLF = 0x20;
  73. public static final int ALL_WOLF = 0x21;
  74. public static final int ALL_PET = 0x3F;
  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. public static final int MATERIAL_STEEL = 0x00; // ??
  109. public static final int MATERIAL_FINE_STEEL = 0x01; // ??
  110. public static final int MATERIAL_BLOOD_STEEL = 0x02; // ??
  111. public static final int MATERIAL_BRONZE = 0x03; // ??
  112. public static final int MATERIAL_SILVER = 0x04; // ??
  113. public static final int MATERIAL_GOLD = 0x05; // ??
  114. public static final int MATERIAL_MITHRIL = 0x06; // ??
  115. public static final int MATERIAL_ORIHARUKON = 0x07; // ??
  116. public static final int MATERIAL_PAPER = 0x08; // ??
  117. public static final int MATERIAL_WOOD = 0x09; // ??
  118. public static final int MATERIAL_CLOTH = 0x0a; // ??
  119. public static final int MATERIAL_LEATHER = 0x0b; // ??
  120. public static final int MATERIAL_BONE = 0x0c; // ??
  121. public static final int MATERIAL_HORN = 0x0d; // ??
  122. public static final int MATERIAL_DAMASCUS = 0x0e; // ??
  123. public static final int MATERIAL_ADAMANTAITE = 0x0f; // ??
  124. public static final int MATERIAL_CHRYSOLITE = 0x10; // ??
  125. public static final int MATERIAL_CRYSTAL = 0x11; // ??
  126. public static final int MATERIAL_LIQUID = 0x12; // ??
  127. public static final int MATERIAL_SCALE_OF_DRAGON = 0x13; // ??
  128. public static final int MATERIAL_DYESTUFF = 0x14; // ??
  129. public static final int MATERIAL_COBWEB = 0x15; // ??
  130. public static final int MATERIAL_SEED = 0x16; // ??
  131. public static final int MATERIAL_FISH = 0x17; // ??
  132. public static final int MATERIAL_RUNE_XP = 0x18; // ??
  133. public static final int MATERIAL_RUNE_SP = 0x19; // ??
  134. public static final int MATERIAL_RUNE_PENALTY = 0x20; // ??
  135. public static final int CRYSTAL_NONE = 0x00; // ??
  136. public static final int CRYSTAL_D = 0x01; // ??
  137. public static final int CRYSTAL_C = 0x02; // ??
  138. public static final int CRYSTAL_B = 0x03; // ??
  139. public static final int CRYSTAL_A = 0x04; // ??
  140. public static final int CRYSTAL_S = 0x05; // ??
  141. public static final int CRYSTAL_S80 = 0x06; // ??
  142. public static final int CRYSTAL_S84 = 0x07; // ??
  143. private static final int[] crystalItemId =
  144. {
  145. 0, 1458, 1459, 1460, 1461, 1462, 1462, 1462
  146. };
  147. private static final int[] crystalEnchantBonusArmor =
  148. {
  149. 0, 11, 6, 11, 19, 25, 25, 25
  150. };
  151. private static final int[] crystalEnchantBonusWeapon =
  152. {
  153. 0, 90, 45, 67, 144, 250, 250, 250
  154. };
  155. private final int _itemId;
  156. private final int _displayId;
  157. private final String _name;
  158. private final String _icon;
  159. private final int _weight;
  160. private final boolean _stackable;
  161. private final int _materialType;
  162. private final int _crystalType; // default to none-grade
  163. private final int _equipReuseDelay;
  164. private final int _duration;
  165. private final int _time;
  166. private final int _autoDestroyTime;
  167. private final int _bodyPart;
  168. private final int _referencePrice;
  169. private final int _crystalCount;
  170. private final boolean _sellable;
  171. private final boolean _dropable;
  172. private final boolean _destroyable;
  173. private final boolean _tradeable;
  174. private final boolean _depositable;
  175. private final int _enchantable;
  176. private final boolean _elementable;
  177. private final boolean _questItem;
  178. private final boolean _freightable;
  179. private final boolean _is_oly_restricted;
  180. private final boolean _common;
  181. private final boolean _heroItem;
  182. private final boolean _pvpItem;
  183. private final boolean _ex_immediate_effect;
  184. private final int _defaultEnchantLevel;
  185. private final L2ActionType _defaultAction;
  186. protected int _type1; // needed for item list (inventory)
  187. protected int _type2; // different lists for armor, weapon, etc
  188. protected Elementals[] _elementals = null;
  189. protected FuncTemplate[] _funcTemplates;
  190. protected EffectTemplate[] _effectTemplates;
  191. protected List <Condition> _preConditions;
  192. private SkillHolder[] _skillHolder;
  193. protected static final Func[] _emptyFunctionSet = new Func[0];
  194. protected static final L2Effect[] _emptyEffectSet = new L2Effect[0];
  195. private final List<Quest> _questEvents = new FastList<>();
  196. private final int _useSkillDisTime;
  197. private final int _reuseDelay;
  198. private int _sharedReuseGroup;
  199. /**
  200. * Constructor of the L2Item that fill class variables.<BR><BR>
  201. * @param set : StatsSet corresponding to a set of couples (key,value) for description of the item
  202. */
  203. protected L2Item(StatsSet set)
  204. {
  205. _itemId = set.getInteger("item_id");
  206. _displayId = set.getInteger("displayId", _itemId);
  207. _name = set.getString("name");
  208. _icon = set.getString("icon", null);
  209. _weight = set.getInteger("weight", 0);
  210. _materialType = ItemTable._materials.get(set.getString("material", "steel")); // default is steel, yeah and what?
  211. _equipReuseDelay = set.getInteger("equip_reuse_delay", 0) * 1000;
  212. _duration = set.getInteger("duration", -1);
  213. _time = set.getInteger("time", -1);
  214. _autoDestroyTime = set.getInteger("auto_destroy_time", -1) * 1000;
  215. _bodyPart = ItemTable._slots.get(set.getString("bodypart", "none"));
  216. _referencePrice = set.getInteger("price", 0);
  217. _crystalType = ItemTable._crystalTypes.get(set.getString("crystal_type", "none")); // default to none-grade
  218. _crystalCount = set.getInteger("crystal_count", 0);
  219. _stackable = set.getBool("is_stackable", false);
  220. _sellable = set.getBool("is_sellable", true);
  221. _dropable = set.getBool("is_dropable", true);
  222. _destroyable = set.getBool("is_destroyable", true);
  223. _tradeable = set.getBool("is_tradable", true);
  224. _depositable = set.getBool("is_depositable", true);
  225. _elementable = set.getBool("element_enabled", false);
  226. _enchantable = set.getInteger("enchant_enabled", 0);
  227. _questItem = set.getBool("is_questitem", false);
  228. _freightable = set.getBool("is_freightable", false);
  229. _is_oly_restricted = set.getBool("is_oly_restricted", false);
  230. //_immediate_effect - herb
  231. _ex_immediate_effect = set.getBool("ex_immediate_effect", false);
  232. //used for custom type select
  233. _defaultAction = set.getEnum("default_action", L2ActionType.class, L2ActionType.none);
  234. _useSkillDisTime = set.getInteger("useSkillDisTime", 0);
  235. _defaultEnchantLevel = set.getInteger("enchanted", 0);
  236. _reuseDelay = set.getInteger("reuse_delay", 0);
  237. _sharedReuseGroup = set.getInteger("shared_reuse_group", 0);
  238. //TODO cleanup + finish
  239. String equip_condition = set.getString("equip_condition", null);
  240. if (equip_condition != null)
  241. {
  242. //pet conditions
  243. ConditionLogicOr cond = new ConditionLogicOr();
  244. if (equip_condition.contains("all_wolf_group"))
  245. cond.add(new ConditionPetType(ALL_WOLF));
  246. if (equip_condition.contains("hatchling_group"))
  247. cond.add(new ConditionPetType(HATCHLING));
  248. if (equip_condition.contains("strider"))
  249. cond.add(new ConditionPetType(STRIDER));
  250. if (equip_condition.contains("baby_pet_group"))
  251. cond.add(new ConditionPetType(BABY));
  252. if (equip_condition.contains("upgrade_baby_pet_group"))
  253. cond.add(new ConditionPetType(IMPROVED_BABY));
  254. if (equip_condition.contains("grown_up_wolf_group"))
  255. cond.add(new ConditionPetType(GROWN_WOLF));
  256. if (equip_condition.contains("item_equip_pet_group"))
  257. cond.add(new ConditionPetType(ALL_PET));
  258. if (cond.conditions.length > 0)
  259. attach(cond);
  260. }
  261. String skills = set.getString("item_skill", null);
  262. if (skills != null)
  263. {
  264. String[] skillsSplit = skills.split(";");
  265. _skillHolder = new SkillHolder[skillsSplit.length];
  266. int used = 0;
  267. for (int i = 0;i < skillsSplit.length;++ i)
  268. {
  269. try
  270. {
  271. String[] skillSplit = skillsSplit[i].split("-");
  272. int id = Integer.parseInt(skillSplit[0]);
  273. int level = Integer.parseInt(skillSplit[1]);
  274. if (id == 0)
  275. {
  276. _log.info(StringUtil.concat("Ignoring item_skill(", skillsSplit[i], ") for item ", toString(), ". Skill id is 0!"));
  277. continue;
  278. }
  279. if (level == 0)
  280. {
  281. _log.info(StringUtil.concat("Ignoring item_skill(", skillsSplit[i], ") for item ", toString(), ". Skill level is 0!"));
  282. continue;
  283. }
  284. _skillHolder[used] = new SkillHolder(id, level);
  285. ++ used;
  286. }
  287. catch (Exception e)
  288. {
  289. _log.warning(StringUtil.concat("Failed to parse item_skill(", skillsSplit[i], ") for item ", toString(), "! Format: SkillId0-SkillLevel0[;SkillIdN-SkillLevelN]"));
  290. }
  291. }
  292. // this is only loading? just don't leave a null or use a collection?
  293. if (used != _skillHolder.length)
  294. {
  295. SkillHolder[] skillHolder = new SkillHolder[used];
  296. System.arraycopy(_skillHolder, 0, skillHolder, 0, used);
  297. _skillHolder = skillHolder;
  298. }
  299. }
  300. _common = (_itemId >= 11605 && _itemId <= 12361);
  301. _heroItem = (_itemId >= 6611 && _itemId <= 6621) || (_itemId >= 9388 && _itemId <= 9390) || _itemId == 6842;
  302. _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);
  303. if (this instanceof L2EtcItem)
  304. {
  305. if (_elementable)
  306. {
  307. _log.log(Level.WARNING, getClass().getSimpleName() + ": " + getItemId() + " " + getName() + " with element enabled");
  308. }
  309. }
  310. }
  311. /**
  312. * Returns the itemType.
  313. * @return Enum
  314. */
  315. public abstract L2ItemType getItemType();
  316. /**
  317. * @return the _equipReuseDelay
  318. */
  319. public int getEquipReuseDelay()
  320. {
  321. return _equipReuseDelay;
  322. }
  323. /**
  324. * Returns the duration of the item
  325. * @return int
  326. */
  327. public final int getDuration()
  328. {
  329. return _duration;
  330. }
  331. /**
  332. * Returns the time of the item
  333. * @return int
  334. */
  335. public final int getTime()
  336. {
  337. return _time;
  338. }
  339. /**
  340. * @return the auto destroy time of the item in seconds: 0 or less - default
  341. */
  342. public final int getAutoDestroyTime()
  343. {
  344. return _autoDestroyTime;
  345. }
  346. /**
  347. * Returns the ID of the item
  348. * @return int
  349. */
  350. public final int getItemId()
  351. {
  352. return _itemId;
  353. }
  354. /**
  355. * Returns the ID of the item
  356. * @return int
  357. */
  358. public final int getDisplayId()
  359. {
  360. return _displayId;
  361. }
  362. public abstract int getItemMask();
  363. /**
  364. * Return the type of material of the item
  365. * @return int
  366. */
  367. public final int getMaterialType()
  368. {
  369. return _materialType;
  370. }
  371. /**
  372. * Returns the type 2 of the item
  373. * @return int
  374. */
  375. public final int getType2()
  376. {
  377. return _type2;
  378. }
  379. /**
  380. * Returns the weight of the item
  381. * @return int
  382. */
  383. public final int getWeight()
  384. {
  385. return _weight;
  386. }
  387. /**
  388. * Returns if the item is crystallizable
  389. * @return boolean
  390. */
  391. public final boolean isCrystallizable()
  392. {
  393. return _crystalType != L2Item.CRYSTAL_NONE && _crystalCount > 0;
  394. }
  395. /**
  396. * Return the type of crystal if item is crystallizable
  397. * @return int
  398. */
  399. public final int getCrystalType()
  400. {
  401. return _crystalType;
  402. }
  403. /**
  404. * Return the type of crystal if item is crystallizable
  405. * @return int
  406. */
  407. public final int getCrystalItemId()
  408. {
  409. return crystalItemId[_crystalType];
  410. }
  411. /**
  412. * Returns the grade of the item.<BR><BR>
  413. * <U><I>Concept :</I></U><BR>
  414. * In fact, this function returns the type of crystal of the item.
  415. * @return int
  416. */
  417. public final int getItemGrade()
  418. {
  419. return getCrystalType();
  420. }
  421. /**
  422. * For grades S80 and S84 return S
  423. * @return the grade of the item.
  424. */
  425. public final int getItemGradeSPlus()
  426. {
  427. switch (getItemGrade())
  428. {
  429. case CRYSTAL_S80:
  430. case CRYSTAL_S84:
  431. return CRYSTAL_S;
  432. default:
  433. return getItemGrade();
  434. }
  435. }
  436. /**
  437. * @return the quantity of crystals for crystallization.
  438. */
  439. public final int getCrystalCount()
  440. {
  441. return _crystalCount;
  442. }
  443. /**
  444. * @param enchantLevel
  445. * @return the quantity of crystals for crystallization on specific enchant level
  446. */
  447. public final int getCrystalCount(int enchantLevel)
  448. {
  449. if (enchantLevel > 3)
  450. switch (_type2)
  451. {
  452. case TYPE2_SHIELD_ARMOR:
  453. case TYPE2_ACCESSORY:
  454. return _crystalCount + crystalEnchantBonusArmor[getCrystalType()] * (3 * enchantLevel - 6);
  455. case TYPE2_WEAPON:
  456. return _crystalCount + crystalEnchantBonusWeapon[getCrystalType()] * (2 * enchantLevel - 3);
  457. default:
  458. return _crystalCount;
  459. }
  460. else if (enchantLevel > 0)
  461. switch (_type2)
  462. {
  463. case TYPE2_SHIELD_ARMOR:
  464. case TYPE2_ACCESSORY:
  465. return _crystalCount + crystalEnchantBonusArmor[getCrystalType()] * enchantLevel;
  466. case TYPE2_WEAPON:
  467. return _crystalCount + crystalEnchantBonusWeapon[getCrystalType()] * enchantLevel;
  468. default:
  469. return _crystalCount;
  470. }
  471. else
  472. return _crystalCount;
  473. }
  474. /**
  475. * @return the name of the item.
  476. */
  477. public final String getName()
  478. {
  479. return _name;
  480. }
  481. /**
  482. * @return the base elemental of the item.
  483. */
  484. public final Elementals[] getElementals()
  485. {
  486. return _elementals;
  487. }
  488. public Elementals getElemental(byte attribute)
  489. {
  490. for (Elementals elm : _elementals)
  491. {
  492. if (elm.getElement() == attribute)
  493. return elm;
  494. }
  495. return null;
  496. }
  497. /**
  498. * Sets the base elemental of the item.
  499. * @param element the element to set.
  500. */
  501. public void setElementals(Elementals element)
  502. {
  503. if (_elementals == null)
  504. {
  505. _elementals = new Elementals[1];
  506. _elementals[0] = element;
  507. }
  508. else
  509. {
  510. Elementals elm = getElemental(element.getElement());
  511. if (elm != null)
  512. {
  513. elm.setValue(element.getValue());
  514. }
  515. else
  516. {
  517. elm = element;
  518. Elementals[] array = new Elementals[_elementals.length + 1];
  519. System.arraycopy(_elementals, 0, array, 0, _elementals.length);
  520. array[_elementals.length] = elm;
  521. _elementals = array;
  522. }
  523. }
  524. }
  525. /**
  526. * @return the part of the body used with the item.
  527. */
  528. public final int getBodyPart()
  529. {
  530. return _bodyPart;
  531. }
  532. /**
  533. * @return the type 1 of the item.
  534. */
  535. public final int getType1()
  536. {
  537. return _type1;
  538. }
  539. /**
  540. * @return {@code true} if the item is stackable, {@code false} otherwise.
  541. */
  542. public final boolean isStackable()
  543. {
  544. return _stackable;
  545. }
  546. /**
  547. * @return {@code true} if the item is consumable, {@code false} otherwise.
  548. */
  549. public boolean isConsumable()
  550. {
  551. return false;
  552. }
  553. /**
  554. * @return {@code true} if the item can be equipped, {@code false} otherwise.
  555. */
  556. public boolean isEquipable()
  557. {
  558. return getBodyPart() != 0 && !(getItemType() instanceof L2EtcItemType);
  559. }
  560. /**
  561. * @return the price of reference of the item.
  562. */
  563. public final int getReferencePrice()
  564. {
  565. return (isConsumable() ? (int)(_referencePrice * Config.RATE_CONSUMABLE_COST) : _referencePrice);
  566. }
  567. /**
  568. * @return {@code true} if the item can be sold, {@code false} otherwise.
  569. */
  570. public final boolean isSellable()
  571. {
  572. return _sellable;
  573. }
  574. /**
  575. * @return {@code true} if the item can be dropped, {@code false} otherwise.
  576. */
  577. public final boolean isDropable()
  578. {
  579. return _dropable;
  580. }
  581. /**
  582. * @return {@code true} if the item can be destroyed, {@code false} otherwise.
  583. */
  584. public final boolean isDestroyable()
  585. {
  586. return _destroyable;
  587. }
  588. /**
  589. * @return {@code true} if the item can be traded, {@code false} otherwise.
  590. */
  591. public final boolean isTradeable()
  592. {
  593. return _tradeable;
  594. }
  595. /**
  596. * @return {@code true} if the item can be put into warehouse, {@code false} otherwise.
  597. */
  598. public final boolean isDepositable()
  599. {
  600. return _depositable;
  601. }
  602. /**
  603. * This method also check the enchant blacklist.
  604. * @return {@code true} if the item can be enchanted, {@code false} otherwise.
  605. */
  606. public final int isEnchantable()
  607. {
  608. return Arrays.binarySearch(Config.ENCHANT_BLACKLIST, getItemId()) < 0 ? _enchantable : 0;
  609. }
  610. /**
  611. * @return {@code true} if the item can be elemented, {@code false} otherwise.
  612. */
  613. public final boolean isElementable()
  614. {
  615. return _elementable;
  616. }
  617. /**
  618. * Returns if item is common
  619. * @return boolean
  620. */
  621. public final boolean isCommon()
  622. {
  623. return _common;
  624. }
  625. /**
  626. * Returns if item is hero-only
  627. * @return
  628. */
  629. public final boolean isHeroItem()
  630. {
  631. return _heroItem;
  632. }
  633. /**
  634. * Returns if item is pvp
  635. * @return
  636. */
  637. public final boolean isPvpItem()
  638. {
  639. return _pvpItem;
  640. }
  641. public boolean isPotion()
  642. {
  643. return (getItemType() == L2EtcItemType.POTION);
  644. }
  645. public boolean isElixir()
  646. {
  647. return (getItemType() == L2EtcItemType.ELIXIR);
  648. }
  649. /**
  650. * Returns array of Func objects containing the list of functions used by the item
  651. * @param item : L2ItemInstance pointing out the item
  652. * @param player : L2Character pointing out the player
  653. * @return Func[] : array of functions
  654. */
  655. public Func[] getStatFuncs(L2ItemInstance item, L2Character player)
  656. {
  657. if (_funcTemplates == null || _funcTemplates.length == 0)
  658. return _emptyFunctionSet;
  659. ArrayList<Func> funcs = new ArrayList<>(_funcTemplates.length);
  660. Env env = new Env();
  661. env.setCharacter(player);
  662. env.setTarget(player);
  663. env.setItem(item);
  664. Func f;
  665. for (FuncTemplate t : _funcTemplates)
  666. {
  667. f = t.getFunc(env, this); // skill is owner
  668. if (f != null)
  669. funcs.add(f);
  670. }
  671. if (funcs.isEmpty())
  672. {
  673. return _emptyFunctionSet;
  674. }
  675. return funcs.toArray(new Func[funcs.size()]);
  676. }
  677. /**
  678. * Returns the effects associated with the item.
  679. * @param item : L2ItemInstance pointing out the item
  680. * @param player : L2Character pointing out the player
  681. * @return L2Effect[] : array of effects generated by the item
  682. */
  683. public L2Effect[] getEffects(L2ItemInstance item, L2Character player)
  684. {
  685. if (_effectTemplates == null || _effectTemplates.length == 0)
  686. return _emptyEffectSet;
  687. FastList<L2Effect> effects = FastList.newInstance();
  688. Env env = new Env();
  689. env.setCharacter(player);
  690. env.setTarget(player);
  691. env.setItem(item);
  692. L2Effect e;
  693. for (EffectTemplate et : _effectTemplates)
  694. {
  695. e = et.getEffect(env);
  696. if (e != null)
  697. {
  698. e.scheduleEffect();
  699. effects.add(e);
  700. }
  701. }
  702. if (effects.isEmpty())
  703. return _emptyEffectSet;
  704. L2Effect[] result = effects.toArray(new L2Effect[effects.size()]);
  705. FastList.recycle(effects);
  706. return result;
  707. }
  708. /**
  709. * Returns effects of skills associated with the item.
  710. * @param caster : L2Character pointing out the caster
  711. * @param target : L2Character pointing out the target
  712. * @return L2Effect[] : array of effects generated by the skill
  713. public L2Effect[] getSkillEffects(L2Character caster, L2Character target)
  714. {
  715. if (_skills == null)
  716. return _emptyEffectSet;
  717. List<L2Effect> effects = new FastList<L2Effect>();
  718. for (L2Skill skill : _skills)
  719. {
  720. if (!skill.checkCondition(caster, target, true))
  721. continue; // Skill condition not met
  722. if (target.getFirstEffect(skill.getId()) != null)
  723. target.removeEffect(target.getFirstEffect(skill.getId()));
  724. for (L2Effect e : skill.getEffects(caster, target))
  725. effects.add(e);
  726. }
  727. if (effects.isEmpty())
  728. return _emptyEffectSet;
  729. return effects.toArray(new L2Effect[effects.size()]);
  730. }
  731. */
  732. /**
  733. * Add the FuncTemplate f to the list of functions used with the item
  734. * @param f : FuncTemplate to add
  735. */
  736. public void attach(FuncTemplate f)
  737. {
  738. switch(f.stat)
  739. {
  740. case FIRE_RES:
  741. case FIRE_POWER:
  742. setElementals(new Elementals(Elementals.FIRE, (int) f.lambda.calc(null)));
  743. break;
  744. case WATER_RES:
  745. case WATER_POWER:
  746. setElementals(new Elementals(Elementals.WATER, (int) f.lambda.calc(null)));
  747. break;
  748. case WIND_RES:
  749. case WIND_POWER:
  750. setElementals(new Elementals(Elementals.WIND, (int) f.lambda.calc(null)));
  751. break;
  752. case EARTH_RES:
  753. case EARTH_POWER:
  754. setElementals(new Elementals(Elementals.EARTH, (int) f.lambda.calc(null)));
  755. break;
  756. case HOLY_RES:
  757. case HOLY_POWER:
  758. setElementals(new Elementals(Elementals.HOLY, (int) f.lambda.calc(null)));
  759. break;
  760. case DARK_RES:
  761. case DARK_POWER:
  762. setElementals(new Elementals(Elementals.DARK, (int) f.lambda.calc(null)));
  763. break;
  764. }
  765. // If _functTemplates is empty, create it and add the FuncTemplate f in it
  766. if (_funcTemplates == null)
  767. {
  768. _funcTemplates = new FuncTemplate[]
  769. {
  770. f
  771. };
  772. }
  773. else
  774. {
  775. int len = _funcTemplates.length;
  776. FuncTemplate[] tmp = new FuncTemplate[len + 1];
  777. // Definition : arraycopy(array source, begins copy at this position of source, array destination, begins copy at this position in dest,
  778. // number of components to be copied)
  779. System.arraycopy(_funcTemplates, 0, tmp, 0, len);
  780. tmp[len] = f;
  781. _funcTemplates = tmp;
  782. }
  783. }
  784. /**
  785. * Add the EffectTemplate effect to the list of effects generated by the item
  786. * @param effect : EffectTemplate
  787. */
  788. public void attach(EffectTemplate effect)
  789. {
  790. if (_effectTemplates == null)
  791. {
  792. _effectTemplates = new EffectTemplate[]
  793. {
  794. effect
  795. };
  796. }
  797. else
  798. {
  799. int len = _effectTemplates.length;
  800. EffectTemplate[] tmp = new EffectTemplate[len + 1];
  801. // Definition : arraycopy(array source, begins copy at this position of source, array destination, begins copy at this position in dest,
  802. // number of components to be copied)
  803. System.arraycopy(_effectTemplates, 0, tmp, 0, len);
  804. tmp[len] = effect;
  805. _effectTemplates = tmp;
  806. }
  807. }
  808. public final void attach(Condition c)
  809. {
  810. if (_preConditions == null)
  811. _preConditions = new FastList<>();
  812. if (!_preConditions.contains(c))
  813. _preConditions.add(c);
  814. }
  815. public boolean hasSkills()
  816. {
  817. return _skillHolder != null;
  818. }
  819. /**
  820. * Method to retrive skills linked to this item
  821. *
  822. * armor and weapon: passive skills
  823. * etcitem: skills used on item use <-- ???
  824. *
  825. * @return Skills linked to this item as SkillHolder[]
  826. */
  827. public final SkillHolder[] getSkills()
  828. {
  829. return _skillHolder;
  830. }
  831. public boolean checkCondition(L2Character activeChar, L2Object target, boolean sendMessage)
  832. {
  833. if (activeChar.isGM() && !Config.GM_ITEM_RESTRICTION)
  834. return true;
  835. // Don't allow hero equipment and restricted items during Olympiad
  836. if ((isOlyRestrictedItem() || isHeroItem()) && ((activeChar instanceof L2PcInstance) && activeChar.getActingPlayer().isInOlympiadMode()))
  837. {
  838. if (isEquipable())
  839. activeChar.sendPacket(SystemMessageId.THIS_ITEM_CANT_BE_EQUIPPED_FOR_THE_OLYMPIAD_EVENT);
  840. else
  841. activeChar.sendPacket(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
  842. return false;
  843. }
  844. if (!isConditionAttached())
  845. return true;
  846. Env env = new Env();
  847. env.setCharacter(activeChar);
  848. if (target instanceof L2Character)
  849. env.setTarget((L2Character) target);
  850. for (Condition preCondition : _preConditions)
  851. {
  852. if (preCondition == null)
  853. continue;
  854. if (!preCondition.test(env))
  855. {
  856. if (activeChar instanceof L2Summon)
  857. {
  858. activeChar.sendPacket(SystemMessageId.PET_CANNOT_USE_ITEM);
  859. return false;
  860. }
  861. if (sendMessage)
  862. {
  863. String msg = preCondition.getMessage();
  864. int msgId = preCondition.getMessageId();
  865. if (msg != null)
  866. {
  867. activeChar.sendMessage(msg);
  868. }
  869. else if (msgId !=0)
  870. {
  871. SystemMessage sm = SystemMessage.getSystemMessage(msgId);
  872. if (preCondition.isAddName())
  873. sm.addItemName(_itemId);
  874. activeChar.sendPacket(sm);
  875. }
  876. }
  877. return false;
  878. }
  879. }
  880. return true;
  881. }
  882. public boolean isConditionAttached()
  883. {
  884. return _preConditions != null && !_preConditions.isEmpty();
  885. }
  886. public boolean isQuestItem()
  887. {
  888. return _questItem;
  889. }
  890. public boolean isFreightable()
  891. {
  892. return _freightable;
  893. }
  894. public boolean isOlyRestrictedItem()
  895. {
  896. return _is_oly_restricted || Config.LIST_OLY_RESTRICTED_ITEMS.contains(_itemId);
  897. }
  898. /**
  899. * Returns the name of the item
  900. * @return String
  901. */
  902. @Override
  903. public String toString()
  904. {
  905. return _name+"("+_itemId+")";
  906. }
  907. /**
  908. * @return the _ex_immediate_effect
  909. */
  910. public boolean is_ex_immediate_effect()
  911. {
  912. return _ex_immediate_effect;
  913. }
  914. /**
  915. * @return the _default_action
  916. */
  917. public L2ActionType getDefaultAction()
  918. {
  919. return _defaultAction;
  920. }
  921. public int useSkillDisTime()
  922. {
  923. return _useSkillDisTime;
  924. }
  925. /**
  926. * @return the Reuse Delay of item.
  927. */
  928. public int getReuseDelay()
  929. {
  930. return _reuseDelay;
  931. }
  932. /**
  933. * @return the shared reuse group.
  934. */
  935. public int getSharedReuseGroup()
  936. {
  937. return _sharedReuseGroup;
  938. }
  939. /**
  940. * Usable in HTML windows.
  941. * @return the icon link in client files.
  942. */
  943. public String getIcon()
  944. {
  945. return _icon;
  946. }
  947. public void addQuestEvent(Quest q)
  948. {
  949. _questEvents.add(q);
  950. }
  951. public List<Quest> getQuestEvents()
  952. {
  953. return _questEvents;
  954. }
  955. public int getDefaultEnchantLevel()
  956. {
  957. return _defaultEnchantLevel;
  958. }
  959. public boolean isPetItem()
  960. {
  961. return getItemType() == L2EtcItemType.PET_COLLAR;
  962. }
  963. }