From 8c661eeede6003ce44da7329c3ac15f003f727ac Mon Sep 17 00:00:00 2001 From: Martijn van Steenbergen Date: Mon, 9 Mar 2015 18:10:52 +0000 Subject: [PATCH] PlayCard now takes an ObjectRef TyCard --- Magic-CLI/src/Magic/Description.hs | 2 +- Magic-Web-Server/src/Magic/Json.hs | 2 +- Magic/src/Magic/Core.hs | 21 ++++++++++++++++++++- Magic/src/Magic/Engine.hs | 10 +++++----- Magic/src/Magic/Types.hs | 2 +- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Magic-CLI/src/Magic/Description.hs b/Magic-CLI/src/Magic/Description.hs index 2349217..7182ea6 100644 --- a/Magic-CLI/src/Magic/Description.hs +++ b/Magic-CLI/src/Magic/Description.hs @@ -75,7 +75,7 @@ nullDesc world (Description (ViewT vt)) = Text.null (runReader vt world) describePriorityAction :: PriorityAction -> Description describePriorityAction a = case a of - PlayCard ro@(zr, _) -> "Play from " <> describeZoneRef zr <> ": " <> describeObjectByRef ro + PlayCard ro@(zr, _) -> "Play from " <> describeZoneRef (Some zr) <> ": " <> describeObjectByRef (someObjectRef ro) ActivateAbility (ro, i) -> "Activate ability " <> sh i <> " of " <> describeObjectByRef ro describePayManaAction :: PayManaAction -> Description diff --git a/Magic-Web-Server/src/Magic/Json.hs b/Magic-Web-Server/src/Magic/Json.hs index 19bb127..7c5bd69 100644 --- a/Magic-Web-Server/src/Magic/Json.hs +++ b/Magic-Web-Server/src/Magic/Json.hs @@ -229,7 +229,7 @@ instance ToJSON StaticKeywordAbility where instance ToJSON PriorityAction where toJSON a = typedObject $ case a of - PlayCard r -> ("playCard", [ "objectRef" .= someObjectRefToJSON r ]) + PlayCard r -> ("playCard", [ "objectRef" .= objectRefToJSON r ]) ActivateAbility r -> ("activateAbility", [ "activatedAbilityRef" .= activatedAbilityRefToJSON r ]) instance ToJSON PayManaAction where diff --git a/Magic/src/Magic/Core.hs b/Magic/src/Magic/Core.hs index 3972b73..2101034 100644 --- a/Magic/src/Magic/Core.hs +++ b/Magic/src/Magic/Core.hs @@ -5,7 +5,7 @@ {-# LANGUAGE GADTs #-} module Magic.Core - ( compileZoneRef, allObjects, askQuestion, debug, object, objectBase, objectPart, anyObject, player, isStackEmpty, viewObject, viewSomeObject, playerHand, + ( compileZoneRef, allObjects, allCards, askQuestion, debug, object, objectBase, objectPart, anyObject, someObjectRef, player, isStackEmpty, viewObject, viewSomeObject, playerHand, allRefsInSomeZone ) where @@ -59,6 +59,22 @@ allObjects = do <> [ ((Some (Graveyard ip), i), c) | (i, CardObject c) <- IdList.toList (_graveyard p) ] +allCards :: View [(ObjectRef TyCard, Object)] +allCards = do + ips <- IdList.toList <$> asks players + sharedObjects <> (concat <$> for ips objectsForPlayer) + where + sharedObjects = + (map (\(i, CardObject c) -> ((Exile, i), c)) . IdList.toList <$> asks exile) + <> + (map (\(i, CardObject c) -> ((Command, i), c)) . IdList.toList <$> asks command) + objectsForPlayer (ip, p) = return $ + [ ((Library ip, i), c) | (i, CardObject c) <- IdList.toList (_library p) ] + <> + [ ((Hand ip, i), c) | (i, CardObject c) <- IdList.toList (_hand p) ] + <> + [ ((Graveyard ip, i), c) | (i, CardObject c) <- IdList.toList (_graveyard p) ] + askQuestion :: (MonadInteract m, MonadView m) => PlayerRef -> Question a -> m a askQuestion p q = do world <- view ask @@ -89,6 +105,9 @@ objectPart = lens getObjectPart modifyObjectPart anyObject :: SomeObjectRef -> World -> Some ObjectOfType anyObject = undefined +someObjectRef :: ObjectRef ty -> SomeObjectRef +someObjectRef (z, i) = (Some z, i) + player :: PlayerRef -> World :-> Player player i = listEl i . players diff --git a/Magic/src/Magic/Engine.hs b/Magic/src/Magic/Engine.hs index 6ffb63d..c512070 100644 --- a/Magic/src/Magic/Engine.hs +++ b/Magic/src/Magic/Engine.hs @@ -427,14 +427,14 @@ collectAvailableActivatedAbilities predicate p = do payCostsOk <- lift (canPayTapCost (tapCost ability) r p) when (predicate ability && ok && payCostsOk) (tell [(r, i)]) -collectPlayableCards :: PlayerRef -> Engine [SomeObjectRef] +collectPlayableCards :: PlayerRef -> Engine [ObjectRef TyCard] collectPlayableCards p = do - objects <- view allObjects + objects <- view allCards execWriterT $ do forM_ objects $ \(r,o) -> do case get play o of Just playAbility -> do - ok <- lift (shouldOfferActivation playAbility r p) + ok <- lift (shouldOfferActivation playAbility (someObjectRef r) p) when ok (tell [r]) Nothing -> return () @@ -452,8 +452,8 @@ executePriorityAction :: PlayerRef -> PriorityAction -> Engine () executePriorityAction p a = do case a of PlayCard r -> do - Just ability <- gets (play . objectBase r) - activate (PriorityActionExecution a) ability r p + Just ability <- gets (play . objectPart . object r) + activate (PriorityActionExecution a) ability (someObjectRef r) p ActivateAbility (r, i) -> do abilities <- gets (activatedAbilities . objectBase r) let ab = abilities !! i diff --git a/Magic/src/Magic/Types.hs b/Magic/src/Magic/Types.hs index e73a875..d488a9f 100644 --- a/Magic/src/Magic/Types.hs +++ b/Magic/src/Magic/Types.hs @@ -523,7 +523,7 @@ type ReplacementEffect = type TriggeredAbilities = [Event] -> Contextual (View [Magic ()]) data PriorityAction - = PlayCard SomeObjectRef + = PlayCard (ObjectRef TyCard) | ActivateAbility ActivatedAbilityRef deriving Show