2020-06-25 14:56:49 -04:00
|
|
|
package d2hero
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
2020-09-20 17:52:01 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2records"
|
2020-06-25 14:56:49 -04:00
|
|
|
)
|
|
|
|
|
2020-06-30 17:03:20 -04:00
|
|
|
// HeroStatsState is a serializable state of hero stats.
|
2020-06-25 14:56:49 -04:00
|
|
|
type HeroStatsState struct {
|
|
|
|
Level int `json:"level"`
|
|
|
|
Experience int `json:"experience"`
|
|
|
|
|
|
|
|
Strength int `json:"strength"`
|
2020-12-15 03:16:40 -05:00
|
|
|
Energy int `json:"energy"`
|
2020-06-25 14:56:49 -04:00
|
|
|
Dexterity int `json:"dexterity"`
|
2020-12-15 03:16:40 -05:00
|
|
|
Vitality int `json:"vitality"`
|
|
|
|
// there are stats and skills points remaining to add.
|
2020-12-15 05:32:34 -05:00
|
|
|
StatsPoints int `json:"statsPoints"`
|
2020-12-15 03:16:40 -05:00
|
|
|
SkillPoints int `json:"skillPoints"`
|
2020-06-25 14:56:49 -04:00
|
|
|
|
2020-12-15 03:16:40 -05:00
|
|
|
Health int `json:"health"`
|
|
|
|
MaxHealth int `json:"maxHealth"`
|
|
|
|
Mana int `json:"mana"`
|
|
|
|
MaxMana int `json:"maxMana"`
|
|
|
|
Stamina float64 `json:"-"` // only MaxStamina is saved, Stamina gets reset on entering world
|
|
|
|
MaxStamina int `json:"maxStamina"`
|
2020-06-25 14:56:49 -04:00
|
|
|
|
|
|
|
// values which are not saved/loaded(computed)
|
2020-12-15 03:16:40 -05:00
|
|
|
NextLevelExp int `json:"-"`
|
2020-06-25 14:56:49 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 17:03:20 -04:00
|
|
|
// CreateHeroStatsState generates a running state from a hero stats.
|
2020-12-18 12:50:42 -05:00
|
|
|
func (f *HeroStateFactory) CreateHeroStatsState(heroClass d2enum.Hero, classStats *d2records.CharStatRecord) *HeroStatsState {
|
2020-06-25 14:56:49 -04:00
|
|
|
result := HeroStatsState{
|
2020-06-30 17:03:20 -04:00
|
|
|
Level: 1,
|
|
|
|
Experience: 0,
|
2020-09-20 17:52:01 -04:00
|
|
|
NextLevelExp: f.asset.Records.GetExperienceBreakpoint(heroClass, 1),
|
2020-06-25 14:56:49 -04:00
|
|
|
Strength: classStats.InitStr,
|
|
|
|
Dexterity: classStats.InitDex,
|
|
|
|
Vitality: classStats.InitVit,
|
|
|
|
Energy: classStats.InitEne,
|
2020-12-15 05:32:34 -05:00
|
|
|
StatsPoints: 0,
|
2020-12-15 03:16:40 -05:00
|
|
|
SkillPoints: 0,
|
2020-06-30 17:03:20 -04:00
|
|
|
|
|
|
|
MaxHealth: classStats.InitVit * classStats.LifePerVit,
|
|
|
|
MaxMana: classStats.InitEne * classStats.ManaPerEne,
|
2020-06-25 14:56:49 -04:00
|
|
|
MaxStamina: classStats.InitStamina,
|
2020-10-25 18:36:12 -04:00
|
|
|
// https://github.com/OpenDiablo2/OpenDiablo2/issues/814
|
2020-06-25 14:56:49 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 17:03:20 -04:00
|
|
|
result.Mana = result.MaxMana
|
|
|
|
result.Health = result.MaxHealth
|
2020-10-21 23:25:53 -04:00
|
|
|
result.Stamina = float64(result.MaxStamina)
|
2020-06-30 17:03:20 -04:00
|
|
|
|
2020-06-25 14:56:49 -04:00
|
|
|
return &result
|
|
|
|
}
|