-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.go
136 lines (107 loc) · 2.74 KB
/
system.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package runequest
import (
"fmt"
"math/rand"
"sort"
"time"
)
// RollDice rolls and sum dice
func RollDice(max, min, bonus, numDice int) int {
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1)
result := 0
for i := 1; i < numDice+1; i++ {
roll := r1.Intn(max+1-min) + min
result += roll
}
result += bonus
return result
}
// Sorting Functions
// ByTotal implements the sort interface for abilities
type ByTotal []*Ability
func (a ByTotal) Len() int { return len(a) }
func (a ByTotal) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByTotal) Less(i, j int) bool { return a[i].Total > a[j].Total }
// IDCoreRunes returns the top 3 runes for the character
func (c *Character) IDCoreRunes() {
// Reset CoreRunes
c.CoreRunes = []*Ability{}
var runes []*Ability
for _, e := range c.ElementalRunes {
e.UpdateAbility()
if e.Total > 50 {
runes = append(runes, e)
}
}
for _, p := range c.PowerRunes {
p.UpdateAbility()
if p.Total > 50 {
runes = append(runes, p)
}
}
for _, c := range c.ConditionRunes {
c.UpdateAbility()
if c.Total > 50 {
runes = append(runes, c)
}
}
// Sort Runes
sort.Sort(ByTotal(runes))
// Return max of 3 runes
l := len(runes)
if l > 3 {
l = 3
}
for _, r := range runes[:l] {
c.CoreRunes = append(c.CoreRunes, r)
}
}
// DetermineRuneModifiers adds stat modifiers based on runes
func (c *Character) DetermineRuneModifiers() []string {
var runes []*Ability
var runeModifiers []string
// Add abilities to array for sorting
for _, a := range c.ElementalRunes {
a.UpdateAbility()
runes = append(runes, a)
}
// Reset Rune Bonuses
for _, v := range c.Statistics {
v.RuneBonus = 0
}
// Sort Runes
sort.Sort(ByTotal(runes))
fmt.Println(runes)
primary, secondary := runes[0].Name, runes[1].Name
switch {
case primary == "Air":
runeModifiers = append(runeModifiers, "STR")
case primary == "Earth":
runeModifiers = append(runeModifiers, "CON")
case primary == "Darkness":
runeModifiers = append(runeModifiers, "SIZ")
case primary == "Fire/Sky":
runeModifiers = append(runeModifiers, "INT")
case primary == "Water":
runeModifiers = append(runeModifiers, "DEX")
case primary == "Moon":
runeModifiers = append(runeModifiers, "POW")
}
switch {
case secondary == "Air":
runeModifiers = append(runeModifiers, "STR")
case secondary == "Earth":
runeModifiers = append(runeModifiers, "CON")
case secondary == "Darkness":
runeModifiers = append(runeModifiers, "SIZ")
case secondary == "Fire/Sky":
runeModifiers = append(runeModifiers, "INT")
case secondary == "Water":
runeModifiers = append(runeModifiers, "DEX")
case secondary == "Moon":
runeModifiers = append(runeModifiers, "POW")
}
fmt.Println(runeModifiers)
return runeModifiers
}