MaxCp.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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.L2Character;
  23. import com.l2jserver.gameserver.model.actor.stat.CharStat;
  24. import com.l2jserver.gameserver.model.conditions.Condition;
  25. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  26. import com.l2jserver.gameserver.model.skills.BuffInfo;
  27. import com.l2jserver.gameserver.model.stats.Stats;
  28. import com.l2jserver.gameserver.model.stats.functions.FuncAdd;
  29. import com.l2jserver.gameserver.model.stats.functions.FuncMul;
  30. import com.l2jserver.gameserver.network.SystemMessageId;
  31. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  32. /**
  33. * @author Zealar
  34. */
  35. public final class MaxCp extends AbstractEffect
  36. {
  37. private final double _power;
  38. private final EffectCalculationType _type;
  39. private final boolean _heal;
  40. public MaxCp(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  41. {
  42. super(attachCond, applyCond, set, params);
  43. _type = params.getEnum("type", EffectCalculationType.class, EffectCalculationType.DIFF);
  44. switch (_type)
  45. {
  46. case DIFF:
  47. {
  48. _power = params.getInt("power", 0);
  49. break;
  50. }
  51. default:
  52. {
  53. _power = 1 + (params.getInt("power", 0) / 100.0);
  54. }
  55. }
  56. _heal = params.getBoolean("heal", false);
  57. if (params.isEmpty())
  58. {
  59. _log.warning(getClass().getSimpleName() + ": must have parameters.");
  60. }
  61. }
  62. @Override
  63. public void onStart(BuffInfo info)
  64. {
  65. final L2Character effected = info.getEffected();
  66. final CharStat charStat = effected.getStat();
  67. final double currentCp = effected.getCurrentCp();
  68. double amount = _power;
  69. synchronized (charStat)
  70. {
  71. switch (_type)
  72. {
  73. case DIFF:
  74. {
  75. charStat.getActiveChar().addStatFunc(new FuncAdd(Stats.MAX_CP, 1, this, _power, null));
  76. if (_heal)
  77. {
  78. effected.setCurrentCp((currentCp + _power));
  79. }
  80. break;
  81. }
  82. case PER:
  83. {
  84. final double maxCp = effected.getMaxCp();
  85. charStat.getActiveChar().addStatFunc(new FuncMul(Stats.MAX_CP, 1, this, _power, null));
  86. if (_heal)
  87. {
  88. amount = (_power - 1) * maxCp;
  89. effected.setCurrentCp(currentCp + amount);
  90. }
  91. break;
  92. }
  93. }
  94. }
  95. if (_heal)
  96. {
  97. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CP_WILL_BE_RESTORED);
  98. sm.addInt((int) amount);
  99. effected.sendPacket(sm);
  100. }
  101. }
  102. @Override
  103. public void onExit(BuffInfo info)
  104. {
  105. final CharStat charStat = info.getEffected().getStat();
  106. synchronized (charStat)
  107. {
  108. charStat.getActiveChar().removeStatsOwner(this);
  109. }
  110. }
  111. }