Work on rocket/grenade launcher
This commit is contained in:
@@ -2,6 +2,7 @@ module Dodge.Creature.Impulse.UseItem (
|
||||
useSelectedItem,
|
||||
) where
|
||||
|
||||
import Data.Foldable (foldl')
|
||||
import Dodge.DoubleTree
|
||||
import Control.Lens
|
||||
import Control.Monad
|
||||
@@ -20,9 +21,7 @@ import qualified IntMapHelp as IM
|
||||
useSelectedItem :: Int -> World -> World
|
||||
useSelectedItem crid w = (worldEventFlags . at InventoryChange ?~ ()) . fromMaybe w $ do
|
||||
cr <- w ^? cWorld . lWorld . creatures . ix crid
|
||||
itRef <- cr ^? crManipulation . manObject . imRootSelectedItem
|
||||
invid <- cr ^? crManipulation . manObject . imSelectedItem
|
||||
itmtree <- invRootTrees (_crInv cr) ^? ix itRef
|
||||
itmloc <- allInvLocs (_crInv cr) ^? ix invid . _2
|
||||
let usedloc = case useLocation itmloc of
|
||||
UseFromLocation -> itmloc ^. locLDT
|
||||
@@ -31,13 +30,15 @@ useSelectedItem crid w = (worldEventFlags . at InventoryChange ?~ ()) . fromMayb
|
||||
case usedloc ^. ldtValue . _2 of
|
||||
HeldPlatformSF ->
|
||||
return $
|
||||
heldEffect (bimap _iatType fst3 itmtree) cr w
|
||||
heldEffect (bimap _iatType fst3 usedloc) cr w
|
||||
& pointerToItem itm . itUse . heldHammer .~ HammerDown
|
||||
GadgetPlatformSF ->
|
||||
return $
|
||||
heldEffect (bimap _iatType fst3 itmtree) cr w
|
||||
heldEffect (bimap _iatType fst3 usedloc) cr w
|
||||
& pointerToItem itm . itUse . heldHammer .~ HammerDown
|
||||
--EquipmentPlatformSF -> do
|
||||
RemoteDetonatorSF -> do
|
||||
guard (_crHammerPosition cr == HammerUp)
|
||||
return $ activateDetonator usedloc cr w
|
||||
_ | isJust $ itm ^? itUse . uequipEffect -> do
|
||||
guard (_crHammerPosition cr == HammerUp)
|
||||
invid' <- itm ^? itLocation . ilInvID
|
||||
@@ -46,11 +47,24 @@ useSelectedItem crid w = (worldEventFlags . at InventoryChange ?~ ()) . fromMayb
|
||||
where
|
||||
fst3 (x,_,_) = x
|
||||
|
||||
activateDetonator
|
||||
:: LabelDoubleTree ItemLink ComposedItem -> Creature -> World
|
||||
-> World
|
||||
activateDetonator det _ w = (foldl' remoteDetonate w
|
||||
$ det ^. ldtValue . _1 . itUse . uaParams . apProjectiles)
|
||||
& pointerToItemID (det ^. ldtValue . _1 . itID) . itUse . uaParams . apProjectiles .~ []
|
||||
|
||||
remoteDetonate :: World -> Int -> World
|
||||
remoteDetonate w pjid = w
|
||||
& cWorld . lWorld . projectiles . ix pjid . prjTimer .~ 0
|
||||
|
||||
useLocation :: LocationLDT ItemLink ComposedItem -> UseFocus
|
||||
useLocation loc
|
||||
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uequipEffect = UseFromLocation
|
||||
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apLinkedProjectile . _Just
|
||||
= UseFromLocation
|
||||
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apProjectiles . ix 0
|
||||
= UseFromLocation
|
||||
| otherwise = UseFromRoot
|
||||
|
||||
toggleEquipmentAt :: Int -> Creature -> World -> World
|
||||
|
||||
Reference in New Issue
Block a user