mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-03-13 09:17:45 +08:00
Fix #593: Accidental death of character
This commit is contained in:
parent
3f91fdcb71
commit
58cb60299c
@ -60,6 +60,7 @@ public class MovementManager {
|
|||||||
private final Player player;
|
private final Player player;
|
||||||
|
|
||||||
private float landSpeed = 0;
|
private float landSpeed = 0;
|
||||||
|
private long landTimeMillisecond = 0;
|
||||||
private Timer movementManagerTickTimer;
|
private Timer movementManagerTickTimer;
|
||||||
private GameSession cachedSession = null;
|
private GameSession cachedSession = null;
|
||||||
private GameEntity cachedEntity = null;
|
private GameEntity cachedEntity = null;
|
||||||
@ -192,12 +193,20 @@ public class MovementManager {
|
|||||||
// cache land speed
|
// cache land speed
|
||||||
if (state == MotionState.MOTION_LAND_SPEED) {
|
if (state == MotionState.MOTION_LAND_SPEED) {
|
||||||
landSpeed = motionInfo.getSpeed().getY();
|
landSpeed = motionInfo.getSpeed().getY();
|
||||||
|
landTimeMillisecond = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
if (state == MotionState.MOTION_FALL_ON_GROUND) {
|
if (state == MotionState.MOTION_FALL_ON_GROUND) {
|
||||||
|
// if not received immediately after MOTION_LAND_SPEED, discard this packet.
|
||||||
|
// TODO: Test in high latency.
|
||||||
|
int maxDelay = 200;
|
||||||
|
if ((System.currentTimeMillis() - landTimeMillisecond) > maxDelay) {
|
||||||
|
Grasscutter.getLogger().debug("MOTION_FALL_ON_GROUND received after " + maxDelay + "ms, discard.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
float currentHP = cachedEntity.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP);
|
float currentHP = cachedEntity.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP);
|
||||||
float maxHP = cachedEntity.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
|
float maxHP = cachedEntity.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP);
|
||||||
float damage = 0;
|
float damage = 0;
|
||||||
// Grasscutter.getLogger().debug("LandSpeed: " + landSpeed);
|
Grasscutter.getLogger().debug("LandSpeed: " + landSpeed);
|
||||||
if (landSpeed < -23.5) {
|
if (landSpeed < -23.5) {
|
||||||
damage = (float)(maxHP * 0.33);
|
damage = (float)(maxHP * 0.33);
|
||||||
}
|
}
|
||||||
@ -214,7 +223,7 @@ public class MovementManager {
|
|||||||
if (newHP < 0) {
|
if (newHP < 0) {
|
||||||
newHP = 0;
|
newHP = 0;
|
||||||
}
|
}
|
||||||
// Grasscutter.getLogger().debug("Max: " + maxHP + "\tCurr: " + currentHP + "\tDamage: " + damage + "\tnewHP: " + newHP);
|
Grasscutter.getLogger().debug("Max: " + maxHP + "\tCurr: " + currentHP + "\tDamage: " + damage + "\tnewHP: " + newHP);
|
||||||
cachedEntity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, newHP);
|
cachedEntity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, newHP);
|
||||||
cachedEntity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(cachedEntity, FightProperty.FIGHT_PROP_CUR_HP));
|
cachedEntity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(cachedEntity, FightProperty.FIGHT_PROP_CUR_HP));
|
||||||
if (newHP == 0) {
|
if (newHP == 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user