Split unit components into seperate module

This commit is contained in:
Emi Simpson 2023-12-05 17:39:37 -05:00
parent 9c80191752
commit 2461dcfb07
Signed by: Emi
GPG key ID: A12F2C2FFDC3D847
4 changed files with 56 additions and 46 deletions

View file

@ -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
@ -39,33 +28,3 @@ computeStat board cid stat = case stat of
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

View file

@ -16,7 +16,7 @@ import GameModel
, Token(..)
, Trigger(..)
)
import Units
import Units.Components
( AttackT(..)
, anyTarget
, buildAttack

51
src/Units/Components.hs Normal file
View file

@ -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

View file

@ -16,7 +16,7 @@ import GameModel
, Trigger(..), ixCharacter, tokenCount, ofToken
, forcedMove, ForcedMoveType (Pull), Player (..)
)
import Units
import Units.Components
( AttackT(..)
, anyTarget
, buildAttack