mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-25 20:56:28 +00:00
Stop stamina consumption on game pause
This commit is contained in:
parent
8e99cb4f35
commit
836e0150b5
@ -1,14 +1,11 @@
|
||||
package emu.grasscutter.game.managers.SotSManager;
|
||||
package emu.grasscutter.game.managers;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.game.avatar.Avatar;
|
||||
import emu.grasscutter.game.entity.EntityAvatar;
|
||||
import emu.grasscutter.game.entity.GameEntity;
|
||||
import emu.grasscutter.game.managers.MovementManager.MovementManager;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.game.props.FightProperty;
|
||||
import emu.grasscutter.game.props.PlayerProperty;
|
||||
import emu.grasscutter.game.world.World;
|
||||
import emu.grasscutter.net.proto.ChangeHpReasonOuterClass;
|
||||
import emu.grasscutter.net.proto.PropChangeReasonOuterClass;
|
||||
import emu.grasscutter.server.game.GameSession;
|
||||
@ -29,6 +26,8 @@ public class SotSManager {
|
||||
private final Player player;
|
||||
private Timer autoRecoverTimer;
|
||||
|
||||
public final static int GlobalMaximumSpringVolume = 8500000;
|
||||
|
||||
public SotSManager(Player player) {
|
||||
this.player = player;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package emu.grasscutter.game.managers.MovementManager;
|
||||
package emu.grasscutter.game.managers;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.game.entity.EntityAvatar;
|
||||
@ -20,9 +20,11 @@ import emu.grasscutter.utils.Position;
|
||||
import java.lang.Math;
|
||||
import java.util.*;
|
||||
|
||||
public class MovementManager {
|
||||
public class StaminaManager {
|
||||
private final Player player;
|
||||
private HashMap<String, HashSet<MotionState>> MotionStatesCategorized = new HashMap<>();
|
||||
|
||||
public final static int GlobalMaximumStamina = 24000;
|
||||
private Position currentCoordinates = new Position(0, 0, 0);
|
||||
private Position previousCoordinates = new Position(0, 0, 0);
|
||||
private MotionState currentState = MotionState.MOTION_STANDBY;
|
||||
@ -84,7 +86,7 @@ public class MovementManager {
|
||||
isInSkillMove = b;
|
||||
}
|
||||
|
||||
public MovementManager(Player player) {
|
||||
public StaminaManager(Player player) {
|
||||
this.player = player;
|
||||
|
||||
MotionStatesCategorized.put("SWIM", new HashSet<>(Arrays.asList(
|
||||
@ -181,11 +183,14 @@ public class MovementManager {
|
||||
}
|
||||
|
||||
public void startSustainedStaminaHandler() {
|
||||
if (sustainedStaminaHandlerTimer == null) {
|
||||
sustainedStaminaHandlerTimer = new Timer();
|
||||
sustainedStaminaHandlerTimer.scheduleAtFixedRate(new SustainedStaminaHandler(), 0, 200);
|
||||
Grasscutter.getLogger().debug("[MovementManager] SustainedStaminaHandlerTimer started");
|
||||
if (!player.isPaused()) {
|
||||
if (sustainedStaminaHandlerTimer == null) {
|
||||
sustainedStaminaHandlerTimer = new Timer();
|
||||
sustainedStaminaHandlerTimer.scheduleAtFixedRate(new SustainedStaminaHandler(), 0, 200);
|
||||
Grasscutter.getLogger().debug("[MovementManager] SustainedStaminaHandlerTimer started");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void stopSustainedStaminaHandler() {
|
@ -22,8 +22,8 @@ import emu.grasscutter.game.inventory.GameItem;
|
||||
import emu.grasscutter.game.inventory.Inventory;
|
||||
import emu.grasscutter.game.mail.Mail;
|
||||
import emu.grasscutter.game.mail.MailHandler;
|
||||
import emu.grasscutter.game.managers.MovementManager.MovementManager;
|
||||
import emu.grasscutter.game.managers.SotSManager.SotSManager;
|
||||
import emu.grasscutter.game.managers.StaminaManager;
|
||||
import emu.grasscutter.game.managers.SotSManager;
|
||||
import emu.grasscutter.game.props.ActionReason;
|
||||
import emu.grasscutter.game.props.EntityType;
|
||||
import emu.grasscutter.game.props.PlayerProperty;
|
||||
@ -62,9 +62,6 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
@Entity(value = "players", useDiscriminator = false)
|
||||
public class Player {
|
||||
|
||||
@Transient private static int GlobalMaximumSpringVolume = 8500000;
|
||||
@Transient private static int GlobalMaximumStamina = 24000;
|
||||
|
||||
@Id private int id;
|
||||
@Indexed(options = @IndexOptions(unique = true)) private String accountId;
|
||||
|
||||
@ -132,7 +129,7 @@ public class Player {
|
||||
@Transient private final InvokeHandler<AbilityInvokeEntry> clientAbilityInitFinishHandler;
|
||||
|
||||
private MapMarksManager mapMarksManager;
|
||||
@Transient private MovementManager movementManager;
|
||||
@Transient private StaminaManager staminaManager;
|
||||
|
||||
private long springLastUsed;
|
||||
|
||||
@ -178,7 +175,7 @@ public class Player {
|
||||
this.expeditionInfo = new HashMap<>();
|
||||
this.messageHandler = null;
|
||||
this.mapMarksManager = new MapMarksManager();
|
||||
this.movementManager = new MovementManager(this);
|
||||
this.staminaManager = new StaminaManager(this);
|
||||
this.sotsManager = new SotSManager(this);
|
||||
}
|
||||
|
||||
@ -206,7 +203,7 @@ public class Player {
|
||||
this.getRotation().set(0, 307, 0);
|
||||
this.messageHandler = null;
|
||||
this.mapMarksManager = new MapMarksManager();
|
||||
this.movementManager = new MovementManager(this);
|
||||
this.staminaManager = new StaminaManager(this);
|
||||
this.sotsManager = new SotSManager(this);
|
||||
}
|
||||
|
||||
@ -875,11 +872,11 @@ public class Player {
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
|
||||
staminaManager.stopSustainedStaminaHandler();
|
||||
}
|
||||
|
||||
public void onUnpause() {
|
||||
|
||||
staminaManager.startSustainedStaminaHandler();
|
||||
}
|
||||
|
||||
public void sendPacket(BasePacket packet) {
|
||||
@ -1024,7 +1021,7 @@ public class Player {
|
||||
return mapMarksManager;
|
||||
}
|
||||
|
||||
public MovementManager getMovementManager() { return movementManager; }
|
||||
public StaminaManager getStaminaManager() { return staminaManager; }
|
||||
|
||||
public SotSManager getSotSManager() { return sotsManager; }
|
||||
|
||||
@ -1152,7 +1149,7 @@ public class Player {
|
||||
|
||||
public void onLogout() {
|
||||
// stop stamina calculation
|
||||
getMovementManager().stopSustainedStaminaHandler();
|
||||
getStaminaManager().stopSustainedStaminaHandler();
|
||||
|
||||
// force to leave the dungeon
|
||||
if (getScene().getSceneType() == SceneType.SCENE_DUNGEON) {
|
||||
@ -1214,7 +1211,7 @@ public class Player {
|
||||
} else if (prop == PlayerProperty.PROP_LAST_CHANGE_AVATAR_TIME) { // 10001
|
||||
// TODO: implement sanity check
|
||||
} else if (prop == PlayerProperty.PROP_MAX_SPRING_VOLUME) { // 10002
|
||||
if (!(value >= 0 && value <= GlobalMaximumSpringVolume)) { return false; }
|
||||
if (!(value >= 0 && value <= getSotSManager().GlobalMaximumSpringVolume)) { return false; }
|
||||
} else if (prop == PlayerProperty.PROP_CUR_SPRING_VOLUME) { // 10003
|
||||
int playerMaximumSpringVolume = getProperty(PlayerProperty.PROP_MAX_SPRING_VOLUME);
|
||||
if (!(value >= 0 && value <= playerMaximumSpringVolume)) { return false; }
|
||||
@ -1231,7 +1228,7 @@ public class Player {
|
||||
} else if (prop == PlayerProperty.PROP_IS_TRANSFERABLE) { // 10009
|
||||
if (!(0 <= value && value <= 1)) { return false; }
|
||||
} else if (prop == PlayerProperty.PROP_MAX_STAMINA) { // 10010
|
||||
if (!(value >= 0 && value <= GlobalMaximumStamina)) { return false; }
|
||||
if (!(value >= 0 && value <= getStaminaManager().GlobalMaximumStamina)) { return false; }
|
||||
} else if (prop == PlayerProperty.PROP_CUR_PERSIST_STAMINA) { // 10011
|
||||
int playerMaximumStamina = getProperty(PlayerProperty.PROP_MAX_STAMINA);
|
||||
if (!(value >= 0 && value <= playerMaximumStamina)) { return false; }
|
||||
@ -1242,7 +1239,7 @@ public class Player {
|
||||
} else if (prop == PlayerProperty.PROP_PLAYER_EXP) { // 10014
|
||||
if (!(0 <= value)) { return false; }
|
||||
} else if (prop == PlayerProperty.PROP_PLAYER_HCOIN) { // 10015
|
||||
// see 10015
|
||||
// see PlayerProperty.PROP_PLAYER_HCOIN comments
|
||||
} else if (prop == PlayerProperty.PROP_PLAYER_SCOIN) { // 10016
|
||||
// See 10015
|
||||
} else if (prop == PlayerProperty.PROP_PLAYER_MP_SETTING_TYPE) { // 10017
|
||||
|
@ -557,7 +557,7 @@ public class TeamManager {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
player.getMovementManager().stopSustainedStaminaHandler(); // prevent drowning immediately after respawn
|
||||
player.getStaminaManager().stopSustainedStaminaHandler(); // prevent drowning immediately after respawn
|
||||
|
||||
// Revive all team members
|
||||
for (EntityAvatar entity : getActiveTeam()) {
|
||||
|
@ -16,8 +16,6 @@ import emu.grasscutter.net.proto.PlayerDieTypeOuterClass;
|
||||
import emu.grasscutter.server.game.GameSession;
|
||||
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@Opcodes(PacketOpcodes.CombatInvocationsNotify)
|
||||
public class HandlerCombatInvocationsNotify extends PacketHandler {
|
||||
|
||||
@ -49,7 +47,7 @@ public class HandlerCombatInvocationsNotify extends PacketHandler {
|
||||
MotionState motionState = motionInfo.getState();
|
||||
entity.setMotionState(motionState);
|
||||
|
||||
session.getPlayer().getMovementManager().handleCombatInvocationsNotify(session, moveInfo, entity);
|
||||
session.getPlayer().getStaminaManager().handleCombatInvocationsNotify(session, moveInfo, entity);
|
||||
|
||||
// TODO: handle MOTION_FIGHT landing
|
||||
// For plunge attacks, LAND_SPEED is always -30 and is not useful.
|
||||
@ -116,7 +114,7 @@ public class HandlerCombatInvocationsNotify extends PacketHandler {
|
||||
entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, newHP);
|
||||
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_HP));
|
||||
if (newHP == 0) {
|
||||
session.getPlayer().getMovementManager().killAvatar(session, entity, PlayerDieTypeOuterClass.PlayerDieType.PLAYER_DIE_FALL);
|
||||
session.getPlayer().getStaminaManager().killAvatar(session, entity, PlayerDieTypeOuterClass.PlayerDieType.PLAYER_DIE_FALL);
|
||||
}
|
||||
cachedLandingSpeed = 0;
|
||||
}
|
||||
|
@ -1,20 +1,11 @@
|
||||
package emu.grasscutter.server.packet.recv;
|
||||
|
||||
import emu.grasscutter.game.managers.SotSManager.SotSManager;
|
||||
import emu.grasscutter.game.managers.SotSManager;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.game.props.FightProperty;
|
||||
import emu.grasscutter.net.packet.Opcodes;
|
||||
import emu.grasscutter.net.packet.PacketHandler;
|
||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.proto.ChangeHpReasonOuterClass.ChangeHpReason;
|
||||
import emu.grasscutter.net.proto.PropChangeReasonOuterClass.PropChangeReason;
|
||||
import emu.grasscutter.server.game.GameSession;
|
||||
import emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketAvatarLifeStateChangeNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketEntityFightPropChangeReasonNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Opcodes(PacketOpcodes.EnterTransPointRegionNotify)
|
||||
public class HandlerEnterTransPointRegionNotify extends PacketHandler {
|
||||
|
@ -14,7 +14,7 @@ public class HandlerEvtDoSkillSuccNotify extends PacketHandler {
|
||||
EvtDoSkillSuccNotify notify = EvtDoSkillSuccNotify.parseFrom(payload);
|
||||
// TODO: Will be used for deducting stamina for charged skills.
|
||||
|
||||
session.getPlayer().getMovementManager().handleEvtDoSkillSuccNotify(session, notify);
|
||||
session.getPlayer().getStaminaManager().handleEvtDoSkillSuccNotify(session, notify);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package emu.grasscutter.server.packet.recv;
|
||||
|
||||
import emu.grasscutter.game.managers.SotSManager.SotSManager;
|
||||
import emu.grasscutter.game.managers.SotSManager;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.net.packet.Opcodes;
|
||||
import emu.grasscutter.net.packet.PacketHandler;
|
||||
|
Loading…
Reference in New Issue
Block a user