Skip to content

Commit

Permalink
Recover run energy when player is idle
Browse files Browse the repository at this point in the history
  • Loading branch information
mbpolan committed Oct 20, 2023
1 parent ab65829 commit fcb4594
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions internal/game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,7 @@ func (g *Game) handleGameUpdate() error {
}

// check if the player is moving
blockRunEnergyRecovery := false
if pe.Moving() {
// determine how many segments are left to traverse in the path
remaining := len(pe.path) - pe.nextPathIdx
Expand All @@ -1627,6 +1628,9 @@ func (g *Game) handleGameUpdate() error {
// move past this path segment
pe.nextPathIdx++
} else {
// prevent the player from recovering run energy
blockRunEnergyRecovery = true

// find the first direction to move in
first := pe.path[pe.nextPathIdx]
pe.nextPathIdx++
Expand Down Expand Up @@ -1695,6 +1699,15 @@ func (g *Game) handleGameUpdate() error {
}
}

// recover run energy if applicable
if pe.player.RunEnergy < model.MaxRunEnergyUnits && !blockRunEnergyRecovery {
agility := pe.player.Skills[model.SkillTypeAgility]
runDelta := int(math.Ceil(float64(agility.Level)/6.0) + 8)

pe.player.RunEnergy = util.Min(pe.player.RunEnergy+runDelta, model.MaxRunEnergyUnits)
pe.DeferSendRunEnergy()
}

// broadcast this player's status to friends and other target players if required
if pe.nextStatusBroadcast != nil {
g.broadcastPlayerStatus(pe, pe.nextStatusBroadcast.targets...)
Expand Down

0 comments on commit fcb4594

Please sign in to comment.