aboutsummaryrefslogtreecommitdiff
path: root/internal/game/hacking.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-19 18:20:26 -0400
committerhistoria <[not public]>2026-06-19 18:20:26 -0400
commit0ea4eec5dd2122c6704216971eb1249276297867 (patch)
tree430fbbef04e837820f1d031c190f52ecd6112e25 /internal/game/hacking.go
parent3a58125d14bb307f861b38c6c5b0a63babde7e08 (diff)
downloadthehouseoficarus-0ea4eec5dd2122c6704216971eb1249276297867.tar.gz
shop fixes, 'toggle' completely removed, movement speed increased
Diffstat (limited to 'internal/game/hacking.go')
-rw-r--r--internal/game/hacking.go88
1 files changed, 12 insertions, 76 deletions
diff --git a/internal/game/hacking.go b/internal/game/hacking.go
index dfefd5c..3457728 100644
--- a/internal/game/hacking.go
+++ b/internal/game/hacking.go
@@ -4,67 +4,14 @@ import (
"fmt"
"strings"
+ "thehouseoficarus/internal/game/hacking"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/player"
)
-type HackingMinigame interface {
- Init(level int) string
- HandleInput(input string) (output string, done bool, won bool)
- Name() string
-}
-
-type XPBonuser interface {
- BonusXP() int
-}
-
-type HackingSession struct {
- Minigame HackingMinigame
- TerminalID string
- Level int
- ReqLevel int
- Started bool
-}
-
-type TerminalDef struct {
- ObjectID string
- Level int
- Minigame func() HackingMinigame
- BaseXPWin int
- BaseXPLose int
- Name string
-}
-
-var terminalDefs = map[string]TerminalDef{
- "terminal_basic": {
- ObjectID: "terminal_basic",
- Level: 1,
- Minigame: func() HackingMinigame { return NewWumpusGame() },
- BaseXPWin: 50,
- BaseXPLose: 10,
- Name: "Hunt the Wumpus",
- },
- "terminal_advanced": {
- ObjectID: "terminal_advanced",
- Level: 20,
- Minigame: func() HackingMinigame { return NewMastermindGame() },
- BaseXPWin: 150,
- BaseXPLose: 30,
- Name: "Code Breaker",
- },
- "terminal_secure": {
- ObjectID: "terminal_secure",
- Level: 40,
- Minigame: func() HackingMinigame { return NewLiarsDiceGame() },
- BaseXPWin: 300,
- BaseXPLose: 50,
- Name: "Signal Bluff",
- },
-}
-
func (g *Game) handleHackingInput(sess *net.Session, input string) {
- p, ok := sess.Player.(*player.Player)
- if !ok {
+ p := sess.Player
+ if p == nil {
sess.State = net.StateGame
return
}
@@ -105,36 +52,33 @@ func (g *Game) endHacking(sess *net.Session, p *player.Player, completed bool, w
return
}
- tDef := terminalDefs[hs.TerminalID]
+ tDef := hacking.Terminals[hs.TerminalID]
var xp int
if completed && won {
- xp = hackingXP(tDef.BaseXPWin, hs.Level, hs.ReqLevel)
- sess.WriteLine(fmt.Sprintf("\nConnection terminated. Contract complete."))
+ xp = hacking.CalcXP(tDef.BaseXPWin, hs.Level, hs.ReqLevel)
+ sess.WriteLine("\nConnection terminated. Contract complete.")
} else if completed {
- xp = hackingXP(tDef.BaseXPLose, hs.Level, hs.ReqLevel)
- sess.WriteLine(fmt.Sprintf("\nConnection lost."))
+ xp = hacking.CalcXP(tDef.BaseXPLose, hs.Level, hs.ReqLevel)
+ sess.WriteLine("\nConnection lost.")
} else if hs.Started {
- xp = hackingXP(tDef.BaseXPLose, hs.Level, hs.ReqLevel)
+ xp = hacking.CalcXP(tDef.BaseXPLose, hs.Level, hs.ReqLevel)
sess.WriteLine("\nYou jack out of the terminal.")
} else {
sess.WriteLine("\nYou jack out of the terminal.")
}
if won {
- if b, ok := hs.Minigame.(XPBonuser); ok {
+ if b, ok := hs.Minigame.(hacking.XPBonuser); ok {
bonus := b.BonusXP()
if bonus > 0 {
- xp += hackingXP(bonus, hs.Level, hs.ReqLevel)
+ xp += hacking.CalcXP(bonus, hs.Level, hs.ReqLevel)
}
}
}
if xp > 0 {
- if newLevel := p.AddSkillXP(player.Hacking, xp); newLevel > 0 {
- sess.WriteLine(g.colorize(sess, "level_up",
- fmt.Sprintf("*** You are now level %d hacking! ***", newLevel)))
- }
+ g.awardSkillXP(sess, p, player.Hacking, xp)
if p.OptionBool("xp_drops") {
sess.WriteLine(g.colorize(sess, "xp",
fmt.Sprintf("(+%dxp %s)", xp, player.SkillAbbr[player.Hacking])))
@@ -147,11 +91,3 @@ func (g *Game) endHacking(sess *net.Session, p *player.Player, completed bool, w
sess.State = net.StateGame
g.writePrompt(sess)
}
-
-func hackingXP(baseXP int, playerLevel int, reqLevel int) int {
- multiplier := 1.0 + 0.01*float64(playerLevel-reqLevel)
- if multiplier < 1.0 {
- multiplier = 1.0
- }
- return int(float64(baseXP) * multiplier)
-}