L2Augmentation.java 4.2 KB

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