forked from p4tin/GoTextAdv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevents.go
44 lines (37 loc) · 851 Bytes
/
events.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
package main
import (
"math/rand"
"time"
)
type Event struct {
Type string
Chance int
Description string
Health int
Evt string
}
func (e *Event) ProcessEvent(player *Character) int {
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1)
if e.Chance >= r1.Intn(100) {
if e.Type == "Combat" {
//Generate opponent
opp := new(Character)
*opp = *Enemies[1+rand.Intn(len(Enemies)-1)]
opp.Npc = true
opp.Speed = 1 + rand.Intn(100)
Output("green", "A " + opp.Name + " jumps in front of you and attacks")
players := Players{*player, *opp}
runBattle(players)
// Run combat
Output("green", "Combat Event")
} else {
Output("green", "\t" + e.Description)
if e.Evt != "" {
e.Health = e.Health + evts[e.Evt].ProcessEvent(player)
}
}
return e.Health
}
return 0
}