aboutsummaryrefslogtreecommitdiff
path: root/internal/action/action.go
blob: 5e667089f6c40c84bb6e1a5d77d94d8af8a955d5 (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
package action

import "strings"

func WordPrefixMatch(input, name string) bool {
	inputWords := strings.Fields(strings.ToLower(input))
	if len(inputWords) == 0 {
		return false
	}
	nameWords := strings.Fields(strings.ToLower(name))
	for _, iw := range inputWords {
		found := false
		for _, nw := range nameWords {
			if strings.HasPrefix(nw, iw) || strings.HasPrefix(iw, nw) {
				found = true
				break
			}
		}
		if !found {
			return false
		}
	}
	return true
}

type Action struct {
	Type       string
	TargetID   string
	TargetName string
	Step       int
	WaitLeft   int
	Data       map[string]any
}

func (a *Action) Advance() bool {
	if a.WaitLeft > 0 {
		a.WaitLeft--
		return false
	}
	return true
}

type DropEntry struct {
	ItemID   string `yaml:"item_id"`
	Table    string `yaml:"table"`
	Weight   int    `yaml:"weight"`
	Quantity int    `yaml:"quantity"`
	Depletes bool   `yaml:"depletes"`
	Message  string `yaml:"message"`
	Level    int    `yaml:"level"`
	XP       int    `yaml:"xp"`
}

type DropTableDef struct {
	ID    string      `yaml:"id"`
	Drops []DropEntry `yaml:"drops"`
}