package game import ( "fmt" "strings" "thehouseoficarus/internal/combat" "thehouseoficarus/internal/game/hacking" "thehouseoficarus/internal/net" "thehouseoficarus/internal/player" ) func (g *Game) executeJack(sess *net.Session, args []string, rawInput string) { p := sess.Player g.cancelAction(p) g.doJack(sess, strings.Join(args, " ")) } func (g *Game) doJack(sess *net.Session, target string) { p := sess.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 := hacking.Terminals[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] = &hacking.Session{ 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 "" }