L2Augmentation.java 4.4 KB

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