maleghast-engine/src/Units.hs

70 lines
2.0 KiB
Haskell

module Units
( computeStat
, AttackT(..)
, anyTarget
, buildAttack
, SelfAbilityT(..)
, mkSelfAbility
)
where
import GameModel
( Attack(..)
, baseStats
, BoardState
, CharacterIdentifier
, Choice
, DamageType
, Effect(..)
, isElevated
, Stat(..)
, statBonusL
, mkChoice, ixCharacter
)
import Util ((??))
import Data.Maybe (fromMaybe)
import Numeric.Natural (Natural)
import Lens.Micro
computeStat :: BoardState -> CharacterIdentifier -> Stat a -> a
computeStat board cid stat = case stat of
AttackDice -> 1 + elevationBonus + fromMaybe 0 specialtyBonus
DefenseDice -> 0 + elevationBonus + fromMaybe 0 specialtyBonus
where
statBonuses = ixCharacter cid . baseStats . statBonusL
specialtyBonus = case board ^? statBonuses 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