L2Item.java 30 KB

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