L2Item.java 31 KB

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