Skip to content

Commit

Permalink
New record field loyalty
Browse files Browse the repository at this point in the history
  • Loading branch information
MedeaMelana committed Sep 4, 2013
1 parent 2fc75c0 commit 300dc54
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Magic-Cards/src/Magic/M13.hs
Expand Up @@ -255,6 +255,8 @@ garrukPrimalHunter = mkCard $ do
types =: planeswalkerWithType Garruk
play =: Just (playPermanent [Nothing, Nothing, Just Green, Just Green, Just Green])
activatedAbilities =: [plusOne, minusThree, minusSix]
loyalty =: Just 3
replacementEffects =: [etbWithLoyaltyCounters]
where
plusOne = loyaltyAbility 1 $ \_ you -> do
mkTargetlessTriggerObject you $ \_ -> do
Expand Down
17 changes: 16 additions & 1 deletion Magic/src/Magic/Abilities.hs
Expand Up @@ -19,6 +19,9 @@ module Magic.Abilities (
-- * Constructing triggers
mkTriggerObject, mkTargetlessTriggerObject, onSelfETB,
ifSelfWasOrIsOnBattlefield,

-- * Constructing replacement effects
etbWithLoyaltyCounters
) where

import Magic.Core
Expand All @@ -35,7 +38,7 @@ import Control.Applicative ((<$>), pure)
import Control.Monad (void)

import Data.Boolean ((&&*))
import Data.Label.Pure (get)
import Data.Label.Pure (get, modify)
import Data.Label.PureM (asks)
import Data.Monoid (mempty)

Expand Down Expand Up @@ -160,3 +163,15 @@ ifSelfWasOrIsOnBattlefield f events rSelf you =
where
ok = fst rSelf == Some Battlefield
|| not (null ([ () | DidMoveObject (Just (Some Battlefield, _)) newRef <- events, newRef == rSelf ] :: [()]))



-- CONSTRUCTING REPLACEMENT EFFECTS

etbWithLoyaltyCounters :: ReplacementEffect
etbWithLoyaltyCounters (WillMoveObject (Just fromRef) Battlefield perm) rSelf you
| fromRef == rSelf =
case get (objectPart .^ loyalty) perm of
Just n -> Just $ return [WillMoveObject (Just fromRef) Battlefield (modify (objectPart .^ counters) (++ replicate n Loyalty) perm)]
Nothing -> Nothing
etbWithLoyaltyCounters _ _ _ = Nothing
2 changes: 1 addition & 1 deletion Magic/src/Magic/Object.hs
Expand Up @@ -5,7 +5,7 @@ module Magic.Object (
name, colors, types, owner, controller, timestamp, counters,
tapStatus,
stackItem,
pt, damage, deathtouched,
pt, loyalty, damage, deathtouched,
play, staticKeywordAbilities, layeredEffects, activatedAbilities, triggeredAbilities, replacementEffects,
temporaryEffects, attachedTo,
ObjectOfType(..),
Expand Down
9 changes: 6 additions & 3 deletions Magic/src/Magic/Types.hs
Expand Up @@ -32,7 +32,7 @@ module Magic.Types (
Card(..), Deck,
Object(..),
name, colors, types, owner, controller, timestamp, counters,
pt,
pt, loyalty,
play, staticKeywordAbilities, layeredEffects, activatedAbilities, triggeredAbilities, replacementEffects,
temporaryEffects, attachedTo,
ObjectOfType(..),
Expand Down Expand Up @@ -228,6 +228,9 @@ data Object = Object
-- for creatures
, _pt :: Maybe PT

-- for planeswalkers
, _loyalty :: Maybe Int

--, _mustBeBlocked :: Maybe Bool
--, _mustAttack :: Maybe Bool

Expand Down Expand Up @@ -497,9 +500,9 @@ data Duration
| UntilEndOfTurn
deriving (Eq, Ord, Show, Read, Enum, Bounded)

type ReplacementEffect = OneShotEffect -> Maybe (Magic [OneShotEffect])
type ReplacementEffect =
OneShotEffect -> Contextual (Maybe (Magic [OneShotEffect]))

-- | Arguments: source, controller, event
type TriggeredAbilities = [Event] -> Contextual (View [Magic ()])

data PriorityAction
Expand Down
1 change: 1 addition & 0 deletions Magic/src/Magic/Utils.hs
Expand Up @@ -27,6 +27,7 @@ emptyObject t rOwner = Object
, _counters = mempty

, _pt = Nothing
, _loyalty = Nothing

, _play = Nothing
, _staticKeywordAbilities = []
Expand Down

0 comments on commit 300dc54

Please sign in to comment.