aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_summon.go
blob: 3aa8d7b556d370e58ecce1912754965b1103f710 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package game

import (
	"fmt"
	"strings"

	"thehouseoficarus/internal/net"
)

func (g *Game) executeSummon(sess *net.Session, args []string, rawInput string) {
	if !g.checkAdmin(sess) {
		sess.WriteLine("Unknown command.")
		return
	}
	adminP := sess.Player
	if adminP == nil {
		return
	}
	if len(args) == 0 {
		sess.WriteLine("Summon whom?")
		return
	}
	targetName := args[0]

	g.charsMu.Lock()
	targetSess, ok := g.loggedInChars[targetName]
	g.charsMu.Unlock()
	if !ok {
		for _, other := range g.Hub.AllSessions() {
			if other.Player != nil && strings.EqualFold(other.Player.Name, targetName) {
				targetSess = other
				break
			}
		}
	}
	if targetSess == nil || targetSess.Player == nil {
		sess.WriteLine("Player not found.")
		return
	}
	if targetSess == sess {
		sess.WriteLine("You can't summon yourself.")
		return
	}

	tp := targetSess.Player
	adminRoom := adminP.RoomID
	oldRoom := tp.RoomID

	tp.ClearMoveState()
	if g.Combat.Get(tp.Name) != nil {
		g.stopCombat(tp.Name)
	}
	tp.Action = nil
	g.cancelRest(tp.Name)
	g.cancelEnterSeq(tp.Name)
	if tp.EnterSeqRoom != 0 && tp.EnterSeqRoom == oldRoom {
		tp.EnterSeqRoom = 0
	}
	if ss, ok := g.safespot.Get(tp.Name); ok {
		g.forceLeaveSafespot(targetSess, tp, &ss, "")
	}

	tp.RoomID = adminRoom
	tp.HazardTimer = 0
	tp.Stats.RecordRoomVisit(adminRoom)
	g.AccountStore.SaveCharacter(tp)

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

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

	targetSess.WriteLine(fmt.Sprintf("You have been summoned by %s.", adminP.Name))
	sess.WriteLine(fmt.Sprintf("Summoned %s.", tp.Name))

	g.doLook(targetSess)
	g.runEnterSteps(targetSess, adminRoom)
	g.checkAggro(targetSess)
}