L2Item.java 30 KB

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