Skip to content

Commit 24cf5e9

Browse files
committed
Next round of changes, moved to loading stats from config
1 parent 75f2c61 commit 24cf5e9

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

_datafiles/config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,27 @@ Validation:
536536
- "join"
537537
- "register"
538538

539+
################################################################################
540+
#
541+
# Statistics Configuration
542+
# Settings for character statistics and stat calculations
543+
#
544+
################################################################################
545+
Statistics:
546+
# Base stat values for new characters
547+
BaseStats:
548+
Strength: 1 # Muscular strength
549+
Speed: 1 # Speed and agility
550+
Smarts: 1 # Intelligence and wisdom
551+
Vitality: 1 # Health and stamina
552+
Mysticism: 1 # Magic and mana
553+
Perception: 1 # How well you notice things
554+
555+
# Stat calculation factors
556+
Factors:
557+
BaseModFactor: 0.3333333334 # How much of a scaling to apply to levels before multiplying by racial stat
558+
NaturalGainsModFactor: 0.5 # Free stats gained per level modded by this
559+
539560
################################################################################
540561
#
541562
# Roles

internal/characters/character.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,21 @@ type Character struct {
9595
}
9696

9797
func New() *Character {
98+
statsConfig := configs.GetStatisticsConfig()
99+
98100
return &Character{
99101
//Name: defaultName,
100102
Adjectives: []string{},
101103
RoomId: StartingRoomId,
102104
Zone: startingZone,
103105
RaceId: startingRace,
104106
Stats: stats.Statistics{
105-
Strength: stats.StatInfo{Base: 1},
106-
Speed: stats.StatInfo{Base: 1},
107-
Smarts: stats.StatInfo{Base: 1},
108-
Vitality: stats.StatInfo{Base: 1},
109-
Mysticism: stats.StatInfo{Base: 1},
110-
Perception: stats.StatInfo{Base: 1},
107+
Strength: stats.StatInfo{Base: int(statsConfig.BaseStats.Strength)},
108+
Speed: stats.StatInfo{Base: int(statsConfig.BaseStats.Speed)},
109+
Smarts: stats.StatInfo{Base: int(statsConfig.BaseStats.Smarts)},
110+
Vitality: stats.StatInfo{Base: int(statsConfig.BaseStats.Vitality)},
111+
Mysticism: stats.StatInfo{Base: int(statsConfig.BaseStats.Mysticism)},
112+
Perception: stats.StatInfo{Base: int(statsConfig.BaseStats.Perception)},
111113
},
112114
Level: 1,
113115
Experience: 1,

internal/configs/configs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type Config struct {
4848
SpecialRooms SpecialRooms `yaml:"SpecialRooms"`
4949
Validation Validation `yaml:"Validation"`
5050
Roles Roles `yaml:"Roles"`
51+
Statistics Statistics `yaml:"Statistics"`
5152
// Plugins is a special case
5253
Modules Modules `yaml:"Modules"`
5354

@@ -197,6 +198,7 @@ func (c *Config) Validate() {
197198
c.Scripting.Validate()
198199
c.SpecialRooms.Validate()
199200
c.Validation.Validate()
201+
c.Statistics.Validate()
200202
c.Modules.Validate()
201203
c.Roles.Validate()
202204

internal/stats/stats.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@ package stats
33
import (
44
"math"
55
"strings"
6-
)
76

8-
const (
9-
BaseModFactor = 0.3333333334 // How much of a scaling to aply to levels before multiplying by racial stat
10-
NaturalGainsModFactor = 0.5 // Free stats gained per level modded by this.
7+
"github.com/GoMudEngine/GoMud/internal/configs"
118
)
129

10+
func getBaseModFactor() float64 {
11+
cfg := configs.GetStatisticsConfig()
12+
return float64(cfg.Factors.BaseModFactor)
13+
}
14+
15+
func getNaturalGainsModFactor() float64 {
16+
cfg := configs.GetStatisticsConfig()
17+
return float64(cfg.Factors.NaturalGainsModFactor)
18+
}
19+
1320
type Statistics struct {
1421
Strength StatInfo `yaml:"strength,omitempty"` // Muscular strength (damage?)
1522
Speed StatInfo `yaml:"speed,omitempty"` // Speed and agility (dodging)
@@ -87,11 +94,11 @@ func (si *StatInfo) GainsForLevel(level int) int {
8794
if level < 1 {
8895
level = 1
8996
}
90-
levelScale := float64(level-1) * BaseModFactor
97+
levelScale := float64(level-1) * getBaseModFactor()
9198
basePoints := int(levelScale * float64(si.Base))
9299

93100
// every x levels we get natural gains
94-
freeStatPoints := int(float64(level) * NaturalGainsModFactor)
101+
freeStatPoints := int(float64(level) * getNaturalGainsModFactor())
95102

96103
return basePoints + freeStatPoints
97104
}

0 commit comments

Comments
 (0)