diff --git a/src/Dodge/Creature/YourControl.hs b/src/Dodge/Creature/YourControl.hs index 5c434721c..5ef57c135 100644 --- a/src/Dodge/Creature/YourControl.hs +++ b/src/Dodge/Creature/YourControl.hs @@ -2,8 +2,6 @@ module Dodge.Creature.YourControl ( yourControl, ) where -import Dodge.Creature.Impulse.UseItem -import Dodge.Hotkey import Control.Monad import Data.Foldable import qualified Data.Map.Strict as M @@ -11,8 +9,10 @@ import Data.Maybe import Dodge.Base.Coordinate import Dodge.Base.You import Dodge.Creature.Impulse.Movement +import Dodge.Creature.Impulse.UseItem import Dodge.Creature.Test import Dodge.Data.World +import Dodge.Hotkey import Dodge.InputFocus import Dodge.WASD import Geometry @@ -92,8 +92,9 @@ tryAssignHotkey w sc = fromMaybe w $ do itid <- cr ^? crManipulation . manObject . inInventory . ispItem return $ w & cWorld . lWorld . creatures . ix 0 %~ assignHotkey itid (scancodeToHotkey sc) --- | Turn key presses into creature movement. --- | note the order of operation, setting the posture first--this prevents the twist fire bug +{- | Turn key presses into creature movement. + | note the order of operation, setting the posture first--this prevents the twist fire bug +-} wasdWithAiming :: World -> -- | Base speed @@ -115,16 +116,11 @@ wasdWithAiming w speed cr addAnyTwist = fromMaybe id $ do itRef <- cr ^? crManipulation . manObject . inInventory . ispItem astance <- cr ^? crInv . ix itRef . itUse . heldAim . aimStance - let currenttwistamount = cr ^. crTwist - case (astance, currenttwistamount) of + case (astance, cr ^. crTwist) of (TwoHandUnder, 0) -> - return $ - (crTwist .~ twistamount * pi) - . (crDir -~ twistamount * pi) + return $ (crTwist .~ twistamount * pi) . (crDir -~ twistamount * pi) (TwoHandOver, 0) -> - return $ - (crTwist .~ twistamount * pi) - . (crDir -~ twistamount * pi) + return $ (crTwist .~ twistamount * pi) . (crDir -~ twistamount * pi) _ -> Nothing theMovement | movDir == V2 0 0 = id @@ -154,11 +150,10 @@ aimTurn a cr = creatureTurnTowardDir a (x * 0.2) cr -- | Set posture according to mouse presses. mouseActionsCr :: M.Map SDL.MouseButton Int -> Creature -> Creature mouseActionsCr pkeys cr - | rbPressed && noaction = + | SDL.ButtonRight `M.member` pkeys && noaction = cr & crStance . posture .~ Aiming | otherwise = cr & crStance . posture .~ AtEase where - rbPressed = SDL.ButtonRight `M.member` pkeys noaction = fromMaybe True $ do theaction <- cr ^? crManipulation . manObject . inInventory . iselAction return $ theaction == NoInvSelAction @@ -167,8 +162,7 @@ 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.ButtonMiddle = - w & wCam . camRot -~ rotation + | isDown SDL.ButtonMiddle = w & wCam . camRot -~ rotation | otherwise = w where inTopInv = case w ^. hud . hudElement of diff --git a/src/Dodge/Default/Item.hs b/src/Dodge/Default/Item.hs index 7bc751c73..2c0f06f07 100644 --- a/src/Dodge/Default/Item.hs +++ b/src/Dodge/Default/Item.hs @@ -85,5 +85,3 @@ defaultConsumable = & itUse .~ ConsumeUse CDoNothing 1 & itInvColor .~ blue -defaultItZoom :: ItZoom -defaultItZoom = ItZoom 20 0.2 1 diff --git a/src/Dodge/Default/Item/Use/AimParams.hs b/src/Dodge/Default/Item/Use/AimParams.hs index d8ecfbaad..1a2166546 100644 --- a/src/Dodge/Default/Item/Use/AimParams.hs +++ b/src/Dodge/Default/Item/Use/AimParams.hs @@ -9,10 +9,18 @@ defaultAimParams = { _aimWeight = 0 , _aimTurnSpeed = 1 , _aimRange = 0 - , _aimZoom = ItZoom 20 0.2 1 + , _aimZoom = defaultItZoom , _aimStance = OneHand - --, _aimHandlePos = 10 - , _aimHandlePos = V2 3 0 + , --, _aimHandlePos = 10 + _aimHandlePos = V2 3 0 , _aimMuzzles = [Muzzle (V2 20 0) 0 0] --- , _aimMuzPos = 20 + -- , _aimMuzPos = 20 + } + +defaultItZoom :: ItZoom +defaultItZoom = + ItZoom + { _izMax = 20 + , _izMin = 0.2 + , _izFac = 1 } diff --git a/src/Dodge/Item/Held/Cane.hs b/src/Dodge/Item/Held/Cane.hs index 6af504c4e..57d373fd8 100644 --- a/src/Dodge/Item/Held/Cane.hs +++ b/src/Dodge/Item/Held/Cane.hs @@ -39,25 +39,14 @@ defaultBangCane = volleyGun :: Int -> Item volleyGun i = defaultBangCane - & itUse . heldDelay . rateMax .~ 6 & itUse . heldMods .~ VolleyGunMod & itUse . heldAim . aimWeight .~ 6 & itUse . heldAim . aimRange .~ 1 & itUse . heldAim . aimStance .~ TwoHandFlat & itUse . heldAim . aimZoom .~ defaultItZoom{_izFac = 1.5} - -- & itUse . heldAim . aimHandlePos .~ 5 & itUse . heldAim . aimMuzzles .~ [Muzzle (V2 15 x) 0 0.01 | x <- spreadAroundCenter i 3] & itUse . heldConsumption . laSource . _InternalSource . iaMax .~ i - & itParams - .~ BulletShooter - { _muzVel = 0.8 - , _rifling = 0.9 - , _bore = 2 - , _recoil = 50 - , _torqueAfter = 0.1 - , _randomOffset = 0 - } - & itParams . torqueAfter .~ 0.48 + 0.2 * fromIntegral i + & itParams . torqueAfter .~ 0.15 + 0.05 * fromIntegral i & itType . iyBase .~ HELD (VOLLEYGUN i) rifle :: Item diff --git a/src/Dodge/Item/Held/Rod.hs b/src/Dodge/Item/Held/Rod.hs index 3ecbcf681..76520c9d3 100644 --- a/src/Dodge/Item/Held/Rod.hs +++ b/src/Dodge/Item/Held/Rod.hs @@ -49,7 +49,6 @@ elephantGun = & itUse . heldAim . aimMuzzles . ix 0 . mzInaccuracy .~ 0.05 & itUse . heldMods .~ ElephantGunMod & itParams . recoil .~ 50 - & itParams . torqueAfter .~ 0.1 amr :: Item amr = diff --git a/src/Dodge/Item/Location.hs b/src/Dodge/Item/Location.hs index 3a3653b18..49e7b5f96 100644 --- a/src/Dodge/Item/Location.hs +++ b/src/Dodge/Item/Location.hs @@ -2,9 +2,11 @@ module Dodge.Item.Location ( pointerToItemLocation, getItem, pointerToItem, + pointerYourItem, ) where import Control.Lens +import Data.Maybe import Dodge.Data.World getItem :: Int -> World -> Maybe Item @@ -26,6 +28,11 @@ pointerToItemLocation (InInv cid invid) = cWorld . lWorld . creatures . ix cid . pointerToItemLocation (OnFloor flid) = cWorld . lWorld . floorItems . ix flid . flIt pointerToItemLocation _ = const pure +pointerYourItem :: Applicative a => (Item -> a Item) -> World -> a World +pointerYourItem f w = fromMaybe (pure w) $ do + itinvid <- w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . inInventory . ispItem + Just $ pointerToItemLocation (InInv 0 itinvid) f w + pointerToItem :: Applicative f => Item -> diff --git a/src/Dodge/Item/Weapon/TriggerType.hs b/src/Dodge/Item/Weapon/TriggerType.hs index fce2d93af..d71f72f56 100644 --- a/src/Dodge/Item/Weapon/TriggerType.hs +++ b/src/Dodge/Item/Weapon/TriggerType.hs @@ -59,6 +59,7 @@ module Dodge.Item.Weapon.TriggerType ( blCheck, ) where +import Dodge.Item.Location import Dodge.Creature.HandPos import Data.Foldable import Data.Maybe @@ -202,16 +203,16 @@ withWarmUp :: withWarmUp soundID f item cr w | curWarmUp < maxWarmUp && crWeaponReady cr = w - & pointerToItem . itUse . heldDelay . warmTime +~ 2 + & pointertoitem . itUse . heldDelay . warmTime +~ 2 & soundContinue (CrWeaponSound cid 0) (_crPos cr) soundID (Just 2) | otherwise = w - & pointerToItem . itUse . heldDelay . warmTime .~ maxWarmUp + & pointertoitem . itUse . heldDelay . warmTime .~ maxWarmUp & f item cr where cid = _crID cr itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change - pointerToItem = cWorld . lWorld . creatures . ix cid . crInv . ix itRef + pointertoitem = cWorld . lWorld . creatures . ix cid . crInv . ix itRef curWarmUp = _warmTime . _heldDelay $ _itUse item maxWarmUp = _warmMax . _heldDelay $ _itUse item @@ -411,7 +412,7 @@ shootL :: World shootL f item cr w | fireCondition = - f item cr w & pointerToItem + f item cr w & cWorld . lWorld . creatures . ix cid . crInv . ix invid %~ ( itUseCharge 1 . (itUse . leftDelay . rateTime .~ _rateMax (_leftDelay (_itUse item))) ) @@ -420,7 +421,6 @@ shootL f item cr w where cid = _crID cr invid = _ipInvID $ _itLocation item - pointerToItem = cWorld . lWorld . creatures . ix cid . crInv . ix invid fireCondition = _rateTime (_leftDelay (_itUse item)) == 0 && _arLoaded (_leftConsumption (_itUse item)) > 0 @@ -587,13 +587,16 @@ torqueBeforeAtLeast minTorque exTorque feff item cr w withTorqueAfter :: ChainEffect withTorqueAfter feff item cr w -- | cid == 0 = rotateScope $ set randGen g $ over cameraRot (+rot) $ feff item cr w - | cid == 0 = set randGen g $ over (wCam . camRot) (+ rot) $ feff item cr w + | cid == 0 = rotateScope . set randGen g $ over (wCam . camRot) (+ rot) $ feff item cr w | otherwise = set randGen g $ over (cWorld . lWorld . creatures . ix cid . crDir) (+ rot) $ feff item cr w where cid = _crID cr (rot, g) = randomR (- torque, torque) $ _randGen w torque = fromMaybe 0 $ item ^? itParams . torqueAfter + --rotateScope = cWorld . lWorld . creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0)) + rotateScope = pointerYourItem . itScope . scopePos %~ rotateV rot + sideEffectOnFrame :: Int -> (Item -> Creature -> WdWd) ->