L2Item.java 29 KB

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