aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_misc.go
blob: f56a0ffde07af736d2df2235f1a6a1b730c941a2 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package game

import (
	"fmt"
	"strings"

	"thirdcollapse/internal/net"
	"thirdcollapse/internal/player"
)

func (g *Game) doSay(sess *net.Session, msg string) {
	p := sess.Player.(*player.Player)
	roomID := p.RoomID

	for _, other := range g.Hub.PlayersInRoom(roomID) {
		if other == sess {
			other.WriteLine(fmt.Sprintf("\nYou say: %s", msg))
		} else {
			other.WriteLine(fmt.Sprintf("\n%s says: %s", p.Name, msg))
		}
	}
}

func (g *Game) doScore(sess *net.Session) {
	p := sess.Player.(*player.Player)
	sess.WriteLines(
		"",
		fmt.Sprintf("Name: %s", p.Name),
		fmt.Sprintf("Combat Level: %d", p.CombatLevel()),
		fmt.Sprintf("HP: %d/%d", p.HP, p.MaxHP()),
		fmt.Sprintf("Credits: %d", p.Credits),
		"",
		"Skills:",
	)
	for _, s := range player.AllSkills {
		level := p.Level(s)
		xp := p.Skills[s]
		next := player.XPForNextLevel(xp)
		sess.WriteLine(fmt.Sprintf("  %-12s Level: %2d  XP: %d / %d", s, level, xp, xp+next))
	}
}

func (g *Game) doInventory(sess *net.Session) {
	p := sess.Player.(*player.Player)
	sess.WriteLine("")
	sess.WriteLine("Inventory (28 slots):")

	empty := 0
	num := 0
	for i := 0; i < 28; i++ {
		slot := p.InvSlot(i)
		if slot == nil {
			empty++
			continue
		}
		num++
		def, err := g.ItemStore.Load(slot.ItemID)
		name := slot.ItemID
		if err == nil {
			name = def.Name
		}
		if slot.Quantity > 1 {
			sess.WriteLine(fmt.Sprintf("  %2d) %d x %s", num, slot.Quantity, name))
		} else {
			sess.WriteLine(fmt.Sprintf("  %2d) %s", num, name))
		}
	}
	sess.WriteLine(fmt.Sprintf("  (%d empty slots)", empty))
}

func (g *Game) doEquipment(sess *net.Session) {
	p := sess.Player.(*player.Player)
	sess.WriteLine("")
	sess.WriteLine("Equipment:")

	for _, slot := range EquipSlots {
		itemID, ok := p.Equipment[slot]
		if !ok {
			sess.WriteLine(fmt.Sprintf("  %-12s (empty)", slot))
			continue
		}
		def, err := g.ItemStore.Load(itemID)
		name := itemID
		if err == nil {
			name = def.Name
		}
		sess.WriteLine(fmt.Sprintf("  %-12s %s", slot, name))
	}
}

func (g *Game) doStyle(sess *net.Session, input string) {
	p := sess.Player.(*player.Player)

	styles := []string{"accurate", "aggressive", "defensive", "balanced"}
	if input == "" {
		sess.WriteLine("\nCombat styles:")
		for _, s := range styles {
			marker := " "
			if string(p.AttackStyle) == s {
				marker = "*"
			}
			sess.WriteLine(fmt.Sprintf("  %s %s", marker, s))
		}
		return
	}

	input = strings.ToLower(input)
	for _, s := range styles {
		if s == input {
			p.AttackStyle = player.AttackStyle(s)
			g.AccountStore.SaveCharacter(p)
			sess.WriteLine(fmt.Sprintf("\nCombat style set to %s.", s))
			return
		}
	}
	sess.WriteLine(fmt.Sprintf("\nUnknown style: %s. Choices: accurate, aggressive, defensive, balanced", input))
}