EnchantItemGroup.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.List;
  22. import java.util.logging.Level;
  23. import java.util.logging.Logger;
  24. import com.l2jserver.gameserver.model.holders.RangeChanceHolder;
  25. /**
  26. * @author UnAfraid
  27. */
  28. public final class EnchantItemGroup
  29. {
  30. private static final Logger _log = Logger.getLogger(EnchantItemGroup.class.getName());
  31. private final List<RangeChanceHolder> _chances = new ArrayList<>();
  32. private final String _name;
  33. public EnchantItemGroup(String name)
  34. {
  35. _name = name;
  36. }
  37. /**
  38. * @return name of current enchant item group.
  39. */
  40. public String getName()
  41. {
  42. return _name;
  43. }
  44. /**
  45. * @param holder
  46. */
  47. public void addChance(RangeChanceHolder holder)
  48. {
  49. _chances.add(holder);
  50. }
  51. /**
  52. * @param index
  53. * @return chance for success rate for current enchant item group.
  54. */
  55. public double getChance(int index)
  56. {
  57. if (!_chances.isEmpty())
  58. {
  59. for (RangeChanceHolder holder : _chances)
  60. {
  61. if ((holder.getMin() <= index) && (holder.getMax() >= index))
  62. {
  63. return holder.getChance();
  64. }
  65. }
  66. _log.log(Level.WARNING, getClass().getSimpleName() + ": Couldn't match proper chance for item group: " + _name, new IllegalStateException());
  67. return _chances.get(_chances.size() - 1).getChance();
  68. }
  69. _log.log(Level.WARNING, getClass().getSimpleName() + ": item group: " + _name + " doesn't have any chances!");
  70. return -1;
  71. }
  72. }