Complete char regeneration task.
Contributed by Liamxroy.
This commit is contained in:
parent
014e6ddfdb
commit
8f200b5606
@ -20,13 +20,11 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.l2jmobius.commons.concurrent.ThreadPool;
|
import com.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||||
import com.l2jmobius.gameserver.model.actor.stat.CharStat;
|
|
||||||
import com.l2jmobius.gameserver.model.events.EventDispatcher;
|
import com.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||||
import com.l2jmobius.gameserver.model.events.impl.character.OnCreatureHpChange;
|
import com.l2jmobius.gameserver.model.events.impl.character.OnCreatureHpChange;
|
||||||
import com.l2jmobius.gameserver.model.skills.AbnormalType;
|
import com.l2jmobius.gameserver.model.skills.AbnormalType;
|
||||||
@ -210,7 +208,7 @@ public class CharStatus
|
|||||||
final int period = Formulas.getRegeneratePeriod(getActiveChar());
|
final int period = Formulas.getRegeneratePeriod(getActiveChar());
|
||||||
|
|
||||||
// Create the HP/MP/CP Regeneration task
|
// Create the HP/MP/CP Regeneration task
|
||||||
_regTask = ThreadPool.scheduleAtFixedRate(new RegenTask(), period, period);
|
_regTask = ThreadPool.scheduleAtFixedRate(this::doRegeneration, period, period);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,49 +406,16 @@ public class CharStatus
|
|||||||
|
|
||||||
protected void doRegeneration()
|
protected void doRegeneration()
|
||||||
{
|
{
|
||||||
final CharStat charstat = getActiveChar().getStat();
|
// Modify the current HP/MP of the L2Character and broadcast Server->Client packet StatusUpdate
|
||||||
|
if (!getActiveChar().isDead() && ((getCurrentHp() < getActiveChar().getMaxRecoverableHp()) || (getCurrentMp() < getActiveChar().getMaxRecoverableMp())))
|
||||||
// Modify the current HP of the L2Character and broadcast Server->Client packet StatusUpdate
|
|
||||||
if (getCurrentHp() < charstat.getMaxRecoverableHp())
|
|
||||||
{
|
{
|
||||||
setCurrentHp(getCurrentHp() + getActiveChar().getStat().getValue(Stats.REGENERATE_HP_RATE), false);
|
final double newHp = getCurrentHp() + getActiveChar().getStat().getValue(Stats.REGENERATE_HP_RATE);
|
||||||
}
|
final double newMp = getCurrentMp() + getActiveChar().getStat().getValue(Stats.REGENERATE_MP_RATE);
|
||||||
|
setCurrentHpMp(newHp, newMp);
|
||||||
// Modify the current MP of the L2Character and broadcast Server->Client packet StatusUpdate
|
|
||||||
if (getCurrentMp() < charstat.getMaxRecoverableMp())
|
|
||||||
{
|
|
||||||
setCurrentMp(getCurrentMp() + getActiveChar().getStat().getValue(Stats.REGENERATE_MP_RATE), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!getActiveChar().isInActiveRegion())
|
|
||||||
{
|
|
||||||
// no broadcast necessary for characters that are in inactive regions.
|
|
||||||
// stop regeneration for characters who are filled up and in an inactive region.
|
|
||||||
if ((getCurrentHp() == charstat.getMaxRecoverableHp()) && (getCurrentMp() == charstat.getMaxMp()))
|
|
||||||
{
|
|
||||||
stopHpMpRegeneration();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
getActiveChar().broadcastStatusUpdate(); // send the StatusUpdate packet
|
stopHpMpRegeneration();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Task of HP/MP regeneration */
|
|
||||||
class RegenTask implements Runnable
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
doRegeneration();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,13 +20,11 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.l2jmobius.commons.concurrent.ThreadPool;
|
import com.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||||
import com.l2jmobius.gameserver.model.actor.stat.CharStat;
|
|
||||||
import com.l2jmobius.gameserver.model.events.EventDispatcher;
|
import com.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||||
import com.l2jmobius.gameserver.model.events.impl.character.OnCreatureHpChange;
|
import com.l2jmobius.gameserver.model.events.impl.character.OnCreatureHpChange;
|
||||||
import com.l2jmobius.gameserver.model.skills.AbnormalType;
|
import com.l2jmobius.gameserver.model.skills.AbnormalType;
|
||||||
@ -210,7 +208,7 @@ public class CharStatus
|
|||||||
final int period = Formulas.getRegeneratePeriod(getActiveChar());
|
final int period = Formulas.getRegeneratePeriod(getActiveChar());
|
||||||
|
|
||||||
// Create the HP/MP/CP Regeneration task
|
// Create the HP/MP/CP Regeneration task
|
||||||
_regTask = ThreadPool.scheduleAtFixedRate(new RegenTask(), period, period);
|
_regTask = ThreadPool.scheduleAtFixedRate(this::doRegeneration, period, period);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,49 +406,16 @@ public class CharStatus
|
|||||||
|
|
||||||
protected void doRegeneration()
|
protected void doRegeneration()
|
||||||
{
|
{
|
||||||
final CharStat charstat = getActiveChar().getStat();
|
// Modify the current HP/MP of the L2Character and broadcast Server->Client packet StatusUpdate
|
||||||
|
if (!getActiveChar().isDead() && ((getCurrentHp() < getActiveChar().getMaxRecoverableHp()) || (getCurrentMp() < getActiveChar().getMaxRecoverableMp())))
|
||||||
// Modify the current HP of the L2Character and broadcast Server->Client packet StatusUpdate
|
|
||||||
if (getCurrentHp() < charstat.getMaxRecoverableHp())
|
|
||||||
{
|
{
|
||||||
setCurrentHp(getCurrentHp() + getActiveChar().getStat().getValue(Stats.REGENERATE_HP_RATE), false);
|
final double newHp = getCurrentHp() + getActiveChar().getStat().getValue(Stats.REGENERATE_HP_RATE);
|
||||||
}
|
final double newMp = getCurrentMp() + getActiveChar().getStat().getValue(Stats.REGENERATE_MP_RATE);
|
||||||
|
setCurrentHpMp(newHp, newMp);
|
||||||
// Modify the current MP of the L2Character and broadcast Server->Client packet StatusUpdate
|
|
||||||
if (getCurrentMp() < charstat.getMaxRecoverableMp())
|
|
||||||
{
|
|
||||||
setCurrentMp(getCurrentMp() + getActiveChar().getStat().getValue(Stats.REGENERATE_MP_RATE), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!getActiveChar().isInActiveRegion())
|
|
||||||
{
|
|
||||||
// no broadcast necessary for characters that are in inactive regions.
|
|
||||||
// stop regeneration for characters who are filled up and in an inactive region.
|
|
||||||
if ((getCurrentHp() == charstat.getMaxRecoverableHp()) && (getCurrentMp() == charstat.getMaxMp()))
|
|
||||||
{
|
|
||||||
stopHpMpRegeneration();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
getActiveChar().broadcastStatusUpdate(); // send the StatusUpdate packet
|
stopHpMpRegeneration();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Task of HP/MP regeneration */
|
|
||||||
class RegenTask implements Runnable
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
doRegeneration();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,13 +20,11 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.l2jmobius.commons.concurrent.ThreadPool;
|
import com.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||||
import com.l2jmobius.gameserver.model.actor.stat.CharStat;
|
|
||||||
import com.l2jmobius.gameserver.model.events.EventDispatcher;
|
import com.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||||
import com.l2jmobius.gameserver.model.events.impl.character.OnCreatureHpChange;
|
import com.l2jmobius.gameserver.model.events.impl.character.OnCreatureHpChange;
|
||||||
import com.l2jmobius.gameserver.model.skills.AbnormalType;
|
import com.l2jmobius.gameserver.model.skills.AbnormalType;
|
||||||
@ -210,7 +208,7 @@ public class CharStatus
|
|||||||
final int period = Formulas.getRegeneratePeriod(getActiveChar());
|
final int period = Formulas.getRegeneratePeriod(getActiveChar());
|
||||||
|
|
||||||
// Create the HP/MP/CP Regeneration task
|
// Create the HP/MP/CP Regeneration task
|
||||||
_regTask = ThreadPool.scheduleAtFixedRate(new RegenTask(), period, period);
|
_regTask = ThreadPool.scheduleAtFixedRate(this::doRegeneration, period, period);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,49 +406,16 @@ public class CharStatus
|
|||||||
|
|
||||||
protected void doRegeneration()
|
protected void doRegeneration()
|
||||||
{
|
{
|
||||||
final CharStat charstat = getActiveChar().getStat();
|
// Modify the current HP/MP of the L2Character and broadcast Server->Client packet StatusUpdate
|
||||||
|
if (!getActiveChar().isDead() && ((getCurrentHp() < getActiveChar().getMaxRecoverableHp()) || (getCurrentMp() < getActiveChar().getMaxRecoverableMp())))
|
||||||
// Modify the current HP of the L2Character and broadcast Server->Client packet StatusUpdate
|
|
||||||
if (getCurrentHp() < charstat.getMaxRecoverableHp())
|
|
||||||
{
|
{
|
||||||
setCurrentHp(getCurrentHp() + getActiveChar().getStat().getValue(Stats.REGENERATE_HP_RATE), false);
|
final double newHp = getCurrentHp() + getActiveChar().getStat().getValue(Stats.REGENERATE_HP_RATE);
|
||||||
}
|
final double newMp = getCurrentMp() + getActiveChar().getStat().getValue(Stats.REGENERATE_MP_RATE);
|
||||||
|
setCurrentHpMp(newHp, newMp);
|
||||||
// Modify the current MP of the L2Character and broadcast Server->Client packet StatusUpdate
|
|
||||||
if (getCurrentMp() < charstat.getMaxRecoverableMp())
|
|
||||||
{
|
|
||||||
setCurrentMp(getCurrentMp() + getActiveChar().getStat().getValue(Stats.REGENERATE_MP_RATE), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!getActiveChar().isInActiveRegion())
|
|
||||||
{
|
|
||||||
// no broadcast necessary for characters that are in inactive regions.
|
|
||||||
// stop regeneration for characters who are filled up and in an inactive region.
|
|
||||||
if ((getCurrentHp() == charstat.getMaxRecoverableHp()) && (getCurrentMp() == charstat.getMaxMp()))
|
|
||||||
{
|
|
||||||
stopHpMpRegeneration();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
getActiveChar().broadcastStatusUpdate(); // send the StatusUpdate packet
|
stopHpMpRegeneration();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Task of HP/MP regeneration */
|
|
||||||
class RegenTask implements Runnable
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
doRegeneration();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,13 +20,11 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.l2jmobius.commons.concurrent.ThreadPool;
|
import com.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||||
import com.l2jmobius.gameserver.model.actor.stat.CharStat;
|
|
||||||
import com.l2jmobius.gameserver.model.events.EventDispatcher;
|
import com.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||||
import com.l2jmobius.gameserver.model.events.impl.character.OnCreatureHpChange;
|
import com.l2jmobius.gameserver.model.events.impl.character.OnCreatureHpChange;
|
||||||
import com.l2jmobius.gameserver.model.skills.AbnormalType;
|
import com.l2jmobius.gameserver.model.skills.AbnormalType;
|
||||||
@ -210,7 +208,7 @@ public class CharStatus
|
|||||||
final int period = Formulas.getRegeneratePeriod(getActiveChar());
|
final int period = Formulas.getRegeneratePeriod(getActiveChar());
|
||||||
|
|
||||||
// Create the HP/MP/CP Regeneration task
|
// Create the HP/MP/CP Regeneration task
|
||||||
_regTask = ThreadPool.scheduleAtFixedRate(new RegenTask(), period, period);
|
_regTask = ThreadPool.scheduleAtFixedRate(this::doRegeneration, period, period);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,49 +406,16 @@ public class CharStatus
|
|||||||
|
|
||||||
protected void doRegeneration()
|
protected void doRegeneration()
|
||||||
{
|
{
|
||||||
final CharStat charstat = getActiveChar().getStat();
|
// Modify the current HP/MP of the L2Character and broadcast Server->Client packet StatusUpdate
|
||||||
|
if (!getActiveChar().isDead() && ((getCurrentHp() < getActiveChar().getMaxRecoverableHp()) || (getCurrentMp() < getActiveChar().getMaxRecoverableMp())))
|
||||||
// Modify the current HP of the L2Character and broadcast Server->Client packet StatusUpdate
|
|
||||||
if (getCurrentHp() < charstat.getMaxRecoverableHp())
|
|
||||||
{
|
{
|
||||||
setCurrentHp(getCurrentHp() + getActiveChar().getStat().getValue(Stats.REGENERATE_HP_RATE), false);
|
final double newHp = getCurrentHp() + getActiveChar().getStat().getValue(Stats.REGENERATE_HP_RATE);
|
||||||
}
|
final double newMp = getCurrentMp() + getActiveChar().getStat().getValue(Stats.REGENERATE_MP_RATE);
|
||||||
|
setCurrentHpMp(newHp, newMp);
|
||||||
// Modify the current MP of the L2Character and broadcast Server->Client packet StatusUpdate
|
|
||||||
if (getCurrentMp() < charstat.getMaxRecoverableMp())
|
|
||||||
{
|
|
||||||
setCurrentMp(getCurrentMp() + getActiveChar().getStat().getValue(Stats.REGENERATE_MP_RATE), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!getActiveChar().isInActiveRegion())
|
|
||||||
{
|
|
||||||
// no broadcast necessary for characters that are in inactive regions.
|
|
||||||
// stop regeneration for characters who are filled up and in an inactive region.
|
|
||||||
if ((getCurrentHp() == charstat.getMaxRecoverableHp()) && (getCurrentMp() == charstat.getMaxMp()))
|
|
||||||
{
|
|
||||||
stopHpMpRegeneration();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
getActiveChar().broadcastStatusUpdate(); // send the StatusUpdate packet
|
stopHpMpRegeneration();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Task of HP/MP regeneration */
|
|
||||||
class RegenTask implements Runnable
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
doRegeneration();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@ package com.l2jmobius.gameserver.model.actor.status;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.l2jmobius.commons.concurrent.ThreadPool;
|
import com.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
@ -195,7 +194,7 @@ public class CharStatus
|
|||||||
final int period = Formulas.getRegeneratePeriod(getActiveChar());
|
final int period = Formulas.getRegeneratePeriod(getActiveChar());
|
||||||
|
|
||||||
// Create the HP/MP/CP Regeneration task
|
// 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()
|
protected void doRegeneration()
|
||||||
{
|
{
|
||||||
// Modify the current HP of the L2Character and broadcast Server->Client packet StatusUpdate
|
// Modify the current HP/MP of the L2Character and broadcast Server->Client packet StatusUpdate
|
||||||
if (getCurrentHp() < getActiveChar().getMaxRecoverableHp())
|
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);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// 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()))
|
|
||||||
{
|
{
|
||||||
stopHpMpRegeneration();
|
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()
|
public L2Character getActiveChar()
|
||||||
|
@ -20,13 +20,11 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.l2jmobius.commons.concurrent.ThreadPool;
|
import com.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||||
import com.l2jmobius.gameserver.model.actor.stat.CharStat;
|
|
||||||
import com.l2jmobius.gameserver.model.events.EventDispatcher;
|
import com.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||||
import com.l2jmobius.gameserver.model.events.impl.character.OnCreatureHpChange;
|
import com.l2jmobius.gameserver.model.events.impl.character.OnCreatureHpChange;
|
||||||
import com.l2jmobius.gameserver.model.skills.AbnormalType;
|
import com.l2jmobius.gameserver.model.skills.AbnormalType;
|
||||||
@ -210,7 +208,7 @@ public class CharStatus
|
|||||||
final int period = Formulas.getRegeneratePeriod(getActiveChar());
|
final int period = Formulas.getRegeneratePeriod(getActiveChar());
|
||||||
|
|
||||||
// Create the HP/MP/CP Regeneration task
|
// Create the HP/MP/CP Regeneration task
|
||||||
_regTask = ThreadPool.scheduleAtFixedRate(new RegenTask(), period, period);
|
_regTask = ThreadPool.scheduleAtFixedRate(this::doRegeneration, period, period);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,49 +406,16 @@ public class CharStatus
|
|||||||
|
|
||||||
protected void doRegeneration()
|
protected void doRegeneration()
|
||||||
{
|
{
|
||||||
final CharStat charstat = getActiveChar().getStat();
|
// Modify the current HP/MP of the L2Character and broadcast Server->Client packet StatusUpdate
|
||||||
|
if (!getActiveChar().isDead() && ((getCurrentHp() < getActiveChar().getMaxRecoverableHp()) || (getCurrentMp() < getActiveChar().getMaxRecoverableMp())))
|
||||||
// Modify the current HP of the L2Character and broadcast Server->Client packet StatusUpdate
|
|
||||||
if (getCurrentHp() < charstat.getMaxRecoverableHp())
|
|
||||||
{
|
{
|
||||||
setCurrentHp(getCurrentHp() + getActiveChar().getStat().getValue(Stats.REGENERATE_HP_RATE), false);
|
final double newHp = getCurrentHp() + getActiveChar().getStat().getValue(Stats.REGENERATE_HP_RATE);
|
||||||
}
|
final double newMp = getCurrentMp() + getActiveChar().getStat().getValue(Stats.REGENERATE_MP_RATE);
|
||||||
|
setCurrentHpMp(newHp, newMp);
|
||||||
// Modify the current MP of the L2Character and broadcast Server->Client packet StatusUpdate
|
|
||||||
if (getCurrentMp() < charstat.getMaxRecoverableMp())
|
|
||||||
{
|
|
||||||
setCurrentMp(getCurrentMp() + getActiveChar().getStat().getValue(Stats.REGENERATE_MP_RATE), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!getActiveChar().isInActiveRegion())
|
|
||||||
{
|
|
||||||
// no broadcast necessary for characters that are in inactive regions.
|
|
||||||
// stop regeneration for characters who are filled up and in an inactive region.
|
|
||||||
if ((getCurrentHp() == charstat.getMaxRecoverableHp()) && (getCurrentMp() == charstat.getMaxMp()))
|
|
||||||
{
|
|
||||||
stopHpMpRegeneration();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
getActiveChar().broadcastStatusUpdate(); // send the StatusUpdate packet
|
stopHpMpRegeneration();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Task of HP/MP regeneration */
|
|
||||||
class RegenTask implements Runnable
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
doRegeneration();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,13 +20,11 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.l2jmobius.commons.concurrent.ThreadPool;
|
import com.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||||
import com.l2jmobius.gameserver.model.actor.stat.CharStat;
|
|
||||||
import com.l2jmobius.gameserver.model.events.EventDispatcher;
|
import com.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||||
import com.l2jmobius.gameserver.model.events.impl.character.OnCreatureHpChange;
|
import com.l2jmobius.gameserver.model.events.impl.character.OnCreatureHpChange;
|
||||||
import com.l2jmobius.gameserver.model.skills.AbnormalType;
|
import com.l2jmobius.gameserver.model.skills.AbnormalType;
|
||||||
@ -210,7 +208,7 @@ public class CharStatus
|
|||||||
final int period = Formulas.getRegeneratePeriod(getActiveChar());
|
final int period = Formulas.getRegeneratePeriod(getActiveChar());
|
||||||
|
|
||||||
// Create the HP/MP/CP Regeneration task
|
// Create the HP/MP/CP Regeneration task
|
||||||
_regTask = ThreadPool.scheduleAtFixedRate(new RegenTask(), period, period);
|
_regTask = ThreadPool.scheduleAtFixedRate(this::doRegeneration, period, period);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,49 +406,16 @@ public class CharStatus
|
|||||||
|
|
||||||
protected void doRegeneration()
|
protected void doRegeneration()
|
||||||
{
|
{
|
||||||
final CharStat charstat = getActiveChar().getStat();
|
// Modify the current HP/MP of the L2Character and broadcast Server->Client packet StatusUpdate
|
||||||
|
if (!getActiveChar().isDead() && ((getCurrentHp() < getActiveChar().getMaxRecoverableHp()) || (getCurrentMp() < getActiveChar().getMaxRecoverableMp())))
|
||||||
// Modify the current HP of the L2Character and broadcast Server->Client packet StatusUpdate
|
|
||||||
if (getCurrentHp() < charstat.getMaxRecoverableHp())
|
|
||||||
{
|
{
|
||||||
setCurrentHp(getCurrentHp() + getActiveChar().getStat().getValue(Stats.REGENERATE_HP_RATE), false);
|
final double newHp = getCurrentHp() + getActiveChar().getStat().getValue(Stats.REGENERATE_HP_RATE);
|
||||||
}
|
final double newMp = getCurrentMp() + getActiveChar().getStat().getValue(Stats.REGENERATE_MP_RATE);
|
||||||
|
setCurrentHpMp(newHp, newMp);
|
||||||
// Modify the current MP of the L2Character and broadcast Server->Client packet StatusUpdate
|
|
||||||
if (getCurrentMp() < charstat.getMaxRecoverableMp())
|
|
||||||
{
|
|
||||||
setCurrentMp(getCurrentMp() + getActiveChar().getStat().getValue(Stats.REGENERATE_MP_RATE), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!getActiveChar().isInActiveRegion())
|
|
||||||
{
|
|
||||||
// no broadcast necessary for characters that are in inactive regions.
|
|
||||||
// stop regeneration for characters who are filled up and in an inactive region.
|
|
||||||
if ((getCurrentHp() == charstat.getMaxRecoverableHp()) && (getCurrentMp() == charstat.getMaxMp()))
|
|
||||||
{
|
|
||||||
stopHpMpRegeneration();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
getActiveChar().broadcastStatusUpdate(); // send the StatusUpdate packet
|
stopHpMpRegeneration();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Task of HP/MP regeneration */
|
|
||||||
class RegenTask implements Runnable
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
doRegeneration();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user