aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_goto.go
blob: 1771f8d864e7e0ed039861e64c8aadca0a6ed488 (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
63
64
65
66
67
68
69
70
71
package game

import (
	"fmt"
	"strconv"

	"thehouseoficarus/internal/net"
)

func (g *Game) executeGoto(sess *net.Session, args []string, rawInput string) {
	if !g.checkAdmin(sess) {
		sess.WriteLine("Unknown command.")
		return
	}
	p := sess.Player
	if p == nil {
		return
	}
	if len(args) == 0 {
		sess.WriteLine("Goto where?")
		return
	}
	roomID, err := strconv.Atoi(args[0])
	if err != nil {
		sess.WriteLine("Invalid room ID.")
		return
	}
	if _, err := g.World.LoadRoom(roomID); err != nil {
		sess.WriteLine(fmt.Sprintf("Room %d not found.", roomID))
		return
	}

	oldRoom := p.RoomID
	p.ClearMoveState()
	if g.Combat.Get(p.Name) != nil {
		g.stopCombat(p.Name)
	}
	p.Action = nil
	g.cancelRest(p.Name)
	g.cancelSequences(p.Name)
	if ss, ok := g.safespot.Get(p.Name); ok {
		g.forceLeaveSafespot(sess, p, &ss, "")
	}

	p.RoomID = roomID
	p.HazardTimer = 0
	p.Stats.RecordRoomVisit(roomID)
	g.AccountStore.SaveCharacter(p)

	g.World.SeedGroundItems(roomID)
	g.seedRoomMobs(roomID)
	g.seedRoomObjects(roomID)

	if g.Hub != nil {
		for _, other := range g.Hub.PlayersInRoom(oldRoom) {
			if other != sess {
				other.WriteLine(fmt.Sprintf("%s vanishes.", p.Name))
			}
		}
		g.Hub.EnterRoom(sess, roomID)
		for _, other := range g.Hub.PlayersInRoom(roomID) {
			if other != sess {
				other.WriteLine(fmt.Sprintf("%s appears.", p.Name))
			}
		}
	}

	g.doLook(sess)
	g.runEnterSteps(sess, roomID)
	g.checkAggro(sess)
}