Refactor
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
module Dodge.Creature.Action.Movement
|
||||
where
|
||||
import Dodge.Data
|
||||
import Geometry
|
||||
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Control.Lens
|
||||
|
||||
strafeTo :: Float -> Point2 -> Int -> World -> World
|
||||
strafeTo speed targPos cid w = over (creatures . ix cid . crPos) (+.+ q) w
|
||||
where q = (*.*) (speed * equipFactor * wpFactor)
|
||||
$ safeNormalizeV $ (targPos -.- _crPos cr)
|
||||
equipFactor = product $ map equipSpeed $ IM.elems $ _crInv $ _creatures w IM.! cid
|
||||
cr = _creatures w IM.! cid
|
||||
wpFactor = _itAimingSpeed (_crInv cr IM.! _crInvSel cr)
|
||||
|
||||
{- Determine the speed modifier of an item. -}
|
||||
equipSpeed :: Item -> Float
|
||||
equipSpeed NoItem = 1
|
||||
equipSpeed it | _itIdentity it == FrontArmour = 0.75
|
||||
| _itIdentity it == FlameShield = 0.75
|
||||
| otherwise = 1
|
||||
@@ -12,7 +12,10 @@ import Data.Maybe (fromMaybe)
|
||||
useItem :: Int -> World -> World
|
||||
useItem n w = equippedItemEffect n w
|
||||
|
||||
tryUseItem :: Int -> World -> World
|
||||
tryUseItem
|
||||
:: Int -- ^ Creature id
|
||||
-> World
|
||||
-> World
|
||||
tryUseItem cid w = case w ^? creatures . ix cid of
|
||||
Just cr -> itemEffect cid (_crInv cr IM.! _crInvSel cr) w
|
||||
Nothing -> w
|
||||
@@ -20,11 +23,15 @@ tryUseItem cid w = case w ^? creatures . ix cid of
|
||||
equippedItemEffect :: Int -> World -> World
|
||||
equippedItemEffect n w = itemEffect n it w
|
||||
where
|
||||
c = (_creatures w IM.! n)
|
||||
c = _creatures w IM.! n
|
||||
it = _crInv c IM.! _crInvSel c
|
||||
|
||||
itemEffect :: Int -> Item -> World -> World
|
||||
itemEffect n (Consumable {_cnEffect=eff }) w = fromMaybe w $ fmap (rmSelectedInvItem n) $ eff n w
|
||||
itemEffect
|
||||
:: Int -- ^ Creature id (I am almost certain)
|
||||
-> Item
|
||||
-> World
|
||||
-> World
|
||||
itemEffect n (Consumable {_cnEffect=eff }) w = fromMaybe w $ rmSelectedInvItem n <$> eff n w
|
||||
itemEffect n (Weapon {_wpFire=eff}) w = eff n w
|
||||
itemEffect n (Throwable {_twFire = eff}) w = eff n w
|
||||
itemEffect _ _ w = w
|
||||
|
||||
Reference in New Issue
Block a user