From 782d3880c8da35b48276a874d396d24ca6dc7004 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sat, 8 Feb 2020 13:42:51 -0500 Subject: 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. --- src/Xanthous/App.hs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/Xanthous/App.hs') diff --git a/src/Xanthous/App.hs b/src/Xanthous/App.hs index 0d4f973d71..d786eb29da 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 -- cgit 1.4.1