L2Augmentation.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 javolution.util.FastList;
  17. import com.l2jserver.gameserver.datatables.AugmentationData;
  18. import com.l2jserver.gameserver.datatables.SkillTable;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.model.skills.L2Skill;
  21. import com.l2jserver.gameserver.model.skills.funcs.FuncAdd;
  22. import com.l2jserver.gameserver.model.skills.funcs.LambdaConst;
  23. import com.l2jserver.gameserver.model.stats.Stats;
  24. import com.l2jserver.gameserver.network.serverpackets.SkillCoolTime;
  25. /**
  26. * Used to store an augmentation and its boni
  27. * @author durgus
  28. */
  29. public final class L2Augmentation
  30. {
  31. private int _effectsId = 0;
  32. private AugmentationStatBoni _boni = null;
  33. private L2Skill _skill = null;
  34. public L2Augmentation(int effects, L2Skill skill)
  35. {
  36. _effectsId = effects;
  37. _boni = new AugmentationStatBoni(_effectsId);
  38. _skill = skill;
  39. }
  40. public L2Augmentation(int effects, int skill, int skillLevel)
  41. {
  42. this(effects, skill != 0 ? SkillTable.getInstance().getInfo(skill, skillLevel) : null);
  43. }
  44. public static class AugmentationStatBoni
  45. {
  46. private final Stats _stats[];
  47. private final float _values[];
  48. private boolean _active;
  49. public AugmentationStatBoni(int augmentationId)
  50. {
  51. _active = false;
  52. FastList<AugmentationData.AugStat> as = AugmentationData.getInstance().getAugStatsById(augmentationId);
  53. _stats = new Stats[as.size()];
  54. _values = new float[as.size()];
  55. int i = 0;
  56. for (AugmentationData.AugStat aStat : as)
  57. {
  58. _stats[i] = aStat.getStat();
  59. _values[i] = aStat.getValue();
  60. i++;
  61. }
  62. }
  63. public void applyBonus(L2PcInstance player)
  64. {
  65. // make sure the bonuses are not applied twice..
  66. if (_active)
  67. {
  68. return;
  69. }
  70. for (int i = 0; i < _stats.length; i++)
  71. {
  72. player.addStatFunc(new FuncAdd(_stats[i], 0x40, this, new LambdaConst(_values[i])));
  73. }
  74. _active = true;
  75. }
  76. public void removeBonus(L2PcInstance player)
  77. {
  78. // make sure the bonuses are not removed twice
  79. if (!_active)
  80. {
  81. return;
  82. }
  83. player.removeStatsOwner(this);
  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. public L2Skill getSkill()
  100. {
  101. return _skill;
  102. }
  103. /**
  104. * Applies the bonuses to the player.
  105. * @param player
  106. */
  107. public void applyBonus(L2PcInstance player)
  108. {
  109. boolean updateTimeStamp = false;
  110. _boni.applyBonus(player);
  111. // add the skill if any
  112. if (_skill != null)
  113. {
  114. player.addSkill(_skill);
  115. if (_skill.isActive())
  116. {
  117. final long delay = player.getSkillRemainingReuseTime(_skill.getReuseHashCode());
  118. if (delay > 0)
  119. {
  120. player.disableSkill(_skill, delay);
  121. updateTimeStamp = true;
  122. }
  123. }
  124. player.sendSkillList();
  125. if (updateTimeStamp)
  126. {
  127. player.sendPacket(new SkillCoolTime(player));
  128. }
  129. }
  130. }
  131. /**
  132. * Removes the augmentation bonuses from the player.
  133. * @param player
  134. */
  135. public void removeBonus(L2PcInstance player)
  136. {
  137. _boni.removeBonus(player);
  138. // remove the skill if any
  139. if (_skill != null)
  140. {
  141. if (_skill.isPassive())
  142. {
  143. player.removeSkill(_skill, false, true);
  144. }
  145. else
  146. {
  147. player.removeSkill(_skill, false, false);
  148. }
  149. player.sendSkillList();
  150. }
  151. }
  152. }