Split unit components into seperate module
This commit is contained in:
parent
9c80191752
commit
2461dcfb07
45
src/Units.hs
45
src/Units.hs
|
@ -1,30 +1,19 @@
|
||||||
module Units
|
module Units
|
||||||
( computeStat
|
( computeStat
|
||||||
, AttackT(..)
|
|
||||||
, anyTarget
|
|
||||||
, buildAttack
|
|
||||||
, SelfAbilityT(..)
|
|
||||||
, mkSelfAbility
|
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
import GameModel
|
import GameModel
|
||||||
( Attack(..)
|
( baseStats
|
||||||
, baseStats
|
|
||||||
, BoardState
|
, BoardState
|
||||||
, CharacterIdentifier
|
, CharacterIdentifier
|
||||||
, Choice
|
|
||||||
, DamageType
|
|
||||||
, Effect(..)
|
|
||||||
, isElevated
|
, isElevated
|
||||||
, Stat(..)
|
, Stat(..)
|
||||||
, statBonusL
|
, statBonusL
|
||||||
, mkChoice, ixCharacter
|
, ixCharacter
|
||||||
)
|
)
|
||||||
import Util ((??))
|
|
||||||
|
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
import Numeric.Natural (Natural)
|
|
||||||
import Lens.Micro
|
import Lens.Micro
|
||||||
|
|
||||||
computeStat :: BoardState -> CharacterIdentifier -> Stat a -> a
|
computeStat :: BoardState -> CharacterIdentifier -> Stat a -> a
|
||||||
|
@ -39,33 +28,3 @@ computeStat board cid stat = case stat of
|
||||||
Nothing -> Nothing
|
Nothing -> Nothing
|
||||||
elevationBonus :: Int
|
elevationBonus :: Int
|
||||||
elevationBonus = if isElevated board cid then 1 else 0
|
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
|
|
|
@ -16,7 +16,7 @@ import GameModel
|
||||||
, Token(..)
|
, Token(..)
|
||||||
, Trigger(..)
|
, Trigger(..)
|
||||||
)
|
)
|
||||||
import Units
|
import Units.Components
|
||||||
( AttackT(..)
|
( AttackT(..)
|
||||||
, anyTarget
|
, anyTarget
|
||||||
, buildAttack
|
, 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
|
, Trigger(..), ixCharacter, tokenCount, ofToken
|
||||||
, forcedMove, ForcedMoveType (Pull), Player (..)
|
, forcedMove, ForcedMoveType (Pull), Player (..)
|
||||||
)
|
)
|
||||||
import Units
|
import Units.Components
|
||||||
( AttackT(..)
|
( AttackT(..)
|
||||||
, anyTarget
|
, anyTarget
|
||||||
, buildAttack
|
, buildAttack
|
||||||
|
|
Loading…
Reference in a new issue