L2Item.java 26 KB

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