From 1ce67611b54871c7541396399da35e0b8d69f2f5 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sun, 1 May 2022 15:51:15 -0400 Subject: feat(grfn/xanthous): Describe items in hand when wielding Describe the items already in the hand when prompting for which hand to wield an item in Change-Id: Ifdf2703e8695aae5cbf06a3195fb790428954012 Reviewed-on: https://cl.tvl.fyi/c/depot/+/5509 Tested-by: BuildkiteCI Reviewed-by: grfn Autosubmit: grfn --- users/grfn/xanthous/src/Xanthous/App.hs | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'users/grfn') diff --git a/users/grfn/xanthous/src/Xanthous/App.hs b/users/grfn/xanthous/src/Xanthous/App.hs index fdc648dda4..32f03e8392 100644 --- a/users/grfn/xanthous/src/Xanthous/App.hs +++ b/users/grfn/xanthous/src/Xanthous/App.hs @@ -59,7 +59,7 @@ import Xanthous.Entities.Common , wieldableItem, wieldedItems, wielded, itemsWithPosition , removeItemFromPosition, asWieldedItem , wieldedItem, items, Hand (..), describeHand, wieldInHand - , WieldedItem + , WieldedItem, Wielded (..) ) import qualified Xanthous.Entities.Character as Character import Xanthous.Entities.Character hiding (pickUpItem) @@ -296,8 +296,9 @@ handleCommand DescribeInventory = do handleCommand Wield = do + hs <- use $ character . inventory . wielded selectItem $ \(MenuResult (item :: WieldedItem)) -> do - selectHand $ \(MenuResult hand) -> do + selectHand hs $ \(MenuResult hand) -> do prevItems <- character . inventory . wielded %%= wieldInHand hand item character . inventory . backpack <>= fromList (map (view wieldedItem) prevItems) @@ -309,13 +310,26 @@ handleCommand Wield = do selectItem = takeItemFromInventory_ ["wield", "menu"] Cancellable asWieldedItem (say_ ["wield", "nothing"]) - selectHand - = menu_ - ["wield", "hand"] - Cancellable - handsMenu - handsMenu = mapFromList - . map (second $ MenuOption =<< describeHand) + selectHand hs = menu_ ["wield", "hand"] Cancellable $ handsMenu hs + itemsInHand (Hands i _) LeftHand = toList i + itemsInHand (DoubleHanded _) LeftHand = [] + itemsInHand (Hands _ i) RightHand = toList i + itemsInHand (DoubleHanded _) RightHand = [] + itemsInHand (Hands l r) BothHands = toList l <> toList r + itemsInHand (DoubleHanded i) BothHands = [i] + describeItems [] = "" + describeItems is + = " (currently holding " + <> (intercalate " and" $ map (view $ wieldedItem . to description) is) + <> ")" + handsMenu hs = mapFromList + . map (second $ \hand -> + MenuOption + ( describeHand hand + <> describeItems (itemsInHand hs hand) + ) + hand + ) $ [ ('l', LeftHand) , ('r', RightHand) , ('b', BothHands) -- cgit 1.4.1