1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-09 11:47:21 -05:00
OpenDiablo2/d2core/d2hero/hero_stats_state.go
Stephen Horan 4dd69e7709
Health/Mana/Exp load values from save file #815 (#886)
* Return errors for #790

* Fixing lint issues

* Returning nil instead of empty struct pointer

* Removed new hero stat calls as new player requires stats to be passed in. These were using defaults regardless of the save file.

* Removed override on the default to health/mana/experience. These should now result is proper values.

* Removed new hero stat calls as new player requires stats to be passed in. These were using defaults regardless of the save file.

* Removed override on the default to health/mana/experience. These should now result is proper values.
2020-10-31 23:59:24 -04:00

60 lines
1.8 KiB
Go

package d2hero
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2records"
)
// HeroStatsState is a serializable state of hero stats.
type HeroStatsState struct {
Level int `json:"level"`
Experience int `json:"experience"`
Vitality int `json:"vitality"`
Energy int `json:"energy"`
Strength int `json:"strength"`
Dexterity int `json:"dexterity"`
AttackRating int `json:"attackRating"`
DefenseRating int `json:"defenseRating"`
MaxStamina int `json:"maxStamina"`
Health int `json:"health"`
MaxHealth int `json:"maxHealth"`
Mana int `json:"mana"`
MaxMana int `json:"maxMana"`
FireResistance int `json:"fireResistance"`
ColdResistance int `json:"coldResistance"`
LightningResistance int `json:"lightningResistance"`
PoisonResistance int `json:"poisonResistance"`
// values which are not saved/loaded(computed)
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.
func (f *HeroStateFactory) CreateHeroStatsState(heroClass d2enum.Hero, classStats *d2records.CharStatsRecord) *HeroStatsState {
result := HeroStatsState{
Level: 1,
Experience: 0,
NextLevelExp: f.asset.Records.GetExperienceBreakpoint(heroClass, 1),
Strength: classStats.InitStr,
Dexterity: classStats.InitDex,
Vitality: classStats.InitVit,
Energy: classStats.InitEne,
MaxHealth: classStats.InitVit * classStats.LifePerVit,
MaxMana: classStats.InitEne * classStats.ManaPerEne,
MaxStamina: classStats.InitStamina,
// https://github.com/OpenDiablo2/OpenDiablo2/issues/814
}
result.Mana = result.MaxMana
result.Health = result.MaxHealth
result.Stamina = float64(result.MaxStamina)
return &result
}