Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
836e0150
Commit
836e0150
authored
May 07, 2022
by
gentlespoon
Committed by
Melledy
May 07, 2022
Browse files
Stop stamina consumption on game pause
parent
8e99cb4f
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/managers/SotSManager
/SotSManager
.java
→
src/main/java/emu/grasscutter/game/managers/SotSManager.java
View file @
836e0150
package
emu.grasscutter.game.managers
.SotSManager
;
package
emu.grasscutter.game.managers
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.game.avatar.Avatar
;
import
emu.grasscutter.game.avatar.Avatar
;
import
emu.grasscutter.game.entity.EntityAvatar
;
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.player.Player
;
import
emu.grasscutter.game.props.FightProperty
;
import
emu.grasscutter.game.props.FightProperty
;
import
emu.grasscutter.game.props.PlayerProperty
;
import
emu.grasscutter.game.props.PlayerProperty
;
import
emu.grasscutter.game.world.World
;
import
emu.grasscutter.net.proto.ChangeHpReasonOuterClass
;
import
emu.grasscutter.net.proto.ChangeHpReasonOuterClass
;
import
emu.grasscutter.net.proto.PropChangeReasonOuterClass
;
import
emu.grasscutter.net.proto.PropChangeReasonOuterClass
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.game.GameSession
;
...
@@ -29,6 +26,8 @@ public class SotSManager {
...
@@ -29,6 +26,8 @@ public class SotSManager {
private
final
Player
player
;
private
final
Player
player
;
private
Timer
autoRecoverTimer
;
private
Timer
autoRecoverTimer
;
public
final
static
int
GlobalMaximumSpringVolume
=
8500000
;
public
SotSManager
(
Player
player
)
{
public
SotSManager
(
Player
player
)
{
this
.
player
=
player
;
this
.
player
=
player
;
}
}
...
...
src/main/java/emu/grasscutter/game/managers/
MovementManager/Movement
Manager.java
→
src/main/java/emu/grasscutter/game/managers/
Stamina
Manager.java
View file @
836e0150
package
emu.grasscutter.game.managers
.MovementManager
;
package
emu.grasscutter.game.managers
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.game.entity.EntityAvatar
;
import
emu.grasscutter.game.entity.EntityAvatar
;
...
@@ -20,9 +20,11 @@ import emu.grasscutter.utils.Position;
...
@@ -20,9 +20,11 @@ import emu.grasscutter.utils.Position;
import
java.lang.Math
;
import
java.lang.Math
;
import
java.util.*
;
import
java.util.*
;
public
class
Movement
Manager
{
public
class
Stamina
Manager
{
private
final
Player
player
;
private
final
Player
player
;
private
HashMap
<
String
,
HashSet
<
MotionState
>>
MotionStatesCategorized
=
new
HashMap
<>();
private
HashMap
<
String
,
HashSet
<
MotionState
>>
MotionStatesCategorized
=
new
HashMap
<>();
public
final
static
int
GlobalMaximumStamina
=
24000
;
private
Position
currentCoordinates
=
new
Position
(
0
,
0
,
0
);
private
Position
currentCoordinates
=
new
Position
(
0
,
0
,
0
);
private
Position
previousCoordinates
=
new
Position
(
0
,
0
,
0
);
private
Position
previousCoordinates
=
new
Position
(
0
,
0
,
0
);
private
MotionState
currentState
=
MotionState
.
MOTION_STANDBY
;
private
MotionState
currentState
=
MotionState
.
MOTION_STANDBY
;
...
@@ -84,7 +86,7 @@ public class MovementManager {
...
@@ -84,7 +86,7 @@ public class MovementManager {
isInSkillMove
=
b
;
isInSkillMove
=
b
;
}
}
public
Movement
Manager
(
Player
player
)
{
public
Stamina
Manager
(
Player
player
)
{
this
.
player
=
player
;
this
.
player
=
player
;
MotionStatesCategorized
.
put
(
"SWIM"
,
new
HashSet
<>(
Arrays
.
asList
(
MotionStatesCategorized
.
put
(
"SWIM"
,
new
HashSet
<>(
Arrays
.
asList
(
...
@@ -181,11 +183,14 @@ public class MovementManager {
...
@@ -181,11 +183,14 @@ public class MovementManager {
}
}
public
void
startSustainedStaminaHandler
()
{
public
void
startSustainedStaminaHandler
()
{
if
(
sustainedStaminaHandlerTimer
==
null
)
{
if
(!
player
.
isPaused
())
{
sustainedStaminaHandlerTimer
=
new
Timer
();
if
(
sustainedStaminaHandlerTimer
==
null
)
{
sustainedStaminaHandlerTimer
.
scheduleAtFixedRate
(
new
SustainedStaminaHandler
(),
0
,
200
);
sustainedStaminaHandlerTimer
=
new
Timer
();
Grasscutter
.
getLogger
().
debug
(
"[MovementManager] SustainedStaminaHandlerTimer started"
);
sustainedStaminaHandlerTimer
.
scheduleAtFixedRate
(
new
SustainedStaminaHandler
(),
0
,
200
);
Grasscutter
.
getLogger
().
debug
(
"[MovementManager] SustainedStaminaHandlerTimer started"
);
}
}
}
}
}
public
void
stopSustainedStaminaHandler
()
{
public
void
stopSustainedStaminaHandler
()
{
...
...
src/main/java/emu/grasscutter/game/player/Player.java
View file @
836e0150
...
@@ -22,8 +22,8 @@ import emu.grasscutter.game.inventory.GameItem;
...
@@ -22,8 +22,8 @@ import emu.grasscutter.game.inventory.GameItem;
import
emu.grasscutter.game.inventory.Inventory
;
import
emu.grasscutter.game.inventory.Inventory
;
import
emu.grasscutter.game.mail.Mail
;
import
emu.grasscutter.game.mail.Mail
;
import
emu.grasscutter.game.mail.MailHandler
;
import
emu.grasscutter.game.mail.MailHandler
;
import
emu.grasscutter.game.managers.
MovementManager.Movement
Manager
;
import
emu.grasscutter.game.managers.
Stamina
Manager
;
import
emu.grasscutter.game.managers.SotSManager
.SotSManager
;
import
emu.grasscutter.game.managers.SotSManager
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.game.props.EntityType
;
import
emu.grasscutter.game.props.EntityType
;
import
emu.grasscutter.game.props.PlayerProperty
;
import
emu.grasscutter.game.props.PlayerProperty
;
...
@@ -62,9 +62,6 @@ import java.util.concurrent.LinkedBlockingQueue;
...
@@ -62,9 +62,6 @@ import java.util.concurrent.LinkedBlockingQueue;
@Entity
(
value
=
"players"
,
useDiscriminator
=
false
)
@Entity
(
value
=
"players"
,
useDiscriminator
=
false
)
public
class
Player
{
public
class
Player
{
@Transient
private
static
int
GlobalMaximumSpringVolume
=
8500000
;
@Transient
private
static
int
GlobalMaximumStamina
=
24000
;
@Id
private
int
id
;
@Id
private
int
id
;
@Indexed
(
options
=
@IndexOptions
(
unique
=
true
))
private
String
accountId
;
@Indexed
(
options
=
@IndexOptions
(
unique
=
true
))
private
String
accountId
;
...
@@ -132,7 +129,7 @@ public class Player {
...
@@ -132,7 +129,7 @@ public class Player {
@Transient
private
final
InvokeHandler
<
AbilityInvokeEntry
>
clientAbilityInitFinishHandler
;
@Transient
private
final
InvokeHandler
<
AbilityInvokeEntry
>
clientAbilityInitFinishHandler
;
private
MapMarksManager
mapMarksManager
;
private
MapMarksManager
mapMarksManager
;
@Transient
private
MovementManager
movement
Manager
;
@Transient
private
StaminaManager
stamina
Manager
;
private
long
springLastUsed
;
private
long
springLastUsed
;
...
@@ -178,7 +175,7 @@ public class Player {
...
@@ -178,7 +175,7 @@ public class Player {
this
.
expeditionInfo
=
new
HashMap
<>();
this
.
expeditionInfo
=
new
HashMap
<>();
this
.
messageHandler
=
null
;
this
.
messageHandler
=
null
;
this
.
mapMarksManager
=
new
MapMarksManager
();
this
.
mapMarksManager
=
new
MapMarksManager
();
this
.
movement
Manager
=
new
Movement
Manager
(
this
);
this
.
stamina
Manager
=
new
Stamina
Manager
(
this
);
this
.
sotsManager
=
new
SotSManager
(
this
);
this
.
sotsManager
=
new
SotSManager
(
this
);
}
}
...
@@ -206,7 +203,7 @@ public class Player {
...
@@ -206,7 +203,7 @@ public class Player {
this
.
getRotation
().
set
(
0
,
307
,
0
);
this
.
getRotation
().
set
(
0
,
307
,
0
);
this
.
messageHandler
=
null
;
this
.
messageHandler
=
null
;
this
.
mapMarksManager
=
new
MapMarksManager
();
this
.
mapMarksManager
=
new
MapMarksManager
();
this
.
movement
Manager
=
new
Movement
Manager
(
this
);
this
.
stamina
Manager
=
new
Stamina
Manager
(
this
);
this
.
sotsManager
=
new
SotSManager
(
this
);
this
.
sotsManager
=
new
SotSManager
(
this
);
}
}
...
@@ -875,11 +872,11 @@ public class Player {
...
@@ -875,11 +872,11 @@ public class Player {
}
}
public
void
onPause
()
{
public
void
onPause
()
{
staminaManager
.
stopSustainedStaminaHandler
();
}
}
public
void
onUnpause
()
{
public
void
onUnpause
()
{
staminaManager
.
startSustainedStaminaHandler
();
}
}
public
void
sendPacket
(
BasePacket
packet
)
{
public
void
sendPacket
(
BasePacket
packet
)
{
...
@@ -1024,7 +1021,7 @@ public class Player {
...
@@ -1024,7 +1021,7 @@ public class Player {
return
mapMarksManager
;
return
mapMarksManager
;
}
}
public
Movement
Manager
get
Movement
Manager
()
{
return
movement
Manager
;
}
public
Stamina
Manager
get
Stamina
Manager
()
{
return
stamina
Manager
;
}
public
SotSManager
getSotSManager
()
{
return
sotsManager
;
}
public
SotSManager
getSotSManager
()
{
return
sotsManager
;
}
...
@@ -1152,7 +1149,7 @@ public class Player {
...
@@ -1152,7 +1149,7 @@ public class Player {
public
void
onLogout
()
{
public
void
onLogout
()
{
// stop stamina calculation
// stop stamina calculation
get
Movement
Manager
().
stopSustainedStaminaHandler
();
get
Stamina
Manager
().
stopSustainedStaminaHandler
();
// force to leave the dungeon
// force to leave the dungeon
if
(
getScene
().
getSceneType
()
==
SceneType
.
SCENE_DUNGEON
)
{
if
(
getScene
().
getSceneType
()
==
SceneType
.
SCENE_DUNGEON
)
{
...
@@ -1214,7 +1211,7 @@ public class Player {
...
@@ -1214,7 +1211,7 @@ public class Player {
}
else
if
(
prop
==
PlayerProperty
.
PROP_LAST_CHANGE_AVATAR_TIME
)
{
// 10001
}
else
if
(
prop
==
PlayerProperty
.
PROP_LAST_CHANGE_AVATAR_TIME
)
{
// 10001
// TODO: implement sanity check
// TODO: implement sanity check
}
else
if
(
prop
==
PlayerProperty
.
PROP_MAX_SPRING_VOLUME
)
{
// 10002
}
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
}
else
if
(
prop
==
PlayerProperty
.
PROP_CUR_SPRING_VOLUME
)
{
// 10003
int
playerMaximumSpringVolume
=
getProperty
(
PlayerProperty
.
PROP_MAX_SPRING_VOLUME
);
int
playerMaximumSpringVolume
=
getProperty
(
PlayerProperty
.
PROP_MAX_SPRING_VOLUME
);
if
(!(
value
>=
0
&&
value
<=
playerMaximumSpringVolume
))
{
return
false
;
}
if
(!(
value
>=
0
&&
value
<=
playerMaximumSpringVolume
))
{
return
false
;
}
...
@@ -1231,7 +1228,7 @@ public class Player {
...
@@ -1231,7 +1228,7 @@ public class Player {
}
else
if
(
prop
==
PlayerProperty
.
PROP_IS_TRANSFERABLE
)
{
// 10009
}
else
if
(
prop
==
PlayerProperty
.
PROP_IS_TRANSFERABLE
)
{
// 10009
if
(!(
0
<=
value
&&
value
<=
1
))
{
return
false
;
}
if
(!(
0
<=
value
&&
value
<=
1
))
{
return
false
;
}
}
else
if
(
prop
==
PlayerProperty
.
PROP_MAX_STAMINA
)
{
// 10010
}
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
}
else
if
(
prop
==
PlayerProperty
.
PROP_CUR_PERSIST_STAMINA
)
{
// 10011
int
playerMaximumStamina
=
getProperty
(
PlayerProperty
.
PROP_MAX_STAMINA
);
int
playerMaximumStamina
=
getProperty
(
PlayerProperty
.
PROP_MAX_STAMINA
);
if
(!(
value
>=
0
&&
value
<=
playerMaximumStamina
))
{
return
false
;
}
if
(!(
value
>=
0
&&
value
<=
playerMaximumStamina
))
{
return
false
;
}
...
@@ -1242,7 +1239,7 @@ public class Player {
...
@@ -1242,7 +1239,7 @@ public class Player {
}
else
if
(
prop
==
PlayerProperty
.
PROP_PLAYER_EXP
)
{
// 10014
}
else
if
(
prop
==
PlayerProperty
.
PROP_PLAYER_EXP
)
{
// 10014
if
(!(
0
<=
value
))
{
return
false
;
}
if
(!(
0
<=
value
))
{
return
false
;
}
}
else
if
(
prop
==
PlayerProperty
.
PROP_PLAYER_HCOIN
)
{
// 10015
}
else
if
(
prop
==
PlayerProperty
.
PROP_PLAYER_HCOIN
)
{
// 10015
// see
10015
// see
PlayerProperty.PROP_PLAYER_HCOIN comments
}
else
if
(
prop
==
PlayerProperty
.
PROP_PLAYER_SCOIN
)
{
// 10016
}
else
if
(
prop
==
PlayerProperty
.
PROP_PLAYER_SCOIN
)
{
// 10016
// See 10015
// See 10015
}
else
if
(
prop
==
PlayerProperty
.
PROP_PLAYER_MP_SETTING_TYPE
)
{
// 10017
}
else
if
(
prop
==
PlayerProperty
.
PROP_PLAYER_MP_SETTING_TYPE
)
{
// 10017
...
...
src/main/java/emu/grasscutter/game/player/TeamManager.java
View file @
836e0150
...
@@ -557,7 +557,7 @@ public class TeamManager {
...
@@ -557,7 +557,7 @@ public class TeamManager {
// return;
// return;
// }
// }
// }
// }
player
.
get
Movement
Manager
().
stopSustainedStaminaHandler
();
// prevent drowning immediately after respawn
player
.
get
Stamina
Manager
().
stopSustainedStaminaHandler
();
// prevent drowning immediately after respawn
// Revive all team members
// Revive all team members
for
(
EntityAvatar
entity
:
getActiveTeam
())
{
for
(
EntityAvatar
entity
:
getActiveTeam
())
{
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerCombatInvocationsNotify.java
View file @
836e0150
...
@@ -16,8 +16,6 @@ import emu.grasscutter.net.proto.PlayerDieTypeOuterClass;
...
@@ -16,8 +16,6 @@ import emu.grasscutter.net.proto.PlayerDieTypeOuterClass;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify
;
import
emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify
;
import
java.util.HashMap
;
@Opcodes
(
PacketOpcodes
.
CombatInvocationsNotify
)
@Opcodes
(
PacketOpcodes
.
CombatInvocationsNotify
)
public
class
HandlerCombatInvocationsNotify
extends
PacketHandler
{
public
class
HandlerCombatInvocationsNotify
extends
PacketHandler
{
...
@@ -49,7 +47,7 @@ public class HandlerCombatInvocationsNotify extends PacketHandler {
...
@@ -49,7 +47,7 @@ public class HandlerCombatInvocationsNotify extends PacketHandler {
MotionState
motionState
=
motionInfo
.
getState
();
MotionState
motionState
=
motionInfo
.
getState
();
entity
.
setMotionState
(
motionState
);
entity
.
setMotionState
(
motionState
);
session
.
getPlayer
().
get
Movement
Manager
().
handleCombatInvocationsNotify
(
session
,
moveInfo
,
entity
);
session
.
getPlayer
().
get
Stamina
Manager
().
handleCombatInvocationsNotify
(
session
,
moveInfo
,
entity
);
// TODO: handle MOTION_FIGHT landing
// TODO: handle MOTION_FIGHT landing
// For plunge attacks, LAND_SPEED is always -30 and is not useful.
// For plunge attacks, LAND_SPEED is always -30 and is not useful.
...
@@ -116,7 +114,7 @@ public class HandlerCombatInvocationsNotify extends PacketHandler {
...
@@ -116,7 +114,7 @@ public class HandlerCombatInvocationsNotify extends PacketHandler {
entity
.
setFightProperty
(
FightProperty
.
FIGHT_PROP_CUR_HP
,
newHP
);
entity
.
setFightProperty
(
FightProperty
.
FIGHT_PROP_CUR_HP
,
newHP
);
entity
.
getWorld
().
broadcastPacket
(
new
PacketEntityFightPropUpdateNotify
(
entity
,
FightProperty
.
FIGHT_PROP_CUR_HP
));
entity
.
getWorld
().
broadcastPacket
(
new
PacketEntityFightPropUpdateNotify
(
entity
,
FightProperty
.
FIGHT_PROP_CUR_HP
));
if
(
newHP
==
0
)
{
if
(
newHP
==
0
)
{
session
.
getPlayer
().
get
Movement
Manager
().
killAvatar
(
session
,
entity
,
PlayerDieTypeOuterClass
.
PlayerDieType
.
PLAYER_DIE_FALL
);
session
.
getPlayer
().
get
Stamina
Manager
().
killAvatar
(
session
,
entity
,
PlayerDieTypeOuterClass
.
PlayerDieType
.
PLAYER_DIE_FALL
);
}
}
cachedLandingSpeed
=
0
;
cachedLandingSpeed
=
0
;
}
}
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterTransPointRegionNotify.java
View file @
836e0150
package
emu.grasscutter.server.packet.recv
;
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.player.Player
;
import
emu.grasscutter.game.props.FightProperty
;
import
emu.grasscutter.net.packet.Opcodes
;
import
emu.grasscutter.net.packet.Opcodes
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
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.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
)
@Opcodes
(
PacketOpcodes
.
EnterTransPointRegionNotify
)
public
class
HandlerEnterTransPointRegionNotify
extends
PacketHandler
{
public
class
HandlerEnterTransPointRegionNotify
extends
PacketHandler
{
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtDoSkillSuccNotify.java
View file @
836e0150
...
@@ -14,7 +14,7 @@ public class HandlerEvtDoSkillSuccNotify extends PacketHandler {
...
@@ -14,7 +14,7 @@ public class HandlerEvtDoSkillSuccNotify extends PacketHandler {
EvtDoSkillSuccNotify
notify
=
EvtDoSkillSuccNotify
.
parseFrom
(
payload
);
EvtDoSkillSuccNotify
notify
=
EvtDoSkillSuccNotify
.
parseFrom
(
payload
);
// TODO: Will be used for deducting stamina for charged skills.
// TODO: Will be used for deducting stamina for charged skills.
session
.
getPlayer
().
get
Movement
Manager
().
handleEvtDoSkillSuccNotify
(
session
,
notify
);
session
.
getPlayer
().
get
Stamina
Manager
().
handleEvtDoSkillSuccNotify
(
session
,
notify
);
}
}
}
}
src/main/java/emu/grasscutter/server/packet/recv/HandlerExitTransPointRegionNotify.java
View file @
836e0150
package
emu.grasscutter.server.packet.recv
;
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.player.Player
;
import
emu.grasscutter.net.packet.Opcodes
;
import
emu.grasscutter.net.packet.Opcodes
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.net.packet.PacketHandler
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment