L2Augmentation.java 3.1 KB

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