module Dodge.Creature.Statistics ( getCrStrength, getCrDexterity, ) where import Data.IntMap.Merge.Strict import Data.Maybe import Dodge.Creature.Test import Dodge.Data.Creature import qualified IntMapHelp as IM import LensHelp getCrDexterity :: Creature -> Int getCrDexterity cr = _dexterity (_crStatistics cr) getCrStrength :: Creature -> Int getCrStrength cr = strFromHeldItem cr + strFromEquipment cr + _strength (_crStatistics cr) strFromEquipment :: Creature -> Int strFromEquipment = sum . fmap equipmentStrValue . crCurrentEquipment equipmentStrValue :: Item -> Int equipmentStrValue itm = case _iyBase $ _itType itm of EQUIP FRONTARMOUR -> negate 3 EQUIP POWERLEGS -> 3 _ -> 0 crCurrentEquipment :: Creature -> IM.IntMap Item crCurrentEquipment cr = merge dropMissing dropMissing (zipWithMatched (\_ _ itm -> itm)) (_crInvEquipped cr) (_crInv cr) strFromHeldItem :: Creature -> Int strFromHeldItem cr | _posture (_crStance cr) == Aiming || crIsReloading cr = negate $ fromMaybe 0 $ cr ^? crInv . ix (crSel cr) . itUse . heldAim . aimWeight | otherwise = 0