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

import (
	"fmt"
	"strconv"

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

func (g *Game) executeGod(sess *net.Session, args []string, rawInput string) {
	if !g.checkAdmin(sess) {
		sess.WriteLine("Unknown command.")
		return
	}
	p := sess.Player
	if p == nil {
		return
	}
	if p.GodMode {
		sess.WriteLine("You are already in god mode.")
		return
	}

	level := 99
	if len(args) > 0 {
		n, err := strconv.Atoi(args[0])
		if err != nil || n < 1 || n > 99 {
			sess.WriteLine("Usage: god [level] (1-99).")
			return
		}
		level = n
	}

	p.GodBackup = make(map[player.SkillName]int, len(p.Skills))
	for k, v := range p.Skills {
		p.GodBackup[k] = v
	}

	lvlXP := player.XPForLevel(level)
	for _, s := range player.AllSkills {
		p.Skills[s] = lvlXP
	}
	p.GodMode = true
	p.HP = p.MaxHP()

	sess.WriteLine(fmt.Sprintf("God mode activated. All skills set to %d.", level))
}

func (g *Game) executeUnGod(sess *net.Session, args []string, rawInput string) {
	if !g.checkAdmin(sess) {
		sess.WriteLine("Unknown command.")
		return
	}
	p := sess.Player
	if p == nil {
		return
	}
	if !p.GodMode {
		sess.WriteLine("You are not in god mode.")
		return
	}
	g.restoreGodPlayer(p)
	g.AccountStore.SaveCharacter(p)
	sess.WriteLine("God mode deactivated. Skills restored.")
}

func (g *Game) restoreGodPlayer(p *player.Player) {
	if p == nil || !p.GodMode {
		return
	}
	if p.GodBackup != nil {
		p.Skills = p.GodBackup
	}
	p.GodMode = false
	p.GodBackup = nil
	if p.HP > p.MaxHP() {
		p.HP = p.MaxHP()
	}
}