about summary refs log tree commit diff
path: root/src/Xanthous/App.hs
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2020-02-08T18·42-0500
committerGriffin Smith <root@gws.fyi>2020-02-08T18·42-0500
commit782d3880c8da35b48276a874d396d24ca6dc7004 (patch)
tree600fdc2d397db39170ee8057951156928684f2e2 /src/Xanthous/App.hs
parent308c7eb4f6cd1e7bb333e438bb4e6c904d9c20ee (diff)
Block doors being closed on gormlaks
Prevent closing doors when there's a gormlak or other entity with the
blocksObject attribute set to true on the same tile. There's a message
sent here which is grammatically incorrect - it says "The a gormlak
blocks the door" - should fix that later.
Diffstat (limited to 'src/Xanthous/App.hs')
-rw-r--r--src/Xanthous/App.hs23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/Xanthous/App.hs b/src/Xanthous/App.hs
index 0d4f973d7120..d786eb29daa3 100644
--- a/src/Xanthous/App.hs
+++ b/src/Xanthous/App.hs
@@ -26,6 +26,7 @@ import           Xanthous.Data
                  ( move
                  , Dimensions'(Dimensions)
                  , positioned
+                 , position
                  , Position
                  , Ticks
                  , (|*|)
@@ -195,12 +196,32 @@ handleCommand Close = do
   prompt_ @'DirectionPrompt ["close", "prompt"] Cancellable
     $ \(DirectionResult dir) -> do
       pos <- move dir <$> use characterPosition
-      doors <- uses entities $ entitiesAtPositionWithType @Door pos
+      (nonDoors, doors) <- uses entities
+        $ partitionEithers
+        . toList
+        . map ( (matching . aside $ _SomeEntity @Door)
+              . over _2 (view positioned)
+              )
+        . EntityMap.atPositionWithIDs pos
       if | null doors -> say_ ["close", "nothingToClose"]
          | all (view $ _2 . closed) doors -> say_ ["close", "alreadyClosed"]
+         | any (blocksObject . snd) nonDoors ->
+           say ["close", "blocked"]
+           $ object [ "entityDescriptions"
+                    A..= ( toSentence . map description . filter blocksObject
+                         . map snd
+                         ) nonDoors
+                    , "blockOrBlocks"
+                    A..= ( if length nonDoors == 1
+                           then "blocks"
+                           else "block"
+                         :: Text)
+                    ]
          | otherwise -> do
              for_ doors $ \(eid, _) ->
                entities . ix eid . positioned . _SomeEntity . closed .= True
+             for_ nonDoors $ \(eid, _) ->
+               entities . ix eid . position %= move dir
              say_ ["close", "success"]
       pure ()
   stepGame -- TODO