Cleanup
This commit is contained in:
@@ -1,97 +1,101 @@
|
||||
module Dodge.Creature.Impulse.UseItem
|
||||
( useItem
|
||||
, useLeftItem
|
||||
, itemEffect
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Luse
|
||||
import Dodge.Cuse
|
||||
import Dodge.Euse
|
||||
import Dodge.Inventory
|
||||
import Dodge.Reloading
|
||||
import Dodge.Item.Location
|
||||
import Dodge.HeldUse
|
||||
module Dodge.Creature.Impulse.UseItem (
|
||||
useItem,
|
||||
useLeftItem,
|
||||
itemEffect,
|
||||
) where
|
||||
|
||||
import qualified IntMapHelp as IM
|
||||
import qualified Data.Map.Strict as M
|
||||
import qualified SDL
|
||||
--import qualified Data.IntSet as IS
|
||||
import Control.Lens
|
||||
import qualified Data.Map.Strict as M
|
||||
import Data.Maybe
|
||||
import Dodge.Cuse
|
||||
import Dodge.Data
|
||||
import Dodge.Euse
|
||||
import Dodge.HeldUse
|
||||
import Dodge.Inventory
|
||||
import Dodge.Item.Location
|
||||
import Dodge.Luse
|
||||
import Dodge.Reloading
|
||||
import qualified IntMapHelp as IM
|
||||
import qualified SDL
|
||||
|
||||
useItem :: Creature -> World -> World
|
||||
useItem cr' w = fromMaybe (f w) $ do
|
||||
cr <- w ^? cWorld . creatures . ix (_crID cr')
|
||||
cr <- w ^? cWorld . creatures . ix (_crID cr')
|
||||
it <- cr ^? crInv . ix (crSel cr)
|
||||
return $ itemEffect cr it w
|
||||
where
|
||||
f = cWorld . creatures . ix (_crID cr') . crHammerPosition .~ HammerDown
|
||||
|
||||
itemEffect :: Creature -> Item -> World -> World
|
||||
itemEffect cr it w = case it ^? itUse of
|
||||
Just RightUse {_rUse = eff,_useMods = usemods}
|
||||
-> hammerTest $ tryReload cr it w $ foldr ($) (useHeld eff) (useMod usemods) it cr
|
||||
Just LeftUse {} -> doequipmentchange
|
||||
Just EquipUse{} -> doequipmentchange
|
||||
itemEffect cr it w = case it ^. itUse of
|
||||
RightUse{_rUse = eff, _useMods = usemods} ->
|
||||
hammerTest $ tryReload cr it w $ foldr ($) (useHeld eff) (useMod usemods) it cr
|
||||
LeftUse{} -> doequipmentchange
|
||||
EquipUse{} -> doequipmentchange
|
||||
-- ConsumeUse will cause problems if the item is not selected
|
||||
Just (ConsumeUse eff) -> setuhamdown $ hammerTest $ useC eff it cr . rmInvItem (_crID cr) (crSel cr)
|
||||
Just NoUse -> setuhamdown w
|
||||
Nothing -> setuhamdown w
|
||||
(ConsumeUse eff _) -> setuhamdown $ hammerTest $ useC eff it cr . rmInvItem (_crID cr) (crSel cr)
|
||||
CraftUse{} -> setuhamdown w
|
||||
where
|
||||
hammerTest f = case _crHammerPosition cr of
|
||||
HammerUp -> f w
|
||||
_ -> w & setuhamdown
|
||||
setuhamdown = cWorld . creatures . ix (_crID cr) . crHammerPosition .~ HammerDown
|
||||
doequipmentchange = setuhamdown $ hammerTest (toggleEquipmentAt (_rbOptions w) (crSel cr) cr
|
||||
. activateEquipmentAt (_rbOptions w) cr)
|
||||
doequipmentchange =
|
||||
setuhamdown $
|
||||
hammerTest
|
||||
( toggleEquipmentAt (_rbOptions w) (crSel cr) cr
|
||||
. activateEquipmentAt (_rbOptions w) cr
|
||||
)
|
||||
|
||||
tryReload :: Creature -> Item -> World -> (World -> World) -> World -> World
|
||||
tryReload cr it w f
|
||||
| _crID cr == _yourID (_cWorld w) && itNeedsLoading it && _mouseButtons w M.!? SDL.ButtonLeft == Just False
|
||||
= crToggleReloading cr
|
||||
| otherwise
|
||||
= (runIdentity . pointToItem (_itPos it) (return . (itUse . useHammer .~ HammerDown)))
|
||||
. f
|
||||
| _crID cr == _yourID (_cWorld w) && itNeedsLoading it && _mouseButtons w M.!? SDL.ButtonLeft == Just False =
|
||||
crToggleReloading cr
|
||||
| otherwise =
|
||||
(runIdentity . pointerToItem (_itPos it) (return . (itUse . useHammer .~ HammerDown)))
|
||||
. f
|
||||
|
||||
itNeedsLoading :: Item -> Bool
|
||||
itNeedsLoading it = _laLoaded ic == 0 || not (_laPrimed ic)
|
||||
where
|
||||
ic = _itConsumption it
|
||||
ic = _heldConsumption (_itUse it)
|
||||
|
||||
activateEquipmentAt :: RightButtonOptions -> Creature -> World -> World
|
||||
activateEquipmentAt rbo cr = cWorld . creatures . ix (_crID cr) %~ case (rbo ^? opActivateEquipment . activateEquipment, rbo ^? opActivateEquipment . deactivateEquipment) of
|
||||
(Just i,_) -> crLeftInvSel ?~ i
|
||||
(_,Just _) -> crLeftInvSel .~ Nothing
|
||||
_ -> id
|
||||
activateEquipmentAt rbo cr =
|
||||
cWorld . creatures . ix (_crID cr) %~ case (rbo ^? opActivateEquipment . activateEquipment, rbo ^? opActivateEquipment . deactivateEquipment) of
|
||||
(Just i, _) -> crLeftInvSel ?~ i
|
||||
(_, Just _) -> crLeftInvSel .~ Nothing
|
||||
_ -> id
|
||||
|
||||
toggleEquipmentAt :: RightButtonOptions -> Int -> Creature -> World -> World
|
||||
toggleEquipmentAt rbops invid cr w = case rbops ^? opAllocateEquipment of
|
||||
Just DoNotMoveEquipment -> w
|
||||
Just PutOnEquipment {_allocNewPos = newp}
|
||||
-> w
|
||||
Just PutOnEquipment{_allocNewPos = newp} ->
|
||||
w
|
||||
& crpoint . crEquipment . at newp ?~ invid
|
||||
& crpoint . crInvEquipped . at invid ?~ newp
|
||||
& onequip itm cr
|
||||
Just MoveEquipment {_allocNewPos=newp,_allocOldPos = oldp }
|
||||
-> w
|
||||
Just MoveEquipment{_allocNewPos = newp, _allocOldPos = oldp} ->
|
||||
w
|
||||
& crpoint . crEquipment . at newp ?~ invid
|
||||
& crpoint . crEquipment . at oldp .~ Nothing
|
||||
& crpoint . crInvEquipped . at invid ?~ newp
|
||||
Just SwapEquipment {_allocNewPos=newp, _allocOldPos = oldp, _allocSwapID = sid }
|
||||
-> w
|
||||
Just SwapEquipment{_allocNewPos = newp, _allocOldPos = oldp, _allocSwapID = sid} ->
|
||||
w
|
||||
& crpoint . crEquipment . at newp ?~ invid
|
||||
& crpoint . crEquipment . at oldp ?~ sid
|
||||
& crpoint . crInvEquipped . at invid ?~ newp
|
||||
& crpoint . crInvEquipped . at sid ?~ oldp
|
||||
Just ReplaceEquipment {_allocNewPos = newp, _allocRemoveID = rid }
|
||||
-> w
|
||||
Just ReplaceEquipment{_allocNewPos = newp, _allocRemoveID = rid} ->
|
||||
w
|
||||
& crpoint . crEquipment . at newp ?~ invid
|
||||
& crpoint . crInvEquipped . at invid ?~ newp
|
||||
& crpoint . crInvEquipped . at rid .~ Nothing
|
||||
& onremove (itmat rid) cr
|
||||
& onequip itm cr
|
||||
Just RemoveEquipment {_allocOldPos = oldp }
|
||||
-> w
|
||||
Just RemoveEquipment{_allocOldPos = oldp} ->
|
||||
w
|
||||
& crpoint . crEquipment . at oldp .~ Nothing
|
||||
& crpoint . crInvEquipped . at invid .~ Nothing
|
||||
& onremove itm cr
|
||||
@@ -104,21 +108,23 @@ toggleEquipmentAt rbops invid cr w = case rbops ^? opAllocateEquipment of
|
||||
onremove itm' = useE ((_eqOnRemove . _eqEq . _itUse) itm') itm'
|
||||
|
||||
useLeftItem :: Int -> World -> World
|
||||
useLeftItem cid w
|
||||
useLeftItem cid w
|
||||
| _crInvLock cr = w
|
||||
| itmShouldBeUsed = useItem cr w -- I believe this ONLY sets equipment options
|
||||
| otherwise = fromMaybe w $ do
|
||||
invid <- _crLeftInvSel cr
|
||||
itm <- cr ^? crInv . ix invid
|
||||
f <- cr ^? crInv . ix invid . itUse . lUse
|
||||
return
|
||||
. (runIdentity . pointToItem (_itPos itm) (return . (itUse . useHammer .~ HammerDown)))
|
||||
. useL f itm cr
|
||||
f <- cr ^? crInv . ix invid . itUse . lUse
|
||||
return
|
||||
. (runIdentity . pointerToItem (_itPos itm) (return . (itUse . useHammer .~ HammerDown)))
|
||||
. useL f itm cr
|
||||
$ w
|
||||
where
|
||||
cr = _creatures (_cWorld w) IM.! cid
|
||||
itmShouldBeUsed = isJust (cr ^? crInv . ix (crSel cr) . itUse . cUse)
|
||||
|| ( isJust (cr ^? crInv . ix (crSel cr) . itUse . eqEq . eqUse)
|
||||
&& _crLeftInvSel cr /= Just (crSel cr)
|
||||
)
|
||||
-- TODO determine itmShouldBeUsed with reference to config options
|
||||
itmShouldBeUsed =
|
||||
isJust (cr ^? crInv . ix (crSel cr) . itUse . cUse)
|
||||
|| ( isJust (cr ^? crInv . ix (crSel cr) . itUse . eqEq . eqUse)
|
||||
&& _crLeftInvSel cr /= Just (crSel cr)
|
||||
)
|
||||
|
||||
-- TODO determine itmShouldBeUsed with reference to config options
|
||||
|
||||
@@ -135,7 +135,7 @@ doStrategyActions cr = case cr ^? crActionPlan . apStrategy of
|
||||
|
||||
reloadOverride :: Creature -> Creature
|
||||
reloadOverride cr
|
||||
| cr ^? crInv . ix (crSel cr) . itConsumption . laLoaded == Just 0
|
||||
| cr ^? crInv . ix (crSel cr) . itUse . heldConsumption . laLoaded == Just 0
|
||||
&& cr ^. crStance . posture == Aiming
|
||||
= cr & crActionPlan . apStrategy .~ StrategyActions Reload reloadActions
|
||||
| otherwise = cr
|
||||
|
||||
@@ -216,10 +216,10 @@ itemUpdate cr i
|
||||
. (itPos .~ InInv (_crID cr) i)
|
||||
. (itIsHeld .~ bool)
|
||||
updateAutoRecharge :: Item -> Item
|
||||
updateAutoRecharge it = case _itConsumption it of
|
||||
AutoRecharging l m t p
|
||||
| l < m && p <= 0 -> it & itConsumption .~ AutoRecharging (l+1) m t t
|
||||
| l < m -> it & itConsumption . arProgress -~ 1
|
||||
updateAutoRecharge it = case it ^? itUse . leftConsumption of
|
||||
Just (AutoRecharging l m t p)
|
||||
| l < m && p <= 0 -> it & itUse . leftConsumption .~ AutoRecharging (l+1) m t t
|
||||
| l < m -> it & itUse . leftConsumption . arProgress -~ 1
|
||||
_ -> it
|
||||
doItemTargeting :: Int -> Creature -> World -> World
|
||||
doItemTargeting invid cr w = case cr ^? crInv . ix invid . itTargeting of
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
module Dodge.Creature.Statistics
|
||||
( getCrStrength
|
||||
, getCrDexterity
|
||||
) where
|
||||
import Dodge.Data
|
||||
module Dodge.Creature.Statistics (
|
||||
getCrStrength,
|
||||
getCrDexterity,
|
||||
) where
|
||||
|
||||
--import Data.Strict.IntMap.Autogen.Merge.Strict
|
||||
import Data.IntMap.Merge.Strict
|
||||
import Data.Maybe
|
||||
import Dodge.Creature.Test
|
||||
import Dodge.Data
|
||||
import qualified IntMapHelp as IM
|
||||
import LensHelp
|
||||
|
||||
import Data.Maybe
|
||||
import Data.Strict.IntMap.Autogen.Merge.Strict
|
||||
--import Data.IntMap.Merge.Strict
|
||||
|
||||
getCrDexterity :: Creature -> Int
|
||||
getCrDexterity cr = _dexterity (_crStatistics cr)
|
||||
|
||||
@@ -23,16 +23,20 @@ strFromEquipment = sum . fmap equipmentStrValue . crCurrentEquipment
|
||||
equipmentStrValue :: Item -> Int
|
||||
equipmentStrValue itm = case _iyBase $ _itType itm of
|
||||
EQUIP FRONTARMOUR -> negate 3
|
||||
EQUIP POWERLEGS -> 3
|
||||
EQUIP POWERLEGS -> 3
|
||||
_ -> 0
|
||||
|
||||
crCurrentEquipment :: Creature -> IM.IntMap Item
|
||||
crCurrentEquipment cr = merge dropMissing dropMissing (zipWithMatched (\_ _ itm -> itm))
|
||||
(_crInvEquipped cr)
|
||||
(_crInv cr)
|
||||
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 . useAim . aimWeight
|
||||
| _posture (_crStance cr) == Aiming || crIsReloading cr =
|
||||
negate $ fromMaybe 0 $ cr ^? crInv . ix (crSel cr) . itUse . useAim . aimWeight
|
||||
| otherwise = 0
|
||||
|
||||
@@ -41,7 +41,7 @@ crIsReloading cr = case cr ^? crInvSel . iselAction of
|
||||
|
||||
crWeaponReady :: Creature -> Bool
|
||||
crWeaponReady cr = fromMaybe False $ do
|
||||
ic <- cr ^? crInv . ix (crSel cr) . itConsumption
|
||||
ic <- cr ^? crInv . ix (crSel cr) . itUse . heldConsumption
|
||||
return (_laLoaded ic > 0 && _laPrimed ic)
|
||||
|
||||
crCanSeeCr :: Creature -> (World, Creature) -> Bool
|
||||
|
||||
Reference in New Issue
Block a user