Move computeStat to GameModel

This commit is contained in:
Emi Simpson 2023-12-05 19:31:30 -05:00
parent a627d87a57
commit 69da0f1dfd
Signed by: Emi
GPG key ID: A12F2C2FFDC3D847
3 changed files with 15 additions and 32 deletions

View file

@ -18,7 +18,6 @@ module GameLogic
) where ) where
import GameModel import GameModel
import Units (computeStat)
import Util (toMaybe, Never, (??), never) import Util (toMaybe, Never, (??), never)
import Data.Maybe (fromMaybe, mapMaybe, isJust) import Data.Maybe (fromMaybe, mapMaybe, isJust)

View file

@ -127,6 +127,7 @@ module GameModel
, ProtoMovementSpecs(..) , ProtoMovementSpecs(..)
, basicMove , basicMove
, forcedMove , forcedMove
, computeStat
) where ) where
import Util (toMaybe, dup, secondClassLensNames, (??)) import Util (toMaybe, dup, secondClassLensNames, (??))
@ -137,7 +138,7 @@ import Control.Monad (join, mfilter)
import Data.Ix (inRange) import Data.Ix (inRange)
import Data.List (intersperse, elemIndex) import Data.List (intersperse, elemIndex)
import Data.List.NonEmpty as NonEmpty (cons, NonEmpty, singleton) import Data.List.NonEmpty as NonEmpty (cons, NonEmpty, singleton)
import Data.Maybe (mapMaybe, catMaybes) import Data.Maybe (mapMaybe, catMaybes, fromMaybe)
import Numeric.Natural (Natural) import Numeric.Natural (Natural)
import Safe (headMay) import Safe (headMay)
import Lens.Micro import Lens.Micro
@ -681,6 +682,19 @@ untapped = not . _movedThisRound
untap :: Character -> Character untap :: Character -> Character
untap = movedThisRound .~ False untap = movedThisRound .~ False
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
FreeMove -> fromMaybe False 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
instance Show BoardState where instance Show BoardState where
show board = join (intersperse "\n" showTiles) ++ '\n':showRound ++ "\n" ++ showCharacters show board = join (intersperse "\n" showTiles) ++ '\n':showRound ++ "\n" ++ showCharacters
where where

View file

@ -1,30 +0,0 @@
module Units
( computeStat
)
where
import GameModel
( baseStats
, BoardState
, CharacterIdentifier
, isElevated
, Stat(..)
, statBonusL
, ixCharacter
)
import Data.Maybe (fromMaybe)
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
FreeMove -> fromMaybe False 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