mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-06-16 12:35:22 +00:00
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:
parent
53e3619781
commit
30b6f0cb4e
|
@ -30,8 +30,8 @@ type HeroStatsState struct {
|
||||||
PoisonResistance int `json:"poisonResistance"`
|
PoisonResistance int `json:"poisonResistance"`
|
||||||
|
|
||||||
// values which are not saved/loaded(computed)
|
// values which are not saved/loaded(computed)
|
||||||
Stamina int `json:"-"` // only MaxStamina is saved, Stamina gets reset on entering world
|
Stamina float64 `json:"-"` // only MaxStamina is saved, Stamina gets reset on entering world
|
||||||
NextLevelExp int `json:"-"`
|
NextLevelExp int `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateHeroStatsState generates a running state from a hero stats.
|
// 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.Mana = result.MaxMana
|
||||||
result.Health = result.MaxHealth
|
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)
|
// TODO: For demonstration purposes (hp, mana, exp, & character stats panel gets updated depending on stats)
|
||||||
result.Health = 50
|
result.Health = 50
|
||||||
|
|
|
@ -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.NextLevelExp = f.asset.Records.GetExperienceBreakpoint(heroType, stats.Level)
|
||||||
stats.Stamina = stats.MaxStamina
|
stats.Stamina = float64(stats.MaxStamina)
|
||||||
|
|
||||||
defaultCharStats := f.asset.Records.Character.Stats[heroType]
|
defaultCharStats := f.asset.Records.Character.Stats[heroType]
|
||||||
statsState := f.HeroStateFactory.CreateHeroStatsState(heroType, defaultCharStats)
|
statsState := f.HeroStateFactory.CreateHeroStatsState(heroType, defaultCharStats)
|
||||||
|
@ -249,7 +249,7 @@ func (f *MapEntityFactory) NewCastOverlay(x, y int, overlayRecord *d2records.Ove
|
||||||
result := &CastOverlay{
|
result := &CastOverlay{
|
||||||
AnimatedEntity: entity,
|
AnimatedEntity: entity,
|
||||||
record: overlayRecord,
|
record: overlayRecord,
|
||||||
playLoop: playLoop,
|
playLoop: playLoop,
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|
|
@ -2,7 +2,6 @@ package d2mapentity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
|
||||||
|
@ -106,6 +105,20 @@ func (p *Player) Advance(tickTime float64) {
|
||||||
if p.composite.GetAnimationMode() != p.animationMode {
|
if p.composite.GetAnimationMode() != p.animationMode {
|
||||||
p.animationMode = p.composite.GetAnimationMode()
|
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.
|
// Render renders the animated composite for this entity.
|
||||||
|
|
|
@ -341,7 +341,7 @@ func (s *HeroStatsPanel) initStatValueLabels() {
|
||||||
s.labels.Energy = s.createStatValueLabel(s.heroState.Energy, 175, 355)
|
s.labels.Energy = s.createStatValueLabel(s.heroState.Energy, 175, 355)
|
||||||
|
|
||||||
s.labels.MaxStamina = s.createStatValueLabel(s.heroState.MaxStamina, 330, 295)
|
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.MaxHealth = s.createStatValueLabel(s.heroState.MaxHealth, 330, 320)
|
||||||
s.labels.Health = s.createStatValueLabel(s.heroState.Health, 370, 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.Health, s.heroState.Health, target)
|
||||||
|
|
||||||
s.renderStatValueNum(s.labels.MaxStamina, s.heroState.MaxStamina, 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.MaxMana, s.heroState.MaxMana, target)
|
||||||
s.renderStatValueNum(s.labels.Mana, s.heroState.Mana, target)
|
s.renderStatValueNum(s.labels.Mana, s.heroState.Mana, target)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user