L2Augmentation.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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.network.serverpackets.SkillCoolTime;
  22. import com.l2jserver.gameserver.skills.Stats;
  23. import com.l2jserver.gameserver.skills.funcs.FuncAdd;
  24. import com.l2jserver.gameserver.skills.funcs.LambdaConst;
  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. // =========================================================
  46. // Nested Class
  47. public static class AugmentationStatBoni
  48. {
  49. private Stats _stats[];
  50. private float _values[];
  51. private boolean _active;
  52. public AugmentationStatBoni(int augmentationId)
  53. {
  54. _active = false;
  55. FastList <AugmentationData.AugStat> as = AugmentationData.getInstance().getAugStatsById(augmentationId);
  56. _stats = new Stats[as.size()];
  57. _values = new float[as.size()];
  58. int i=0;
  59. for (AugmentationData.AugStat aStat : as)
  60. {
  61. _stats[i] = aStat.getStat();
  62. _values[i] = aStat.getValue();
  63. i++;
  64. }
  65. }
  66. public void applyBonus(L2PcInstance player)
  67. {
  68. // make sure the bonuses are not applied twice..
  69. if (_active) return;
  70. for (int i=0; i < _stats.length; i++)
  71. ((L2Character)player).addStatFunc(new FuncAdd(_stats[i], 0x40, this, new LambdaConst(_values[i])));
  72. _active = true;
  73. }
  74. public void removeBonus(L2PcInstance player)
  75. {
  76. // make sure the bonuses are not removed twice
  77. if (!_active) return;
  78. ((L2Character)player).removeStatsOwner(this);
  79. _active = false;
  80. }
  81. }
  82. public int getAttributes()
  83. {
  84. return _effectsId;
  85. }
  86. /**
  87. * Get the augmentation "id" used in serverpackets.
  88. * @return augmentationId
  89. */
  90. public int getAugmentationId()
  91. {
  92. return _effectsId;
  93. }
  94. public L2Skill getSkill()
  95. {
  96. return _skill;
  97. }
  98. /**
  99. * Applies the bonuses to the player.
  100. * @param player
  101. */
  102. public void applyBonus(L2PcInstance player)
  103. {
  104. boolean updateTimeStamp = false;
  105. _boni.applyBonus(player);
  106. // add the skill if any
  107. if (_skill != null)
  108. {
  109. player.addSkill(_skill);
  110. if (_skill.isActive())
  111. {
  112. if (!player.getReuseTimeStamp().isEmpty() && player.getReuseTimeStamp().containsKey(_skill.getReuseHashCode()))
  113. {
  114. final long delay = player.getReuseTimeStamp().get(_skill.getReuseHashCode()).getRemaining();
  115. if (delay > 0)
  116. {
  117. player.disableSkill(_skill, delay);
  118. updateTimeStamp = true;
  119. }
  120. }
  121. }
  122. player.sendSkillList();
  123. if (updateTimeStamp)
  124. player.sendPacket(new SkillCoolTime(player));
  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. }