-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathItem.go
86 lines (70 loc) · 1.4 KB
/
Item.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
package main
import (
"encoding/xml"
)
type Item_I interface {
GetName() string
GetDescription() []FormattedString
GetWorth() int
GetType() int
GetCopy() Item_I
ToXML() ItemXML_I
}
type ItemXML_I interface {
ToItem() Item_I
}
const (
BASE_ITEM = 0
WEAPON = 1
ARMOUR = 2
)
type Item struct {
name string
description string
itemLevel int
itemWorth int
typeOfItem int
}
type ItemXML struct {
XMLName xml.Name `xml:"Item"`
Name string `xml:"Name"`
Description string `xml:"Description"`
ItemLevel int `xml:"Level"`
ItemWorth int `xml:"Worth"`
}
func NewItem(itemData *ItemXML) *Item {
itm := new(Item)
itm.description = itemData.Description
itm.itemLevel = itemData.ItemLevel
itm.itemWorth = itemData.ItemWorth
itm.name = itemData.Name
return itm
}
func (i *Item) GetName() string {
return i.name
}
func (i *Item) GetDescription() []FormattedString {
return newFormattedStringSplice(i.description)
}
func (i *Item) GetWorth() int {
return i.itemWorth
}
func (i *Item) GetType() int {
return BASE_ITEM
}
func (i *Item) GetCopy() Item_I {
itm := new(Item)
*itm = *i
return itm
}
func (i *Item) ToXML() ItemXML_I {
xmlItem := new(ItemXML)
xmlItem.Name = i.name
xmlItem.Description = i.description
xmlItem.ItemLevel = i.itemLevel
xmlItem.ItemWorth = i.itemWorth
return xmlItem
}
func (i ItemXML) ToItem() Item_I {
return NewItem(&i)
}