diff options
| author | historia <[not public]> | 2026-07-01 22:39:42 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-07-01 22:39:42 -0400 |
| commit | 778157981cccb8cb4856e3ab5a72085830c59120 (patch) | |
| tree | 95a69bd1586609cdc960a1e721cbde0b4cfa1b9a | |
| parent | c14c2e403c75a913e1a6d962fb6fe64f013adae5 (diff) | |
| download | thehouseoficarus-778157981cccb8cb4856e3ab5a72085830c59120.tar.gz | |
feat: god <level> lets admins set all stats to level
| -rw-r--r-- | data/help/god.yaml | 10 | ||||
| -rw-r--r-- | internal/game/cmd_god.go | 23 | ||||
| -rw-r--r-- | internal/game/game.go | 1 | ||||
| -rw-r--r-- | internal/player/store.go | 12 |
4 files changed, 39 insertions, 7 deletions
diff --git a/data/help/god.yaml b/data/help/god.yaml index d68e045..ac0fc97 100644 --- a/data/help/god.yaml +++ b/data/help/god.yaml @@ -1,7 +1,9 @@ name: god description: |- - Admin-only. Temporarily sets all your skills to level 99, prevents mobs - from aggressing you, lets you walk through blocked exits, and makes you - immune to hazard damage and death. Does not persist across reconnects. - Usage: god + Admin-only. Temporarily sets all your skills to a given level, prevents + mobs from aggressing you, lets you walk through blocked exits, and makes + you immune to hazard damage and death. Does not persist across reconnects. + Usage: god [level] + god - set all skills to 99 + god 20 - set all skills to level 20 (1-99) Use 'ungod' to restore your normal stats and privileges. diff --git a/internal/game/cmd_god.go b/internal/game/cmd_god.go index 0545c3f..56311cb 100644 --- a/internal/game/cmd_god.go +++ b/internal/game/cmd_god.go @@ -1,6 +1,9 @@ package game import ( + "fmt" + "strconv" + "thehouseoficarus/internal/net" "thehouseoficarus/internal/player" ) @@ -19,19 +22,29 @@ func (g *Game) executeGod(sess *net.Session, args []string, rawInput string) { 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 } - lvl99xp := player.XPForLevel(99) + lvlXP := player.XPForLevel(level) for _, s := range player.AllSkills { - p.Skills[s] = lvl99xp + p.Skills[s] = lvlXP } p.GodMode = true p.HP = p.MaxHP() - sess.WriteLine("God mode activated. All skills set to 99.") + sess.WriteLine(fmt.Sprintf("God mode activated. All skills set to %d.", level)) } func (g *Game) executeUnGod(sess *net.Session, args []string, rawInput string) { @@ -48,6 +61,7 @@ func (g *Game) executeUnGod(sess *net.Session, args []string, rawInput string) { return } g.restoreGodPlayer(p) + g.AccountStore.SaveCharacter(p) sess.WriteLine("God mode deactivated. Skills restored.") } @@ -60,4 +74,7 @@ func (g *Game) restoreGodPlayer(p *player.Player) { } p.GodMode = false p.GodBackup = nil + if p.HP > p.MaxHP() { + p.HP = p.MaxHP() + } } diff --git a/internal/game/game.go b/internal/game/game.go index 4cd3b30..bf7bdc2 100644 --- a/internal/game/game.go +++ b/internal/game/game.go @@ -115,6 +115,7 @@ func (g *Game) SetHub(hub *net.Hub) { hub.OnRemove(func(sess *net.Session) { if p := sess.Player; p != nil { g.restoreGodPlayer(p) + g.AccountStore.SaveCharacter(p) p.DeactivateAllTechs() g.cancelEnterSeq(p.Name) g.charsMu.Lock() diff --git a/internal/player/store.go b/internal/player/store.go index bcadf3b..bc5db11 100644 --- a/internal/player/store.go +++ b/internal/player/store.go @@ -103,6 +103,18 @@ func (s *AccountStore) LoadCharacter(name string) (*Player, error) { func (s *AccountStore) SaveCharacter(p *Player) error { path := s.CharPath(p.Name) + if p.GodMode && p.GodBackup != nil { + buffedSkills := p.Skills + buffedHP := p.HP + p.Skills = p.GodBackup + if p.HP > p.MaxHP() { + p.HP = p.MaxHP() + } + defer func() { + p.Skills = buffedSkills + p.HP = buffedHP + }() + } data, err := yaml.Marshal(p) if err != nil { return err |
