Cleanup
This commit is contained in:
@@ -190,18 +190,20 @@ dropItem cr invid =
|
||||
youDropItem :: World -> World
|
||||
youDropItem w = fromMaybe w $ do
|
||||
curpos <-
|
||||
you w ^? crManipulation . manObject . imSelectedItem
|
||||
-- <|> fmap fst (IM.lookupMax =<< w ^? hud . hudElement . diSections . ix 0 . ssItems)
|
||||
<|> fmap fst (IM.lookupMax (you w ^. crInv))
|
||||
guard $ not $ _crInvLock (you w)
|
||||
return $
|
||||
w
|
||||
& dropItem cr curpos
|
||||
cr ^? crManipulation . manObject . imSelectedItem
|
||||
<|> fmap fst (IM.lookupMax (cr ^. crInv))
|
||||
guard $ not $ _crInvLock cr
|
||||
return $ case cr ^. crStance . posture of
|
||||
Aiming -> throwItem w
|
||||
AtEase -> dropItem cr curpos w
|
||||
where
|
||||
-- & soundStart (CrSound (_crID cr)) (_crPos cr) whiteNoiseFadeOutS Nothing
|
||||
|
||||
cr = you w
|
||||
|
||||
-- placeholder, remember to deal with two handed weapon twist
|
||||
-- should throw all attached items?
|
||||
throwItem :: World -> World
|
||||
throwItem = id
|
||||
|
||||
sizeSelf :: Float -> Creature -> World -> Maybe World
|
||||
sizeSelf x cr w
|
||||
| not (crOnWall cr1 w) =
|
||||
|
||||
@@ -9,7 +9,7 @@ import qualified IntMapHelp as IM
|
||||
import LensHelp
|
||||
|
||||
getCrDexterity :: Creature -> Int
|
||||
getCrDexterity cr = _dexterity (_crStatistics cr)
|
||||
getCrDexterity = _dexterity . _crStatistics
|
||||
|
||||
getCrMoveSpeed :: Creature -> Int
|
||||
getCrMoveSpeed cr = strFromHeldItem cr + strFromEquipment cr + _strength (_crStatistics cr)
|
||||
@@ -27,10 +27,7 @@ crCurrentEquipment :: Creature -> IM.IntMap Item
|
||||
crCurrentEquipment = IM.filter (isJust . (^? itLocation . ilEquipSite . _Just)) . _crInv
|
||||
|
||||
strFromHeldItem :: Creature -> Int
|
||||
strFromHeldItem cr
|
||||
--x--- | _posture (_crStance cr) == Aiming || crIsReloading cr = negate $ fromMaybe 0 $ do
|
||||
-- | _posture (_crStance cr) == Aiming = negate $ fromMaybe 0 $ do
|
||||
| Aiming {} <- _posture (_crStance cr) = negate $ fromMaybe 0 $ do
|
||||
i <- cr ^? crManipulation . manObject . imRootSelectedItem
|
||||
cr ^? crInv . ix i . itUse . heldAim . aimWeight
|
||||
| otherwise = 0
|
||||
strFromHeldItem cr = fromMaybe 0 $ do
|
||||
Aiming <- cr ^? crStance . posture
|
||||
i <- cr ^? crManipulation . manObject . imRootSelectedItem
|
||||
fmap negate $ cr ^? crInv . ix i . itUse . heldAim . aimWeight
|
||||
|
||||
@@ -2,9 +2,7 @@ module Dodge.Creature.YourControl (
|
||||
yourControl,
|
||||
) where
|
||||
|
||||
import Dodge.SelectedClose
|
||||
import Control.Monad
|
||||
import Data.Foldable
|
||||
import qualified Data.Map.Strict as M
|
||||
import Data.Maybe
|
||||
import Dodge.Base.Coordinate
|
||||
@@ -14,6 +12,7 @@ import Dodge.Data.World
|
||||
import Dodge.Hotkey
|
||||
import Dodge.InputFocus
|
||||
import Dodge.Inventory
|
||||
import Dodge.SelectedClose
|
||||
import Dodge.WASD
|
||||
import Geometry
|
||||
import LensHelp
|
||||
@@ -27,9 +26,7 @@ yourControl _ w
|
||||
| Just x <- w ^? hud . hudElement . subInventory
|
||||
, f x =
|
||||
w
|
||||
& cWorld . lWorld . creatures . ix 0
|
||||
-- %~ (wasdWithAiming w . setCrPosture pkeys)
|
||||
%~ wasdWithAiming w
|
||||
& cWorld . lWorld . creatures . ix 0 %~ wasdWithAiming w
|
||||
& tryClickUse pkeys
|
||||
& handleHotkeys
|
||||
| otherwise =
|
||||
@@ -42,17 +39,17 @@ yourControl _ w
|
||||
|
||||
handleHotkeys :: World -> World
|
||||
handleHotkeys w
|
||||
| SDL.ScancodeLShift `M.member` _pressedKeys (_input w)
|
||||
|| SDL.ScancodeRShift `M.member` _pressedKeys (_input w)
|
||||
, hks <- mapMaybe scancodeToHotkey $ M.keys $ w ^. input . pressedKeys
|
||||
| ispressed SDL.ScancodeLShift || ispressed SDL.ScancodeRShift
|
||||
, Just hk <- listToMaybe . mapMaybe scancodeToHotkey . M.keys $ w ^. input . pressedKeys
|
||||
, Just invid <- lw ^? creatures . ix 0 . crManipulation . manObject . imSelectedItem
|
||||
, Just itid <- lw ^? creatures . ix 0 . crInv . ix invid . itID =
|
||||
w & cWorld . lWorld %~ \lw' -> foldl' (flip $ assignHotkey itid) lw' hks
|
||||
| SDL.ScancodeLCtrl `M.member` _pressedKeys (_input w)
|
||||
|| SDL.ScancodeRCtrl `M.member` _pressedKeys (_input w)
|
||||
, Just hk <- listToMaybe . mapMaybe scancodeToHotkey . M.keys $ w ^. input . pressedKeys
|
||||
, Just itid <- w ^? cWorld . lWorld . hotkeys . ix hk . unNInt
|
||||
, Just invid <- w ^? cWorld . lWorld . itemLocations . ix itid . ilInvID =
|
||||
w & cWorld . lWorld %~ assignHotkey itid hk
|
||||
| ispressed SDL.ScancodeLCtrl || ispressed SDL.ScancodeRCtrl
|
||||
, Just hk <-
|
||||
listToMaybe . mapMaybe scancodeToHotkey . M.keys $
|
||||
w ^. input . pressedKeys
|
||||
, Just itid <- lw ^? hotkeys . ix hk . unNInt
|
||||
, Just invid <- lw ^? itemLocations . ix itid . ilInvID =
|
||||
w & augInvDirectSelect (0, invid, mempty)
|
||||
| otherwise =
|
||||
M.foldl'
|
||||
@@ -60,6 +57,7 @@ handleHotkeys w
|
||||
w
|
||||
(M.intersectionWith (,) thehotkeys (w ^. input . pressedKeys))
|
||||
where
|
||||
ispressed k = k `M.member` _pressedKeys (_input w)
|
||||
thehotkeys = M.mapKeys hotkeyToScancode $ w ^. cWorld . lWorld . hotkeys
|
||||
lw = w ^. cWorld . lWorld
|
||||
|
||||
@@ -112,11 +110,7 @@ scancodeToHotkey x = case x of
|
||||
{- | The order of these MAY be important, in particular the setting of crMvAim
|
||||
within wasdMovement should probably be done first
|
||||
-}
|
||||
wasdWithAiming ::
|
||||
World ->
|
||||
Creature ->
|
||||
Creature
|
||||
--wasdWithAiming w cr = wasdAim inp cam . wasdTwist $ wasdMovement inp cam speed cr
|
||||
wasdWithAiming :: World -> Creature -> Creature
|
||||
wasdWithAiming w cr = wasdAim inp cam $ wasdMovement inp cam speed cr
|
||||
where
|
||||
speed = _mvSpeed $ _crMvType cr
|
||||
@@ -125,57 +119,32 @@ wasdWithAiming w cr = wasdAim inp cam $ wasdMovement inp cam speed cr
|
||||
|
||||
wasdAim :: Input -> Camera -> Creature -> Creature
|
||||
wasdAim inp cam cr
|
||||
| Just 0 <- inp ^? mouseButtons . ix SDL.ButtonRight
|
||||
= setAimPosture cr
|
||||
| Just 0 <- inp ^? mouseButtonsReleased . ix SDL.ButtonRight
|
||||
= removeAimPosture cr
|
||||
| Just 0 <- inp ^? mouseButtons . ix SDL.ButtonRight =
|
||||
setAimPosture cr
|
||||
| Just 0 <- inp ^? mouseButtonsReleased . ix SDL.ButtonRight =
|
||||
removeAimPosture cr
|
||||
| SDL.ButtonRight `M.member` _mouseButtons inp = aimTurn mouseDir cr
|
||||
| otherwise = creatureTurnTowardDir (_crMvAim cr) 0.2 cr
|
||||
where
|
||||
mouseDir = argV $ mouseWorldPos inp cam - (cr ^. crPos)
|
||||
|
||||
---- aim with the root item
|
||||
---- when initiating aim with a two handed weapon, change the creature direction
|
||||
---- to be closer to where the two handed weapon was pointing
|
||||
--wasdTwist :: Creature -> Creature
|
||||
--wasdTwist cr
|
||||
---- | _posture (_crStance cr) == Aiming
|
||||
-- | Aiming {} <- cr ^. crStance . posture = fromMaybe cr $ do
|
||||
-- itRef <- cr ^? crManipulation . manObject . imRootSelectedItem
|
||||
-- astance <- cr ^? crInv . ix itRef . itUse . heldAim . aimStance
|
||||
-- case (astance, cr ^. crTwist) of
|
||||
-- (TwoHandUnder, 0) ->
|
||||
-- return $ cr & crTwist .~ twistamount * pi & crDir -~ twistamount * pi
|
||||
-- (TwoHandOver, 0) ->
|
||||
-- return $ cr & crTwist .~ twistamount * pi & crDir -~ twistamount * pi
|
||||
-- _ -> Nothing
|
||||
-- | otherwise =
|
||||
-- cr
|
||||
-- & crDir +~ _crTwist cr
|
||||
-- & crTwist .~ 0 --remove twistk
|
||||
-- where
|
||||
-- twistamount = 1.6
|
||||
|
||||
setAimPosture :: Creature -> Creature
|
||||
setAimPosture cr = fromMaybe cr $ do
|
||||
setAimPosture = (crStance . posture .~ Aiming) . doAimTwist (- twoHandTwistAmount)
|
||||
|
||||
doAimTwist :: Float -> Creature -> Creature
|
||||
doAimTwist x cr = fromMaybe cr $ do
|
||||
itRef <- cr ^? crManipulation . manObject . imRootSelectedItem
|
||||
astance <- cr ^? crInv . ix itRef . itUse . heldAim . aimStance
|
||||
case astance of
|
||||
TwoHandUnder ->
|
||||
return $ cr & crStance . posture .~ Aiming
|
||||
& crDir -~ twoHandTwistAmount
|
||||
TwoHandOver ->
|
||||
return $ cr & crStance . posture .~ Aiming
|
||||
& crDir -~ twoHandTwistAmount
|
||||
_ -> return $ cr & crStance . posture .~ Aiming
|
||||
return $ case astance of
|
||||
TwoHandUnder -> cr & crDir +~ x
|
||||
TwoHandOver -> cr & crDir +~ x
|
||||
_ -> cr
|
||||
|
||||
removeAimPosture :: Creature -> Creature
|
||||
removeAimPosture = (crStance . posture .~ AtEase) . doAimTwist twoHandTwistAmount
|
||||
|
||||
twoHandTwistAmount :: Float
|
||||
twoHandTwistAmount = 1.6 * pi
|
||||
|
||||
removeAimPosture :: Creature -> Creature
|
||||
removeAimPosture cr = cr
|
||||
& crDir +~ twoHandTwistAmount
|
||||
& crStance . posture .~ AtEase
|
||||
|
||||
wasdMovement :: Input -> Camera -> Float -> Creature -> Creature
|
||||
wasdMovement inp cam speed = theMovement . setMvAim
|
||||
@@ -201,10 +170,11 @@ tryClickUse pkeys w = fromMaybe w $ do
|
||||
ltime <- pkeys ^? ix SDL.ButtonLeft
|
||||
rtime <- pkeys ^? ix SDL.ButtonRight
|
||||
guard $ ltime <= rtime
|
||||
case w ^? cWorld . lWorld . creatures . ix 0
|
||||
. crManipulation
|
||||
. manObject
|
||||
. imSelectedItem of
|
||||
case w
|
||||
^? cWorld . lWorld . creatures . ix 0
|
||||
. crManipulation
|
||||
. manObject
|
||||
. imSelectedItem of
|
||||
Just invid -> useItem invid (f ltime) w
|
||||
Nothing -> interactWithCloseObj <$> getSelectedCloseObj w ?? w
|
||||
where
|
||||
|
||||
+1
-3
@@ -9,10 +9,8 @@ import NewInt
|
||||
|
||||
-- it is not obvious to me whether hotkeys should belong to LWorld, CWorld or
|
||||
-- World
|
||||
|
||||
assignHotkey :: NewInt ItmInt -> Hotkey -> LWorld -> LWorld
|
||||
assignHotkey (NInt itid) hk lw =
|
||||
lw
|
||||
assignHotkey (NInt itid) hk lw = lw
|
||||
& handleoldposition
|
||||
& hotkeys . at hk ?~ NInt itid
|
||||
& imHotkeys . unNIntMap . at itid ?~ hk
|
||||
|
||||
@@ -28,23 +28,23 @@ heldItemOrient2D itm cr p a = (V2 x y, argV . Q.qToV2 $ q )
|
||||
where
|
||||
(V3 x y _,q) = heldItemRelativeOrient itm cr (p `v2z` 0, Q.axisAngle (V3 0 0 1) a)
|
||||
|
||||
heldItemRelativeOrient :: Item -> Creature -> (Point3, Q.Quaternion Float) -> (Point3, Q.Quaternion Float)
|
||||
heldItemRelativeOrient
|
||||
:: Item -> Creature -> (Point3, Q.Quaternion Float) -> (Point3, Q.Quaternion Float)
|
||||
heldItemRelativeOrient itm cr (p,q)
|
||||
| Aiming {} <- _posture (_crStance cr) =
|
||||
(p + aimingWeaponZeroPos cr itm `v2z` shoulderHeight, Q.qID * q)
|
||||
| isTwoHandFlat =
|
||||
( V3 (_crRad cr) 0 handD
|
||||
+ rotate3 (twoFlatHRot cr) (transToHandle itm p)
|
||||
( V3 (_crRad cr) 0 handD + rotate3 (twoFlatHRot cr) (transToHandle itm p)
|
||||
, Q.axisAngle (V3 0 0 1) (twoFlatHRot cr) * q
|
||||
)
|
||||
| isOneHand =
|
||||
( V3 (_crRad cr * 0.7 + handPos) (_crRad cr * negate 0.7) handD
|
||||
+ transToHandle itm p
|
||||
+ transToHandle itm p
|
||||
, Q.qID * q
|
||||
)
|
||||
| otherwise =
|
||||
( V3 (_crRad cr) 0 handD
|
||||
+ rotate3 (strideRot cr + 1.2) (V3 (-8) 0 0 + transToHandle itm p)
|
||||
( V3 (_crRad cr) 0 handD
|
||||
+ rotate3 (strideRot cr + 1.2) (V3 (-8) 0 0 + transToHandle itm p)
|
||||
, Q.axisAngle (V3 0 0 1) (strideRot cr + 1.2) * q
|
||||
)
|
||||
where
|
||||
@@ -74,7 +74,6 @@ aimingWeaponHandlePos _ it = case it ^? itUse . heldAim . aimStance of
|
||||
Just TwoHandFlat -> V2 10 0
|
||||
Nothing -> 0
|
||||
|
||||
|
||||
heldItemOffset :: Item -> Creature -> Point3 -> Point3
|
||||
heldItemOffset itm cr p = fst (heldItemRelativeOrient itm cr (p,Q.qID))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user