L2Item.java 31 KB

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