L2Augmentation.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. *
  28. * @author durgus
  29. */
  30. public final class L2Augmentation
  31. {
  32. private int _effectsId = 0;
  33. private AugmentationStatBoni _boni = null;
  34. private L2Skill _skill = null;
  35. public L2Augmentation(int effects, L2Skill skill)
  36. {
  37. _effectsId = effects;
  38. _boni = new AugmentationStatBoni(_effectsId);
  39. _skill = skill;
  40. }
  41. public L2Augmentation(int effects, int skill, int skillLevel)
  42. {
  43. this(effects, skill != 0 ? SkillTable.getInstance().getInfo(skill, skillLevel) : null);
  44. }
  45. public static class AugmentationStatBoni
  46. {
  47. private Stats _stats[];
  48. private float _values[];
  49. private boolean _active;
  50. public AugmentationStatBoni(int augmentationId)
  51. {
  52. _active = false;
  53. FastList <AugmentationData.AugStat> as = AugmentationData.getInstance().getAugStatsById(augmentationId);
  54. _stats = new Stats[as.size()];
  55. _values = new float[as.size()];
  56. int i=0;
  57. for (AugmentationData.AugStat aStat : as)
  58. {
  59. _stats[i] = aStat.getStat();
  60. _values[i] = aStat.getValue();
  61. i++;
  62. }
  63. }
  64. public void applyBonus(L2PcInstance player)
  65. {
  66. // make sure the bonuses are not applied twice..
  67. if (_active) return;
  68. for (int i=0; i < _stats.length; i++)
  69. player.addStatFunc(new FuncAdd(_stats[i], 0x40, this, new LambdaConst(_values[i])));
  70. _active = true;
  71. }
  72. public void removeBonus(L2PcInstance player)
  73. {
  74. // make sure the bonuses are not removed twice
  75. if (!_active)
  76. {
  77. return;
  78. }
  79. player.removeStatsOwner(this);
  80. _active = false;
  81. }
  82. }
  83. public int getAttributes()
  84. {
  85. return _effectsId;
  86. }
  87. /**
  88. * Get the augmentation "id" used in serverpackets.
  89. * @return augmentationId
  90. */
  91. public int getAugmentationId()
  92. {
  93. return _effectsId;
  94. }
  95. public L2Skill getSkill()
  96. {
  97. return _skill;
  98. }
  99. /**
  100. * Applies the bonuses to the player.
  101. * @param player
  102. */
  103. public void applyBonus(L2PcInstance player)
  104. {
  105. boolean updateTimeStamp = false;
  106. _boni.applyBonus(player);
  107. // add the skill if any
  108. if (_skill != null)
  109. {
  110. player.addSkill(_skill);
  111. if (_skill.isActive())
  112. {
  113. final long delay = player.getSkillRemainingReuseTime(_skill.getReuseHashCode());
  114. if (delay > 0)
  115. {
  116. player.disableSkill(_skill, delay);
  117. updateTimeStamp = true;
  118. }
  119. }
  120. player.sendSkillList();
  121. if (updateTimeStamp)
  122. {
  123. player.sendPacket(new SkillCoolTime(player));
  124. }
  125. }
  126. }
  127. /**
  128. * Removes the augmentation bonuses from the player.
  129. * @param player
  130. */
  131. public void removeBonus(L2PcInstance player)
  132. {
  133. _boni.removeBonus(player);
  134. // remove the skill if any
  135. if (_skill != null)
  136. {
  137. if (_skill.isPassive())
  138. player.removeSkill(_skill, false, true);
  139. else
  140. player.removeSkill(_skill, false, false);
  141. player.sendSkillList();
  142. }
  143. }
  144. }