80 lines
2.1 KiB
Haskell
80 lines
2.1 KiB
Haskell
module Units.Components
|
|
( AttackT(..)
|
|
, ProtoEffect
|
|
, anyTarget
|
|
, buildAttack
|
|
, SelfAbilityT(..)
|
|
, mkSelfAbility
|
|
, inflictTokens
|
|
, push
|
|
, pull
|
|
)
|
|
where
|
|
|
|
import GameModel
|
|
( Attack(..)
|
|
, BoardState
|
|
, CharacterIdentifier
|
|
, Choice
|
|
, DamageType
|
|
, Effect(..)
|
|
, mkChoice, Token, forcedMove, ForcedMoveType (..), owner
|
|
)
|
|
|
|
import Numeric.Natural (Natural)
|
|
|
|
-------------------------
|
|
-- Attacks & Abilities --
|
|
-------------------------
|
|
|
|
data AttackT = AttackT
|
|
{ tName :: String
|
|
, tRange :: (Natural, Natural)
|
|
, tValidTargets :: BoardState -> CharacterIdentifier -> Bool
|
|
, tMelee :: Bool
|
|
, tDamageType :: DamageType
|
|
, tDamageAmount :: Natural
|
|
, tHeadshotEffects :: [ProtoEffect]
|
|
, tStandardEffects :: [ProtoEffect]
|
|
}
|
|
|
|
anyTarget :: BoardState -> CharacterIdentifier -> Bool
|
|
anyTarget = const $ const True
|
|
|
|
buildAttack :: AttackT -> CharacterIdentifier -> Choice
|
|
buildAttack (AttackT {..}) attacker = mkChoice tName [targetEffect]
|
|
where
|
|
attackDetails target = Attack
|
|
((sequence $ sequence tHeadshotEffects attacker) target)
|
|
tMelee
|
|
((sequence $ sequence tStandardEffects attacker) target)
|
|
tDamageType
|
|
tDamageAmount
|
|
attackEffect target = [ResolveAttack attacker (attackDetails target) target]
|
|
targetEffect = Target attacker tRange tValidTargets attackEffect
|
|
|
|
data SelfAbilityT = SelfAbilityT
|
|
{ tName :: String
|
|
, tEffects :: [ProtoEffect]
|
|
}
|
|
|
|
mkSelfAbility :: SelfAbilityT -> CharacterIdentifier -> Choice
|
|
mkSelfAbility (SelfAbilityT {..}) cid = mkChoice tName (sequence (sequence tEffects cid) cid)
|
|
|
|
-----------------------------
|
|
--------- Effects -----------
|
|
-----------------------------
|
|
|
|
type ProtoEffect = CharacterIdentifier -> CharacterIdentifier -> Effect
|
|
|
|
inflictTokens :: Num n => Token n -> n -> ProtoEffect
|
|
inflictTokens tokenType tokenCount _ = InflictTokens tokenType tokenCount
|
|
|
|
genericShift :: ForcedMoveType -> Natural -> ProtoEffect
|
|
genericShift fmType amount puller = forcedMove fmType amount (owner puller) (Left puller)
|
|
|
|
push :: Natural -> ProtoEffect
|
|
push = genericShift Push
|
|
|
|
pull :: Natural -> ProtoEffect
|
|
pull = genericShift Pull |