L2Item.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  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. * @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<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 - herb
  261. _ex_immediate_effect = set.getBoolean("ex_immediate_effect", false);
  262. // used for custom type select
  263. _defaultAction = set.getEnum("default_action", L2ActionType.class, L2ActionType.none);
  264. _useSkillDisTime = set.getInt("useSkillDisTime", 0);
  265. _defaultEnchantLevel = set.getInt("enchanted", 0);
  266. _reuseDelay = set.getInt("reuse_delay", 0);
  267. _sharedReuseGroup = set.getInt("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. * Applies the effects from this item to the creature.
  758. * @param item the item
  759. * @param creature the creature
  760. */
  761. public void applyEffects(L2ItemInstance item, L2Character creature)
  762. {
  763. if ((_effects == null) || _effects.isEmpty())
  764. {
  765. return;
  766. }
  767. final Env env = new Env();
  768. env.setCharacter(creature);
  769. env.setTarget(creature);
  770. env.setItem(item);
  771. final BuffInfo info = new BuffInfo(env);
  772. for (AbstractEffect effect : _effects)
  773. {
  774. if (effect.calcSuccess(info))
  775. {
  776. effect.onStart(info);
  777. }
  778. }
  779. }
  780. /**
  781. * Returns effects of skills associated with the item.
  782. * @param caster : L2Character pointing out the caster
  783. * @param target : L2Character pointing out the target
  784. * @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
  785. * (!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())
  786. * return _emptyEffectSet; return effects.toArray(new L2Effect[effects.size()]); }
  787. */
  788. /**
  789. * Add the FuncTemplate f to the list of functions used with the item
  790. * @param f : FuncTemplate to add
  791. */
  792. public void attach(FuncTemplate f)
  793. {
  794. switch (f.stat)
  795. {
  796. case FIRE_RES:
  797. case FIRE_POWER:
  798. setElementals(new Elementals(Elementals.FIRE, (int) f.lambda.calc(null)));
  799. break;
  800. case WATER_RES:
  801. case WATER_POWER:
  802. setElementals(new Elementals(Elementals.WATER, (int) f.lambda.calc(null)));
  803. break;
  804. case WIND_RES:
  805. case WIND_POWER:
  806. setElementals(new Elementals(Elementals.WIND, (int) f.lambda.calc(null)));
  807. break;
  808. case EARTH_RES:
  809. case EARTH_POWER:
  810. setElementals(new Elementals(Elementals.EARTH, (int) f.lambda.calc(null)));
  811. break;
  812. case HOLY_RES:
  813. case HOLY_POWER:
  814. setElementals(new Elementals(Elementals.HOLY, (int) f.lambda.calc(null)));
  815. break;
  816. case DARK_RES:
  817. case DARK_POWER:
  818. setElementals(new Elementals(Elementals.DARK, (int) f.lambda.calc(null)));
  819. break;
  820. }
  821. if (_funcTemplates == null)
  822. {
  823. _funcTemplates = new ArrayList<>(1);
  824. }
  825. _funcTemplates.add(f);
  826. }
  827. /**
  828. * Add the EffectTemplate effect to the list of effects generated by the item
  829. * @param effect : EffectTemplate
  830. */
  831. public void attach(AbstractEffect effect)
  832. {
  833. if (_effects == null)
  834. {
  835. _effects = new ArrayList<>(1);
  836. }
  837. _effects.add(effect);
  838. }
  839. public final void attach(Condition c)
  840. {
  841. if (_preConditions == null)
  842. {
  843. _preConditions = new ArrayList<>(1);
  844. }
  845. if (!_preConditions.contains(c))
  846. {
  847. _preConditions.add(c);
  848. }
  849. }
  850. public boolean hasSkills()
  851. {
  852. return _skillHolder != null;
  853. }
  854. /**
  855. * Method to retrieve skills linked to this item armor and weapon: passive skills etcitem: skills used on item use <-- ???
  856. * @return Skills linked to this item as SkillHolder[]
  857. */
  858. public final SkillHolder[] getSkills()
  859. {
  860. return _skillHolder;
  861. }
  862. /**
  863. * @return skill that activates, when player unequip this weapon or armor
  864. */
  865. public final L2Skill getUnequipSkill()
  866. {
  867. return _unequipSkill == null ? null : _unequipSkill.getSkill();
  868. }
  869. public boolean checkCondition(L2Character activeChar, L2Object target, boolean sendMessage)
  870. {
  871. if (activeChar.canOverrideCond(PcCondOverride.ITEM_CONDITIONS) && !Config.GM_ITEM_RESTRICTION)
  872. {
  873. return true;
  874. }
  875. // Don't allow hero equipment and restricted items during Olympiad
  876. if ((isOlyRestrictedItem() || isHeroItem()) && ((activeChar instanceof L2PcInstance) && activeChar.getActingPlayer().isInOlympiadMode()))
  877. {
  878. if (isEquipable())
  879. {
  880. activeChar.sendPacket(SystemMessageId.THIS_ITEM_CANT_BE_EQUIPPED_FOR_THE_OLYMPIAD_EVENT);
  881. }
  882. else
  883. {
  884. activeChar.sendPacket(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
  885. }
  886. return false;
  887. }
  888. if (!isConditionAttached())
  889. {
  890. return true;
  891. }
  892. Env env = new Env();
  893. env.setCharacter(activeChar);
  894. if (target instanceof L2Character)
  895. {
  896. env.setTarget((L2Character) target);
  897. }
  898. for (Condition preCondition : _preConditions)
  899. {
  900. if (preCondition == null)
  901. {
  902. continue;
  903. }
  904. if (!preCondition.test(env))
  905. {
  906. if (activeChar instanceof L2Summon)
  907. {
  908. activeChar.sendPacket(SystemMessageId.PET_CANNOT_USE_ITEM);
  909. return false;
  910. }
  911. if (sendMessage)
  912. {
  913. String msg = preCondition.getMessage();
  914. int msgId = preCondition.getMessageId();
  915. if (msg != null)
  916. {
  917. activeChar.sendMessage(msg);
  918. }
  919. else if (msgId != 0)
  920. {
  921. SystemMessage sm = SystemMessage.getSystemMessage(msgId);
  922. if (preCondition.isAddName())
  923. {
  924. sm.addItemName(_itemId);
  925. }
  926. activeChar.sendPacket(sm);
  927. }
  928. }
  929. return false;
  930. }
  931. }
  932. return true;
  933. }
  934. public boolean isConditionAttached()
  935. {
  936. return (_preConditions != null) && !_preConditions.isEmpty();
  937. }
  938. public boolean isQuestItem()
  939. {
  940. return _questItem;
  941. }
  942. public boolean isFreightable()
  943. {
  944. return _freightable;
  945. }
  946. public boolean isOlyRestrictedItem()
  947. {
  948. return _is_oly_restricted || Config.LIST_OLY_RESTRICTED_ITEMS.contains(_itemId);
  949. }
  950. public boolean isForNpc()
  951. {
  952. return _for_npc;
  953. }
  954. /**
  955. * Returns the name of the item
  956. * @return String
  957. */
  958. @Override
  959. public String toString()
  960. {
  961. return _name + "(" + _itemId + ")";
  962. }
  963. /**
  964. * @return the _ex_immediate_effect
  965. */
  966. public boolean is_ex_immediate_effect()
  967. {
  968. return _ex_immediate_effect;
  969. }
  970. /**
  971. * @return the _default_action
  972. */
  973. public L2ActionType getDefaultAction()
  974. {
  975. return _defaultAction;
  976. }
  977. public int useSkillDisTime()
  978. {
  979. return _useSkillDisTime;
  980. }
  981. /**
  982. * @return the Reuse Delay of item.
  983. */
  984. public int getReuseDelay()
  985. {
  986. return _reuseDelay;
  987. }
  988. /**
  989. * @return the shared reuse group.
  990. */
  991. public int getSharedReuseGroup()
  992. {
  993. return _sharedReuseGroup;
  994. }
  995. /**
  996. * Usable in HTML windows.
  997. * @return the icon link in client files.
  998. */
  999. public String getIcon()
  1000. {
  1001. return _icon;
  1002. }
  1003. public void addQuestEvent(Quest q)
  1004. {
  1005. if (_questEvents == null)
  1006. {
  1007. _questEvents = new ArrayList<>();
  1008. }
  1009. _questEvents.add(q);
  1010. }
  1011. public List<Quest> getQuestEvents()
  1012. {
  1013. return _questEvents;
  1014. }
  1015. public int getDefaultEnchantLevel()
  1016. {
  1017. return _defaultEnchantLevel;
  1018. }
  1019. public boolean isPetItem()
  1020. {
  1021. return getItemType() == L2EtcItemType.PET_COLLAR;
  1022. }
  1023. public L2Skill getEnchant4Skill()
  1024. {
  1025. return null;
  1026. }
  1027. }