diff --git a/src/Units.hs b/src/Units.hs index 1ff11da..4cbbe2f 100644 --- a/src/Units.hs +++ b/src/Units.hs @@ -1,30 +1,19 @@ module Units ( computeStat - , AttackT(..) - , anyTarget - , buildAttack - , SelfAbilityT(..) - , mkSelfAbility ) where import GameModel - ( Attack(..) - , baseStats + ( baseStats , BoardState , CharacterIdentifier - , Choice - , DamageType - , Effect(..) , isElevated , Stat(..) , statBonusL - , mkChoice, ixCharacter + , ixCharacter ) -import Util ((??)) import Data.Maybe (fromMaybe) -import Numeric.Natural (Natural) import Lens.Micro computeStat :: BoardState -> CharacterIdentifier -> Stat a -> a @@ -38,34 +27,4 @@ computeStat board cid stat = case stat of Just statB -> Just $ statB board cid stat Nothing -> Nothing elevationBonus :: Int - elevationBonus = if isElevated board cid then 1 else 0 - -data AttackT = AttackT - { tName :: String - , tRange :: (Natural, Natural) - , tValidTargets :: BoardState -> CharacterIdentifier -> Bool - , tMelee :: Bool - , tDamageType :: DamageType - , tDamageAmount :: Natural - , tHeadshotEffects :: [CharacterIdentifier -> Effect] - , tStandardEffects :: [CharacterIdentifier -> Effect] - } - -anyTarget :: BoardState -> CharacterIdentifier -> Bool -anyTarget = const $ const True - -buildAttack :: AttackT -> CharacterIdentifier -> Choice -buildAttack (AttackT {..}) attacker = mkChoice tName [targetEffect] - where - attackDetails = - Attack <$> sequence tHeadshotEffects ?? tMelee <*> sequence tStandardEffects ?? tDamageType ?? tDamageAmount - attackEffect target = [ResolveAttack attacker (attackDetails target) target] - targetEffect = Target attacker tRange tValidTargets attackEffect - -data SelfAbilityT = SelfAbilityT - { tName :: String - , tEffects :: [CharacterIdentifier -> Effect] - } - -mkSelfAbility :: SelfAbilityT -> CharacterIdentifier -> Choice -mkSelfAbility (SelfAbilityT {..}) = mkChoice tName <$> sequence tEffects \ No newline at end of file + elevationBonus = if isElevated board cid then 1 else 0 \ No newline at end of file diff --git a/src/Units/Carcass.hs b/src/Units/Carcass.hs index 0c2543e..880d9fb 100644 --- a/src/Units/Carcass.hs +++ b/src/Units/Carcass.hs @@ -16,7 +16,7 @@ import GameModel , Token(..) , Trigger(..) ) -import Units +import Units.Components ( AttackT(..) , anyTarget , buildAttack diff --git a/src/Units/Components.hs b/src/Units/Components.hs new file mode 100644 index 0000000..2ca7512 --- /dev/null +++ b/src/Units/Components.hs @@ -0,0 +1,51 @@ +module Units.Components + ( AttackT(..) + , anyTarget + , buildAttack + , SelfAbilityT(..) + , mkSelfAbility + ) + where + +import GameModel + ( Attack(..) + , BoardState + , CharacterIdentifier + , Choice + , DamageType + , Effect(..) + , mkChoice + ) +import Util ((??)) + +import Numeric.Natural (Natural) + +data AttackT = AttackT + { tName :: String + , tRange :: (Natural, Natural) + , tValidTargets :: BoardState -> CharacterIdentifier -> Bool + , tMelee :: Bool + , tDamageType :: DamageType + , tDamageAmount :: Natural + , tHeadshotEffects :: [CharacterIdentifier -> Effect] + , tStandardEffects :: [CharacterIdentifier -> Effect] + } + +anyTarget :: BoardState -> CharacterIdentifier -> Bool +anyTarget = const $ const True + +buildAttack :: AttackT -> CharacterIdentifier -> Choice +buildAttack (AttackT {..}) attacker = mkChoice tName [targetEffect] + where + attackDetails = + Attack <$> sequence tHeadshotEffects ?? tMelee <*> sequence tStandardEffects ?? tDamageType ?? tDamageAmount + attackEffect target = [ResolveAttack attacker (attackDetails target) target] + targetEffect = Target attacker tRange tValidTargets attackEffect + +data SelfAbilityT = SelfAbilityT + { tName :: String + , tEffects :: [CharacterIdentifier -> Effect] + } + +mkSelfAbility :: SelfAbilityT -> CharacterIdentifier -> Choice +mkSelfAbility (SelfAbilityT {..}) = mkChoice tName <$> sequence tEffects \ No newline at end of file diff --git a/src/Units/Debug.hs b/src/Units/Debug.hs index b73c08a..09e045c 100644 --- a/src/Units/Debug.hs +++ b/src/Units/Debug.hs @@ -16,7 +16,7 @@ import GameModel , Trigger(..), ixCharacter, tokenCount, ofToken , forcedMove, ForcedMoveType (Pull), Player (..) ) -import Units +import Units.Components ( AttackT(..) , anyTarget , buildAttack