Split unit components into seperate module
This commit is contained in:
parent
9c80191752
commit
2461dcfb07
47
src/Units.hs
47
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
|
||||
elevationBonus = if isElevated board cid then 1 else 0
|
|
@ -16,7 +16,7 @@ import GameModel
|
|||
, Token(..)
|
||||
, Trigger(..)
|
||||
)
|
||||
import Units
|
||||
import Units.Components
|
||||
( AttackT(..)
|
||||
, anyTarget
|
||||
, buildAttack
|
||||
|
|
51
src/Units/Components.hs
Normal file
51
src/Units/Components.hs
Normal 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
|
|
@ -16,7 +16,7 @@ import GameModel
|
|||
, Trigger(..), ixCharacter, tokenCount, ofToken
|
||||
, forcedMove, ForcedMoveType (Pull), Player (..)
|
||||
)
|
||||
import Units
|
||||
import Units.Components
|
||||
( AttackT(..)
|
||||
, anyTarget
|
||||
, buildAttack
|
||||
|
|
Loading…
Reference in a new issue