aboutsummaryrefslogtreecommitdiff
path: root/internal/game/core_hacking.go
diff options
context:
space:
mode:
authorworkhorse <workhorse@localhost.localdomain>2026-06-19 20:24:52 -0400
committerworkhorse <workhorse@localhost.localdomain>2026-06-19 20:24:52 -0400
commit8ee8982b8759bcae116647cc993867f4c8b0a6ce (patch)
treeee01f7b1d745cbc94d9981108a1209527487b3e5 /internal/game/core_hacking.go
parent2bec24859af8f03c80a0a58e3240519942450167 (diff)
downloadthehouseoficarus-8ee8982b8759bcae116647cc993867f4c8b0a6ce.tar.gz
reorganized items, objects, and rooms in directories. oranized module names. added startup checks.
Diffstat (limited to 'internal/game/core_hacking.go')
-rw-r--r--internal/game/core_hacking.go93
1 files changed, 93 insertions, 0 deletions
diff --git a/internal/game/core_hacking.go b/internal/game/core_hacking.go
new file mode 100644
index 0000000..3457728
--- /dev/null
+++ b/internal/game/core_hacking.go
@@ -0,0 +1,93 @@
+package game
+
+import (
+ "fmt"
+ "strings"
+
+ "thehouseoficarus/internal/game/hacking"
+ "thehouseoficarus/internal/net"
+ "thehouseoficarus/internal/player"
+)
+
+func (g *Game) handleHackingInput(sess *net.Session, input string) {
+ p := sess.Player
+ if p == nil {
+ sess.State = net.StateGame
+ return
+ }
+
+ hs, ok := g.hackingStates[p.Name]
+ if !ok {
+ sess.State = net.StateGame
+ g.writePrompt(sess)
+ return
+ }
+
+ input = strings.TrimSpace(input)
+ lower := strings.ToLower(input)
+
+ if lower == "jack out" || lower == "quit" || lower == "disconnect" {
+ g.endHacking(sess, p, false, false)
+ return
+ }
+
+ hs.Started = true
+ output, done, won := hs.Minigame.HandleInput(input)
+
+ sess.WriteLine(output)
+
+ if done {
+ g.endHacking(sess, p, true, won)
+ return
+ }
+
+ sess.Write("\nhack> ")
+}
+
+func (g *Game) endHacking(sess *net.Session, p *player.Player, completed bool, won bool) {
+ hs, ok := g.hackingStates[p.Name]
+ if !ok {
+ sess.State = net.StateGame
+ g.writePrompt(sess)
+ return
+ }
+
+ tDef := hacking.Terminals[hs.TerminalID]
+ var xp int
+
+ if completed && won {
+ xp = hacking.CalcXP(tDef.BaseXPWin, hs.Level, hs.ReqLevel)
+ sess.WriteLine("\nConnection terminated. Contract complete.")
+ } else if completed {
+ xp = hacking.CalcXP(tDef.BaseXPLose, hs.Level, hs.ReqLevel)
+ sess.WriteLine("\nConnection lost.")
+ } else if hs.Started {
+ 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.(hacking.XPBonuser); ok {
+ bonus := b.BonusXP()
+ if bonus > 0 {
+ xp += hacking.CalcXP(bonus, hs.Level, hs.ReqLevel)
+ }
+ }
+ }
+
+ if xp > 0 {
+ 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])))
+ }
+ g.AccountStore.SaveCharacter(p)
+ }
+
+ delete(g.hackingStates, p.Name)
+ p.ActionState = nil
+ sess.State = net.StateGame
+ g.writePrompt(sess)
+}