L2Item.java 30 KB

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