aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_dig.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/cmd_dig.go')
-rw-r--r--internal/game/cmd_dig.go76
1 files changed, 59 insertions, 17 deletions
diff --git a/internal/game/cmd_dig.go b/internal/game/cmd_dig.go
index e7023b2..653f045 100644
--- a/internal/game/cmd_dig.go
+++ b/internal/game/cmd_dig.go
@@ -23,13 +23,13 @@ func (g *Game) executeDig(sess *net.Session, args []string, rawInput string) {
return
}
if len(args) == 0 {
- sess.WriteLine("Dig where? (north/south/east/west/up/down)")
+ sess.WriteLine("Dig where? (n/s/e/w/ne/nw/se/sw/u/d)")
return
}
dir := g.World.ResolveExit(args[0])
if dir == "" {
- sess.WriteLine("Invalid direction. Use north/south/east/west/up/down.")
+ sess.WriteLine("Invalid direction. Use n/s/e/w/ne/nw/se/sw/u/d.")
return
}
@@ -82,6 +82,49 @@ func (g *Game) executeDig(sess *net.Session, args []string, rawInput string) {
}
sess.WriteLine(fmt.Sprintf("That spot is already occupied by %s. Created a two-way link instead.", conflictName))
+
+ oldRoom := p.RoomID
+ p.ClearMoveState()
+ if g.Combat.Get(p.Name) != nil {
+ g.stopCombat(p.Name)
+ }
+ p.Action = nil
+ g.cancelRest(p.Name)
+ g.cancelEnterSeq(p.Name)
+ if p.EnterSeqRoom != 0 && p.EnterSeqRoom == oldRoom {
+ p.EnterSeqRoom = 0
+ }
+ if ss, ok := g.safespot.Get(p.Name); ok {
+ g.forceLeaveSafespot(sess, p, &ss, "")
+ }
+
+ p.RoomID = conflictID
+ p.HazardTimer = 0
+ p.Stats.RecordRoomVisit(conflictID)
+ g.AccountStore.SaveCharacter(p)
+
+ g.World.SeedGroundItems(conflictID)
+ g.seedRoomMobs(conflictID)
+ g.seedRoomObjects(conflictID)
+
+ if g.Hub != nil {
+ for _, other := range g.Hub.PlayersInRoom(oldRoom) {
+ if other != sess {
+ other.WriteLine(fmt.Sprintf("%s digs to the %s and vanishes.", p.Name, dir))
+ }
+ }
+ g.Hub.EnterRoom(sess, conflictID)
+ for _, other := range g.Hub.PlayersInRoom(conflictID) {
+ if other != sess {
+ other.WriteLine(fmt.Sprintf("%s appears from a freshly dug tunnel.", p.Name))
+ }
+ }
+ }
+
+ sess.WriteLine(fmt.Sprintf("You step through the new link to %s.", conflictName))
+ g.doLook(sess)
+ g.runEnterSteps(sess, conflictID)
+ g.checkAggro(sess)
return
}
@@ -220,22 +263,11 @@ func findNextRoomID(currentRoomPath string) (int, error) {
}
}
-var gridDeltas = map[world.ExitDir][2]int{
- world.North: {0, -1},
- world.South: {0, 1},
- world.East: {1, 0},
- world.West: {-1, 0},
-}
-
-func (g *Game) findGridConflict(fromRoomID int, dir world.ExitDir) int {
- delta, ok := gridDeltas[dir]
- if !ok {
- return 0
- }
+func (g *Game) buildGridFrom(fromRoomID int) (coord map[int][2]int, roomAt map[[2]int]int) {
roomIndex := g.World.RoomIndex()
- coord := map[int][2]int{fromRoomID: {0, 0}}
- roomAt := map[[2]int]int{{0, 0}: fromRoomID}
+ coord = map[int][2]int{fromRoomID: {0, 0}}
+ roomAt = map[[2]int]int{{0, 0}: fromRoomID}
queue := []int{fromRoomID}
for len(queue) > 0 {
@@ -255,7 +287,7 @@ func (g *Game) findGridConflict(fromRoomID int, dir world.ExitDir) int {
if ed == world.Up || ed == world.Down {
continue
}
- gd, ok := gridDeltas[ed]
+ gd, ok := world.DirectionDeltas[ed]
if !ok {
continue
}
@@ -272,6 +304,16 @@ func (g *Game) findGridConflict(fromRoomID int, dir world.ExitDir) int {
queue = append(queue, target)
}
}
+ return coord, roomAt
+}
+
+func (g *Game) findGridConflict(fromRoomID int, dir world.ExitDir) int {
+ delta, ok := world.DirectionDeltas[dir]
+ if !ok {
+ return 0
+ }
+
+ _, roomAt := g.buildGridFrom(fromRoomID)
targetCoord := [2]int{delta[0], delta[1]}
if occupier, ok := roomAt[targetCoord]; ok && occupier != fromRoomID {