~nromdotcom/gemif

ref: 0d4b60a8720279f402503491905f77a2a27b9d1e gemif/pkg/gamemanager/room.go -rw-r--r-- 1.5 KiB
0d4b60a8Norm MacLennan Add a few more tests 1 year, 5 months ago
                                                                                
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
package gamemanager

import "fmt"

// Room contains information about a room and its Exits.
type Room struct {
	ID          string `yaml:"room_id" json:"room_id" binding:"uuid"`
	Name        string `yaml:"room_name" json:"room_name"`
	Description string `yaml:"room_description,omitempty" json:"room_description"`
	Exits       []Exit `yaml:"exits,omitempty" json:"exits"`
}

// Exit describes actions applied to GameState as part of leaving a Room.
type Exit struct {
	ID             string `yaml:"exit_id" json:"exit_id" binding:"uuid"`
	Description    string `yaml:"exit_description" json:"exit_description"`
	Destination    string `yaml:"destination_id" json:"destination_id" binding:"uuid"`
	SetCondition   string `yaml:"set_condition,omitempty" json:"set_condition"`
	IfCondition    string `yaml:"if_condition,omitempty" json:"if_condition"`
	NotCondition   string `yaml:"not_condition,omitempty" json:"not_condition"`
	UnsetCondition string `yaml:"unset_condition,omitempty" json:"unset_condition"`
}

func (r Room) filterExits(gameState GameState) []Exit {
	usableExits := []Exit{}

	for _, e := range r.Exits {
		if e.IfCondition != "" && !gameState.ConditionMet(e.IfCondition) {
			fmt.Printf("Cant use exit %s due to not meeting condition\n", e.ID)

			continue
		}

		if e.NotCondition != "" && gameState.ConditionMet(e.NotCondition) {
			fmt.Printf("Can't use exit %s due to meeting condition\n", e.ID)

			continue
		}

		usableExits = append(usableExits, e)
	}

	return usableExits
}