EnchantRateItem.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (C) 2004-2013 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.model.enchant;
  20. import com.l2jserver.gameserver.model.items.L2Item;
  21. /**
  22. * @author UnAfraid
  23. */
  24. public final class EnchantRateItem
  25. {
  26. private final String _name;
  27. private int _itemId;
  28. private int _slot;
  29. private Boolean _isMagicWeapon = null;
  30. public EnchantRateItem(String name)
  31. {
  32. _name = name;
  33. }
  34. /**
  35. * @return name of enchant group.
  36. */
  37. public String getName()
  38. {
  39. return _name;
  40. }
  41. /**
  42. * Adds item id verification.
  43. * @param id
  44. */
  45. public void setItemId(int id)
  46. {
  47. _itemId = id;
  48. }
  49. /**
  50. * Adds body slot verification.
  51. * @param slot
  52. */
  53. public void addSlot(int slot)
  54. {
  55. _slot |= slot;
  56. }
  57. /**
  58. * Adds magic weapon verification.
  59. * @param magicWeapon
  60. */
  61. public void setMagicWeapon(boolean magicWeapon)
  62. {
  63. _isMagicWeapon = magicWeapon;
  64. }
  65. /**
  66. * @param item
  67. * @return {@code true} if item can be used with this rate group, {@code false} otherwise.
  68. */
  69. public boolean validate(L2Item item)
  70. {
  71. if ((_itemId != 0) && (_itemId != item.getItemId()))
  72. {
  73. return false;
  74. }
  75. else if ((_slot != 0) && ((item.getBodyPart() & _slot) == 0))
  76. {
  77. return false;
  78. }
  79. else if ((_isMagicWeapon != null) && (item.isMagicWeapon() != _isMagicWeapon))
  80. {
  81. return false;
  82. }
  83. return true;
  84. }
  85. }