Distinguish between selected item and root-selected item
This commit is contained in:
@@ -192,7 +192,7 @@ dropItem cr invid = rmInvItem (_crID cr) invid . copyInvItemToFloor cr invid --
|
||||
youDropItem :: World -> World
|
||||
youDropItem w = fromMaybe w $ do
|
||||
curpos <-
|
||||
you w ^? crManipulation . manObject . inInventory . ispItem
|
||||
you w ^? crManipulation . manObject . inInventory . imSelectedItem
|
||||
<|> fmap fst (IM.lookupMax =<< w ^? hud . hudElement . diSections . sssSections . ix 0 . ssItems)
|
||||
guard $ not $ _crInvLock (you w) || cursed
|
||||
return $
|
||||
@@ -202,7 +202,7 @@ youDropItem w = fromMaybe w $ do
|
||||
where
|
||||
cr = you w
|
||||
cursed = fromMaybe False $ do
|
||||
it <- yourItem w
|
||||
it <- yourSelectedItem w
|
||||
return $ it ^. itCurseStatus /= Uncursed
|
||||
|
||||
-- | Copy an inventory item to the floor.
|
||||
@@ -210,7 +210,8 @@ copyInvItemToFloor :: Creature -> Int -> World -> World
|
||||
copyInvItemToFloor cr i =
|
||||
copyItemToFloor (_crPos cr) $
|
||||
_crInv cr IM.! i
|
||||
& itIsHeld .~ False
|
||||
& itIsSelected .~ False
|
||||
& itIsRoot .~ False
|
||||
|
||||
sizeSelf :: Float -> Creature -> World -> Maybe World
|
||||
sizeSelf x cr w
|
||||
|
||||
@@ -33,6 +33,7 @@ followImpulses w cr = foldl' (flip f) (id, cr) (reverse $ _apImpulse $ _crAction
|
||||
where
|
||||
f imp (theupdate, cr') = first (. theupdate) $ followImpulse cr' w imp
|
||||
|
||||
-- note SwitchToItem doesn't necessarily update the root item correctly
|
||||
followImpulse :: Creature -> World -> Impulse -> (World -> World, Creature)
|
||||
followImpulse cr w imp = case imp of
|
||||
ImpulseNothing -> (id, cr)
|
||||
@@ -47,7 +48,7 @@ followImpulse cr w imp = case imp of
|
||||
TurnTo p -> crup $ creatureTurnTo p cr
|
||||
ChangePosture post -> crup $ cr & crStance . posture .~ post
|
||||
UseItem -> (useItemRightClick cr, cr)
|
||||
SwitchToItem i -> crup $ cr & crManipulation . manObject .~ InInventory (SelItem i NoInvSelAction)
|
||||
SwitchToItem i -> crup $ cr & crManipulation . manObject .~ InInventory (SelectedItem i i)
|
||||
Melee cid' ->
|
||||
( hitCr cid'
|
||||
, crMvAbsolute (10 *.* normalizeV (posFromID cid' -.- cpos)) $ cr & crMeleeCooldown .~ 20
|
||||
|
||||
@@ -25,7 +25,7 @@ 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 . ispItem
|
||||
itRef <- cr ^? crManipulation . manObject . inInventory . imRootItem
|
||||
it <- invTrees (_crInv cr) ^? ix itRef
|
||||
return $
|
||||
itemEffect cr it w
|
||||
@@ -51,7 +51,7 @@ itemEffect cr it w = case it ^. ldtValue . itUse of
|
||||
AmmoMagUse{} -> w
|
||||
where
|
||||
itm = it ^. ldtValue
|
||||
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
|
||||
itRef = cr ^?! crManipulation . manObject . inInventory . imRootItem -- unsafe!! TODO change
|
||||
hammerTest f = case _crHammerPosition cr of
|
||||
HammerUp -> f w & setuhamdown
|
||||
_ -> w & setuhamdown
|
||||
@@ -97,14 +97,16 @@ 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 . ispItem -- unsafe!! TODO change?
|
||||
itRef = cr ^?! crManipulation . manObject . inInventory . imSelectedItem -- unsafe!! TODO change?
|
||||
onequip itm' = useE ((_eeOnEquip . _equipEffect . _itUse) itm') itm'
|
||||
onremove itm' = useE ((_eeOnRemove . _equipEffect . _itUse) itm') itm'
|
||||
|
||||
-- need to make sure that the root item is not erroneously selected in the
|
||||
-- following
|
||||
useItemLeftClick :: Creature -> World -> World
|
||||
useItemLeftClick cr w = fromMaybe w $ do
|
||||
guard . not $ _crInvLock cr
|
||||
invid <- cr ^? crManipulation . manObject . inInventory . ispItem
|
||||
invid <- cr ^? crManipulation . manObject . inInventory . imSelectedItem
|
||||
ituse <- cr ^? crInv . ix invid . itUse
|
||||
case ituse of
|
||||
--HeldUse{} -> return $ hammerTest (cWorld . lWorld . creatures . ix (_crID cr) %~ crReloadToggle)
|
||||
|
||||
@@ -251,7 +251,7 @@ itemInvSideEffect cr it
|
||||
| hastorchattach = createAttachLight cr it
|
||||
| otherwise = id
|
||||
where
|
||||
hastorchattach = it ^? itType . iyModules . ix ModHeldAttach == Just ATTACHTORCH && _itIsHeld it
|
||||
hastorchattach = it ^? itType . iyModules . ix ModHeldAttach == Just ATTACHTORCH && _itIsRoot it
|
||||
|
||||
createAttachLight :: Creature -> Item -> World -> World
|
||||
createAttachLight cr it = createTorchLightOffset cr it attachoff
|
||||
@@ -263,9 +263,11 @@ itemUpdate cr i =
|
||||
updateAutoRecharge
|
||||
. (itUse %~ useUpdate)
|
||||
. (itLocation .~ InInv (_crID cr) i)
|
||||
. (itIsHeld .~ itmisheld)
|
||||
. (itIsRoot .~ itmisroot)
|
||||
. (itIsSelected .~ itmisselected)
|
||||
where
|
||||
itmisheld = Just i == (cr ^? crManipulation . manObject . inInventory . ispItem)
|
||||
itmisroot = Just i == (cr ^? crManipulation . manObject . inInventory . imRootItem)
|
||||
itmisselected = Just i == (cr ^? crManipulation . manObject . inInventory . imSelectedItem)
|
||||
|
||||
updateAutoRecharge :: Item -> Item
|
||||
updateAutoRecharge it = case it ^? itUse . leftConsumption of
|
||||
@@ -281,7 +283,7 @@ updateAutoRecharge it = case it ^? itUse . leftConsumption of
|
||||
-- in the inventory
|
||||
crGetTargeting :: Creature -> Maybe TargetType
|
||||
crGetTargeting cr = do
|
||||
i <- cr ^? crManipulation . manObject . inInventory . ispItem
|
||||
i <- cr ^? crManipulation . manObject . inInventory . imRootItem
|
||||
itm <- cr ^? crInv . ix i
|
||||
itm ^? itType . iyModules . ix ModTarget . imtTargetType
|
||||
<|> do
|
||||
|
||||
@@ -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 . ispItem
|
||||
i <- cr ^? crManipulation . manObject . inInventory . imRootItem
|
||||
cr ^? crInv . ix i . itUse . heldAim . aimWeight
|
||||
| otherwise = 0
|
||||
|
||||
+11
-11
@@ -12,11 +12,11 @@ module Dodge.Creature.Test (
|
||||
oneH,
|
||||
twists,
|
||||
twoFlat,
|
||||
crWeaponReady,
|
||||
-- crWeaponReady,
|
||||
crInAimStance,
|
||||
crNearPoint,
|
||||
isAnimate,
|
||||
crCanShoot,
|
||||
-- crCanShoot,
|
||||
crHasTargetLOS,
|
||||
crAwayFromPost,
|
||||
crHasTarget,
|
||||
@@ -38,12 +38,12 @@ import Geometry
|
||||
-- Just ReloadAction{} -> True
|
||||
-- _ -> False
|
||||
|
||||
-- Assumes the ammotype below the selected item is correct
|
||||
crWeaponReady :: Creature -> Bool
|
||||
crWeaponReady cr = fromMaybe False $ do
|
||||
i <- cr ^? crManipulation . manObject . inInventory . ispItem
|
||||
x <- cr ^? crInv . ix (i + 1) . itUse . amagLoadStatus . iaLoaded
|
||||
return (x > 0)
|
||||
---- Assumes the ammotype below the selected item is correct
|
||||
--crWeaponReady :: Creature -> Bool
|
||||
--crWeaponReady cr = fromMaybe False $ do
|
||||
-- i <- cr ^? crManipulation . manObject . inInventory . ispItem
|
||||
-- x <- cr ^? crInv . ix (i + 1) . itUse . amagLoadStatus . iaLoaded
|
||||
-- return (x > 0)
|
||||
|
||||
crCanSeeCr :: Creature -> (World, Creature) -> Bool
|
||||
crCanSeeCr tcr (w, cr) = hasLOS (_crPos cr) (_crPos tcr) w
|
||||
@@ -82,8 +82,8 @@ crAwayFromPost cr = case find sentinelGoal . _apGoal $ _crActionPlan cr of
|
||||
sentinelGoal (SentinelAt _ _) = True
|
||||
sentinelGoal _ = False
|
||||
|
||||
crCanShoot :: Creature -> Bool
|
||||
crCanShoot cr = crIsAiming cr && crWeaponReady cr
|
||||
--crCanShoot :: Creature -> Bool
|
||||
--crCanShoot cr = crIsAiming cr && crWeaponReady cr
|
||||
|
||||
crInAimStance :: AimStance -> Creature -> Bool
|
||||
crInAimStance as cr =
|
||||
@@ -91,7 +91,7 @@ crInAimStance as cr =
|
||||
&& mitstance == Just as
|
||||
where
|
||||
mitstance = do
|
||||
i <- cr ^? crManipulation . manObject . inInventory . ispItem
|
||||
i <- cr ^? crManipulation . manObject . inInventory . imRootItem
|
||||
cr ^? crInv . ix i . itUse . heldAim . aimStance
|
||||
|
||||
oneH :: Creature -> Bool
|
||||
|
||||
@@ -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 . ispItem
|
||||
itid <- cr ^? crManipulation . manObject . inInventory . imSelectedItem
|
||||
return $ w & cWorld . lWorld . creatures . ix 0 %~ assignHotkey itid (scancodeToHotkey sc)
|
||||
|
||||
{- | Turn key presses into creature movement.
|
||||
@@ -152,6 +152,7 @@ wasdAim inp cam cr
|
||||
theTurn cr' = creatureTurnTowardDir (_crMvAim cr') 0.2 cr'
|
||||
mouseDir = argV $ mouseWorldPos inp cam - (cr ^. crPos)
|
||||
|
||||
-- aim with the root item
|
||||
wasdTwist :: Creature -> Creature
|
||||
wasdTwist cr
|
||||
| _posture (_crStance cr) == Aiming = addAnyTwist cr
|
||||
@@ -163,7 +164,7 @@ wasdTwist cr
|
||||
& crDir +~ _crTwist cr'
|
||||
& crTwist .~ 0
|
||||
addAnyTwist = fromMaybe id $ do
|
||||
itRef <- cr ^? crManipulation . manObject . inInventory . ispItem
|
||||
itRef <- cr ^? crManipulation . manObject . inInventory . imRootItem
|
||||
astance <- cr ^? crInv . ix itRef . itUse . heldAim . aimStance
|
||||
case (astance, cr ^. crTwist) of
|
||||
(TwoHandUnder, 0) ->
|
||||
@@ -189,19 +190,18 @@ aimTurn :: Float -> Creature -> Creature
|
||||
aimTurn a cr = creatureTurnTowardDir a (x * 0.2) cr
|
||||
where
|
||||
x = fromMaybe 1 $ do
|
||||
itRef <- cr ^? crManipulation . manObject . inInventory . ispItem
|
||||
itRef <- cr ^? crManipulation . manObject . inInventory . imRootItem
|
||||
cr ^? crInv . ix itRef . itUse . heldAim . aimTurnSpeed
|
||||
|
||||
-- | Set posture according to mouse presses.
|
||||
mouseActionsCr :: M.Map SDL.MouseButton Int -> Creature -> Creature
|
||||
mouseActionsCr pkeys cr
|
||||
| SDL.ButtonRight `M.member` pkeys && noaction =
|
||||
cr & crStance . posture .~ Aiming
|
||||
| SDL.ButtonRight `M.member` pkeys = cr & crStance . posture .~ Aiming
|
||||
| otherwise = cr & crStance . posture .~ AtEase
|
||||
where
|
||||
noaction = fromMaybe True $ do
|
||||
theaction <- cr ^? crManipulation . manObject . inInventory . iselAction
|
||||
return $ theaction == NoInvSelAction
|
||||
-- where
|
||||
-- noaction = fromMaybe True $ do
|
||||
-- theaction <- cr ^? crManipulation . manObject . inInventory . iselAction
|
||||
-- return $ theaction == NoInvSelAction
|
||||
|
||||
pressedMBEffectsTopInventory :: M.Map SDL.MouseButton Int -> World -> World
|
||||
pressedMBEffectsTopInventory pkeys w
|
||||
|
||||
Reference in New Issue
Block a user