L2Item.java 29 KB

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