L2Item.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  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.List;
  23. import java.util.logging.Logger;
  24. import javolution.util.FastList;
  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.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.L2Skill;
  46. import com.l2jserver.gameserver.model.skills.funcs.Func;
  47. import com.l2jserver.gameserver.model.skills.funcs.FuncTemplate;
  48. import com.l2jserver.gameserver.model.stats.Env;
  49. import com.l2jserver.gameserver.network.SystemMessageId;
  50. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  51. import com.l2jserver.util.StringUtil;
  52. /**
  53. * This class contains all informations concerning the item (weapon, armor, etc).<BR>
  54. * Mother class of :
  55. * <ul>
  56. * <li>L2Armor</li>
  57. * <li>L2EtcItem</li>
  58. * <li>L2Weapon</li>
  59. * </ul>
  60. * @version $Revision: 1.7.2.2.2.5 $ $Date: 2005/04/06 18:25:18 $
  61. */
  62. public abstract class L2Item
  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 _ex_immediate_effect;
  212. private final int _defaultEnchantLevel;
  213. private final L2ActionType _defaultAction;
  214. protected int _type1; // needed for item list (inventory)
  215. protected int _type2; // different lists for armor, weapon, etc
  216. protected Elementals[] _elementals = null;
  217. protected FuncTemplate[] _funcTemplates;
  218. protected EffectTemplate[] _effectTemplates;
  219. protected List<Condition> _preConditions;
  220. private SkillHolder[] _skillHolder;
  221. private SkillHolder _unequipSkill = null;
  222. protected static final Func[] _emptyFunctionSet = new Func[0];
  223. protected static final L2Effect[] _emptyEffectSet = new L2Effect[0];
  224. private final List<Quest> _questEvents = new FastList<>();
  225. private final int _useSkillDisTime;
  226. private final int _reuseDelay;
  227. private final int _sharedReuseGroup;
  228. /**
  229. * Constructor of the L2Item that fill class variables.<BR>
  230. * <BR>
  231. * @param set : StatsSet corresponding to a set of couples (key,value) for description of the item
  232. */
  233. protected L2Item(StatsSet set)
  234. {
  235. _itemId = set.getInteger("item_id");
  236. _displayId = set.getInteger("displayId", _itemId);
  237. _name = set.getString("name");
  238. _icon = set.getString("icon", null);
  239. _weight = set.getInteger("weight", 0);
  240. _materialType = ItemTable._materials.get(set.getString("material", "steel")); // default is steel, yeah and what?
  241. _equipReuseDelay = set.getInteger("equip_reuse_delay", 0) * 1000;
  242. _duration = set.getInteger("duration", -1);
  243. _time = set.getInteger("time", -1);
  244. _autoDestroyTime = set.getInteger("auto_destroy_time", -1) * 1000;
  245. _bodyPart = ItemTable._slots.get(set.getString("bodypart", "none"));
  246. _referencePrice = set.getInteger("price", 0);
  247. _crystalType = ItemTable._crystalTypes.get(set.getString("crystal_type", "none")); // default to none-grade
  248. _crystalCount = set.getInteger("crystal_count", 0);
  249. _stackable = set.getBool("is_stackable", false);
  250. _sellable = set.getBool("is_sellable", true);
  251. _dropable = set.getBool("is_dropable", true);
  252. _destroyable = set.getBool("is_destroyable", true);
  253. _tradeable = set.getBool("is_tradable", true);
  254. _depositable = set.getBool("is_depositable", true);
  255. _elementable = set.getBool("element_enabled", false);
  256. _enchantable = set.getInteger("enchant_enabled", 0);
  257. _questItem = set.getBool("is_questitem", false);
  258. _freightable = set.getBool("is_freightable", false);
  259. _is_oly_restricted = set.getBool("is_oly_restricted", false);
  260. _for_npc = set.getBool("for_npc", false);
  261. // _immediate_effect - herb
  262. _ex_immediate_effect = set.getBool("ex_immediate_effect", false);
  263. // used for custom type select
  264. _defaultAction = set.getEnum("default_action", L2ActionType.class, L2ActionType.none);
  265. _useSkillDisTime = set.getInteger("useSkillDisTime", 0);
  266. _defaultEnchantLevel = set.getInteger("enchanted", 0);
  267. _reuseDelay = set.getInteger("reuse_delay", 0);
  268. _sharedReuseGroup = set.getInteger("shared_reuse_group", 0);
  269. // TODO: This should be done with proper conditions and a categoryData.xml file.
  270. String equip_condition = set.getString("equip_condition", null);
  271. if (equip_condition != null)
  272. {
  273. // pet conditions
  274. ConditionLogicOr cond = new ConditionLogicOr();
  275. if (equip_condition.contains("strider"))
  276. {
  277. cond.add(new ConditionPetType(STRIDER));
  278. }
  279. if (equip_condition.contains("grown_up_wolf_group"))
  280. {
  281. cond.add(new ConditionPetType(GROWN_UP_WOLF_GROUP));
  282. }
  283. if (equip_condition.contains("hatchling_group"))
  284. {
  285. cond.add(new ConditionPetType(HATCHLING_GROUP));
  286. }
  287. if (equip_condition.contains("all_wolf_group"))
  288. {
  289. cond.add(new ConditionPetType(ALL_WOLF_GROUP));
  290. }
  291. if (equip_condition.contains("baby_pet_group"))
  292. {
  293. cond.add(new ConditionPetType(BABY_PET_GROUP));
  294. }
  295. if (equip_condition.contains("upgrade_baby_pet_group"))
  296. {
  297. cond.add(new ConditionPetType(UPGRADE_BABY_PET_GROUP));
  298. }
  299. if (equip_condition.contains("item_equip_pet_group"))
  300. {
  301. cond.add(new ConditionPetType(ITEM_EQUIP_PET_GROUP));
  302. }
  303. if (cond.conditions.length > 0)
  304. {
  305. attach(cond);
  306. }
  307. }
  308. String skills = set.getString("item_skill", null);
  309. if (skills != null)
  310. {
  311. String[] skillsSplit = skills.split(";");
  312. _skillHolder = new SkillHolder[skillsSplit.length];
  313. int used = 0;
  314. for (String element : skillsSplit)
  315. {
  316. try
  317. {
  318. String[] skillSplit = element.split("-");
  319. int id = Integer.parseInt(skillSplit[0]);
  320. int level = Integer.parseInt(skillSplit[1]);
  321. if (id == 0)
  322. {
  323. _log.info(StringUtil.concat("Ignoring item_skill(", element, ") for item ", toString(), ". Skill id is 0!"));
  324. continue;
  325. }
  326. if (level == 0)
  327. {
  328. _log.info(StringUtil.concat("Ignoring item_skill(", element, ") for item ", toString(), ". Skill level is 0!"));
  329. continue;
  330. }
  331. _skillHolder[used] = new SkillHolder(id, level);
  332. ++used;
  333. }
  334. catch (Exception e)
  335. {
  336. _log.warning(StringUtil.concat("Failed to parse item_skill(", element, ") for item ", toString(), "! Format: SkillId0-SkillLevel0[;SkillIdN-SkillLevelN]"));
  337. }
  338. }
  339. // this is only loading? just don't leave a null or use a collection?
  340. if (used != _skillHolder.length)
  341. {
  342. SkillHolder[] skillHolder = new SkillHolder[used];
  343. System.arraycopy(_skillHolder, 0, skillHolder, 0, used);
  344. _skillHolder = skillHolder;
  345. }
  346. }
  347. skills = set.getString("unequip_skill", null);
  348. if (skills != null)
  349. {
  350. String[] info = skills.split("-");
  351. if ((info != null) && (info.length == 2))
  352. {
  353. int id = 0;
  354. int level = 0;
  355. try
  356. {
  357. id = Integer.parseInt(info[0]);
  358. level = Integer.parseInt(info[1]);
  359. }
  360. catch (Exception nfe)
  361. {
  362. // Incorrect syntax, don't add new skill
  363. _log.info(StringUtil.concat("Couldnt parse ", skills, " in weapon unequip skills! item ", toString()));
  364. }
  365. if ((id > 0) && (level > 0))
  366. {
  367. _unequipSkill = new SkillHolder(id, level);
  368. }
  369. }
  370. }
  371. _common = ((_itemId >= 11605) && (_itemId <= 12361));
  372. _heroItem = ((_itemId >= 6611) && (_itemId <= 6621)) || ((_itemId >= 9388) && (_itemId <= 9390)) || (_itemId == 6842);
  373. _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));
  374. }
  375. /**
  376. * Returns the itemType.
  377. * @return Enum
  378. */
  379. public abstract L2ItemType getItemType();
  380. /**
  381. * @return the _equipReuseDelay
  382. */
  383. public int getEquipReuseDelay()
  384. {
  385. return _equipReuseDelay;
  386. }
  387. /**
  388. * Returns the duration of the item
  389. * @return int
  390. */
  391. public final int getDuration()
  392. {
  393. return _duration;
  394. }
  395. /**
  396. * Returns the time of the item
  397. * @return int
  398. */
  399. public final int getTime()
  400. {
  401. return _time;
  402. }
  403. /**
  404. * @return the auto destroy time of the item in seconds: 0 or less - default
  405. */
  406. public final int getAutoDestroyTime()
  407. {
  408. return _autoDestroyTime;
  409. }
  410. /**
  411. * Returns the ID of the item
  412. * @return int
  413. */
  414. public final int getItemId()
  415. {
  416. return _itemId;
  417. }
  418. /**
  419. * Returns the ID of the item
  420. * @return int
  421. */
  422. public final int getDisplayId()
  423. {
  424. return _displayId;
  425. }
  426. public abstract int getItemMask();
  427. /**
  428. * Return the type of material of the item
  429. * @return int
  430. */
  431. public final int getMaterialType()
  432. {
  433. return _materialType;
  434. }
  435. /**
  436. * Returns the type 2 of the item
  437. * @return int
  438. */
  439. public final int getType2()
  440. {
  441. return _type2;
  442. }
  443. /**
  444. * Returns the weight of the item
  445. * @return int
  446. */
  447. public final int getWeight()
  448. {
  449. return _weight;
  450. }
  451. /**
  452. * Returns if the item is crystallizable
  453. * @return boolean
  454. */
  455. public final boolean isCrystallizable()
  456. {
  457. return (_crystalType != L2Item.CRYSTAL_NONE) && (_crystalCount > 0);
  458. }
  459. /**
  460. * Return the type of crystal if item is crystallizable
  461. * @return int
  462. */
  463. public final int getCrystalType()
  464. {
  465. return _crystalType;
  466. }
  467. /**
  468. * Return the type of crystal if item is crystallizable
  469. * @return int
  470. */
  471. public final int getCrystalItemId()
  472. {
  473. return CRYSTAL_ITEM_ID[_crystalType];
  474. }
  475. /**
  476. * Returns the grade of the item.<BR>
  477. * <BR>
  478. * <U><I>Concept :</I></U><BR>
  479. * In fact, this function returns the type of crystal of the item.
  480. * @return int
  481. */
  482. public final int getItemGrade()
  483. {
  484. return getCrystalType();
  485. }
  486. /**
  487. * For grades S80 and S84 return S
  488. * @return the grade of the item.
  489. */
  490. public final int getItemGradeSPlus()
  491. {
  492. switch (getItemGrade())
  493. {
  494. case CRYSTAL_S80:
  495. case CRYSTAL_S84:
  496. return CRYSTAL_S;
  497. default:
  498. return getItemGrade();
  499. }
  500. }
  501. /**
  502. * @return the quantity of crystals for crystallization.
  503. */
  504. public final int getCrystalCount()
  505. {
  506. return _crystalCount;
  507. }
  508. /**
  509. * @param enchantLevel
  510. * @return the quantity of crystals for crystallization on specific enchant level
  511. */
  512. public final int getCrystalCount(int enchantLevel)
  513. {
  514. if (enchantLevel > 3)
  515. {
  516. switch (_type2)
  517. {
  518. case TYPE2_SHIELD_ARMOR:
  519. case TYPE2_ACCESSORY:
  520. return _crystalCount + (CRYSTAL_ENCHANT_BONUS_ARMOR[getCrystalType()] * ((3 * enchantLevel) - 6));
  521. case TYPE2_WEAPON:
  522. return _crystalCount + (CRYSTAL_ENCHANT_BONUS_WEAPON[getCrystalType()] * ((2 * enchantLevel) - 3));
  523. default:
  524. return _crystalCount;
  525. }
  526. }
  527. else if (enchantLevel > 0)
  528. {
  529. switch (_type2)
  530. {
  531. case TYPE2_SHIELD_ARMOR:
  532. case TYPE2_ACCESSORY:
  533. return _crystalCount + (CRYSTAL_ENCHANT_BONUS_ARMOR[getCrystalType()] * enchantLevel);
  534. case TYPE2_WEAPON:
  535. return _crystalCount + (CRYSTAL_ENCHANT_BONUS_WEAPON[getCrystalType()] * enchantLevel);
  536. default:
  537. return _crystalCount;
  538. }
  539. }
  540. else
  541. {
  542. return _crystalCount;
  543. }
  544. }
  545. /**
  546. * @return the name of the item.
  547. */
  548. public final String getName()
  549. {
  550. return _name;
  551. }
  552. /**
  553. * @return the base elemental of the item.
  554. */
  555. public final Elementals[] getElementals()
  556. {
  557. return _elementals;
  558. }
  559. public Elementals getElemental(byte attribute)
  560. {
  561. for (Elementals elm : _elementals)
  562. {
  563. if (elm.getElement() == attribute)
  564. {
  565. return elm;
  566. }
  567. }
  568. return null;
  569. }
  570. /**
  571. * Sets the base elemental of the item.
  572. * @param element the element to set.
  573. */
  574. public void setElementals(Elementals element)
  575. {
  576. if (_elementals == null)
  577. {
  578. _elementals = new Elementals[1];
  579. _elementals[0] = element;
  580. }
  581. else
  582. {
  583. Elementals elm = getElemental(element.getElement());
  584. if (elm != null)
  585. {
  586. elm.setValue(element.getValue());
  587. }
  588. else
  589. {
  590. elm = element;
  591. Elementals[] array = new Elementals[_elementals.length + 1];
  592. System.arraycopy(_elementals, 0, array, 0, _elementals.length);
  593. array[_elementals.length] = elm;
  594. _elementals = array;
  595. }
  596. }
  597. }
  598. /**
  599. * @return the part of the body used with the item.
  600. */
  601. public final int getBodyPart()
  602. {
  603. return _bodyPart;
  604. }
  605. /**
  606. * @return the type 1 of the item.
  607. */
  608. public final int getType1()
  609. {
  610. return _type1;
  611. }
  612. /**
  613. * @return {@code true} if the item is stackable, {@code false} otherwise.
  614. */
  615. public final boolean isStackable()
  616. {
  617. return _stackable;
  618. }
  619. /**
  620. * @return {@code true} if the item is consumable, {@code false} otherwise.
  621. */
  622. public boolean isConsumable()
  623. {
  624. return false;
  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 (isConsumable() ? (int) (_referencePrice * Config.RATE_CONSUMABLE_COST) : _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, getItemId()) < 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. * Returns array of Func objects containing the list of functions used by the item
  724. * @param item : L2ItemInstance pointing out the item
  725. * @param player : L2Character pointing out the player
  726. * @return Func[] : array of functions
  727. */
  728. public Func[] getStatFuncs(L2ItemInstance item, L2Character player)
  729. {
  730. if ((_funcTemplates == null) || (_funcTemplates.length == 0))
  731. {
  732. return _emptyFunctionSet;
  733. }
  734. ArrayList<Func> funcs = new ArrayList<>(_funcTemplates.length);
  735. Env env = new Env();
  736. env.setCharacter(player);
  737. env.setTarget(player);
  738. env.setItem(item);
  739. Func f;
  740. for (FuncTemplate t : _funcTemplates)
  741. {
  742. f = t.getFunc(env, this); // skill is owner
  743. if (f != null)
  744. {
  745. funcs.add(f);
  746. }
  747. }
  748. if (funcs.isEmpty())
  749. {
  750. return _emptyFunctionSet;
  751. }
  752. return funcs.toArray(new Func[funcs.size()]);
  753. }
  754. /**
  755. * Returns the effects associated with the item.
  756. * @param item : L2ItemInstance pointing out the item
  757. * @param player : L2Character pointing out the player
  758. * @return L2Effect[] : array of effects generated by the item
  759. */
  760. public L2Effect[] getEffects(L2ItemInstance item, L2Character player)
  761. {
  762. if ((_effectTemplates == null) || (_effectTemplates.length == 0))
  763. {
  764. return _emptyEffectSet;
  765. }
  766. FastList<L2Effect> effects = FastList.newInstance();
  767. Env env = new Env();
  768. env.setCharacter(player);
  769. env.setTarget(player);
  770. env.setItem(item);
  771. L2Effect e;
  772. for (EffectTemplate et : _effectTemplates)
  773. {
  774. e = et.getEffect(env);
  775. if (e != null)
  776. {
  777. e.scheduleEffect();
  778. effects.add(e);
  779. }
  780. }
  781. if (effects.isEmpty())
  782. {
  783. return _emptyEffectSet;
  784. }
  785. L2Effect[] result = effects.toArray(new L2Effect[effects.size()]);
  786. FastList.recycle(effects);
  787. return result;
  788. }
  789. /**
  790. * Returns effects of skills associated with the item.
  791. * @param caster : L2Character pointing out the caster
  792. * @param target : L2Character pointing out the target
  793. * @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
  794. * (!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())
  795. * return _emptyEffectSet; return effects.toArray(new L2Effect[effects.size()]); }
  796. */
  797. /**
  798. * Add the FuncTemplate f to the list of functions used with the item
  799. * @param f : FuncTemplate to add
  800. */
  801. public void attach(FuncTemplate f)
  802. {
  803. switch (f.stat)
  804. {
  805. case FIRE_RES:
  806. case FIRE_POWER:
  807. setElementals(new Elementals(Elementals.FIRE, (int) f.lambda.calc(null)));
  808. break;
  809. case WATER_RES:
  810. case WATER_POWER:
  811. setElementals(new Elementals(Elementals.WATER, (int) f.lambda.calc(null)));
  812. break;
  813. case WIND_RES:
  814. case WIND_POWER:
  815. setElementals(new Elementals(Elementals.WIND, (int) f.lambda.calc(null)));
  816. break;
  817. case EARTH_RES:
  818. case EARTH_POWER:
  819. setElementals(new Elementals(Elementals.EARTH, (int) f.lambda.calc(null)));
  820. break;
  821. case HOLY_RES:
  822. case HOLY_POWER:
  823. setElementals(new Elementals(Elementals.HOLY, (int) f.lambda.calc(null)));
  824. break;
  825. case DARK_RES:
  826. case DARK_POWER:
  827. setElementals(new Elementals(Elementals.DARK, (int) f.lambda.calc(null)));
  828. break;
  829. }
  830. // If _functTemplates is empty, create it and add the FuncTemplate f in it
  831. if (_funcTemplates == null)
  832. {
  833. _funcTemplates = new FuncTemplate[]
  834. {
  835. f
  836. };
  837. }
  838. else
  839. {
  840. int len = _funcTemplates.length;
  841. FuncTemplate[] tmp = new FuncTemplate[len + 1];
  842. // Definition : arraycopy(array source, begins copy at this position of source, array destination, begins copy at this position in dest,
  843. // number of components to be copied)
  844. System.arraycopy(_funcTemplates, 0, tmp, 0, len);
  845. tmp[len] = f;
  846. _funcTemplates = tmp;
  847. }
  848. }
  849. /**
  850. * Add the EffectTemplate effect to the list of effects generated by the item
  851. * @param effect : EffectTemplate
  852. */
  853. public void attach(EffectTemplate effect)
  854. {
  855. if (_effectTemplates == null)
  856. {
  857. _effectTemplates = new EffectTemplate[]
  858. {
  859. effect
  860. };
  861. }
  862. else
  863. {
  864. int len = _effectTemplates.length;
  865. EffectTemplate[] tmp = new EffectTemplate[len + 1];
  866. // Definition : arraycopy(array source, begins copy at this position of source, array destination, begins copy at this position in dest,
  867. // number of components to be copied)
  868. System.arraycopy(_effectTemplates, 0, tmp, 0, len);
  869. tmp[len] = effect;
  870. _effectTemplates = tmp;
  871. }
  872. }
  873. public final void attach(Condition c)
  874. {
  875. if (_preConditions == null)
  876. {
  877. _preConditions = new FastList<>();
  878. }
  879. if (!_preConditions.contains(c))
  880. {
  881. _preConditions.add(c);
  882. }
  883. }
  884. public boolean hasSkills()
  885. {
  886. return _skillHolder != null;
  887. }
  888. /**
  889. * Method to retrive skills linked to this item armor and weapon: passive skills etcitem: skills used on item use <-- ???
  890. * @return Skills linked to this item as SkillHolder[]
  891. */
  892. public final SkillHolder[] getSkills()
  893. {
  894. return _skillHolder;
  895. }
  896. /**
  897. * @return skill that activates, when player unequip this weapon or armor
  898. */
  899. public final L2Skill getUnequipSkill()
  900. {
  901. return _unequipSkill == null ? null : _unequipSkill.getSkill();
  902. }
  903. public boolean checkCondition(L2Character activeChar, L2Object target, boolean sendMessage)
  904. {
  905. if (activeChar.canOverrideCond(PcCondOverride.ITEM_CONDITIONS) && !Config.GM_ITEM_RESTRICTION)
  906. {
  907. return true;
  908. }
  909. // Don't allow hero equipment and restricted items during Olympiad
  910. if ((isOlyRestrictedItem() || isHeroItem()) && ((activeChar instanceof L2PcInstance) && activeChar.getActingPlayer().isInOlympiadMode()))
  911. {
  912. if (isEquipable())
  913. {
  914. activeChar.sendPacket(SystemMessageId.THIS_ITEM_CANT_BE_EQUIPPED_FOR_THE_OLYMPIAD_EVENT);
  915. }
  916. else
  917. {
  918. activeChar.sendPacket(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
  919. }
  920. return false;
  921. }
  922. if (!isConditionAttached())
  923. {
  924. return true;
  925. }
  926. Env env = new Env();
  927. env.setCharacter(activeChar);
  928. if (target instanceof L2Character)
  929. {
  930. env.setTarget((L2Character) target);
  931. }
  932. for (Condition preCondition : _preConditions)
  933. {
  934. if (preCondition == null)
  935. {
  936. continue;
  937. }
  938. if (!preCondition.test(env))
  939. {
  940. if (activeChar instanceof L2Summon)
  941. {
  942. activeChar.sendPacket(SystemMessageId.PET_CANNOT_USE_ITEM);
  943. return false;
  944. }
  945. if (sendMessage)
  946. {
  947. String msg = preCondition.getMessage();
  948. int msgId = preCondition.getMessageId();
  949. if (msg != null)
  950. {
  951. activeChar.sendMessage(msg);
  952. }
  953. else if (msgId != 0)
  954. {
  955. SystemMessage sm = SystemMessage.getSystemMessage(msgId);
  956. if (preCondition.isAddName())
  957. {
  958. sm.addItemName(_itemId);
  959. }
  960. activeChar.sendPacket(sm);
  961. }
  962. }
  963. return false;
  964. }
  965. }
  966. return true;
  967. }
  968. public boolean isConditionAttached()
  969. {
  970. return (_preConditions != null) && !_preConditions.isEmpty();
  971. }
  972. public boolean isQuestItem()
  973. {
  974. return _questItem;
  975. }
  976. public boolean isFreightable()
  977. {
  978. return _freightable;
  979. }
  980. public boolean isOlyRestrictedItem()
  981. {
  982. return _is_oly_restricted || Config.LIST_OLY_RESTRICTED_ITEMS.contains(_itemId);
  983. }
  984. public boolean isForNpc()
  985. {
  986. return _for_npc;
  987. }
  988. /**
  989. * Returns the name of the item
  990. * @return String
  991. */
  992. @Override
  993. public String toString()
  994. {
  995. return _name + "(" + _itemId + ")";
  996. }
  997. /**
  998. * @return the _ex_immediate_effect
  999. */
  1000. public boolean is_ex_immediate_effect()
  1001. {
  1002. return _ex_immediate_effect;
  1003. }
  1004. /**
  1005. * @return the _default_action
  1006. */
  1007. public L2ActionType getDefaultAction()
  1008. {
  1009. return _defaultAction;
  1010. }
  1011. public int useSkillDisTime()
  1012. {
  1013. return _useSkillDisTime;
  1014. }
  1015. /**
  1016. * @return the Reuse Delay of item.
  1017. */
  1018. public int getReuseDelay()
  1019. {
  1020. return _reuseDelay;
  1021. }
  1022. /**
  1023. * @return the shared reuse group.
  1024. */
  1025. public int getSharedReuseGroup()
  1026. {
  1027. return _sharedReuseGroup;
  1028. }
  1029. /**
  1030. * Usable in HTML windows.
  1031. * @return the icon link in client files.
  1032. */
  1033. public String getIcon()
  1034. {
  1035. return _icon;
  1036. }
  1037. public void addQuestEvent(Quest q)
  1038. {
  1039. _questEvents.add(q);
  1040. }
  1041. public List<Quest> getQuestEvents()
  1042. {
  1043. return _questEvents;
  1044. }
  1045. public int getDefaultEnchantLevel()
  1046. {
  1047. return _defaultEnchantLevel;
  1048. }
  1049. public boolean isPetItem()
  1050. {
  1051. return getItemType() == L2EtcItemType.PET_COLLAR;
  1052. }
  1053. }