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

import (
	"fmt"

	"thehouseoficarus/internal/combat"
	"thehouseoficarus/internal/net"
	"thehouseoficarus/internal/player"
)

func (g *Game) triggerTransport(sess *net.Session, p *player.Player, mod *ModDef) {
	if combat.GetCombat(p.Name) != nil {
		sess.WriteLine("You can't teleport during combat!")
		return
	}

	if p.Action != nil {
		g.cancelAction(p)
	}

	g.consumeJunkCost(p, mod)

	sciXP := mod.BaseXP
	g.awardSkillXP(sess, p, player.Science, sciXP)
	if p.OptionBool("xp_drops") {
		sess.WriteLine(g.colorize(sess, "xp", fmt.Sprintf("+%dxp sci", sciXP)))
	}
	g.AccountStore.SaveCharacter(p)

	if g.Hub != nil {
		for _, other := range g.Hub.PlayersInRoom(p.RoomID) {
			if other != sess {
				other.WriteLine(fmt.Sprintf("\n%s teleports away.", p.Name))
			}
		}
	}

	sess.WriteLine(fmt.Sprintf("\nYou activate %s...", mod.Name))

	p.RoomID = mod.Destination
	if g.Hub != nil {
		g.Hub.LeaveRoom(sess)
		g.Hub.EnterRoom(sess, p.RoomID)
	}

	room, _ := g.World.LoadRoom(p.RoomID)
	destName := fmt.Sprintf("room %d", p.RoomID)
	if room != nil {
		destName = room.Name
	}
	sess.WriteLine(fmt.Sprintf("You materialize at %s.", destName))
	g.AccountStore.SaveCharacter(p)
	g.doLook(sess)
}