Cleanup, think about removing creature "hammer"
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user