forked from jasonbot/mud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreatures.go
88 lines (75 loc) · 2.35 KB
/
creatures.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
package mud
import (
"encoding/json"
"io/ioutil"
"log"
)
// CreatureTypes is a mapping of string IDs to creature types
var CreatureTypes map[string]CreatureType
// CreatureSpawn is a JSON struct used for the generation of monsters
type CreatureSpawn struct {
Name string `json:""` // ID of creature in bestiary
Probability float32 `json:""` // 0-1.0
Cluster float32 `json:""` // 0-1.0
}
// CreatureType is the type of creature (Hostile: true is monster, false is NPC)
type CreatureType struct {
ID string `json:"-"`
Name string `json:""`
Hostile bool `json:""`
MaxHP uint64 `json:""`
MaxMP uint64 `json:""`
MaxAP uint64 `json:""`
MaxRP uint64 `json:""`
Attacks []Attack `json:""`
ItemDrops []ItemDrop `json:""` // List of items and probabilities of them appearing in each terrain type
}
// Creature is an instance of a Creature
type Creature struct {
ID string `json:""`
CreatureType string `json:""`
X uint32 `json:""`
Y uint32 `json:""`
HP uint64 `json:""`
AP uint64 `json:""`
RP uint64 `json:""`
MP uint64 `json:""`
CreatureTypeStruct CreatureType `json:"-"`
Charge int64 `json:"-"`
maxCharge int64
world World
}
// StatPoints is for StatPointable
func (creature *Creature) StatPoints() StatPoints {
return StatPoints{
AP: creature.CreatureTypeStruct.MaxAP,
RP: creature.CreatureTypeStruct.MaxRP,
MP: creature.CreatureTypeStruct.MaxMP}
}
// FullStatPoints gets a fullstatinfo object for battle calculation arithmetic
func (creature *Creature) FullStatPoints() FullStatPoints {
return FullStatPoints{
StatPoints: creature.StatPoints(),
HP: creature.HP,
Trample: 0}
}
// CreatureList represents the creatures in a DB
type CreatureList struct {
CreatureIDs []string `json:""`
}
func loadCreatureTypes(creatureInfoFile string) {
data, err := ioutil.ReadFile(creatureInfoFile)
if err == nil {
err = json.Unmarshal(data, &CreatureTypes)
}
for k, v := range CreatureTypes {
v.ID = k
CreatureTypes[k] = v
}
if err != nil {
log.Printf("Error parsing %s: %v", creatureInfoFile, err)
}
}
func init() {
CreatureTypes = make(map[string]CreatureType)
}