Complete char regeneration task.

Contributed by Liamxroy.
This commit is contained in:
MobiusDev
2018-04-26 13:23:34 +00:00
parent 014e6ddfdb
commit 8f200b5606
7 changed files with 49 additions and 287 deletions

View File

@@ -19,7 +19,6 @@ package com.l2jmobius.gameserver.model.actor.status;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.commons.concurrent.ThreadPool;
@@ -195,7 +194,7 @@ public class CharStatus
final int period = Formulas.getRegeneratePeriod(getActiveChar());
// Create the HP/MP/CP Regeneration task
_regTask = ThreadPool.scheduleAtFixedRate(new RegenTask(), period, period);
_regTask = ThreadPool.scheduleAtFixedRate(this::doRegeneration, period, period);
}
}
@@ -367,44 +366,17 @@ public class CharStatus
protected void doRegeneration()
{
// Modify the current HP of the L2Character and broadcast Server->Client packet StatusUpdate
if (getCurrentHp() < getActiveChar().getMaxRecoverableHp())
// Modify the current HP/MP of the L2Character and broadcast Server->Client packet StatusUpdate
if (!getActiveChar().isDead() && ((getCurrentHp() < getActiveChar().getMaxRecoverableHp()) || (getCurrentMp() < getActiveChar().getMaxRecoverableMp())))
{
setCurrentHp(getCurrentHp() + Formulas.calcHpRegen(getActiveChar()), false);
final double newHp = getCurrentHp() + Formulas.calcHpRegen(getActiveChar());
final double newMp = getCurrentMp() + Formulas.calcMpRegen(getActiveChar());
setCurrentHpMp(newHp, newMp);
}
// Modify the current MP of the L2Character and broadcast Server->Client packet StatusUpdate
if (getCurrentMp() < getActiveChar().getMaxRecoverableMp())
{
setCurrentMp(getCurrentMp() + Formulas.calcMpRegen(getActiveChar()), false);
}
if ((getCurrentHp() >= getActiveChar().getMaxRecoverableHp()) && (getCurrentMp() >= getActiveChar().getMaxMp()))
else
{
stopHpMpRegeneration();
}
if (getActiveChar().isInActiveRegion())
{
getActiveChar().broadcastStatusUpdate();
}
}
/** Task of HP/MP regeneration */
class RegenTask implements Runnable
{
@Override
public void run()
{
try
{
doRegeneration();
}
catch (Exception e)
{
LOGGER.log(Level.SEVERE, "", e);
}
}
}
public L2Character getActiveChar()