L2Item.java 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136
  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.EffectTemplate;
  38. import com.l2jserver.gameserver.model.effects.L2Effect;
  39. import com.l2jserver.gameserver.model.holders.SkillHolder;
  40. import com.l2jserver.gameserver.model.interfaces.IIdentifiable;
  41. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  42. import com.l2jserver.gameserver.model.items.type.L2ActionType;
  43. import com.l2jserver.gameserver.model.items.type.L2EtcItemType;
  44. import com.l2jserver.gameserver.model.items.type.L2ItemType;
  45. import com.l2jserver.gameserver.model.quest.Quest;
  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. * @version $Revision: 1.7.2.2.2.5 $ $Date: 2005/04/06 18:25:18 $
  62. */
  63. public abstract class L2Item 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 STRIDER = 0x1;
  76. public static final int GROWN_UP_WOLF_GROUP = 0x2;
  77. public static final int HATCHLING_GROUP = 0x4;
  78. public static final int ALL_WOLF_GROUP = 0x8;
  79. public static final int BABY_PET_GROUP = 0x16;
  80. public static final int UPGRADE_BABY_PET_GROUP = 0x32;
  81. public static final int ITEM_EQUIP_PET_GROUP = 0x64;
  82. public static final int SLOT_NONE = 0x0000;
  83. public static final int SLOT_UNDERWEAR = 0x0001;
  84. public static final int SLOT_R_EAR = 0x0002;
  85. public static final int SLOT_L_EAR = 0x0004;
  86. public static final int SLOT_LR_EAR = 0x00006;
  87. public static final int SLOT_NECK = 0x0008;
  88. public static final int SLOT_R_FINGER = 0x0010;
  89. public static final int SLOT_L_FINGER = 0x0020;
  90. public static final int SLOT_LR_FINGER = 0x0030;
  91. public static final int SLOT_HEAD = 0x0040;
  92. public static final int SLOT_R_HAND = 0x0080;
  93. public static final int SLOT_L_HAND = 0x0100;
  94. public static final int SLOT_GLOVES = 0x0200;
  95. public static final int SLOT_CHEST = 0x0400;
  96. public static final int SLOT_LEGS = 0x0800;
  97. public static final int SLOT_FEET = 0x1000;
  98. public static final int SLOT_BACK = 0x2000;
  99. public static final int SLOT_LR_HAND = 0x4000;
  100. public static final int SLOT_FULL_ARMOR = 0x8000;
  101. public static final int SLOT_HAIR = 0x010000;
  102. public static final int SLOT_ALLDRESS = 0x020000;
  103. public static final int SLOT_HAIR2 = 0x040000;
  104. public static final int SLOT_HAIRALL = 0x080000;
  105. public static final int SLOT_R_BRACELET = 0x100000;
  106. public static final int SLOT_L_BRACELET = 0x200000;
  107. public static final int SLOT_DECO = 0x400000;
  108. public static final int SLOT_BELT = 0x10000000;
  109. public static final int SLOT_WOLF = -100;
  110. public static final int SLOT_HATCHLING = -101;
  111. public static final int SLOT_STRIDER = -102;
  112. public static final int SLOT_BABYPET = -103;
  113. public static final int SLOT_GREATWOLF = -104;
  114. public static final int SLOT_MULTI_ALLWEAPON = SLOT_LR_HAND | SLOT_R_HAND;
  115. public static final int MATERIAL_STEEL = 0x00; // ??
  116. public static final int MATERIAL_FINE_STEEL = 0x01; // ??
  117. public static final int MATERIAL_BLOOD_STEEL = 0x02; // ??
  118. public static final int MATERIAL_BRONZE = 0x03; // ??
  119. public static final int MATERIAL_SILVER = 0x04; // ??
  120. public static final int MATERIAL_GOLD = 0x05; // ??
  121. public static final int MATERIAL_MITHRIL = 0x06; // ??
  122. public static final int MATERIAL_ORIHARUKON = 0x07; // ??
  123. public static final int MATERIAL_PAPER = 0x08; // ??
  124. public static final int MATERIAL_WOOD = 0x09; // ??
  125. public static final int MATERIAL_CLOTH = 0x0a; // ??
  126. public static final int MATERIAL_LEATHER = 0x0b; // ??
  127. public static final int MATERIAL_BONE = 0x0c; // ??
  128. public static final int MATERIAL_HORN = 0x0d; // ??
  129. public static final int MATERIAL_DAMASCUS = 0x0e; // ??
  130. public static final int MATERIAL_ADAMANTAITE = 0x0f; // ??
  131. public static final int MATERIAL_CHRYSOLITE = 0x10; // ??
  132. public static final int MATERIAL_CRYSTAL = 0x11; // ??
  133. public static final int MATERIAL_LIQUID = 0x12; // ??
  134. public static final int MATERIAL_SCALE_OF_DRAGON = 0x13; // ??
  135. public static final int MATERIAL_DYESTUFF = 0x14; // ??
  136. public static final int MATERIAL_COBWEB = 0x15; // ??
  137. public static final int MATERIAL_SEED = 0x16; // ??
  138. public static final int MATERIAL_FISH = 0x17; // ??
  139. public static final int MATERIAL_RUNE_XP = 0x18; // ??
  140. public static final int MATERIAL_RUNE_SP = 0x19; // ??
  141. public static final int MATERIAL_RUNE_PENALTY = 0x20; // ??
  142. public static final int CRYSTAL_NONE = 0x00; // ??
  143. public static final int CRYSTAL_D = 0x01; // ??
  144. public static final int CRYSTAL_C = 0x02; // ??
  145. public static final int CRYSTAL_B = 0x03; // ??
  146. public static final int CRYSTAL_A = 0x04; // ??
  147. public static final int CRYSTAL_S = 0x05; // ??
  148. public static final int CRYSTAL_S80 = 0x06; // ??
  149. public static final int CRYSTAL_S84 = 0x07; // ??
  150. private static final int[] CRYSTAL_ITEM_ID =
  151. {
  152. 0,
  153. 1458,
  154. 1459,
  155. 1460,
  156. 1461,
  157. 1462,
  158. 1462,
  159. 1462
  160. };
  161. private static final int[] CRYSTAL_ENCHANT_BONUS_ARMOR =
  162. {
  163. 0,
  164. 11,
  165. 6,
  166. 11,
  167. 19,
  168. 25,
  169. 25,
  170. 25
  171. };
  172. private static final int[] CRYSTAL_ENCHANT_BONUS_WEAPON =
  173. {
  174. 0,
  175. 90,
  176. 45,
  177. 67,
  178. 144,
  179. 250,
  180. 250,
  181. 250
  182. };
  183. private final int _itemId;
  184. private final int _displayId;
  185. private final String _name;
  186. private final String _icon;
  187. private final int _weight;
  188. private final boolean _stackable;
  189. private final int _materialType;
  190. private final int _crystalType; // default to none-grade
  191. private final int _equipReuseDelay;
  192. private final int _duration;
  193. private final int _time;
  194. private final int _autoDestroyTime;
  195. private final int _bodyPart;
  196. private final int _referencePrice;
  197. private final int _crystalCount;
  198. private final boolean _sellable;
  199. private final boolean _dropable;
  200. private final boolean _destroyable;
  201. private final boolean _tradeable;
  202. private final boolean _depositable;
  203. private final int _enchantable;
  204. private final boolean _elementable;
  205. private final boolean _questItem;
  206. private final boolean _freightable;
  207. private final boolean _is_oly_restricted;
  208. private final boolean _for_npc;
  209. private final boolean _common;
  210. private final boolean _heroItem;
  211. private final boolean _pvpItem;
  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<EffectTemplate> _effectTemplates;
  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.getInteger("item_id");
  235. _displayId = set.getInteger("displayId", _itemId);
  236. _name = set.getString("name");
  237. _icon = set.getString("icon", null);
  238. _weight = set.getInteger("weight", 0);
  239. _materialType = ItemTable._materials.get(set.getString("material", "steel")); // default is steel, yeah and what?
  240. _equipReuseDelay = set.getInteger("equip_reuse_delay", 0) * 1000;
  241. _duration = set.getInteger("duration", -1);
  242. _time = set.getInteger("time", -1);
  243. _autoDestroyTime = set.getInteger("auto_destroy_time", -1) * 1000;
  244. _bodyPart = ItemTable._slots.get(set.getString("bodypart", "none"));
  245. _referencePrice = set.getInteger("price", 0);
  246. _crystalType = ItemTable._crystalTypes.get(set.getString("crystal_type", "none")); // default to none-grade
  247. _crystalCount = set.getInteger("crystal_count", 0);
  248. _stackable = set.getBool("is_stackable", false);
  249. _sellable = set.getBool("is_sellable", true);
  250. _dropable = set.getBool("is_dropable", true);
  251. _destroyable = set.getBool("is_destroyable", true);
  252. _tradeable = set.getBool("is_tradable", true);
  253. _depositable = set.getBool("is_depositable", true);
  254. _elementable = set.getBool("element_enabled", false);
  255. _enchantable = set.getInteger("enchant_enabled", 0);
  256. _questItem = set.getBool("is_questitem", false);
  257. _freightable = set.getBool("is_freightable", false);
  258. _is_oly_restricted = set.getBool("is_oly_restricted", false);
  259. _for_npc = set.getBool("for_npc", false);
  260. // _immediate_effect - herb
  261. _ex_immediate_effect = set.getBool("ex_immediate_effect", false);
  262. // used for custom type select
  263. _defaultAction = set.getEnum("default_action", L2ActionType.class, L2ActionType.none);
  264. _useSkillDisTime = set.getInteger("useSkillDisTime", 0);
  265. _defaultEnchantLevel = set.getInteger("enchanted", 0);
  266. _reuseDelay = set.getInteger("reuse_delay", 0);
  267. _sharedReuseGroup = set.getInteger("shared_reuse_group", 0);
  268. // TODO: This should be done with proper conditions and a categoryData.xml file.
  269. String equip_condition = set.getString("equip_condition", null);
  270. if (equip_condition != null)
  271. {
  272. // pet conditions
  273. ConditionLogicOr cond = new ConditionLogicOr();
  274. if (equip_condition.contains("strider"))
  275. {
  276. cond.add(new ConditionPetType(STRIDER));
  277. }
  278. if (equip_condition.contains("grown_up_wolf_group"))
  279. {
  280. cond.add(new ConditionPetType(GROWN_UP_WOLF_GROUP));
  281. }
  282. if (equip_condition.contains("hatchling_group"))
  283. {
  284. cond.add(new ConditionPetType(HATCHLING_GROUP));
  285. }
  286. if (equip_condition.contains("all_wolf_group"))
  287. {
  288. cond.add(new ConditionPetType(ALL_WOLF_GROUP));
  289. }
  290. if (equip_condition.contains("baby_pet_group"))
  291. {
  292. cond.add(new ConditionPetType(BABY_PET_GROUP));
  293. }
  294. if (equip_condition.contains("upgrade_baby_pet_group"))
  295. {
  296. cond.add(new ConditionPetType(UPGRADE_BABY_PET_GROUP));
  297. }
  298. if (equip_condition.contains("item_equip_pet_group"))
  299. {
  300. cond.add(new ConditionPetType(ITEM_EQUIP_PET_GROUP));
  301. }
  302. if (cond.conditions.length > 0)
  303. {
  304. attach(cond);
  305. }
  306. }
  307. String skills = set.getString("item_skill", null);
  308. if (skills != null)
  309. {
  310. String[] skillsSplit = skills.split(";");
  311. _skillHolder = new SkillHolder[skillsSplit.length];
  312. int used = 0;
  313. for (String element : skillsSplit)
  314. {
  315. try
  316. {
  317. String[] skillSplit = element.split("-");
  318. int id = Integer.parseInt(skillSplit[0]);
  319. int level = Integer.parseInt(skillSplit[1]);
  320. if (id == 0)
  321. {
  322. _log.info(StringUtil.concat("Ignoring item_skill(", element, ") for item ", toString(), ". Skill id is 0!"));
  323. continue;
  324. }
  325. if (level == 0)
  326. {
  327. _log.info(StringUtil.concat("Ignoring item_skill(", element, ") for item ", toString(), ". Skill level is 0!"));
  328. continue;
  329. }
  330. _skillHolder[used] = new SkillHolder(id, level);
  331. ++used;
  332. }
  333. catch (Exception e)
  334. {
  335. _log.warning(StringUtil.concat("Failed to parse item_skill(", element, ") for item ", toString(), "! Format: SkillId0-SkillLevel0[;SkillIdN-SkillLevelN]"));
  336. }
  337. }
  338. // this is only loading? just don't leave a null or use a collection?
  339. if (used != _skillHolder.length)
  340. {
  341. SkillHolder[] skillHolder = new SkillHolder[used];
  342. System.arraycopy(_skillHolder, 0, skillHolder, 0, used);
  343. _skillHolder = skillHolder;
  344. }
  345. }
  346. skills = set.getString("unequip_skill", null);
  347. if (skills != null)
  348. {
  349. String[] info = skills.split("-");
  350. if ((info != null) && (info.length == 2))
  351. {
  352. int id = 0;
  353. int level = 0;
  354. try
  355. {
  356. id = Integer.parseInt(info[0]);
  357. level = Integer.parseInt(info[1]);
  358. }
  359. catch (Exception nfe)
  360. {
  361. // Incorrect syntax, don't add new skill
  362. _log.info(StringUtil.concat("Couldnt parse ", skills, " in weapon unequip skills! item ", toString()));
  363. }
  364. if ((id > 0) && (level > 0))
  365. {
  366. _unequipSkill = new SkillHolder(id, level);
  367. }
  368. }
  369. }
  370. _common = ((_itemId >= 11605) && (_itemId <= 12361));
  371. _heroItem = ((_itemId >= 6611) && (_itemId <= 6621)) || ((_itemId >= 9388) && (_itemId <= 9390)) || (_itemId == 6842);
  372. _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));
  373. }
  374. /**
  375. * Returns the itemType.
  376. * @return Enum
  377. */
  378. public abstract L2ItemType getItemType();
  379. /**
  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 is consumable, {@code false} otherwise.
  628. */
  629. public boolean isConsumable()
  630. {
  631. return false;
  632. }
  633. /**
  634. * @return {@code true} if the item can be equipped, {@code false} otherwise.
  635. */
  636. public boolean isEquipable()
  637. {
  638. return (getBodyPart() != 0) && !(getItemType() instanceof L2EtcItemType);
  639. }
  640. /**
  641. * @return the price of reference of the item.
  642. */
  643. public final int getReferencePrice()
  644. {
  645. return (isConsumable() ? (int) (_referencePrice * Config.RATE_CONSUMABLE_COST) : _referencePrice);
  646. }
  647. /**
  648. * @return {@code true} if the item can be sold, {@code false} otherwise.
  649. */
  650. public final boolean isSellable()
  651. {
  652. return _sellable;
  653. }
  654. /**
  655. * @return {@code true} if the item can be dropped, {@code false} otherwise.
  656. */
  657. public final boolean isDropable()
  658. {
  659. return _dropable;
  660. }
  661. /**
  662. * @return {@code true} if the item can be destroyed, {@code false} otherwise.
  663. */
  664. public final boolean isDestroyable()
  665. {
  666. return _destroyable;
  667. }
  668. /**
  669. * @return {@code true} if the item can be traded, {@code false} otherwise.
  670. */
  671. public final boolean isTradeable()
  672. {
  673. return _tradeable;
  674. }
  675. /**
  676. * @return {@code true} if the item can be put into warehouse, {@code false} otherwise.
  677. */
  678. public final boolean isDepositable()
  679. {
  680. return _depositable;
  681. }
  682. /**
  683. * This method also check the enchant blacklist.
  684. * @return {@code true} if the item can be enchanted, {@code false} otherwise.
  685. */
  686. public final int isEnchantable()
  687. {
  688. return Arrays.binarySearch(Config.ENCHANT_BLACKLIST, getId()) < 0 ? _enchantable : 0;
  689. }
  690. /**
  691. * @return {@code true} if the item can be elemented, {@code false} otherwise.
  692. */
  693. public final boolean isElementable()
  694. {
  695. return _elementable;
  696. }
  697. /**
  698. * Returns if item is common
  699. * @return boolean
  700. */
  701. public final boolean isCommon()
  702. {
  703. return _common;
  704. }
  705. /**
  706. * Returns if item is hero-only
  707. * @return
  708. */
  709. public final boolean isHeroItem()
  710. {
  711. return _heroItem;
  712. }
  713. /**
  714. * Returns if item is pvp
  715. * @return
  716. */
  717. public final boolean isPvpItem()
  718. {
  719. return _pvpItem;
  720. }
  721. public boolean isPotion()
  722. {
  723. return (getItemType() == L2EtcItemType.POTION);
  724. }
  725. public boolean isElixir()
  726. {
  727. return (getItemType() == L2EtcItemType.ELIXIR);
  728. }
  729. /**
  730. * Get the functions used by this item.
  731. * @param item : L2ItemInstance pointing out the item
  732. * @param player : L2Character pointing out the player
  733. * @return the list of functions
  734. */
  735. public final List<Func> getStatFuncs(L2ItemInstance item, L2Character player)
  736. {
  737. if ((_funcTemplates == null) || _funcTemplates.isEmpty())
  738. {
  739. return Collections.<Func> emptyList();
  740. }
  741. final List<Func> funcs = new ArrayList<>(_funcTemplates.size());
  742. final Env env = new Env();
  743. env.setCharacter(player);
  744. env.setTarget(player);
  745. env.setItem(item);
  746. for (FuncTemplate t : _funcTemplates)
  747. {
  748. Func f = t.getFunc(env, item);
  749. if (f != null)
  750. {
  751. funcs.add(f);
  752. }
  753. }
  754. return funcs;
  755. }
  756. /**
  757. * Returns the effects associated with the item.
  758. * @param item : L2ItemInstance pointing out the item
  759. * @param player : L2Character pointing out the player
  760. * @return a list of effects generated by the item
  761. */
  762. public List<L2Effect> getEffects(L2ItemInstance item, L2Character player)
  763. {
  764. if ((_effectTemplates == null) || _effectTemplates.isEmpty())
  765. {
  766. return Collections.<L2Effect> emptyList();
  767. }
  768. final Env env = new Env();
  769. env.setCharacter(player);
  770. env.setTarget(player);
  771. env.setItem(item);
  772. final List<L2Effect> effects = new ArrayList<>(_effectTemplates.size());
  773. for (EffectTemplate et : _effectTemplates)
  774. {
  775. L2Effect e = et.getEffect(env);
  776. if (e != null)
  777. {
  778. e.scheduleEffect();
  779. effects.add(e);
  780. }
  781. }
  782. return effects;
  783. }
  784. /**
  785. * Returns effects of skills associated with the item.
  786. * @param caster : L2Character pointing out the caster
  787. * @param target : L2Character pointing out the target
  788. * @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
  789. * (!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())
  790. * return _emptyEffectSet; return effects.toArray(new L2Effect[effects.size()]); }
  791. */
  792. /**
  793. * Add the FuncTemplate f to the list of functions used with the item
  794. * @param f : FuncTemplate to add
  795. */
  796. public void attach(FuncTemplate f)
  797. {
  798. switch (f.stat)
  799. {
  800. case FIRE_RES:
  801. case FIRE_POWER:
  802. setElementals(new Elementals(Elementals.FIRE, (int) f.lambda.calc(null)));
  803. break;
  804. case WATER_RES:
  805. case WATER_POWER:
  806. setElementals(new Elementals(Elementals.WATER, (int) f.lambda.calc(null)));
  807. break;
  808. case WIND_RES:
  809. case WIND_POWER:
  810. setElementals(new Elementals(Elementals.WIND, (int) f.lambda.calc(null)));
  811. break;
  812. case EARTH_RES:
  813. case EARTH_POWER:
  814. setElementals(new Elementals(Elementals.EARTH, (int) f.lambda.calc(null)));
  815. break;
  816. case HOLY_RES:
  817. case HOLY_POWER:
  818. setElementals(new Elementals(Elementals.HOLY, (int) f.lambda.calc(null)));
  819. break;
  820. case DARK_RES:
  821. case DARK_POWER:
  822. setElementals(new Elementals(Elementals.DARK, (int) f.lambda.calc(null)));
  823. break;
  824. }
  825. if (_funcTemplates == null)
  826. {
  827. _funcTemplates = new ArrayList<>(1);
  828. }
  829. _funcTemplates.add(f);
  830. }
  831. /**
  832. * Add the EffectTemplate effect to the list of effects generated by the item
  833. * @param effect : EffectTemplate
  834. */
  835. public void attach(EffectTemplate effect)
  836. {
  837. if (_effectTemplates == null)
  838. {
  839. _effectTemplates = new ArrayList<>(1);
  840. }
  841. _effectTemplates.add(effect);
  842. }
  843. public final void attach(Condition c)
  844. {
  845. if (_preConditions == null)
  846. {
  847. _preConditions = new ArrayList<>(1);
  848. }
  849. if (!_preConditions.contains(c))
  850. {
  851. _preConditions.add(c);
  852. }
  853. }
  854. public boolean hasSkills()
  855. {
  856. return _skillHolder != null;
  857. }
  858. /**
  859. * Method to retrieve skills linked to this item armor and weapon: passive skills etcitem: skills used on item use <-- ???
  860. * @return Skills linked to this item as SkillHolder[]
  861. */
  862. public final SkillHolder[] getSkills()
  863. {
  864. return _skillHolder;
  865. }
  866. /**
  867. * @return skill that activates, when player unequip this weapon or armor
  868. */
  869. public final L2Skill getUnequipSkill()
  870. {
  871. return _unequipSkill == null ? null : _unequipSkill.getSkill();
  872. }
  873. public boolean checkCondition(L2Character activeChar, L2Object target, boolean sendMessage)
  874. {
  875. if (activeChar.canOverrideCond(PcCondOverride.ITEM_CONDITIONS) && !Config.GM_ITEM_RESTRICTION)
  876. {
  877. return true;
  878. }
  879. // Don't allow hero equipment and restricted items during Olympiad
  880. if ((isOlyRestrictedItem() || isHeroItem()) && ((activeChar instanceof L2PcInstance) && activeChar.getActingPlayer().isInOlympiadMode()))
  881. {
  882. if (isEquipable())
  883. {
  884. activeChar.sendPacket(SystemMessageId.THIS_ITEM_CANT_BE_EQUIPPED_FOR_THE_OLYMPIAD_EVENT);
  885. }
  886. else
  887. {
  888. activeChar.sendPacket(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
  889. }
  890. return false;
  891. }
  892. if (!isConditionAttached())
  893. {
  894. return true;
  895. }
  896. Env env = new Env();
  897. env.setCharacter(activeChar);
  898. if (target instanceof L2Character)
  899. {
  900. env.setTarget((L2Character) target);
  901. }
  902. for (Condition preCondition : _preConditions)
  903. {
  904. if (preCondition == null)
  905. {
  906. continue;
  907. }
  908. if (!preCondition.test(env))
  909. {
  910. if (activeChar instanceof L2Summon)
  911. {
  912. activeChar.sendPacket(SystemMessageId.PET_CANNOT_USE_ITEM);
  913. return false;
  914. }
  915. if (sendMessage)
  916. {
  917. String msg = preCondition.getMessage();
  918. int msgId = preCondition.getMessageId();
  919. if (msg != null)
  920. {
  921. activeChar.sendMessage(msg);
  922. }
  923. else if (msgId != 0)
  924. {
  925. SystemMessage sm = SystemMessage.getSystemMessage(msgId);
  926. if (preCondition.isAddName())
  927. {
  928. sm.addItemName(_itemId);
  929. }
  930. activeChar.sendPacket(sm);
  931. }
  932. }
  933. return false;
  934. }
  935. }
  936. return true;
  937. }
  938. public boolean isConditionAttached()
  939. {
  940. return (_preConditions != null) && !_preConditions.isEmpty();
  941. }
  942. public boolean isQuestItem()
  943. {
  944. return _questItem;
  945. }
  946. public boolean isFreightable()
  947. {
  948. return _freightable;
  949. }
  950. public boolean isOlyRestrictedItem()
  951. {
  952. return _is_oly_restricted || Config.LIST_OLY_RESTRICTED_ITEMS.contains(_itemId);
  953. }
  954. public boolean isForNpc()
  955. {
  956. return _for_npc;
  957. }
  958. /**
  959. * Returns the name of the item
  960. * @return String
  961. */
  962. @Override
  963. public String toString()
  964. {
  965. return _name + "(" + _itemId + ")";
  966. }
  967. /**
  968. * @return the _ex_immediate_effect
  969. */
  970. public boolean is_ex_immediate_effect()
  971. {
  972. return _ex_immediate_effect;
  973. }
  974. /**
  975. * @return the _default_action
  976. */
  977. public L2ActionType getDefaultAction()
  978. {
  979. return _defaultAction;
  980. }
  981. public int useSkillDisTime()
  982. {
  983. return _useSkillDisTime;
  984. }
  985. /**
  986. * @return the Reuse Delay of item.
  987. */
  988. public int getReuseDelay()
  989. {
  990. return _reuseDelay;
  991. }
  992. /**
  993. * @return the shared reuse group.
  994. */
  995. public int getSharedReuseGroup()
  996. {
  997. return _sharedReuseGroup;
  998. }
  999. /**
  1000. * Usable in HTML windows.
  1001. * @return the icon link in client files.
  1002. */
  1003. public String getIcon()
  1004. {
  1005. return _icon;
  1006. }
  1007. public void addQuestEvent(Quest q)
  1008. {
  1009. if (_questEvents == null)
  1010. {
  1011. _questEvents = new ArrayList<>();
  1012. }
  1013. _questEvents.add(q);
  1014. }
  1015. public List<Quest> getQuestEvents()
  1016. {
  1017. return _questEvents;
  1018. }
  1019. public int getDefaultEnchantLevel()
  1020. {
  1021. return _defaultEnchantLevel;
  1022. }
  1023. public boolean isPetItem()
  1024. {
  1025. return getItemType() == L2EtcItemType.PET_COLLAR;
  1026. }
  1027. public L2Skill getEnchant4Skill()
  1028. {
  1029. return null;
  1030. }
  1031. }