L2Augmentation.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.model;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import java.util.logging.Level;
  19. import java.util.logging.Logger;
  20. import com.l2jserver.gameserver.datatables.OptionsData;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.model.options.Options;
  23. /**
  24. * Used to store an augmentation and its boni
  25. * @author durgus, UnAfraid
  26. */
  27. public final class L2Augmentation
  28. {
  29. private int _effectsId = 0;
  30. private AugmentationStatBoni _boni = null;
  31. public L2Augmentation(int effects)
  32. {
  33. _effectsId = effects;
  34. _boni = new AugmentationStatBoni(_effectsId);
  35. }
  36. public static class AugmentationStatBoni
  37. {
  38. private static final Logger _log = Logger.getLogger(AugmentationStatBoni.class.getName());
  39. private final List<Options> _options = new ArrayList<>();
  40. private boolean _active;
  41. public AugmentationStatBoni(int augmentationId)
  42. {
  43. _active = false;
  44. int[] stats = new int[2];
  45. stats[0] = 0x0000FFFF & augmentationId;
  46. stats[1] = (augmentationId >> 16);
  47. for (int stat : stats)
  48. {
  49. Options op = OptionsData.getInstance().getOptions(stat);
  50. if (op != null)
  51. {
  52. _options.add(op);
  53. }
  54. else
  55. {
  56. _log.log(Level.WARNING, getClass().getSimpleName() + ": Couldn't find option: " + stat);
  57. }
  58. }
  59. }
  60. public void applyBonus(L2PcInstance player)
  61. {
  62. // make sure the bonuses are not applied twice..
  63. if (_active)
  64. {
  65. return;
  66. }
  67. for (Options op : _options)
  68. {
  69. op.apply(player);
  70. }
  71. _active = true;
  72. }
  73. public void removeBonus(L2PcInstance player)
  74. {
  75. // make sure the bonuses are not removed twice
  76. if (!_active)
  77. {
  78. return;
  79. }
  80. for (Options op : _options)
  81. {
  82. op.remove(player);
  83. }
  84. _active = false;
  85. }
  86. }
  87. public int getAttributes()
  88. {
  89. return _effectsId;
  90. }
  91. /**
  92. * Get the augmentation "id" used in serverpackets.
  93. * @return augmentationId
  94. */
  95. public int getAugmentationId()
  96. {
  97. return _effectsId;
  98. }
  99. /**
  100. * Applies the bonuses to the player.
  101. * @param player
  102. */
  103. public void applyBonus(L2PcInstance player)
  104. {
  105. _boni.applyBonus(player);
  106. }
  107. /**
  108. * Removes the augmentation bonuses from the player.
  109. * @param player
  110. */
  111. public void removeBonus(L2PcInstance player)
  112. {
  113. _boni.removeBonus(player);
  114. }
  115. }