From 8838d1120b04f68834fb7b6ba07f4d8c56c7d866 Mon Sep 17 00:00:00 2001 From: justin Date: Sat, 31 Dec 2022 23:01:54 +0000 Subject: [PATCH] Cleanup --- src/Dodge/Data/Item/Effect.hs | 1 + src/Dodge/HeldUse.hs | 20 ++++++++- src/Dodge/ItEffect.hs | 21 +++++---- src/Dodge/Item/Held/Cane.hs | 2 +- src/Dodge/Item/Weapon/Utility.hs | 73 +++++++------------------------- src/Dodge/Update/Scroll.hs | 8 ++-- 6 files changed, 54 insertions(+), 71 deletions(-) diff --git a/src/Dodge/Data/Item/Effect.hs b/src/Dodge/Data/Item/Effect.hs index d0e1bc10d..3da083ac0 100644 --- a/src/Dodge/Data/Item/Effect.hs +++ b/src/Dodge/Data/Item/Effect.hs @@ -21,6 +21,7 @@ data ItInvEffect = NoInvEffect | ChargeIfEquipped | ChargeIfInInventory + | SetCharge Int | EffectIfHeld ItInvEffect ItInvEffect | CreateHeldLight | CreateShieldWall diff --git a/src/Dodge/HeldUse.hs b/src/Dodge/HeldUse.hs index 2a8e17484..d3f9515af 100644 --- a/src/Dodge/HeldUse.hs +++ b/src/Dodge/HeldUse.hs @@ -1,5 +1,7 @@ module Dodge.HeldUse where +import Dodge.Wall.Move +import Dodge.Wall.ForceField import Color import Data.Maybe import Data.Traversable @@ -13,7 +15,6 @@ import Dodge.Item.Weapon.Launcher import Dodge.Item.Weapon.Radar import Dodge.Item.Weapon.Shatter import Dodge.Item.Weapon.TriggerType -import Dodge.Item.Weapon.Utility import Dodge.Projectile.Create import Dodge.SoundLogic import Dodge.Tesla.Arc @@ -504,3 +505,20 @@ shootTeslaArc it cr w = (w', ip) = makeTeslaArc (_itParams it) pos dir w pos = _crPos cr +.+ aimingMuzzlePos cr it *.* unitVectorAtAngle dir dir = _crDir cr + +-- I believe because the targeting returns to nothing straight after you release +-- the rmb, it is possible for this to do nothing +-- TODO investigate more and fix +useForceFieldGun :: Item -> Creature -> World -> World +useForceFieldGun itm cr w = fromMaybe w $ do + a <- _tgPos $ _itTargeting itm + let mwp = mouseWorldPos (w ^. input) (w ^. cWorld . camPos) + b = if dist a mwp < 100 then mwp else a +.+ 100 *.* normalizeV (mwp -.- a) + wlline = (a, b) + return $ + w + & cWorld . lWorld . walls %~ IM.insertWith (\_ x -> x) i forceField{_wlID = i} + & cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix (_ipInvID (_itLocation itm)) . itParams . paramMID ?~ i + & moveWallIDUnsafe i wlline + where + i = fromMaybe (IM.newKey (_walls (_lWorld (_cWorld w)))) $ itm ^? itParams . paramMID . _Just diff --git a/src/Dodge/ItEffect.hs b/src/Dodge/ItEffect.hs index 20c46c942..bc9e85383 100644 --- a/src/Dodge/ItEffect.hs +++ b/src/Dodge/ItEffect.hs @@ -10,6 +10,7 @@ doInvEffect iie = case iie of NoInvEffect -> const $ const id ChargeIfEquipped -> chargeIfEquipped ChargeIfInInventory -> chargeIfInInventory + SetCharge i -> setItemCharge i EffectIfHeld f g -> onOffEff f g CreateHeldLight -> createHeldLight CreateShieldWall -> createShieldWall @@ -31,27 +32,31 @@ onOffEff f g it -- , _futureWorlds = [] -- } +setItemCharge :: Int -> Item -> Creature -> World -> World +setItemCharge i itm cr w = + w & ptrWpCharge %~ const i + where + invid = _ipInvID $ _itLocation itm + ptrWpCharge = cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itUse . leftConsumption . wpCharge + chargeIfInInventory :: Item -> Creature -> World -> World -chargeIfInInventory itm cr w = - w & ptrWpCharge %~ (min maxcharge . (+ 1)) +chargeIfInInventory itm cr w = + w & ptrWpCharge %~ (min maxcharge . (+ 1)) where invid = _ipInvID $ _itLocation itm ptrWpCharge = cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itUse . leftConsumption . wpCharge maxcharge = itm ^?! itUse . leftConsumption . wpMaxCharge - chargeIfEquipped :: Item -> Creature -> World -> World -chargeIfEquipped itm cr w +chargeIfEquipped itm cr | Just invid == cr ^. crLeftInvSel . lisMPos = - w & ptrWpCharge %~ (min maxcharge . (+ 1)) - | otherwise = - w & ptrWpCharge .~ 0 + ptrWpCharge %~ (min maxcharge . (+ 1)) + | otherwise = ptrWpCharge .~ 0 where invid = _ipInvID $ _itLocation itm ptrWpCharge = cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itUse . leftConsumption . wpCharge maxcharge = itm ^?! itUse . leftConsumption . wpMaxCharge - --resetAttachmentEffect :: Item -> Creature -> World -> World --resetAttachmentEffect itm cr w -- | _ieCounter iteff < 0 = w & pointToIt . itAttachment .~ NoItAttachment diff --git a/src/Dodge/Item/Held/Cane.hs b/src/Dodge/Item/Held/Cane.hs index 976dfecfd..b3d2bc876 100644 --- a/src/Dodge/Item/Held/Cane.hs +++ b/src/Dodge/Item/Held/Cane.hs @@ -82,7 +82,7 @@ rifle = & itUse . heldConsumption . laCycle .~ [loadEject 5, loadInsert 5, loadPrime 5] & itUse . heldAim . aimWeight .~ 6 & itUse . heldAim . aimRange .~ 1 - & itUse . heldAim . aimZoom .~ defaultItZoom{_izFac = 2} + & itUse . heldAim . aimZoom .~ defaultItZoom{_izFac = 1.5} & itType . iyModules . at ModHeldAttach ?~ EMPTYMODULE repeater :: Item diff --git a/src/Dodge/Item/Weapon/Utility.hs b/src/Dodge/Item/Weapon/Utility.hs index cb8689fc1..1c00bb720 100644 --- a/src/Dodge/Item/Weapon/Utility.hs +++ b/src/Dodge/Item/Weapon/Utility.hs @@ -1,18 +1,17 @@ -module Dodge.Item.Weapon.Utility where +module Dodge.Item.Weapon.Utility + ( stopWatch + , rewindWatch + , scrollWatch + , blinkGun + , unsafeBlinkGun + , shrinkGun +-- , useForceFieldGun + ) where import Control.Lens -import Data.Maybe -import Dodge.Base.Coordinate -import Dodge.Data.World +import Dodge.Data.Item import Dodge.Default ---import Dodge.Default.Item.Use -import Dodge.Wall.ForceField -import Dodge.Wall.Move -import Geometry -import qualified IntMapHelp as IM import Picture -import Shape -import ShapePicture stopWatch :: Item stopWatch = @@ -23,7 +22,8 @@ stopWatch = & equipEffect . eeSite .~ GoesOnWrist ) & itInvColor .~ cyan - & itEffect . ieInv .~ ChargeIfInInventory + & itEffect . ieInv .~ ChargeIfEquipped + & itEffect . ieOnDrop .~ SetCharge 0 & itType . iyBase .~ LEFT STOPWATCH & itUse . leftConsumption .~ ChargeableAmmo @@ -33,37 +33,15 @@ stopWatch = scrollWatch :: Item scrollWatch = - defaultLeftItem - & itUse - .~ ( defaultLeftUse - & leftUse .~ LTimeScroll - & equipEffect . eeSite .~ GoesOnWrist - ) - & itInvColor .~ cyan - & itEffect . ieInv .~ ChargeIfInInventory + stopWatch + & itUse . leftUse .~ LTimeScroll & itType . iyBase .~ LEFT SCROLLWATCH - & itUse . leftConsumption - .~ ChargeableAmmo - { _wpMaxCharge = 100 - , _wpCharge = 0 - } rewindWatch :: Item rewindWatch = - defaultLeftItem - & itUse - .~ ( defaultLeftUse - & leftUse .~ LRewind --useRewindGun - & equipEffect . eeSite .~ GoesOnWrist - ) - & itInvColor .~ cyan - & itEffect . ieInv .~ ChargeIfEquipped + stopWatch + & itUse . leftUse .~ LRewind --useRewindGun & itType . iyBase .~ LEFT REWINDWATCH - & itUse . leftConsumption - .~ ChargeableAmmo - { _wpMaxCharge = 100 - , _wpCharge = 0 - } -- needs to shift this item to the current inventory slot shrinkGun :: Item @@ -73,9 +51,6 @@ shrinkGun = & itParams .~ ShrinkGunParams FullSize & itType . iyBase .~ LEFT SHRINKER -shrinkGunPic :: Item -> SPic -shrinkGunPic _ = noPic $ colorSH violet $ upperPrismPoly 5 $ square 5 - blinkGun :: Item blinkGun = defaultLeftItem @@ -95,22 +70,6 @@ unsafeBlinkGun = & itUse . leftUse .~ LUnsafeBlink --hammerCheckL (shootL $ const unsafeBlinkAction) & itUse . equipEffect . eeViewDist ?~ 400 --- I believe because the targeting returns to nothing straight after you release --- the rmb, it is possible for this to do nothing --- TODO investigate more and fix -useForceFieldGun :: Item -> Creature -> World -> World -useForceFieldGun itm cr w = fromMaybe w $ do - a <- _tgPos $ _itTargeting itm - let mwp = mouseWorldPos (w ^. input) (w ^. cWorld . camPos) - b = if dist a mwp < 100 then mwp else a +.+ 100 *.* normalizeV (mwp -.- a) - wlline = (a, b) - return $ - w - & cWorld . lWorld . walls %~ IM.insertWith (\_ x -> x) i forceField{_wlID = i} - & cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix (_ipInvID (_itLocation itm)) . itParams . paramMID ?~ i - & moveWallIDUnsafe i wlline - where - i = fromMaybe (IM.newKey (_walls (_lWorld (_cWorld w)))) $ itm ^? itParams . paramMID . _Just -- grapGun = defaultGun -- { _itName = "grapGun" diff --git a/src/Dodge/Update/Scroll.hs b/src/Dodge/Update/Scroll.hs index 9bfaf37d9..032f35ad5 100644 --- a/src/Dodge/Update/Scroll.hs +++ b/src/Dodge/Update/Scroll.hs @@ -28,7 +28,7 @@ updateWheelEvent yi w = case w ^. hud . hudElement of -- this lock can be sensibly applied, perhaps | w ^?! cWorld . lWorld . creatures . ix 0 . crInvLock -> w | rbDown -> case (yourItem w ^? _Just . itUse . heldScroll, _rbOptions w) of - (_, EquipOptions{}) -> scrollRBOption yi w + (_, EquipOptions{}) -> w & rbOptions %~ scrollRBOption yi (Nothing, _) -> closeObjScrollDir y w (Just f, _) -> doHeldScroll f y (you w) w | lbDown -> w & cWorld . camPos . camZoom +~ y @@ -92,10 +92,10 @@ terminalWheelEvent yi tmid w tc = scrollCommands tm !! i arg = getArguments' tc tm w' !! j -scrollRBOption :: Int -> World -> World +scrollRBOption :: Int -> RightButtonOptions -> RightButtonOptions scrollRBOption y w - | y < 0 = w & rbOptions . opSel %~ (min (length (_opEquip (_rbOptions w)) -1) . subtract y) - | y > 0 = w & rbOptions . opSel %~ (max 0 . subtract y) + | y < 0 = w & opSel %~ (min (length (_opEquip w) -1) . subtract y) + | y > 0 = w & opSel %~ (max 0 . subtract y) | otherwise = w moveTweakSel :: Int -> World -> World