MaxCp.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.effecthandlers;
  20. import com.l2jserver.gameserver.enums.EffectCalculationType;
  21. import com.l2jserver.gameserver.model.StatsSet;
  22. import com.l2jserver.gameserver.model.actor.stat.CharStat;
  23. import com.l2jserver.gameserver.model.conditions.Condition;
  24. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  25. import com.l2jserver.gameserver.model.skills.BuffInfo;
  26. import com.l2jserver.gameserver.model.stats.Stats;
  27. import com.l2jserver.gameserver.model.stats.functions.FuncAdd;
  28. import com.l2jserver.gameserver.model.stats.functions.FuncMul;
  29. /**
  30. * @author Zealar
  31. */
  32. public final class MaxCp extends AbstractEffect
  33. {
  34. private final double _power;
  35. private final EffectCalculationType _type;
  36. private final boolean _heal;
  37. public MaxCp(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  38. {
  39. super(attachCond, applyCond, set, params);
  40. _type = params.getEnum("type", EffectCalculationType.class, EffectCalculationType.DIFF);
  41. switch (_type)
  42. {
  43. case DIFF:
  44. {
  45. _power = params.getInt("power", 0);
  46. break;
  47. }
  48. default:
  49. {
  50. _power = 1 + (params.getInt("power", 0) / 100.0);
  51. }
  52. }
  53. _heal = params.getBoolean("heal", false);
  54. if (params.isEmpty())
  55. {
  56. _log.warning(getClass().getSimpleName() + ": must have parameters.");
  57. }
  58. }
  59. @Override
  60. public void onStart(BuffInfo info)
  61. {
  62. final CharStat charStat = info.getEffected().getStat();
  63. synchronized (charStat)
  64. {
  65. final double currentCp = info.getEffected().getCurrentCp();
  66. switch (_type)
  67. {
  68. case DIFF:
  69. {
  70. charStat.getActiveChar().addStatFunc(new FuncAdd(Stats.MAX_CP, 1, this, _power, null));
  71. if (_heal)
  72. {
  73. info.getEffected().setCurrentCp((currentCp + _power));
  74. }
  75. break;
  76. }
  77. case PER:
  78. {
  79. charStat.getActiveChar().addStatFunc(new FuncMul(Stats.MAX_CP, 1, this, _power, null));
  80. if (_heal)
  81. {
  82. info.getEffected().setCurrentCp((currentCp * _power));
  83. }
  84. break;
  85. }
  86. }
  87. }
  88. }
  89. @Override
  90. public void onExit(BuffInfo info)
  91. {
  92. final CharStat charStat = info.getEffected().getStat();
  93. synchronized (charStat)
  94. {
  95. charStat.getActiveChar().removeStatsOwner(this);
  96. }
  97. }
  98. }