L2Item.java 27 KB

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