Flatten values in creature manipulation data types

This commit is contained in:
2024-09-24 21:50:21 +01:00
parent fe00af0e73
commit 25cec10313
24 changed files with 69 additions and 86 deletions
+1 -1
View File
@@ -188,7 +188,7 @@ dropItem cr invid = rmInvItem (_crID cr) invid .
youDropItem :: World -> World
youDropItem w = fromMaybe w $ do
curpos <-
you w ^? crManipulation . manObject . inInventory . imSelectedItem
you w ^? crManipulation . manObject . imSelectedItem
<|> fmap fst (IM.lookupMax =<< w ^? hud . hudElement . diSections . sssSections . ix 0 . ssItems)
guard $ not $ _crInvLock (you w) || cursed
return $
+1 -1
View File
@@ -48,7 +48,7 @@ followImpulse cr w imp = case imp of
TurnTo p -> crup $ creatureTurnTo p cr
ChangePosture post -> crup $ cr & crStance . posture .~ post
UseItem -> (useRootItem $ _crID cr, cr)
SwitchToItem i -> crup $ cr & crManipulation . manObject .~ InInventory (SelectedItem i i mempty)
SwitchToItem i -> crup $ cr & crManipulation . manObject .~ SelectedItem i i mempty
Melee cid' ->
( hitCr cid'
, crMvAbsolute (10 *.* normalizeV (posFromID cid' -.- cpos)) $ cr & crMeleeCooldown .~ 20
+4 -4
View File
@@ -26,7 +26,7 @@ import qualified IntMapHelp as IM
useRootItem :: Int -> World -> World
useRootItem crid w = fromMaybe w $ do
cr <- w ^? cWorld . lWorld . creatures . ix crid
itRef <- cr ^? crManipulation . manObject . inInventory . imRootItem
itRef <- cr ^? crManipulation . manObject . imRootItem
it <- invTrees (_crInv cr) ^? ix itRef
return $
itemEffect cr it w
@@ -89,7 +89,7 @@ toggleEquipmentAt invid cr w = case getEquipmentAllocation w of
crpoint = cWorld . lWorld . creatures . ix (_crID cr)
itmat i = _crInv cr IM.! i
itm = itmat itRef
itRef = cr ^?! crManipulation . manObject . inInventory . imSelectedItem -- unsafe!! TODO change?
itRef = cr ^?! crManipulation . manObject . imSelectedItem -- unsafe!! TODO change?
onequip itm' = useE ((_eeOnEquip . _equipEffect . _itUse) itm') itm'
onremove itm' = useE ((_eeOnRemove . _equipEffect . _itUse) itm') itm'
@@ -98,7 +98,7 @@ toggleEquipmentAt invid cr w = case getEquipmentAllocation w of
useItemLeftClick :: Creature -> World -> World
useItemLeftClick cr w = fromMaybe w $ do
guard . not $ _crInvLock cr
invid <- cr ^? crManipulation . manObject . inInventory . imSelectedItem
invid <- cr ^? crManipulation . manObject . imSelectedItem
ituse <- cr ^? crInv . ix invid . itUse
case ituse of
--HeldUse{} -> return $ hammerTest (cWorld . lWorld . creatures . ix (_crID cr) %~ crReloadToggle)
@@ -114,7 +114,7 @@ useItemLeftClick' :: Creature -> World -> World
--useItemLeftClick' cr' w = fromMaybe (f w) $ do
useItemLeftClick' cr' w = fromMaybe w $ do
cr <- w ^? cWorld . lWorld . creatures . ix (_crID cr')
itRef <- cr ^? crManipulation . manObject . inInventory . imSelectedItem
itRef <- cr ^? crManipulation . manObject . imSelectedItem
it <- invTrees (_crInv cr) ^? ix itRef
return $
itemEffect cr it w
+1 -1
View File
@@ -282,7 +282,7 @@ updateAutoRecharge it = case it ^? itUse . leftConsumption of
-- in the inventory
crGetTargeting :: Creature -> Maybe TargetType
crGetTargeting cr = do
i <- cr ^? crManipulation . manObject . inInventory . imRootItem
i <- cr ^? crManipulation . manObject . imRootItem
itm <- cr ^? crInv . ix i
itm ^? itType . iyModules . ix ModTarget . imtTargetType
<|> do
+1 -1
View File
@@ -38,6 +38,6 @@ strFromHeldItem :: Creature -> Int
strFromHeldItem cr
--x--- | _posture (_crStance cr) == Aiming || crIsReloading cr = negate $ fromMaybe 0 $ do
| _posture (_crStance cr) == Aiming = negate $ fromMaybe 0 $ do
i <- cr ^? crManipulation . manObject . inInventory . imRootItem
i <- cr ^? crManipulation . manObject . imRootItem
cr ^? crInv . ix i . itUse . heldAim . aimWeight
| otherwise = 0
+1 -1
View File
@@ -91,7 +91,7 @@ crInAimStance as cr =
&& mitstance == Just as
where
mitstance = do
i <- cr ^? crManipulation . manObject . inInventory . imRootItem
i <- cr ^? crManipulation . manObject . imRootItem
cr ^? crInv . ix i . itUse . heldAim . aimStance
oneH :: Creature -> Bool
+3 -3
View File
@@ -88,7 +88,7 @@ tryAssignHotkey w sc = fromMaybe w $ do
pt <- w ^? input . pressedKeys . ix sc
guard (pt == InitialPress)
cr <- w ^? cWorld . lWorld . creatures . ix 0
itid <- cr ^? crManipulation . manObject . inInventory . imSelectedItem
itid <- cr ^? crManipulation . manObject . imSelectedItem
return $ w & cWorld . lWorld . creatures . ix 0 %~ assignHotkey itid (scancodeToHotkey sc)
{- | Turn key presses into creature movement.
@@ -164,7 +164,7 @@ wasdTwist cr
& crDir +~ _crTwist cr'
& crTwist .~ 0
addAnyTwist = fromMaybe id $ do
itRef <- cr ^? crManipulation . manObject . inInventory . imRootItem
itRef <- cr ^? crManipulation . manObject . imRootItem
astance <- cr ^? crInv . ix itRef . itUse . heldAim . aimStance
case (astance, cr ^. crTwist) of
(TwoHandUnder, 0) ->
@@ -190,7 +190,7 @@ aimTurn :: Float -> Creature -> Creature
aimTurn a cr = creatureTurnTowardDir a (x * 0.2) cr
where
x = fromMaybe 1 $ do
itRef <- cr ^? crManipulation . manObject . inInventory . imRootItem
itRef <- cr ^? crManipulation . manObject . imRootItem
cr ^? crInv . ix itRef . itUse . heldAim . aimTurnSpeed
-- | Set posture according to mouse presses.