first stamina drain implementation (#778)

Bugs: 1. In D2 when Stamina is drained it does not regenerate until you completely stop
2. Stamina Bar does not get red when near the end
This commit is contained in:
Thomas Christlieb 2020-10-22 05:25:53 +02:00 committed by GitHub
parent 53e3619781
commit 30b6f0cb4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 8 deletions

View File

@ -30,8 +30,8 @@ type HeroStatsState struct {
PoisonResistance int `json:"poisonResistance"`
// values which are not saved/loaded(computed)
Stamina int `json:"-"` // only MaxStamina is saved, Stamina gets reset on entering world
NextLevelExp int `json:"-"`
Stamina float64 `json:"-"` // only MaxStamina is saved, Stamina gets reset on entering world
NextLevelExp int `json:"-"`
}
// CreateHeroStatsState generates a running state from a hero stats.
@ -53,7 +53,7 @@ func (f *HeroStateFactory) CreateHeroStatsState(heroClass d2enum.Hero, classStat
result.Mana = result.MaxMana
result.Health = result.MaxHealth
result.Stamina = result.MaxStamina
result.Stamina = float64(result.MaxStamina)
// TODO: For demonstration purposes (hp, mana, exp, & character stats panel gets updated depending on stats)
result.Health = 50

View File

@ -77,7 +77,7 @@ func (f *MapEntityFactory) NewPlayer(id, name string, x, y, direction int, heroT
}
stats.NextLevelExp = f.asset.Records.GetExperienceBreakpoint(heroType, stats.Level)
stats.Stamina = stats.MaxStamina
stats.Stamina = float64(stats.MaxStamina)
defaultCharStats := f.asset.Records.Character.Stats[heroType]
statsState := f.HeroStateFactory.CreateHeroStatsState(heroType, defaultCharStats)
@ -249,7 +249,7 @@ func (f *MapEntityFactory) NewCastOverlay(x, y int, overlayRecord *d2records.Ove
result := &CastOverlay{
AnimatedEntity: entity,
record: overlayRecord,
playLoop: playLoop,
playLoop: playLoop,
}
return result, nil

View File

@ -2,7 +2,6 @@ package d2mapentity
import (
"fmt"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
@ -106,6 +105,20 @@ func (p *Player) Advance(tickTime float64) {
if p.composite.GetAnimationMode() != p.animationMode {
p.animationMode = p.composite.GetAnimationMode()
}
// Drain and regenerate Stamina
if p.IsRunning() && !p.atTarget() && !p.IsInTown() {
p.Stats.Stamina -= float64(p.composite.AssetManager.Records.Character.Stats[p.Class].StaminaRunDrain) * tickTime / 5
if p.Stats.Stamina < 0 {
p.SetSpeed(baseWalkSpeed)
p.Stats.Stamina = 0
}
} else if p.Stats.Stamina < float64(p.Stats.MaxStamina) {
p.Stats.Stamina += float64(p.composite.AssetManager.Records.Character.Stats[p.Class].StaminaRunDrain) * tickTime / 5
if p.IsRunning() {
p.SetSpeed(baseRunSpeed)
}
}
}
// Render renders the animated composite for this entity.

View File

@ -341,7 +341,7 @@ func (s *HeroStatsPanel) initStatValueLabels() {
s.labels.Energy = s.createStatValueLabel(s.heroState.Energy, 175, 355)
s.labels.MaxStamina = s.createStatValueLabel(s.heroState.MaxStamina, 330, 295)
s.labels.Stamina = s.createStatValueLabel(s.heroState.Stamina, 370, 295)
s.labels.Stamina = s.createStatValueLabel(int(s.heroState.Stamina), 370, 295)
s.labels.MaxHealth = s.createStatValueLabel(s.heroState.MaxHealth, 330, 320)
s.labels.Health = s.createStatValueLabel(s.heroState.Health, 370, 320)
@ -364,7 +364,7 @@ func (s *HeroStatsPanel) renderStatValues(target d2interface.Surface) {
s.renderStatValueNum(s.labels.Health, s.heroState.Health, target)
s.renderStatValueNum(s.labels.MaxStamina, s.heroState.MaxStamina, target)
s.renderStatValueNum(s.labels.Stamina, s.heroState.Stamina, target)
s.renderStatValueNum(s.labels.Stamina, int(s.heroState.Stamina), target)
s.renderStatValueNum(s.labels.MaxMana, s.heroState.MaxMana, target)
s.renderStatValueNum(s.labels.Mana, s.heroState.Mana, target)