Move computeStat to GameModel
This commit is contained in:
parent
a627d87a57
commit
69da0f1dfd
|
@ -18,7 +18,6 @@ module GameLogic
|
|||
) where
|
||||
|
||||
import GameModel
|
||||
import Units (computeStat)
|
||||
import Util (toMaybe, Never, (??), never)
|
||||
|
||||
import Data.Maybe (fromMaybe, mapMaybe, isJust)
|
||||
|
|
|
@ -127,6 +127,7 @@ module GameModel
|
|||
, ProtoMovementSpecs(..)
|
||||
, basicMove
|
||||
, forcedMove
|
||||
, computeStat
|
||||
) where
|
||||
|
||||
import Util (toMaybe, dup, secondClassLensNames, (??))
|
||||
|
@ -137,7 +138,7 @@ import Control.Monad (join, mfilter)
|
|||
import Data.Ix (inRange)
|
||||
import Data.List (intersperse, elemIndex)
|
||||
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 Safe (headMay)
|
||||
import Lens.Micro
|
||||
|
@ -681,6 +682,19 @@ untapped = not . _movedThisRound
|
|||
untap :: Character -> Character
|
||||
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
|
||||
show board = join (intersperse "\n" showTiles) ++ '\n':showRound ++ "\n" ++ showCharacters
|
||||
where
|
||||
|
|
30
src/Units.hs
30
src/Units.hs
|
@ -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
|
Loading…
Reference in a new issue