-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWeapon.go
80 lines (65 loc) · 1.74 KB
/
Weapon.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
package main
import (
"encoding/xml"
"fmt"
"github.com/daviddengcn/go-colortext"
"math/rand"
"strconv"
)
type Weapon struct {
Item
attack int
minDmg int
maxDmg int
}
func (wpn *Weapon) GetType() int {
return WEAPON
}
func (wpn *Weapon) GetAttack() int {
return wpn.attack
}
func (wpn *Weapon) GetDamage() int {
return rand.Intn(wpn.GetDamageRange()) + wpn.minDmg
}
func (wpn *Weapon) GetDamageRange() int {
return wpn.maxDmg - wpn.minDmg + 1
}
func (w *Weapon) GetCopy() Item_I {
wpn := new(Weapon)
*wpn = *w
return wpn
}
func (w *Weapon) GetWeaponPage() []FormattedString {
output := newFormattedStringCollection()
output.addMessage(ct.Green, "\t\t\tEquipped Weapon\n")
output.addMessage2(fmt.Sprintf("\t%-15s %-15s %-15s %-15s\n", "Name", "Attack", "MinDmg", "MaxDmg"))
output.addMessage(ct.Green, "--------------------------------------------------------------------\n")
output.addMessage2(fmt.Sprintf("\t%-15s %-15s %-15s %-15s\n\n", w.name, strconv.Itoa(w.attack), strconv.Itoa(w.minDmg), strconv.Itoa(w.maxDmg)))
return output.fmtedStrings
}
type WeaponXML struct {
XMLName xml.Name `xml:"Weapon"`
ItemInfo *ItemXML `xml:"Item"`
Attack int `xml:"Attack"`
MinDmg int `xml:"MinDmg"`
MaxDmg int `xml:"MaxDmg"`
}
func NewWeaponFromXML(weaponData *WeaponXML) *Weapon {
wpn := new(Weapon)
wpn.Item = *NewItem(weaponData.ItemInfo)
wpn.attack = weaponData.Attack
wpn.minDmg = weaponData.MinDmg
wpn.maxDmg = weaponData.MaxDmg
return wpn
}
func (w *Weapon) ToXML() ItemXML_I {
wpnXML := new(WeaponXML)
wpnXML.ItemInfo = w.Item.ToXML().(*ItemXML)
wpnXML.Attack = w.attack
wpnXML.MinDmg = w.minDmg
wpnXML.MaxDmg = w.maxDmg
return wpnXML
}
func (w WeaponXML) ToItem() Item_I {
return NewWeaponFromXML(&w)
}