-
Notifications
You must be signed in to change notification settings - Fork 4
/
entityItem.go
55 lines (47 loc) · 1.3 KB
/
entityItem.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
package gamecs
import (
"github.com/Flokey82/go_gens/vectors"
)
// ItemLocation indicates the type of location where an item
// is located.
type ItemLocation int
const (
LocWorld ItemLocation = iota
LocContainer
LocInventory
)
// Item represents a movable item in the world.
type Item struct {
id int // ID of the item
Location ItemLocation // Type of location (world, inventory, ...)
LocationID int // ID of the entity if in inventory
Pos vectors.Vec2 // World position if in world
*ItemType // Base information
}
// ID returns the unique identifier for this item.
func (it *Item) ID() int {
return it.id
}
// ItemType represents the base type of an item.
type ItemType struct {
Name string
Tags []string // Food, Weapon
Properties map[string]int // Price, weight, damage, ...
Requires []*ItemType // Requires items to craft
}
// NewItemType returns a new item type with the given name and tags.
func NewItemType(name string, tags ...string) *ItemType {
return &ItemType{
Name: name,
Properties: make(map[string]int),
Tags: tags,
}
}
// New returns a new item of the current type.
func (i *ItemType) New(w *World, pos vectors.Vec2) *Item {
return &Item{
ItemType: i,
Pos: pos,
id: w.mgr.NextID(),
}
}