Documentation ¶
Overview ¶
Package d2hero utilities for managing a hero state.
Index ¶
- func HydrateSkills(skills map[int]*HeroSkill, asset *d2asset.AssetManager)
- type HeroSkill
- type HeroState
- type HeroStateFactory
- func (f *HeroStateFactory) CreateHeroSkill(points int, name string) (*HeroSkill, error)
- func (f *HeroStateFactory) CreateHeroSkillsState(classStats *d2records.CharStatRecord, heroType d2enum.Hero) (map[int]*HeroSkill, error)
- func (f *HeroStateFactory) CreateHeroState(heroName string, hero d2enum.Hero, statsState *HeroStatsState) (*HeroState, error)
- func (f *HeroStateFactory) CreateHeroStatsState(heroClass d2enum.Hero, classStats *d2records.CharStatRecord) *HeroStatsState
- func (f *HeroStateFactory) CreateTestGameState() *HeroState
- func (f *HeroStateFactory) GetAllHeroStates() ([]*HeroState, error)
- func (f *HeroStateFactory) HasGameStates() bool
- func (f *HeroStateFactory) LoadHeroState(filePath string) *HeroState
- func (f *HeroStateFactory) Save(state *HeroState) error
- type HeroStatsState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HydrateSkills ¶
func HydrateSkills(skills map[int]*HeroSkill, asset *d2asset.AssetManager)
HydrateSkills will load the SkillRecord & SkillDescriptionRecord from the asset manager, using the skill ID. This is done to avoid serializing the whole record data of HeroSkill to a game save or network packets. We cant do this while unmarshalling because there is no reference to the asset manager.
Types ¶
type HeroSkill ¶
type HeroSkill struct { *d2records.SkillRecord *d2records.SkillDescriptionRecord SkillPoints int Shallow *shallowHeroSkill }
HeroSkill stores additional payload for a skill of a hero.
func (*HeroSkill) MarshalJSON ¶
MarshalJSON overrides the default logic used when the HeroSkill is serialized to a byte array.
func (*HeroSkill) UnmarshalJSON ¶
UnmarshalJSON overrides the default logic used when the HeroSkill is deserialized from a byte array.
type HeroState ¶
type HeroState struct { HeroName string `json:"heroName"` HeroType d2enum.Hero `json:"heroType"` Act int `json:"act"` FilePath string `json:"-"` Equipment d2inventory.CharacterEquipment `json:"equipment"` Stats *HeroStatsState `json:"stats"` Skills map[int]*HeroSkill `json:"skills"` X float64 `json:"x"` Y float64 `json:"y"` LeftSkill int `json:"leftSkill"` RightSkill int `json:"rightSkill"` Gold int `json:"Gold"` Difficulty d2enum.DifficultyType `json:"difficulty"` }
HeroState stores the state of the player
type HeroStateFactory ¶
type HeroStateFactory struct { *d2inventory.InventoryItemFactory // contains filtered or unexported fields }
HeroStateFactory is responsible for creating player state objects
func NewHeroStateFactory ¶
func NewHeroStateFactory(asset *d2asset.AssetManager) (*HeroStateFactory, error)
NewHeroStateFactory creates a new HeroStateFactory and initializes it.
func (*HeroStateFactory) CreateHeroSkill ¶
func (f *HeroStateFactory) CreateHeroSkill(points int, name string) (*HeroSkill, error)
CreateHeroSkill creates an instance of a skill
func (*HeroStateFactory) CreateHeroSkillsState ¶
func (f *HeroStateFactory) CreateHeroSkillsState(classStats *d2records.CharStatRecord, heroType d2enum.Hero) (map[int]*HeroSkill, error)
CreateHeroSkillsState will assemble the hero skills from the class stats record.
func (*HeroStateFactory) CreateHeroState ¶
func (f *HeroStateFactory) CreateHeroState( heroName string, hero d2enum.Hero, statsState *HeroStatsState, ) (*HeroState, error)
CreateHeroState creates a HeroState instance and returns a pointer to it
func (*HeroStateFactory) CreateHeroStatsState ¶
func (f *HeroStateFactory) CreateHeroStatsState(heroClass d2enum.Hero, classStats *d2records.CharStatRecord) *HeroStatsState
CreateHeroStatsState generates a running state from a hero stats.
func (*HeroStateFactory) CreateTestGameState ¶
func (f *HeroStateFactory) CreateTestGameState() *HeroState
CreateTestGameState is used for the map engine previewer
func (*HeroStateFactory) GetAllHeroStates ¶
func (f *HeroStateFactory) GetAllHeroStates() ([]*HeroState, error)
GetAllHeroStates returns all player saves
func (*HeroStateFactory) HasGameStates ¶
func (f *HeroStateFactory) HasGameStates() bool
HasGameStates returns true if the player has any previously saved game
func (*HeroStateFactory) LoadHeroState ¶
func (f *HeroStateFactory) LoadHeroState(filePath string) *HeroState
LoadHeroState loads the player state from the file
func (*HeroStateFactory) Save ¶
func (f *HeroStateFactory) Save(state *HeroState) error
Save saves the player state to a file
type HeroStatsState ¶
type HeroStatsState struct { Level int `json:"level"` Experience int `json:"experience"` Strength int `json:"strength"` Energy int `json:"energy"` Dexterity int `json:"dexterity"` Vitality int `json:"vitality"` // there are stats and skills points remaining to add. StatsPoints int `json:"statsPoints"` SkillPoints int `json:"skillPoints"` 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"` // values which are not saved/loaded(computed) NextLevelExp int `json:"-"` }
HeroStatsState is a serializable state of hero stats.