diff options
Diffstat (limited to 'internal/game/cmd_move.go')
| -rw-r--r-- | internal/game/cmd_move.go | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/internal/game/cmd_move.go b/internal/game/cmd_move.go index 85abbdf..b7cab37 100644 --- a/internal/game/cmd_move.go +++ b/internal/game/cmd_move.go @@ -42,12 +42,34 @@ func (g *Game) doMove(sess *net.Session, dir string, multiplier float64) { targetID := exitDef.Room - _, err = g.World.LoadRoom(targetID) + targetRoom, err := g.World.LoadRoom(targetID) if err != nil { sess.WriteLine("That path seems blocked.") return } + // Warn before walking from a safe room into a dangerous (hazardous) one. + // Dangerous->dangerous never prompts (the current room is already hazardous). + if targetRoom.Hazard != "" && room.Hazard == "" && p.OptionBool("danger_warning") { + if p.PendingDangerDir == dir { + p.PendingDangerDir = "" + } else { + p.PendingDangerDir = dir + p.WalkSequence = nil + sess.State = net.StateDangerConfirm + name := targetRoom.Hazard + if hz, herr := g.World.LoadHazard(targetRoom.Hazard); herr == nil && hz.Name != "" { + name = hz.Name + } + sess.WriteLine(g.colorize(sess, "warning", fmt.Sprintf("WARNING: that area is exposed to %s.", name))) + sess.WriteLine("Enter anyway? [Y/n]") + return + } + } + + p.MovePendingFlags = exitDef.SetFlags + p.MovePendingPlayerFlags = exitDef.SetPlayerFlags + inCombat := combat.GetCombat(p.Name) != nil if !inCombat && p.Action != nil { @@ -108,6 +130,8 @@ func (g *Game) moveTicks(p *player.Player, multiplier float64) int { func (g *Game) completeMove(sess *net.Session, p *player.Player) { exitDir := p.MoveDirection targetID := p.MoveTarget + pendingFlags := p.MovePendingFlags + pendingPlayerFlags := p.MovePendingPlayerFlags p.ClearMoveState() @@ -127,7 +151,16 @@ func (g *Game) completeMove(sess *net.Session, p *player.Player) { oldRoom := p.RoomID p.RoomID = targetID + p.HazardTimer = 0 p.Stats.RecordRoomVisit(targetID) + + g.cancelEnterSeq(p.Name) + if p.CutsceneRoom != 0 && p.CutsceneRoom == oldRoom { + p.CutsceneRoom = 0 + } + if len(pendingFlags) > 0 || len(pendingPlayerFlags) > 0 { + g.applyFlagMutations(p, pendingFlags, pendingPlayerFlags) + } g.AccountStore.SaveCharacter(p) g.World.SeedGroundItems(p.RoomID) @@ -179,6 +212,35 @@ func (g *Game) executeMove(sess *net.Session, args []string, rawInput string) { g.doMove(sess, strings.TrimSpace(rawInput), 1.0) } +// handleDangerConfirm processes the [Y/n] reply to the dangerous-area warning. +// Pressing return (empty), "y", or "yes" enters; anything else cancels. +func (g *Game) handleDangerConfirm(sess *net.Session, input string) { + p := sess.Player + if p == nil { + sess.State = net.StateGame + g.writePrompt(sess) + return + } + + dir := p.PendingDangerDir + choice := strings.TrimSpace(strings.ToLower(input)) + sess.State = net.StateGame + + if choice != "" && choice != "y" && choice != "yes" { + p.PendingDangerDir = "" + sess.WriteLine("You decide against it.") + g.writePrompt(sess) + return + } + + if dir == "" { + g.writePrompt(sess) + return + } + g.doMove(sess, dir, 1.0) + g.writePrompt(sess) +} + func (g *Game) seedRoomObjects(roomID int) { room, err := g.World.LoadRoom(roomID) if err != nil { @@ -195,6 +257,9 @@ func (g *Game) seedRoomObjects(roomID int) { continue } g.World.SetObjName(roomID, obj.ID, def.Name) + if len(def.Aliases) > 0 { + g.World.SetObjAliases(roomID, obj.ID, def.Aliases) + } if len(obj.WanderRooms) > 0 { g.World.SetObjWander(roomID, obj.ID, obj.WanderRooms, obj.WanderInterval) } |
