blob: a2b362889dd789a87f92d165ae2bde88519a7d21 (
plain)
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
|
package models
import "time"
type ActionType string
const (
ActionTypePlus ActionType = "ActionTypePlus"
ActionTypeMinus ActionType = "ActionTypeMinus"
)
type (
UserScore struct {
Username string
Actions []*Action
BurnTime time.Time
Score int8
}
Action struct {
ID uint32
Name string
Magnitude uint8
Repeatable bool
Type ActionType
Done bool
Username string
}
)
func (us *UserScore) UpdateScore(act *Action) {
switch act.Type {
case ActionTypePlus:
us.Score += int8(act.Magnitude)
if !act.Repeatable {
act.Done = true
}
case ActionTypeMinus:
us.Score -= int8(act.Magnitude)
}
}
|