Cleanup, think about removing creature "hammer"

This commit is contained in:
2024-09-22 10:47:47 +01:00
parent 80e5c69489
commit efd3e17cbf
6 changed files with 132 additions and 122 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ followImpulse cr w imp = case imp of
TurnToward p a -> crup $ creatureTurnToward p a cr
TurnTo p -> crup $ creatureTurnTo p cr
ChangePosture post -> crup $ cr & crStance . posture .~ post
UseItem -> (useItemRightClick cr, cr)
UseItem -> (useRootItem $ _crID cr, cr)
SwitchToItem i -> crup $ cr & crManipulation . manObject .~ InInventory (SelectedItem i i)
Melee cid' ->
( hitCr cid'
+32 -30
View File
@@ -1,5 +1,5 @@
module Dodge.Creature.Impulse.UseItem (
useItemRightClick,
useRootItem,
useItemLeftClick,
itemEffect,
useItemHotkey,
@@ -22,41 +22,35 @@ import Dodge.Item.Location
import Dodge.Luse
import qualified IntMapHelp as IM
useItemRightClick :: Creature -> World -> World
useItemRightClick cr' w = fromMaybe (f w) $ do
cr <- w ^? cWorld . lWorld . creatures . ix (_crID cr')
itRef <- cr ^? crManipulation . manObject . inInventory . imRootItem
it <- invTrees (_crInv cr) ^? ix itRef
return $
itemEffect cr it w
& worldEventFlags . at InventoryChange ?~ ()
& f
where
f = cWorld . lWorld . creatures . ix (_crID cr') . crHammerPosition .~ HammerDown
useRootItem :: Int -> World -> World
useRootItem crid w = fromMaybe w $ do
cr <- w ^? cWorld . lWorld . creatures . ix crid
itRef <- cr ^? crManipulation . manObject . inInventory . imRootItem
it <- invTrees (_crInv cr) ^? ix itRef
return $
itemEffect cr it w
& worldEventFlags . at InventoryChange ?~ ()
itemEffect :: Creature -> LabelDoubleTree ComposeLinkType Item -> World -> World
itemEffect cr it w = case it ^. ldtValue . itUse of
-- HeldUse{_heldUse = eff, _heldMods = usemods} ->
-- foldl' (&) (useHeld eff) (useMod usemods) it cr w
-- & pointerToItem itm . itUse . heldHammer .~ HammerDown
HeldUse{ _heldMods = usemods} ->
heldEffect usemods it cr w
& pointerToItem itm . itUse . heldHammer .~ HammerDown
LeftUse{} -> doequipmentchange
EquipUse{} -> doequipmentchange
-- ConsumeUse will cause problems if the item is not selected
(ConsumeUse eff) -> useC eff (_ldtValue it) cr $ rmInvItem (_crID cr) itRef w
(ConsumeUse eff) -> useC eff (_ldtValue it) cr w
CraftUse{} -> w
AttachUse{} -> w
AmmoMagUse{} -> w
where
itm = it ^. ldtValue
itRef = cr ^?! crManipulation . manObject . inInventory . imRootItem -- unsafe!! TODO change
hammerTest f = case _crHammerPosition cr of
HammerUp -> f w & setuhamdown
_ -> w & setuhamdown
setuhamdown = cWorld . lWorld . creatures . ix (_crID cr) . crHammerPosition .~ HammerDown
doequipmentchange = hammerTest $ toggleEquipmentAt itRef cr
HammerUp -> f w -- & setuhamdown
_ -> w -- & setuhamdown
-- setuhamdown = cWorld . lWorld . creatures . ix (_crID cr) . crHammerPosition .~ HammerDown
doequipmentchange = fromMaybe w $ do
invid <- itm ^? itLocation . ipInvID
return $ hammerTest $ toggleEquipmentAt invid cr
toggleEquipmentAt :: Int -> Creature -> World -> World
toggleEquipmentAt invid cr w = case getEquipmentAllocation w of
@@ -111,17 +105,25 @@ useItemLeftClick cr w = fromMaybe w $ do
case ituse of
--HeldUse{} -> return $ hammerTest (cWorld . lWorld . creatures . ix (_crID cr) %~ crReloadToggle)
HeldUse{} -> return w
ConsumeUse{} -> return $ useItemRightClick cr w
EquipUse{} -> return $ useItemRightClick cr w
LeftUse{} -> return $ useItemRightClick cr w
ConsumeUse{} -> return $ useItemLeftClick' cr w
EquipUse{} -> return $ useItemLeftClick' cr w
LeftUse{} -> return $ useItemLeftClick' cr w
AmmoMagUse{} -> return w
--AmmoMagUse{} -> return $ hammerTest (cWorld . lWorld . creatures . ix (_crID cr) %~ crReloadToggle)
_ -> Nothing
where
--hammerTest f = case _crHammerPosition cr of
-- HammerUp -> f w & setuhamdown
-- _ -> w & setuhamdown
--setuhamdown = cWorld . lWorld . creatures . ix (_crID cr) . crHammerPosition .~ HammerDown
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
it <- invTrees (_crInv cr) ^? ix itRef
return $
itemEffect cr it w
& worldEventFlags . at InventoryChange ?~ ()
-- & f
-- where
-- f = cWorld . lWorld . creatures . ix (_crID cr') . crHammerPosition .~ HammerDown
useItemHotkey :: Int -> Int -> World -> World
useItemHotkey crid invid w = fromMaybe w $ do
+3 -2
View File
@@ -205,11 +205,12 @@ mouseActionsCr pkeys cr
pressedMBEffectsTopInventory :: M.Map SDL.MouseButton Int -> World -> World
pressedMBEffectsTopInventory pkeys w
| isDown SDL.ButtonLeft && isDown SDL.ButtonRight && inTopInv = useItemRightClick (you w) w
| isDown SDL.ButtonLeft && inTopInv = useItemLeftClick (you w) w
| isDown SDL.ButtonLeft && isDown SDL.ButtonRight && inTopInv = youhammerdown $ useRootItem 0 w
| isDown SDL.ButtonLeft && inTopInv = youhammerdown $ useItemLeftClick (you w) w
| isDown SDL.ButtonMiddle = w & wCam . camRot -~ rotation
| otherwise = w
where
youhammerdown = set (cWorld . lWorld . creatures . ix 0 . crHammerPosition) HammerDown
inTopInv = case w ^. hud . hudElement of
DisplayInventory{_subInventory = NoSubInventory} -> True
_ -> False
+8 -1
View File
@@ -1,9 +1,16 @@
module Dodge.Cuse where
import Dodge.Inventory
import Control.Lens
import Dodge.Data.World
import Data.Maybe
useC :: Cuse -> Item -> Creature -> World -> World
useC cu = case cu of
useC cu itm cr = fromMaybe id $ do
i <- itm ^? itLocation . ipInvID
return $ rmInvItem (_crID cr) i . useC' cu itm cr
useC' :: Cuse -> Item -> Creature -> World -> World
useC' cu = case cu of
CDoNothing -> const $ const id
CHeal x -> const $ \cr -> cWorld . lWorld . creatures . ix (_crID cr) . crHP +~ x