aboutsummaryrefslogtreecommitdiff
path: root/internal/object/item.go
blob: 67a29987084a732ce731045cb446c1eb7aa57b10 (plain)
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
package object

import "strings"

type EquipSlot string

const (
	SlotHead      EquipSlot = "head"
	SlotNeck      EquipSlot = "neck"
	SlotTorso     EquipSlot = "torso"
	SlotLegs      EquipSlot = "legs"
	SlotHands     EquipSlot = "hands"
	SlotFeet      EquipSlot = "feet"
	SlotBack      EquipSlot = "back"
	SlotAmmo      EquipSlot = "ammo"
	SlotMainHand  EquipSlot = "main_hand"
	SlotOffHand   EquipSlot = "off_hand"
	SlotRing      EquipSlot = "ring"
)

type WeaponType string

const (
	WeaponMelee      WeaponType = "melee"
	WeaponRanged     WeaponType = "ranged"
	WeaponTechnology WeaponType = "technology"
)

type ItemDef struct {
	ID          string         `yaml:"id"`
	Name        string         `yaml:"name"`
	Aliases     []string       `yaml:"aliases"`
	Description string         `yaml:"description"`
	Value       int            `yaml:"value"` // credits
	Stackable   bool           `yaml:"stackable"`
	EquipSlot   EquipSlot      `yaml:"equip_slot"`
	WeaponType  WeaponType     `yaml:"weapon_type"`
	Stats       ItemStats      `yaml:"stats"`
	Speed       int            `yaml:"speed"`    // ticks between attacks
	Toolbelt    bool           `yaml:"toolbelt"` // can go on toolbelt
}

type ItemStats struct {
	AttackBonus    int `yaml:"attack_bonus"`
	StrengthBonus  int `yaml:"strength_bonus"`
	DefenseBonus   int `yaml:"defense_bonus"`
	ScienceBonus   int `yaml:"science_bonus"`
	TechnologyBonus int `yaml:"technology_bonus"`
}

func (d *ItemDef) MatchesName(input string) bool {
	lower := strings.ToLower(input)
	if strings.ToLower(d.Name) == lower {
		return true
	}
	for _, a := range d.Aliases {
		if strings.ToLower(a) == lower {
			return true
		}
	}
	return false
}