Documentation ¶
Overview ¶
Package gamesheet provides a minimal character sheet for agents, or players.
Index ¶
- Variables
- type Attribute
- type CharacterSheet
- func (c *CharacterSheet) AddExperience(xp uint16)
- func (c *CharacterSheet) Heal(hp int)
- func (c *CharacterSheet) Log()
- func (c *CharacterSheet) NextLevelXP() uint16
- func (c *CharacterSheet) RestoreAP(ap int)
- func (c *CharacterSheet) SetState(state *State)
- func (c *CharacterSheet) SetStates(states []*State)
- func (c *CharacterSheet) TakeAction(ap int) bool
- func (c *CharacterSheet) TakeDamage(hp int) bool
- func (c *CharacterSheet) Tick(delta float64)
- func (c *CharacterSheet) Update()
- func (c *CharacterSheet) UpdatePoints()
- func (c *CharacterSheet) UpdateStates()
- type Slider
- type State
- type Status
Constants ¶
This section is empty.
Variables ¶
var ( StateAwake = &State{ Name: "awake", Exhaustion: 100.0 / (4 * dayToSecond), Hunger: 100.0 / (10 * dayToSecond), Thirst: 100.0 / (3 * dayToSecond), Stress: 100.0 / (2 * dayToSecond), } StateAsleep = &State{ Name: "asleep", Exhaustion: -100.0 / (8 * hourToSecond), Hunger: 100.0 / (20 * dayToSecond), Thirst: 100.0 / (20 * dayToSecond), Stress: -100.0 / (8 * hourToSecond), } )
Some constants related to stats.
TODO: This should be on a per-creature basis. - A camel needs less water than a human. - A humpback whale survives 6 MONTHS without food!
TODO: There should also be the recovery rate.
- After 7 hours of sleep, the exhaustion stat should be reduced by a day's worth of exhaustion.
- One hour of rest should reduce stress significantly.
- While sleeping, hunger and thirst should increase much slower.
- During strenuous activity, hunger, thirst, and exhaustion should increase much faster.
- When in combat and in danger, stress should increase.
Functions ¶
This section is empty.
Types ¶
type CharacterSheet ¶
type CharacterSheet struct { CurrentXP uint16 // Collected XP for the current level. Level byte // Current level. SkillPoints byte // Skill points to distribute. BaseHP byte // Level 0 HP, will be used to calculate leveled HP. BaseAP byte // Level 0 AP, will be used to calculate leveled AP. HP Slider // Hit points. AP Slider // Action points. Dead bool // Is the character dead? // Active states. States []*State // Physical stats. StatExhaustion Status StatHunger Status StatThirst Status StatStress Status // Physical attributes. AttrStrength Attribute AttrIntelligence Attribute AttrDexterity Attribute AttrResilience Attribute Messages []string // Messages to display. // contains filtered or unexported fields }
CharacterSheet represents a character sheet.
TODO:
- Add conditions like poisoned, blinded, etc.
- Find a better way to handle max level (100).
- Handle stats.
NOTE TO SELF: Do we allow the attribute values to change? If so, will retroactively the HP and AP increase or decrease? Would that even matter?
func New ¶
func New(baseHP, baseAP, level, str, itl, dex, res byte) *CharacterSheet
New returns a new character sheet with the given base HP and AP.
NOTE: The base HP and AP are the unleveled values. Depending on the character's stats, the HP and AP will increase as the character levels up or if a starting level > 0 has been set.
func (*CharacterSheet) AddExperience ¶
func (c *CharacterSheet) AddExperience(xp uint16)
AddExperience adds experience to the character sheet.
func (*CharacterSheet) Heal ¶
func (c *CharacterSheet) Heal(hp int)
Heal heals the character for the given amount of hit points. NOTE: This is only for experimentation and will be removed or refactored
func (*CharacterSheet) Log ¶
func (c *CharacterSheet) Log()
func (*CharacterSheet) NextLevelXP ¶
func (c *CharacterSheet) NextLevelXP() uint16
NextLevelXP returns the XP required for the next level.
NOTE: The required XP increases exponentially up to about 65100 XP for level 100. This way we make the best use of the unsigned 16 bit integer.
Of course we could make the formula a bit more complicated so it doesn't irritate our more math-savvy players.
See: https://pavcreations.com/level-systems-and-character-growth-in-rpg-games/
func (*CharacterSheet) RestoreAP ¶
func (c *CharacterSheet) RestoreAP(ap int)
RestoreAP restores the given amount of action points to the AP. NOTE: This is only for experimentation and will be removed or refactored
func (*CharacterSheet) SetState ¶
func (c *CharacterSheet) SetState(state *State)
SetState sets the states to this single state. NOTE: This is only for experimentation and will be removed or refactored
func (*CharacterSheet) SetStates ¶
func (c *CharacterSheet) SetStates(states []*State)
SetStates applies the given states to the statuses.
func (*CharacterSheet) TakeAction ¶
func (c *CharacterSheet) TakeAction(ap int) bool
TakeAction deducts the given action points from the APs and returns true on success. NOTE: This is only for experimentation and will be removed or refactored
func (*CharacterSheet) TakeDamage ¶
func (c *CharacterSheet) TakeDamage(hp int) bool
TakeDamage removes the given amount of hit points from the HP. Return true if the character is dead. NOTE: This is only for experimentation and will be removed or refactored.
func (*CharacterSheet) Tick ¶
func (c *CharacterSheet) Tick(delta float64)
Advance the simulation by a step.
func (*CharacterSheet) Update ¶
func (c *CharacterSheet) Update()
Update updates the character sheet.
func (*CharacterSheet) UpdatePoints ¶
func (c *CharacterSheet) UpdatePoints()
UpdatePoints recalculates stats like HP and AP based on the current level and attributes.
Call this function if any of the attributes change to update the stats.
func (*CharacterSheet) UpdateStates ¶
func (c *CharacterSheet) UpdateStates()
type Slider ¶
type Slider [2]uint16
Slider represents a variable value with a variable upper bound. Example: Health, mana, etc.
type Status ¶
type Status struct { Val float32 // Current value. Rate float32 // Increase / decrease per second. }
Status is a character sheet status value that changes at a set rate. TODO: Reduce the memory footprint of this struct.
func NewStatus ¶
func NewStatus() Status
NewStatus returns a new status with the given rate and limit.