Browse files

Partially implemented collectActions

  • Loading branch information...
1 parent 4431fd4 commit 2d2be226335feea486cff39946b6c295ff2202ce @MedeaMelana committed Nov 5, 2012
Showing with 21 additions and 4 deletions.
  1. +10 −1 Core.hs
  2. +7 −1 Engine.hs
  3. +4 −2 Types.hs
View
11 Core.hs
@@ -3,7 +3,7 @@
module Core
( compileZoneRef
- , evaluateTargetList, singleTarget, (<?>), askMagicTargets, allTargets
+ , evaluateTargetList, singleTarget, (<?>), askMagicTargets, allTargets, allObjects
, module Types
) where
@@ -74,3 +74,12 @@ allTargets = do
os <- IdList.ids <$> asks (compileZoneRef zr)
return (map (\o -> (zr, o)) os)
return (map TargetPlayer ps ++ map TargetObject (concat oss))
+
+allObjects :: Magic [(ObjectRef, Object)]
+allObjects = do
+ ps <- IdList.ids <$> asks players
+ let zrs = [Exile, Battlefield, Stack, Command] ++
+ [ z p | z <- [Library, Hand, Graveyard], p <- ps ]
+ fmap concat $ forM zrs $ \zr -> do
+ ios <- IdList.toList <$> asks (compileZoneRef zr)
+ return (map (\(i,o) -> ((zr,i),o)) ios)
View
8 Engine.hs
@@ -350,7 +350,13 @@ object :: ObjectRef -> World :-> Object
object (zoneRef, i) = compileZoneRef zoneRef .^ listEl i
collectActions :: PlayerRef -> Engine [PriorityAction]
-collectActions = undefined
+collectActions p = do
+ objects <- executeMagic allObjects
+ execWriterT $ do
+ for objects $ \(r,o) -> do
+ let Just playAbility = get play o
+ ok <- lift $ executeMagic (view (get available (playAbility r p)))
+ when ok (tell [PlayCard r])
executeAction :: Ability -> ObjectRef -> PlayerRef -> Engine ()
executeAction ability rSource activatorId = do
View
6 Types.hs
@@ -44,7 +44,9 @@ module Types (
PlaneswalkerSubtype(..),
-- * Abilities
- Ability, ClosedAbility(..), Action(..), StackItem, ManaCost(..), AdditionalCost(..),
+ Ability,
+ ClosedAbility(..), available, manaCost, additionalCosts, effect,
+ Action(..), StackItem, ManaCost(..), AdditionalCost(..),
StaticKeywordAbility(..), ContinuousEffect(..), Layer(..),
PriorityAction(..),
@@ -463,4 +465,4 @@ data Ask a where
view :: View a -> Magic a
view v = ReaderT $ return . runIdentity . runReaderT v
-$(mkLabels [''World, ''Player, ''Object, ''ObjectTypes, ''Action])
+$(mkLabels [''World, ''Player, ''Object, ''ObjectTypes, ''Action, ''ClosedAbility])

0 comments on commit 2d2be22

Please sign in to comment.