aboutsummaryrefslogtreecommitdiff
path: root/internal/game/action_room.go
blob: af5b99b077bf8c4a4c542cb9564124ba0a587241 (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
package game

import (
	"fmt"
	"strings"

	"thehouseoficarus/internal/net"
)

func (g *Game) runEnterSteps(sess *net.Session, roomID int) {
	room, err := g.World.LoadRoom(roomID)
	if err != nil || len(room.OnEnter) == 0 {
		return
	}
	for _, step := range room.OnEnter {
		if step.Condition != nil && !g.checkCondition(sess, step.Condition) {
			continue
		}
		if step.Message != "" {
			sess.WriteLine(fmt.Sprintf("%s", step.Message))
		}
	}
}

func (g *Game) BroadcastRespawns() {
	respawns := g.World.FlushObjRespawns()
	for _, st := range respawns {
		def, err := g.ObjectStore.Load(st.DefID)
		if err != nil || !def.IsGatherable() {
			continue
		}
		cfg := def.Gather
		if cfg.RespawnBroadcast == "" {
			continue
		}
		name := def.Name
		if idx := st.Index + 1; len(g.World.FindObjInstances(st.RoomID, st.DefID)) > 1 {
			name += fmt.Sprintf(" [%d]", idx)
		}
		msg := strings.ReplaceAll(cfg.RespawnBroadcast, "{name}", name)
		if g.Hub != nil {
			for _, sess := range g.Hub.PlayersInRoom(st.RoomID) {
				sess.WriteLine(g.colorize(sess, "broadcast", fmt.Sprintf("\n%s", msg)))
			}
		}
	}
}