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

import (
	"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
	}

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

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

	sess.WriteLine("God mode activated. All skills set to 99.")
}

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)
	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
}