aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_jack.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/cmd_jack.go')
-rw-r--r--internal/game/cmd_jack.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/internal/game/cmd_jack.go b/internal/game/cmd_jack.go
new file mode 100644
index 0000000..db157f3
--- /dev/null
+++ b/internal/game/cmd_jack.go
@@ -0,0 +1,83 @@
+package game
+
+import (
+ "fmt"
+ "strings"
+
+ "thehouseoficarus/internal/combat"
+ "thehouseoficarus/internal/net"
+ "thehouseoficarus/internal/player"
+)
+
+func (g *Game) doJack(sess *net.Session, target string) {
+ p := sess.Player.(*player.Player)
+
+ if combat.GetCombat(p.Name) != nil {
+ sess.WriteLine("You can't do that during combat!")
+ return
+ }
+
+ if target == "" {
+ target = g.findTerminalInRoom(p.RoomID)
+ if target == "" {
+ sess.WriteLine("There's no terminal here to jack into.")
+ return
+ }
+ }
+
+ instances := g.World.FindObjInstances(p.RoomID, strings.ToLower(target))
+ if len(instances) == 0 {
+ sess.WriteLine("You don't see that here.")
+ return
+ }
+
+ defID := instances[0].DefID
+ tDef, ok := terminalDefs[defID]
+ if !ok {
+ sess.WriteLine("You can't jack into that.")
+ return
+ }
+
+ hackLevel := p.Level(player.Hacking)
+ if hackLevel < tDef.Level {
+ sess.WriteLine(fmt.Sprintf("You need level %d Hacking to use this terminal.", tDef.Level))
+ return
+ }
+
+ g.CancelAction(p)
+ g.CancelBackgroundAction(p)
+
+ minigame := tDef.Minigame()
+ display := minigame.Init(hackLevel)
+
+ g.hackingStates[p.Name] = &HackingSession{
+ Minigame: minigame,
+ TerminalID: defID,
+ Level: hackLevel,
+ ReqLevel: tDef.Level,
+ Started: false,
+ }
+
+ p.ActionState = &ActionState{Type: ActionHacking, TargetName: tDef.Name}
+ sess.State = net.StateHacking
+
+ if g.Hub != nil {
+ for _, other := range g.Hub.PlayersInRoom(p.RoomID) {
+ if other != sess {
+ other.WriteLine(fmt.Sprintf("\n%s jacks into a terminal.", p.Name))
+ }
+ }
+ }
+
+ sess.WriteLine(display)
+ sess.Write("\nhack> ")
+}
+
+func (g *Game) findTerminalInRoom(roomID int) string {
+ for _, st := range g.World.FindObjInstances(roomID, "") {
+ if strings.HasPrefix(st.DefID, "terminal_") {
+ return st.Name
+ }
+ }
+ return ""
+}