-
Notifications
You must be signed in to change notification settings - Fork 0
/
charStats.go
86 lines (74 loc) · 1.5 KB
/
charStats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"log"
"math"
)
type Stat uint8
const (
STAT_STRENGTH = iota
STAT_CONSTITUTION
STAT_AGILITY
STAT_DEXTERITY
STAT_INTELLIGENCE
STAT_WISDOM
NUM_STATS
)
func StatToString(S uint8) string {
switch S {
case STAT_STRENGTH:
return "Strength"
case STAT_CONSTITUTION:
return "Constitution"
case STAT_AGILITY:
return "Agility"
case STAT_DEXTERITY:
return "Dexterity"
case STAT_INTELLIGENCE:
return "Intelligence"
case STAT_WISDOM:
return "Wisdom"
default:
log.Fatalln("ERROR: Stat.String() default case")
return ""
}
}
type CharStats struct {
stats [NUM_STATS]uint8
charClass CharClass
race Race
}
func (cState *CharStats) Race() Race {
return cState.race
}
func (cState *CharStats) CurrentClass() CharClass {
return cState.charClass
}
func (cState *CharStats) copyOf() *CharStats {
var statsCopy [NUM_STATS]uint8
for stat, value := range cState.stats {
statsCopy[stat] = value
}
copyOf := CharStats{
stats: statsCopy,
charClass: cState.CurrentClass(),
}
return ©Of
}
func (cState *CharStats) SetStat(stat uint8, value uint8) {
if stat < NUM_STATS {
cState.stats[stat] = value
}
}
func (cState *CharStats) Stats() *[NUM_STATS]uint8 {
return &cState.stats
}
func (cState *CharStats) Stat(stat Stat) uint8 {
return cState.stats[stat]
}
func (cState *CharStats) StatBonus(stat uint8) uint8 {
if stat >= NUM_STATS {
return 0
}
bonus := float64(cState.Stats()[stat]) * cState.charClass.StatBonuses()[stat]
return uint8(math.Round(bonus))
}