Held item rclick use, tweak reload on lclick

This commit is contained in:
2023-05-28 10:17:32 +01:00
parent ec8317c14e
commit 10c9e2261f
9 changed files with 68 additions and 65 deletions
+13 -1
View File
@@ -19,6 +19,7 @@ import Dodge.Base.Arithmetic
import Dodge.Base.NewID import Dodge.Base.NewID
import Dodge.Base.Coordinate import Dodge.Base.Coordinate
import Dodge.Base.CardinalPoint import Dodge.Base.CardinalPoint
import Data.List (unfoldr)
--import Dodge.Zone --import Dodge.Zone
--import Dodge.Zone.Data --import Dodge.Zone.Data
import Dodge.Base.Window import Dodge.Base.Window
@@ -151,4 +152,15 @@ spreadAroundCenter :: Int -> Float -> [Float]
spreadAroundCenter i x = [x * fromIntegral j - x*fromIntegral (i-1)*0.5 | j <- [0 .. i - 1]] spreadAroundCenter i x = [x * fromIntegral j - x*fromIntegral (i-1)*0.5 | j <- [0 .. i - 1]]
spreadFromCenter :: Int -> Float -> [Float] spreadFromCenter :: Int -> Float -> [Float]
spreadFromCenter i x = [x * fromIntegral j - x*fromIntegral (i-1)*0.5 | j <- [0 .. i - 1]] spreadFromCenter i x = [x * fromIntegral j | j <- js]
where
js = take i outwardIntegers
outwardIntegers :: [Int]
outwardIntegers = unfoldr f (0, False)
where
f (x,True) = Just (x, (x,False))
f (x,False) = Just (-x, (x+1,True))
spreadCenter :: Int -> Float -> [Float]
spreadCenter i x = [x * fromIntegral j - x*fromIntegral (i-1)*0.5 | j <- [0 .. i - 1]]
+1 -1
View File
@@ -259,7 +259,7 @@ stackedInventory =
, flatShield , flatShield
, spawnGun (lamp 5) , spawnGun (lamp 5)
, lasGun , lasGun
, lasWide 5 , lasWide 20
, flameThrower , flameThrower
, poisonSprayer , poisonSprayer
, launcher , launcher
+4 -2
View File
@@ -5,8 +5,6 @@ module Dodge.Creature.Impulse.UseItem (
useItemHotkey, useItemHotkey,
) where ) where
import Dodge.Inventory.RBList
import Dodge.Hotkey
import Control.Lens import Control.Lens
import Control.Monad import Control.Monad
import Data.Foldable import Data.Foldable
@@ -15,7 +13,9 @@ import Dodge.Cuse
import Dodge.Data.World import Dodge.Data.World
import Dodge.Euse import Dodge.Euse
import Dodge.HeldUse import Dodge.HeldUse
import Dodge.Hotkey
import Dodge.Inventory import Dodge.Inventory
import Dodge.Item.Location
import Dodge.Luse import Dodge.Luse
import Dodge.Reloading import Dodge.Reloading
import qualified IntMapHelp as IM import qualified IntMapHelp as IM
@@ -28,6 +28,7 @@ useItemRightClick cr' w = fromMaybe (f w) $ do
return $ return $
itemEffect cr it w itemEffect cr it w
& worldEventFlags . at InventoryChange ?~ () & worldEventFlags . at InventoryChange ?~ ()
& f
where where
f = cWorld . lWorld . creatures . ix (_crID cr') . crHammerPosition .~ HammerDown f = cWorld . lWorld . creatures . ix (_crID cr') . crHammerPosition .~ HammerDown
@@ -35,6 +36,7 @@ itemEffect :: Creature -> Item -> World -> World
itemEffect cr it w = case it ^. itUse of itemEffect cr it w = case it ^. itUse of
HeldUse{_heldUse = eff, _heldMods = usemods} -> HeldUse{_heldUse = eff, _heldMods = usemods} ->
foldl' (&) (useHeld eff) (useMod usemods) it cr w foldl' (&) (useHeld eff) (useMod usemods) it cr w
& pointerToItem it . itUse . heldHammer .~ HammerDown
LeftUse{} -> doequipmentchange LeftUse{} -> doequipmentchange
EquipUse{} -> doequipmentchange EquipUse{} -> doequipmentchange
-- ConsumeUse will cause problems if the item is not selected -- ConsumeUse will cause problems if the item is not selected
+17 -18
View File
@@ -72,36 +72,36 @@ useMod hm = case hm of
] ]
CircleLaserMod -> CircleLaserMod ->
[ duplicateItem fLasCircle [ duplicateItem fLasCircle
, withItemUpdate' increasecycleLasCircle
, useAmmoAmount 1 , useAmmoAmount 1
, withSoundForI tone440sawtoothquietS 2 , withSoundForI tone440sawtoothquietS 2
, withItem $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) 0.8 , withItem $ \it -> withCrPos $ flareCircleAt (_lasColor $ _itParams it) 0.8
, withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it)) , withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it))
, withItemUpdateFirst increasecycleLasCircle
, ammoCheckI , ammoCheckI
] ]
LasWideMod n -> LasWideMod n ->
[ withItem $ \it -> duplicateOffsetsV2 (xsLasWide it) [ useAmmoAmount 1
, withItemUpdate' (increasecycleLasWide n) , withItem $ \it -> duplicateNumBarrels (min
, crAtMuzPos (it ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded)
, useAmmoAmount 1 (it ^?! itParams . lasCycle `div` lasWideRate))
, withSoundForI tone440sawtoothquietS 2 , withItem $ \it -> withCrPos $ flareCircleAt (_lasColor $ _itParams it) 0.8
, withItem $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) 0.8
, withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it)) , withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it))
, duplicateLoadedBarrels , withSoundForI tone440sawtoothquietS 2
, withItemUpdateFirst (increasecycleLasWide n)
, ammoCheckI , ammoCheckI
] ]
DualBeamMod -> DualBeamMod ->
[ useAmmoAmount 1 [ useAmmoAmount 1
, withSoundForI tone440sawtoothquietS 2 , withSoundForI tone440sawtoothquietS 2
, withItem $ \it -> withMuzPosShift (V2 0 (- thegapDualBeam it)) $ flareCircleAt (_lasColor2 $ _itParams it) 0.8 , withItem $ \it -> withCrPosShift (V2 0 (- thegapDualBeam it)) $ flareCircleAt (_lasColor2 $ _itParams it) 0.8
, withItem $ \it -> withMuzPosShift (V2 0 (thegapDualBeam it)) $ flareCircleAt (_lasColor $ _itParams it) 0.8 , withItem $ \it -> withCrPosShift (V2 0 (thegapDualBeam it)) $ flareCircleAt (_lasColor $ _itParams it) 0.8
, ammoCheckI , ammoCheckI
] ]
LasMod -> LasMod ->
[ useAmmoAmount 1 [ useAmmoAmount 1
-- , withItem $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) 0.8 , withItem $ \it -> withCrPos $ flareCircleAt (_lasColor $ _itParams it) 0.8
, withSoundForI tone440sawtoothquietS 2 , withSoundForI tone440sawtoothquietS 2
-- , withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it)) , withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it))
, duplicateLoadedBarrels , duplicateLoadedBarrels
, ammoCheckI , ammoCheckI
] ]
@@ -349,11 +349,7 @@ useMod hm = case hm of
fLasCircle it = [it & itParams . lasCycle +~ x | x <- [0, 50 .. 1999]] fLasCircle it = [it & itParams . lasCycle +~ x | x <- [0, 50 .. 1999]]
increasecycleLasWide n it = case _heldHammer (_itUse it) of increasecycleLasWide n it = case _heldHammer (_itUse it) of
HammerUp -> it & itParams . lasCycle .~ 1 HammerUp -> it & itParams . lasCycle .~ 1
_ -> it & itParams . lasCycle %~ (min (n * 5) . (+ 1)) _ -> it & itParams . lasCycle %~ (min (n * lasWideRate) . (+ 1))
xsLasWide it = [V2 ((0.2 * yoff x) ^ (2 :: Int)) (yoff x) | x <- [(0 :: Int) .. n' -1]]
where
yoff x = fromIntegral x - fromIntegral (n' -1) / 2
n' = _lasCycle (_itParams it)
thegapDualBeam = _dbGap . _itParams thegapDualBeam = _dbGap . _itParams
directedTelPos _ cr w = (p, a) directedTelPos _ cr w = (p, a)
where where
@@ -364,6 +360,9 @@ useMod hm = case hm of
cr & crDir %~ tweenAngles x (_crOldDir cr) cr & crDir %~ tweenAngles x (_crOldDir cr)
& crPos %~ alongSegBy x (_crOldPos cr) & crPos %~ alongSegBy x (_crOldPos cr)
lasWideRate :: Int
lasWideRate = 2
mcUseHeld :: HeldItemType -> Item -> Machine -> World -> World mcUseHeld :: HeldItemType -> Item -> Machine -> World -> World
mcUseHeld hit = case hit of mcUseHeld hit = case hit of
LASGUN -> mcShootLaser LASGUN -> mcShootLaser
+1 -1
View File
@@ -21,7 +21,7 @@ import Padding
itemDisplayOffset :: Creature -> Item -> (Int,[String]) itemDisplayOffset :: Creature -> Item -> (Int,[String])
itemDisplayOffset cr itm = case itm ^. itType . iyBase of itemDisplayOffset cr itm = case itm ^. itType . iyBase of
EQUIP (TARGETINGHAT tt) | targetItemCanAttachAbove cr itm EQUIP (TARGETINGHAT tt) | targetItemCanAttachAbove cr itm
-> ((-1), leftPad 15 ' ' (targetingTypeString tt) : -> (-1, leftPad 15 ' ' (targetingTypeString tt) :
(itemDisplay cr itm & ix 0 %~ (\s -> itemDisplayPad s (replicate (length (targetingTypeString tt)) '^') ))) (itemDisplay cr itm & ix 0 %~ (\s -> itemDisplayPad s (replicate (length (targetingTypeString tt)) '^') )))
EQUIP (TARGETINGHAT tt) EQUIP (TARGETINGHAT tt)
-> (0, itemDisplay cr itm & ix 0 %~ (\s -> itemDisplayPad s (targetingTypeString tt))) -> (0, itemDisplay cr itm & ix 0 %~ (\s -> itemDisplayPad s (targetingTypeString tt)))
+3 -1
View File
@@ -1,5 +1,6 @@
module Dodge.Item.Held.BatteryGuns where module Dodge.Item.Held.BatteryGuns where
import Dodge.Base
import Dodge.Data.Beam import Dodge.Data.Beam
import Dodge.Default.Item import Dodge.Default.Item
import Color import Color
@@ -40,7 +41,7 @@ lasGun =
defaultAutoBatteryGun defaultAutoBatteryGun
& itUse . heldConsumption & itUse . heldConsumption
.~ ( defaultLoadable .~ ( defaultLoadable
& laSource . _InternalSource . iaMax .~ 200 & laSource . _InternalSource . iaMax .~ 200000
& laSource . _InternalSource . iaCycle .~ [loadEject 10, loadInsert 10, loadPrime 60] & laSource . _InternalSource . iaCycle .~ [loadEject 10, loadInsert 10, loadPrime 60]
) )
& itParams & itParams
@@ -114,6 +115,7 @@ lasWide n =
& itParams . lasColor .~ yellow & itParams . lasColor .~ yellow
& itParams . lasDamage .~ 2 & itParams . lasDamage .~ 2
& itUse . heldMods .~ LasWideMod n & itUse . heldMods .~ LasWideMod n
& itUse . heldAim . aimMuzzles .~ [Muzzle (V2 30 y) 0 0 | y <- spreadFromCenter n 1]
defaultBatteryGun :: Item defaultBatteryGun :: Item
defaultBatteryGun = defaultBatteryGun =
+9 -15
View File
@@ -3,7 +3,7 @@ module Dodge.Item.Weapon.BatteryGuns (
flameBeamCombine, flameBeamCombine,
teslaBeamCombine, teslaBeamCombine,
splitBeamCombine, splitBeamCombine,
-- shootTeslaArc, -- shootTeslaArc,
shootLaser, shootLaser,
circleLaser, circleLaser,
shootDualLaser, shootDualLaser,
@@ -22,8 +22,6 @@ import Picture
--import Control.Monad.State --import Control.Monad.State
--lasPulse :: Item --lasPulse :: Item
--lasPulse = lasGun --lasPulse = lasGun
-- & itType . iyBase .~ LASPULSE -- & itType . iyBase .~ LASPULSE
@@ -42,8 +40,6 @@ import Picture
-- & itParams . lasColor .~ frac it * orange -- & itParams . lasColor .~ frac it * orange
-- frac it = 0.5 * (1 + sin (pi * fromIntegral (_lasCycle $ _itParams it) * 0.1)) -- frac it = 0.5 * (1 + sin (pi * fromIntegral (_lasCycle $ _itParams it) * 0.1))
--lasWidePulse :: Item --lasWidePulse :: Item
--lasWidePulse = lasGun --lasWidePulse = lasGun
-- & itType . iyBase .~ LASGUNWIDEPULSE -- & itType . iyBase .~ LASGUNWIDEPULSE
@@ -109,7 +105,6 @@ import Picture
-- n' = 9 * n -- n' = 9 * n
-- xs = [ 0.25 * (fromIntegral x - fromIntegral (n'-1) /2) | x <- [0..n'-1] ] -- xs = [ 0.25 * (fromIntegral x - fromIntegral (n'-1) /2) | x <- [0..n'-1] ]
--lasSwing :: Item --lasSwing :: Item
--lasSwing = lasGun --lasSwing = lasGun
-- & itType . iyBase .~ LASGUNSWING -- & itType . iyBase .~ LASGUNSWING
@@ -129,16 +124,15 @@ import Picture
-- y = 15 * sin (pi * fromIntegral x' * 0.01) -- y = 15 * sin (pi * fromIntegral x' * 0.01)
-- x' = _lasCycle $ _itParams it -- x' = _lasCycle $ _itParams it
shootLaser :: Item -> Creature -> World -> World shootLaser :: Item -> Creature -> World -> World
shootLaser it cr = cWorld . lWorld . lasers .:~ lasRayAt (_lasColor $ _itParams it) dam phasev pos dir shootLaser it cr =
where cWorld . lWorld . lasers
pos = _crPos cr .:~ lasRayAt
dir = _crDir cr (_lasColor $ _itParams it)
phasev = _phaseV . _itParams $ _crInv cr IM.! itRef (_lasDamage $ _itParams it)
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change (_phaseV $ _itParams it)
dam = _lasDamage $ _itParams it (_crPos cr)
(_crDir cr)
-- this has the feel of a left click item -- this has the feel of a left click item
circleLaser :: Item -> Creature -> World -> World circleLaser :: Item -> Creature -> World -> World
+19 -25
View File
@@ -9,16 +9,15 @@ module Dodge.Item.Weapon.TriggerType (
useAmmoUpTo, useAmmoUpTo,
lockInvFor, lockInvFor,
withMuzFlareI, withMuzFlareI,
withMuzPos, withCrPos,
withMuzPosShift, withCrPosShift,
crAtMuzPos,
withOldDir, withOldDir,
trigDoAlso, trigDoAlso,
trigDoAlso', trigDoAlso',
withTempLight, withTempLight,
withItem, withItem,
withItemUpdate, withItemUpdate,
withItemUpdate', withItemUpdateFirst,
rateIncAB, rateIncAB,
torqueBefore, torqueBefore,
torqueBeforeAtLeast, torqueBeforeAtLeast,
@@ -48,6 +47,7 @@ module Dodge.Item.Weapon.TriggerType (
sideEffectOnFrame, sideEffectOnFrame,
duplicateItem, duplicateItem,
duplicateLoadedBarrels, duplicateLoadedBarrels,
duplicateNumBarrels,
duplicateLoaded, duplicateLoaded,
duplicateOffsetsV2, duplicateOffsetsV2,
duplicateOffsetsFocus, duplicateOffsetsFocus,
@@ -429,8 +429,8 @@ withItem :: (Item -> ChainEffect) -> ChainEffect
withItem g f it = g it f it withItem g f it = g it f it
-- not ideal -- not ideal
withItemUpdate' :: (Item -> Item) -> ChainEffect withItemUpdateFirst :: (Item -> Item) -> ChainEffect
withItemUpdate' up f it cr = f (up it) cr . (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef %~ up) withItemUpdateFirst up f it cr = f (up it) cr . (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef %~ up)
where where
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
@@ -475,23 +475,13 @@ withMuzFlareI f it cr w =
-- | crInAimStance OneHand cr = 10 -- | crInAimStance OneHand cr = 10
-- | otherwise = 0 -- | otherwise = 0
withMuzPos :: (Point3 -> World -> World) -> ChainEffect withCrPos :: (Point3 -> World -> World) -> ChainEffect
withMuzPos = withMuzPosShift (V2 0 0) withCrPos = withCrPosShift (V2 0 0)
withMuzPosShift :: Point2 -> (Point3 -> World -> World) -> ChainEffect withCrPosShift :: Point2 -> (Point3 -> World -> World) -> ChainEffect
withMuzPosShift p g f it cr = g thepos . f it cr withCrPosShift p g f it cr = g thepos . f it cr
where where
thepos = (_crPos cr `v2z` 20) thepos = (_crPos cr +.+ rotateV (_crDir cr) p) `v2z` 20
--thepos = (pos `v2z` 20)
--pos =
-- _crPos cr
-- +.+ rotateV dir p
-- +.+ aimingMuzzlePos cr it *.* unitVectorAtAngle dir
--dir = _crDir cr
crAtMuzPos :: ChainEffect
--crAtMuzPos f it cr = f it (cr & crPos +.+.~ (aimingMuzzlePos cr it *.* unitVectorAtAngle (_crDir cr)))
crAtMuzPos f it cr = f it cr
-- | Applies the effect to a randomly rotated creature. -- | Applies the effect to a randomly rotated creature.
withRandomDirI :: withRandomDirI ::
@@ -641,14 +631,13 @@ duplicateLoaded eff it cr w = foldr f w [1 .. numBul]
f _ = eff it cr f _ = eff it cr
numBul = it ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded numBul = it ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded
duplicateLoadedBarrels :: ChainEffect duplicateNumBarrels :: Int -> ChainEffect
duplicateLoadedBarrels eff itm cr w = foldr f w (take numbul $ itm ^?! itUse . heldAim . aimMuzzles) duplicateNumBarrels n eff itm cr w = foldr f w (take n $ itm ^?! itUse . heldAim . aimMuzzles)
where where
numbul = itm ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded
f brl w' = f brl w' =
eff eff
itm itm
( cr & crPos +~ (rotateV (_crDir cr) (_mzPos brl)) ( cr & crPos +~ rotateV (_crDir cr) (_mzPos brl)
& crDir +~ (_mzRot brl + a) & crDir +~ (_mzRot brl + a)
) )
(w' & randGen .~ g) (w' & randGen .~ g)
@@ -656,6 +645,11 @@ duplicateLoadedBarrels eff itm cr w = foldr f w (take numbul $ itm ^?! itUse . h
inacc = _mzInaccuracy brl inacc = _mzInaccuracy brl
(a,g) = randomR (-inacc,inacc) $ _randGen w' (a,g) = randomR (-inacc,inacc) $ _randGen w'
duplicateLoadedBarrels :: ChainEffect
duplicateLoadedBarrels eff itm = duplicateNumBarrels numbul eff itm
where
numbul = itm ^?! itUse . heldConsumption . laSource . _InternalSource . iaLoaded
duplicateOffsetsFocus :: [Float] -> ChainEffect duplicateOffsetsFocus :: [Float] -> ChainEffect
duplicateOffsetsFocus xs eff item cr w = foldr f w poss duplicateOffsetsFocus xs eff item cr w = foldr f w poss
where where
+1 -1
View File
@@ -130,7 +130,7 @@ selSecYint i j sss = do
return . (secpos +) return . (secpos +)
. subtract (ss ^. ssOffset) . subtract (ss ^. ssOffset)
. sum . sum
. fmap (_siHeight) . fmap _siHeight
. fst . fst
$ IM.split j (ss ^. ssItems) $ IM.split j (ss ^. ssItems)
where where