EnchantScrollGroup.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 java.util.ArrayList;
  21. import java.util.Collections;
  22. import java.util.List;
  23. import com.l2jserver.gameserver.model.items.L2Item;
  24. /**
  25. * @author UnAfraid
  26. */
  27. public final class EnchantScrollGroup
  28. {
  29. private final int _id;
  30. private List<EnchantRateItem> _rateGroups;
  31. public EnchantScrollGroup(int id)
  32. {
  33. _id = id;
  34. }
  35. /**
  36. * @return id of current enchant scroll group.
  37. */
  38. public int getId()
  39. {
  40. return _id;
  41. }
  42. /**
  43. * Adds new rate group.
  44. * @param group
  45. */
  46. public void addRateGroup(EnchantRateItem group)
  47. {
  48. if (_rateGroups == null)
  49. {
  50. _rateGroups = new ArrayList<>();
  51. }
  52. _rateGroups.add(group);
  53. }
  54. /**
  55. * @return {@code List} of all enchant rate items, Empty list if none.
  56. */
  57. public List<EnchantRateItem> getRateGroups()
  58. {
  59. return _rateGroups != null ? _rateGroups : Collections.<EnchantRateItem> emptyList();
  60. }
  61. /**
  62. * @param item
  63. * @return {@link EnchantRateItem}, {@code NULL} in case non of rate items can be used with.
  64. */
  65. public EnchantRateItem getRateGroup(L2Item item)
  66. {
  67. for (EnchantRateItem group : getRateGroups())
  68. {
  69. if (group.validate(item))
  70. {
  71. return group;
  72. }
  73. }
  74. return null;
  75. }
  76. }