From ce533c22cbf93bb75f074eaee61146812ed9a4e0 Mon Sep 17 00:00:00 2001 From: justin Date: Fri, 8 Jul 2022 22:14:44 +0100 Subject: [PATCH] Add lasCircle --- src/Dodge/Combine/Combinations.hs | 7 +-- src/Dodge/Combine/Data.hs | 1 + src/Dodge/Creature/Impulse/UseItem.hs | 6 +-- src/Dodge/Debug/Terminal.hs | 10 ++++- src/Dodge/Item.hs | 2 + src/Dodge/Item/Weapon/BatteryGuns.hs | 61 ++++++++++++++++++++++----- src/Dodge/Item/Weapon/TriggerType.hs | 24 ++++++++++- src/Geometry/Zone.hs | 1 + 8 files changed, 91 insertions(+), 21 deletions(-) diff --git a/src/Dodge/Combine/Combinations.hs b/src/Dodge/Combine/Combinations.hs index 128a3e82d..f89de507b 100644 --- a/src/Dodge/Combine/Combinations.hs +++ b/src/Dodge/Combine/Combinations.hs @@ -32,7 +32,7 @@ itemCombinations = -- , po [cr PIPE, cr HARDWARE] (volleyGun 1) , po [BANGSTICK 1,cr PLANK] rifle - , p [p 3 $ BANGSTICK 1] (volleyGun 3) + , po [BANGSTICK 1,BANGSTICK 1,BANGSTICK 1] (volleyGun 3) , po [RIFLE,cr TIN] repeater , po [REPEATER,cr SPRING] autoRifle , po [REPEATER,cr CAN] burstRifle @@ -63,9 +63,10 @@ itemCombinations = -- , p [o LASGUN,o $ cr PRISM] lasSway -- , p [o LASGUN,o $ cr HARDWARE] lasSwing -- , p [o LASGUN,o PIPE] lasGunPulse - , p [p 2 LASGUN,p 1 $ cr HARDWARE] dualBeam + , po [LASGUN,LASGUN,cr HARDWARE] dualBeam -- , p [o LASGUN,o $ cr PIPE, o $ cr PRISM] lasWidePulse - , p [o LASGUN,o $ cr TRANSFORMER] (lasWide 2) + , po [LASGUN, cr TRANSFORMER] (lasWide 2) + , po [LASGUN,LASGUN,LASGUN,cr HARDWARE] lasCircle , p [o $ cr TRANSFORMER,p 2 $ cr CAN] sparkGun , p [o SPARKGUN,p 2 $ cr PIPE] teslaGun diff --git a/src/Dodge/Combine/Data.hs b/src/Dodge/Combine/Data.hs index 84b3172e4..fbebe6b5c 100644 --- a/src/Dodge/Combine/Data.hs +++ b/src/Dodge/Combine/Data.hs @@ -108,6 +108,7 @@ data ItemBaseType | SPARKGUN | TESLAGUN | LASGUN + | LASCIRCLE | LASPULSE | DUALBEAM | LASGUNSWING diff --git a/src/Dodge/Creature/Impulse/UseItem.hs b/src/Dodge/Creature/Impulse/UseItem.hs index 6d689a462..3685eaeec 100644 --- a/src/Dodge/Creature/Impulse/UseItem.hs +++ b/src/Dodge/Creature/Impulse/UseItem.hs @@ -25,7 +25,7 @@ useItem cr' w = fromMaybe (f w) $ do itemEffect :: Creature -> Item -> World -> World itemEffect cr it w = case it ^? itUse of Just RightUse {_rUse = eff,_useMods = usemods} - -> hammerTest $ tryClickReload cr it w $ foldr ($) eff usemods it cr + -> hammerTest $ tryReload cr it w $ foldr ($) eff usemods it cr Just LeftUse {} -> doequipmentchange Just EquipUse{} -> doequipmentchange -- ConsumeUse will cause problems if the item is not selected @@ -40,8 +40,8 @@ itemEffect cr it w = case it ^? itUse of doequipmentchange = setuhamdown $ hammerTest (toggleEquipmentAt (_rbOptions w) (crSel cr) cr . activateEquipmentAt (_rbOptions w) cr) -tryClickReload :: Creature -> Item -> World -> (World -> World) -> World -> World -tryClickReload cr it w f +tryReload :: Creature -> Item -> World -> (World -> World) -> World -> World +tryReload cr it w f | _crID cr == _yourID w && itNeedsLoading it && _mouseButtons w M.!? SDL.ButtonLeft == Just False = crToggleReloading cr | otherwise diff --git a/src/Dodge/Debug/Terminal.hs b/src/Dodge/Debug/Terminal.hs index f91b75d72..1ee07be8c 100644 --- a/src/Dodge/Debug/Terminal.hs +++ b/src/Dodge/Debug/Terminal.hs @@ -17,6 +17,7 @@ import Control.Lens import Text.Read (readMaybe) import Data.List --(isPrefixOf, isInfixOf, intercalate) import Data.Maybe +import Control.Applicative import LensHelp import qualified Data.Text as T import qualified IntMapHelp as IM @@ -61,10 +62,15 @@ applyTerminalCommand s = case s of applyTerminalCommandArguments :: String -> [String] -> Universe -> Universe applyTerminalCommandArguments command args u = case command of "ITEM" -> fromMaybe u $ do - ibt <- safeHead args >>= readMaybe - return $ u & uvWorld %~ (snd . createPutItem (itemFromBase ibt)) + ibt <- (safeHead args >>= readMaybe) <|> (safeTake2 args >>= (readMaybe . unwords)) + n <- (args ^? ix 1 >>= readMaybe) <|> Just 1 + return $ u & uvWorld %~ (flip (foldr ($)) $ replicate n (snd . createPutItem (itemFromBase ibt))) _ -> u +safeTake2 :: [a] -> Maybe [a] +safeTake2 (x:y:_) = Just (x:y:[]) +safeTake2 _ = Nothing + showTerminalError :: String -> String -> Universe -> Universe showTerminalError cmd s = menuLayers .:~ InputScreen (T.pack cmd) s diff --git a/src/Dodge/Item.hs b/src/Dodge/Item.hs index e48108918..8f38768c7 100644 --- a/src/Dodge/Item.hs +++ b/src/Dodge/Item.hs @@ -59,6 +59,7 @@ itemFromBase ibt = case ibt of SPARKGUN -> sparkGun TESLAGUN -> teslaGun LASGUN -> lasGun + LASCIRCLE -> lasCircle LASPULSE -> lasPulse DUALBEAM -> dualBeam LASGUNSWING -> lasSwing @@ -200,6 +201,7 @@ baseToFamily ibt = case ibt of SPARKGUN -> HeldFamily TESLAGUN -> HeldFamily LASGUN -> HeldFamily + LASCIRCLE -> HeldFamily LASPULSE -> HeldFamily DUALBEAM -> HeldFamily LASGUNSWING -> HeldFamily diff --git a/src/Dodge/Item/Weapon/BatteryGuns.hs b/src/Dodge/Item/Weapon/BatteryGuns.hs index 0b1f6fca7..bd6b99bb4 100644 --- a/src/Dodge/Item/Weapon/BatteryGuns.hs +++ b/src/Dodge/Item/Weapon/BatteryGuns.hs @@ -1,5 +1,6 @@ module Dodge.Item.Weapon.BatteryGuns ( lasGun + , lasCircle , dualBeam , lasWide -- , lasWidePulse @@ -122,14 +123,16 @@ lasPulse = lasGun & itParams . lasDamage .~ ceiling ((22 :: Float) * frac it) & itParams . lasColor .~ frac it * orange frac it = 0.5 * (1 + sin (pi * fromIntegral (_lasCycle $ _itParams it) * 0.1)) - -lasWide :: Int -> Item -lasWide n = lasGun - & itType . iyBase .~ LASWIDE n + +lasCircle :: Item +lasCircle = lasGun + & itType . iyBase .~ LASCIRCLE & itParams . lasColor .~ orange & itParams . lasDamage .~ 2 + & itConsumption . laMax .~ 10000 & itUse . rUse .~ shootLaser & itUse . useDelay .~ NoDelay + & itUse . rUse .~ circleLaser & itUse . useMods .~ [ ammoCheckI , withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it)) @@ -137,11 +140,31 @@ lasWide n = lasGun , withSoundForI tone440sawtoothquietS 2 , useAmmoAmount 1 , withItemUpdate' increasecycle - , withItem $ \it -> duplicateOffsetsV2 (xs it) + , duplicateItem f ] & itUse . useAim . aimWeight .~ 6 & itUse . useAim . aimRange .~ 1 & itUse . useAim . aimStance .~ TwoHandTwist + where + increasecycle it = it & itParams . lasCycle %~ (flip mod 2000 . (+ 1)) + --f it = [it & itParams . lasCycle +~ x | x <- [0,100 .. 1900] ] + f it = [it & itParams . lasCycle +~ x | x <- [0,50 .. 1999] ] + +lasWide :: Int -> Item +lasWide n = lasGun + & itType . iyBase .~ LASWIDE n + & itParams . lasColor .~ yellow + & itParams . lasDamage .~ 2 + & itUse . useMods .~ + [ ammoCheckI + , withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it)) + , withItem $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) 0.8 + , withSoundForI tone440sawtoothquietS 2 + , useAmmoAmount 1 + , crAtMuzPos + , withItemUpdate' increasecycle + , withItem $ \it -> duplicateOffsetsV2 (xs it) + ] where increasecycle it = case _useHammer (_itUse it) of HammerUp -> it & itParams . lasCycle .~ 1 @@ -265,27 +288,27 @@ lasSwing = lasGun x' = _lasCycle $ _itParams it lasGun :: Item lasGun = defaultAutoBatteryGun - { _itConsumption = defaultLoadable + & itConsumption .~ ( defaultLoadable & laMax .~ 200 & laCycle .~ [loadEject 10, loadInsert 10 , loadPrime 60] - , _itParams = Refracting + ) + & itParams .~ Refracting { _phaseV = 1 , _lasColor = yellow , _lasColor2 = yellow , _lasCycle = 0 , _lasDamage = 11 } - , _itTweaks = Tweakable + & itTweaks .~ Tweakable { _tweakParams = IM.fromList [(0,lasGunTweak)] , _tweakSel = 0 } - , _itDimension = ItemDimension + & itDimension .~ ItemDimension { _dimRad = 10 , _dimCenter = V3 15 0 0 , _dimPortage = HeldItem 5 30 , _dimSPic = lasGunPic } - } & itUse . rUse .~ shootLaser & itUse . useDelay .~ NoDelay & itUse . useMods .~ @@ -294,6 +317,7 @@ lasGun = defaultAutoBatteryGun , withSoundForI tone440sawtoothquietS 2 , withItem $ \it -> withMuzPos $ flareCircleAt (_lasColor $ _itParams it) 0.8 , useAmmoAmount 1 + , crAtMuzPos ] & itUse . useAim . aimWeight .~ 6 & itUse . useAim . aimRange .~ 1 @@ -413,11 +437,26 @@ shootTeslaArc it cr w = w' shootLaser :: Item -> Creature -> World -> World shootLaser it cr = instantParticles .:~ lasRayAt (_lasColor $ _itParams it) dam phasev pos dir where - pos = _crPos cr +.+ aimingMuzzlePos cr it *.* unitVectorAtAngle dir + --pos = _crPos cr +.+ aimingMuzzlePos cr it *.* unitVectorAtAngle dir + pos = _crPos cr dir = _crDir cr phasev = _phaseV . _itParams $ _crInv cr IM.! crSel cr dam = _lasDamage $ _itParams it +-- this has the feel of a left click item +circleLaser :: Item -> Creature -> World -> World +circleLaser it cr w + | hasLOSIndirect cpos pos w = w + & instantParticles .:~ lasRayAt (_lasColor $ _itParams it) dam phasev pos dir + | otherwise = w + where + cpos = _crPos cr + mwp = mouseWorldPos w + pos = _crPos cr +.+ rotateV dir (V2 0 (max 70 $ dist cpos mwp)) + dir = fromIntegral (_lasCycle (_itParams it)) * pi / 1000 + phasev = _phaseV . _itParams $ _crInv cr IM.! crSel cr + dam = _lasDamage $ _itParams it + shootDualLaser :: Item -> Creature -> World -> World shootDualLaser it cr w = w' & newBeams . positronBeams .:~ dualRayAt (_lasBeam $ _itParams it) itid w (_lasColor $ _itParams it) dam phasev posl dirl diff --git a/src/Dodge/Item/Weapon/TriggerType.hs b/src/Dodge/Item/Weapon/TriggerType.hs index 3c45ffff6..9cd3cbc73 100644 --- a/src/Dodge/Item/Weapon/TriggerType.hs +++ b/src/Dodge/Item/Weapon/TriggerType.hs @@ -9,6 +9,7 @@ module Dodge.Item.Weapon.TriggerType , withMuzFlareI , withMuzPos , withMuzPosShift + , crAtMuzPos , withOldDir , trigDoAlso , withTempLight @@ -46,10 +47,12 @@ module Dodge.Item.Weapon.TriggerType , spreadLoaded , repeatOnFrames , sideEffectOnFrame + , duplicateItem , duplicateLoadedBarrels , duplicateLoaded , duplicateOffsets , duplicateOffsetsV2 + , duplicateOffsetsV2Dir , duplicateOffsetsFocus , hammerCheckI , hammerCheckL @@ -403,10 +406,13 @@ withMuzPosShift p g f it cr w = g (pos `v2z` 20) $ f it cr w where pos = _crPos cr - +.+ rotateV dir p - +.+ aimingMuzzlePos cr it *.* unitVectorAtAngle dir + +.+ 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))) + {- | Applies the effect to a randomly rotated creature, - rotation amount given by inaccuracy in itParams -} applyInaccuracy :: ChainEffect @@ -587,6 +593,11 @@ duplicateOffsetsFocus xs eff item cr w = foldr f w poss -.- (_crPos cr +.+ pos)) | otherwise = argV (mouseWorldPos w -.- (_crPos cr +.+ pos)) +duplicateItem :: (Item -> [Item]) -> ChainEffect +duplicateItem fit eff itm cr w = foldr f w (fit itm) + where + f itm' = eff itm' cr + duplicateOffsetsV2 :: [Point2] -> ChainEffect duplicateOffsetsV2 xs eff item cr w = foldr f w poss where @@ -599,3 +610,12 @@ duplicateOffsets xs eff item cr w = foldr f w poss poss :: [V2 Float] poss = map (rotateV (_crDir cr) . V2 0 ) xs f pos = eff item (cr & crPos +.+.~ pos) + +duplicateOffsetsV2Dir :: [(Point2,Float)] -> ChainEffect +duplicateOffsetsV2Dir xs eff item cr w = foldr f w + -- $ xs + $ map (over _1 (rotateV (_crDir cr))) xs + where + f (pos,dir) = eff item $ cr + & crPos +.+.~ pos + & crDir +~ dir diff --git a/src/Geometry/Zone.hs b/src/Geometry/Zone.hs index 68f40aa71..f5173ed73 100644 --- a/src/Geometry/Zone.hs +++ b/src/Geometry/Zone.hs @@ -5,6 +5,7 @@ module Geometry.Zone , xIntercepts , yIntercepts , divTo + , modTo , zoneOfPoint , zoneOfSeg , zoneInsideCirc