From 8ee8982b8759bcae116647cc993867f4c8b0a6ce Mon Sep 17 00:00:00 2001 From: workhorse Date: Fri, 19 Jun 2026 20:24:52 -0400 Subject: reorganized items, objects, and rooms in directories. oranized module names. added startup checks. --- internal/game/core_hacking.go | 93 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 internal/game/core_hacking.go (limited to 'internal/game/core_hacking.go') 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) +} -- cgit v1.2.3