From a85cf4d1fb500109549e9668bc094f0a6903d11c Mon Sep 17 00:00:00 2001 From: justin Date: Mon, 20 Jun 2022 11:12:24 +0100 Subject: [PATCH] Continue refactor of reloading --- src/Dodge/Combine/Data.hs | 3 - src/Dodge/Combine/Module.hs | 12 ++-- src/Dodge/Creature.hs | 1 - src/Dodge/Creature/State.hs | 23 +++---- src/Dodge/Data.hs | 28 +++++---- src/Dodge/Default/Weapon.hs | 49 +++++++-------- src/Dodge/Event/Keyboard.hs | 2 +- src/Dodge/Item.hs | 2 - src/Dodge/Item/Display.hs | 22 ++++--- src/Dodge/Item/Equipment/Booster.hs | 8 +-- src/Dodge/Item/Weapon/AmmoParams.hs | 2 +- src/Dodge/Item/Weapon/BatteryGuns.hs | 29 ++++----- src/Dodge/Item/Weapon/BulletGun/Cane.hs | 26 ++++---- src/Dodge/Item/Weapon/BulletGun/Rod.hs | 16 +++-- src/Dodge/Item/Weapon/BulletGun/Stick.hs | 43 +++++--------- src/Dodge/Item/Weapon/BulletGuns.hs | 68 ++++++--------------- src/Dodge/Item/Weapon/Drone.hs | 16 +++-- src/Dodge/Item/Weapon/ExtraEffect.hs | 16 ++--- src/Dodge/Item/Weapon/Launcher.hs | 26 ++++---- src/Dodge/Item/Weapon/Radar.hs | 5 +- src/Dodge/Item/Weapon/Shatter.hs | 3 +- src/Dodge/Item/Weapon/SonicGuns.hs | 9 ++- src/Dodge/Item/Weapon/Spawn.hs | 11 ++-- src/Dodge/Item/Weapon/SprayGuns.hs | 18 +++--- src/Dodge/Item/Weapon/TriggerType.hs | 10 ++-- src/Dodge/Item/Weapon/Utility.hs | 18 +++--- src/Dodge/Reloading.hs | 76 ++++++++++++++---------- 27 files changed, 243 insertions(+), 299 deletions(-) diff --git a/src/Dodge/Combine/Data.hs b/src/Dodge/Combine/Data.hs index b66e00033..7c5bc38b4 100644 --- a/src/Dodge/Combine/Data.hs +++ b/src/Dodge/Combine/Data.hs @@ -109,9 +109,6 @@ data ItemBaseType | FLAMEWALL | BLOWTORCH | AUTOGUN --- | SPREADGUN --- | MULTGUN - | LONGGUN | SPARKGUN | TESLAGUN | LASGUN diff --git a/src/Dodge/Combine/Module.hs b/src/Dodge/Combine/Module.hs index a1c6a6767..fbb57bac4 100644 --- a/src/Dodge/Combine/Module.hs +++ b/src/Dodge/Combine/Module.hs @@ -27,19 +27,19 @@ moduleModification imt = case imt of TARGCR -> itTargeting .~ targetRBCreature TARGLAS -> itTargeting .~ targetLaser TARGPOS -> itTargeting .~ targetRBPress - MAGNETTRAJ -> (itConsumption . laType . amBulTraj .~ MagnetTrajectory) - . (itConsumption . laType . amBulVel .~ V2 10 0) - FLECHETRAJ -> itConsumption . laType . amBulTraj .~ FlechetteTrajectory - BEZIERTRAJ -> itConsumption . laType . amBulTraj .~ BezierTrajectory + MAGNETTRAJ -> (itConsumption . laAmmoType . amBulTraj .~ MagnetTrajectory) + . (itConsumption . laAmmoType . amBulVel .~ V2 10 0) + FLECHETRAJ -> itConsumption . laAmmoType . amBulTraj .~ FlechetteTrajectory + BEZIERTRAJ -> itConsumption . laAmmoType . amBulTraj .~ BezierTrajectory INCENDLAS -> itParams . lasBeam .~ BeamCombine flameBeamCombine SPLITLAS -> itParams . lasBeam .~ BeamCombine splitBeamCombine STATICLAS -> (itParams . lasBeam .~ BeamCombine teslaBeamCombine) . (itParams . subParams ?~ teslaParams) WEPTELE -> makeDirectedTele - LAUNCHHOME -> itConsumption . laType . amPjCreation .~ fireTrackingShell + LAUNCHHOME -> itConsumption . laAmmoType . amPjCreation .~ fireTrackingShell EXTRABATTERY -> itConsumption . laMax +~ 1000 where - f ameff = itConsumption . laType . amBulEff .~ ameff + f ameff = itConsumption . laAmmoType . amBulEff .~ ameff makeDirectedTele it = it & itTargeting .~ targetRBPress & itUse . useMods .:~ withPosDirWallCheck directedTelPos diff --git a/src/Dodge/Creature.hs b/src/Dodge/Creature.hs index 4dd89981d..c56091dde 100644 --- a/src/Dodge/Creature.hs +++ b/src/Dodge/Creature.hs @@ -283,7 +283,6 @@ stackedInventory = IM.fromList $ zip [0..] , pipe ,rewindGun ,tractorGun - ,longGun ,autoGun ,autoPistol ,pistol diff --git a/src/Dodge/Creature/State.hs b/src/Dodge/Creature/State.hs index 8861ca005..81e99eb9a 100644 --- a/src/Dodge/Creature/State.hs +++ b/src/Dodge/Creature/State.hs @@ -231,16 +231,19 @@ doItemTargeting invid cr w = case cr ^? crInv . ix invid . itTargeting of weaponReloadSounds :: Creature -> World -> World weaponReloadSounds cr w = case cr ^? crInv . ix (_crInvSel cr) . itConsumption of - Just am@LoadableAmmo{} -> case _laReloadType am of - PassiveReload stype | Just (_laReloadTime am) == am ^? laTransfer . transferTime - -> soundContinue (CrReloadSound 0) (_crPos cr) stype Nothing w - PassiveReload _ -> w - ActiveClear | am ^? laTransfer . transferTime == Just 0 -> stopSoundFrom (CrReloadSound cid) w - ActiveClear | _laTransfer am == NoTransfer -> w - ActiveClear -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w - ActivePartial{} | am ^? laTransfer . transferTime == Just 0 -> stopSoundFrom (CrReloadSound cid) w - ActivePartial{} | _laTransfer am == NoTransfer -> w - ActivePartial{} -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w + Just am@LoadableAmmo{} -> case am ^? laLoadType . loadProgress of + Just NoTransfer -> w -- stopSoundFrom (CrReloadSound cid) w + Just _ -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w + Nothing -> w +-- PassiveReload stype | Just (_laReloadTime am) == am ^? laTransfer . transferTime +-- -> soundContinue (CrReloadSound 0) (_crPos cr) stype Nothing w +-- PassiveReload _ -> w +-- ActiveClear | am ^? laTransfer . transferTime == Just 0 -> stopSoundFrom (CrReloadSound cid) w +-- ActiveClear | _laTransfer am == NoTransfer -> w +-- ActiveClear -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w +-- ActivePartial{} | am ^? laTransfer . transferTime == Just 0 -> stopSoundFrom (CrReloadSound cid) w +-- ActivePartial{} | _laTransfer am == NoTransfer -> w +-- ActivePartial{} -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w Just ChargeableAmmo {} -> w Just NoConsumption {} -> w Just ItemItselfConsumable {} -> w diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index f5d5fb243..37f0574ae 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -482,19 +482,12 @@ data Equipment = Equipment _itUseAimStance :: Item -> AimStance _itUseAimStance = _aimStance . _useAim . _itUse -data TransferState - = Transfer { _transferAmount :: Int , _transferTime :: Int} - | NoTransfer - deriving (Eq,Ord,Show) - data ItemConsumption = LoadableAmmo - { _laType :: AmmoType + { _laAmmoType :: AmmoType , _laMax :: Int , _laLoaded :: Int - , _laReloadTime :: Int - , _laTransfer :: TransferState - , _laReloadType :: ReloadType + , _laLoadType :: LoadType } | ChargeableAmmo { _wpMaxCharge :: Int @@ -552,9 +545,17 @@ data ItemPortage | WornItem | NoPortage -data ReloadType - = ActiveClear - | ActivePartial {_partialReloadAmount :: Int} +data LoadProgress + = NoTransfer + | Eject {_ejectProgress :: Int} + | Insert {_insertProgress :: Int, _insertAmount :: Int } + deriving (Eq,Ord,Show) + +data LoadType + = ActiveEject + {_ejectTime :: Int, _insertTime :: Int,_loadProgress :: LoadProgress } + | ActivePartial + {_insertTime :: Int, _loadAmount :: Int, _loadProgress :: LoadProgress } | PassiveReload SoundID deriving Eq @@ -1481,7 +1482,8 @@ makeLenses ''ItEffect makeLenses ''FloorItem makeLenses ''ItemConsumption makeLenses ''AmmoType -makeLenses ''TransferState +makeLenses ''LoadType +makeLenses ''LoadProgress makeLenses ''TweakParam makeLenses ''Prop makeLenses ''Modification diff --git a/src/Dodge/Default/Weapon.hs b/src/Dodge/Default/Weapon.hs index 3e11d6d9d..345da83c9 100644 --- a/src/Dodge/Default/Weapon.hs +++ b/src/Dodge/Default/Weapon.hs @@ -1,6 +1,7 @@ module Dodge.Default.Weapon where import Dodge.Data +import Dodge.Item.Weapon.Bullet import Dodge.Default.Item import Dodge.Item.Draw import Picture @@ -13,15 +14,17 @@ import Geometry import qualified Data.Map.Strict as M import Control.Lens -defaultAmmo :: ItemConsumption -defaultAmmo = LoadableAmmo - { _laType = GenericAmmo +defaultLoadable :: ItemConsumption +defaultLoadable = LoadableAmmo + { _laAmmoType = GenericAmmo , _laMax = 15 , _laLoaded = 0 - , _laReloadTime = 40 - , _laTransfer = NoTransfer - , _laReloadType = ActiveClear + , _laLoadType = ActiveEject 20 20 NoTransfer } +defaultBulletLoadable :: ItemConsumption +defaultBulletLoadable = defaultLoadable & laAmmoType .~ basicBullet +defaultChargeable :: ItemConsumption +defaultChargeable = ChargeableAmmo 100 100 ruseRate :: Int -> (Item -> Creature -> World -> World) @@ -94,26 +97,17 @@ defaultAimParams = AimParams , _aimStance = OneHand } +-- TODO change this +defaultLeftItem :: Item +defaultLeftItem = defaultWeapon -defaultGun :: Item -defaultGun = defaultItem - { _itCurseStatus = Uncursed - , _itConsumption = defaultAmmo - , _itUse = defaultrUse - , _itDimension = defItDimCol white - , _itEquipPict = pictureWeaponOnAim - , _itAttachment = NoItAttachment - , _itID = Nothing - , _itInvPos = Nothing - , _itIsHeld = False - , _itEffect = NoItEffect - , _itInvColor = white - , _itInvSize = 1 - , _itParams = NoParams - , _itTweaks = NoTweaks - , _itScope = NoScope - , _itTargeting = NoTargeting - } +defaultWeapon :: Item +defaultWeapon = defaultItem + & itConsumption .~ defaultLoadable + & itUse .~ defaultrUse + & itDimension .~ defItDimCol white + & itEquipPict .~ pictureWeaponOnAim + & itInvColor .~ white & itType . iyModules .~ M.fromList [(ModBullet, EMPTYMODULE) ,(ModTarget, EMPTYMODULE) @@ -121,6 +115,9 @@ defaultGun = defaultItem ,(ModTeleport, EMPTYMODULE) ] +defaultBulletWeapon :: Item +defaultBulletWeapon = defaultWeapon & itConsumption .~ defaultBulletLoadable + defaultItemValue :: ItemValue defaultItemValue = ItemValue 10 MundaneItem defaultCraftable :: Item @@ -161,5 +158,5 @@ defBulletShooter = BulletShooter } defaultAutoGun :: Item -defaultAutoGun = defaultGun +defaultAutoGun = defaultBulletWeapon & itUse . useAim . aimStance .~ TwoHandTwist diff --git a/src/Dodge/Event/Keyboard.hs b/src/Dodge/Event/Keyboard.hs index 555546a08..baa9a7d58 100644 --- a/src/Dodge/Event/Keyboard.hs +++ b/src/Dodge/Event/Keyboard.hs @@ -87,7 +87,7 @@ handlePressedKeyInGame scode w = case scode of ScancodeP -> pauseGame $ escapeMap w ScancodeF -> youDropItem w ScancodeM -> toggleMap w - ScancodeR -> fromMaybe w $ tryStartReloading (you w) w + ScancodeR -> crStartReloading (you w) w ScancodeT -> testEvent w ScancodeX -> w & hud . hudElement %~ toggleTweakInv ScancodeC -> toggleCombineInv w diff --git a/src/Dodge/Item.hs b/src/Dodge/Item.hs index f04280684..0d583fdee 100644 --- a/src/Dodge/Item.hs +++ b/src/Dodge/Item.hs @@ -60,7 +60,6 @@ itemFromBase ibt = case ibt of AUTOGUN -> autoGun -- SPREADGUN -> spreadGun -- MULTGUN -> multGun - LONGGUN -> longGun SPARKGUN -> sparkGun TESLAGUN -> teslaGun LASGUN -> lasGun @@ -206,7 +205,6 @@ baseToFamily ibt = case ibt of AUTOGUN -> HeldFamily -- | SPREADGUN -> HeldFamily -- | MULTGUN -> HeldFamily - LONGGUN -> HeldFamily SPARKGUN -> HeldFamily TESLAGUN -> HeldFamily LASGUN -> HeldFamily diff --git a/src/Dodge/Item/Display.hs b/src/Dodge/Item/Display.hs index e28809885..d0a8ac612 100644 --- a/src/Dodge/Item/Display.hs +++ b/src/Dodge/Item/Display.hs @@ -20,14 +20,7 @@ itemDisplay it = Prelude.take (itSlotsTaken it) $ ++ moduleStrings it ++ repeat "*" where thename = show . _iyBase $ _itType it - thenumber = case it ^? itConsumption of - Just am@LoadableAmmo{} -> case _laTransfer am of - NoTransfer -> show (_laLoaded am) - Transfer _ time -> show time ++ "R" ++ show (_laLoaded am) - Just am@ChargeableAmmo{} -> show $ _wpCharge am - Just x@ItemItselfConsumable{} -> show (_icAmount x) - Just NoConsumption -> "" - Nothing -> "" + thenumber = showConsumption (_itConsumption it) theparam = fromMaybe [] . listToMaybe $ mapMaybe ($ it) @@ -36,6 +29,19 @@ itemDisplay it = Prelude.take (itSlotsTaken it) $ -- , maybeRateStatus ] +showConsumption :: ItemConsumption -> String +showConsumption ic = case ic of + am@LoadableAmmo{} -> showLoading (_laLoadType ic) ++ show (_laLoaded am) + am@ChargeableAmmo{} -> show $ _wpCharge am + x@ItemItselfConsumable{} -> show (_icAmount x) + NoConsumption -> "" +showLoading :: LoadType -> String +showLoading lt = case lt ^? loadProgress of + Just (Eject t) -> show t ++ "E" + Just (Insert t _) -> show t ++ "R" + Just NoTransfer -> "" + Nothing -> "" + -- & itInvDisplay .~ \it -> head (basicItemDisplay it) : -- ["*FIRERATE:" ++ fromMaybe "" (maybeRateStatus it) -- ] diff --git a/src/Dodge/Item/Equipment/Booster.hs b/src/Dodge/Item/Equipment/Booster.hs index f40c839ba..dc569bca5 100644 --- a/src/Dodge/Item/Equipment/Booster.hs +++ b/src/Dodge/Item/Equipment/Booster.hs @@ -110,13 +110,9 @@ maxT :: Int maxT = 20 boosterGun :: Item -boosterGun = defaultGun +boosterGun = defaultLeftItem { _itInvColor = cyan - , _itConsumption = defaultAmmo - { _laMax = 100 - , _laLoaded = 100 - , _laReloadTime = 20 - } + , _itConsumption = defaultChargeable , _itUse = luseInstantNoH $ boostSelfL 10 , _itEffect = resetAttachmentID } diff --git a/src/Dodge/Item/Weapon/AmmoParams.hs b/src/Dodge/Item/Weapon/AmmoParams.hs index dca4514ac..f9cd557fc 100644 --- a/src/Dodge/Item/Weapon/AmmoParams.hs +++ b/src/Dodge/Item/Weapon/AmmoParams.hs @@ -49,7 +49,7 @@ useAmmoParams vfact it cr w = w & instantParticles .:~ aBulAt sp = _crPos cr +.+ muzlength *.* unitVectorAtAngle dir cid = _crID cr dir = _crDir cr - bultype = _laType $ _itConsumption it + bultype = _laAmmoType $ _itConsumption it muzvel = _muzVel $ _itParams it muzlength = aimingMuzzlePos cr it thetraj = case _amBulTraj bultype of diff --git a/src/Dodge/Item/Weapon/BatteryGuns.hs b/src/Dodge/Item/Weapon/BatteryGuns.hs index e071f8a4b..778be2f89 100644 --- a/src/Dodge/Item/Weapon/BatteryGuns.hs +++ b/src/Dodge/Item/Weapon/BatteryGuns.hs @@ -53,7 +53,7 @@ import qualified Data.Map.Strict as M --import Control.Monad.State defaultBatteryGun :: Item -defaultBatteryGun = defaultGun +defaultBatteryGun = defaultWeapon & itType . iyModules .~ batteryModules batteryModules :: M.Map ModuleSlot ItemModuleType @@ -72,11 +72,10 @@ sparkGun = teslaGun & itParams . arcSize .~ 10 teslaGun :: Item teslaGun = defaultBatteryGun - { _itConsumption = defaultAmmo - { _laMax = 200 - , _laLoaded = 200 - , _laReloadTime = 80 - } + { _itConsumption = defaultLoadable + & laMax .~ 200 + & laLoadType . ejectTime .~ 40 + & laLoadType . insertTime .~ 40 , _itUse = ruseInstant shootTeslaArc NoHammer [ ammoCheckI , withTempLight 1 100 (V3 0 0 1) @@ -253,11 +252,10 @@ lasSwing = lasGun x' = _lasCycle $ _itParams it lasGun :: Item lasGun = defaultAutoBatteryGun - { _itConsumption = defaultAmmo - { _laMax = 200 - , _laLoaded = 200 - , _laReloadTime = 80 - } + { _itConsumption = defaultLoadable + & laMax .~ 200 + & laLoadType . ejectTime .~ 40 + & laLoadType . insertTime .~ 40 , _itUse = ruseInstant shootLaser NoHammer [ ammoCheckI , withItem $ \it -> withTempLight 1 100 (xyzV4 (_lasColor $ _itParams it)) @@ -320,11 +318,10 @@ lasGunTweak = TweakParam tractorGun :: Item tractorGun = lasGun - { _itConsumption = defaultAmmo - { _laMax = 10000 - , _laLoaded = 10000 - , _laReloadTime = 40 - } + { _itConsumption = defaultLoadable + & laMax .~ 10000 + & laLoadType . ejectTime .~ 20 + & laLoadType . insertTime .~ 20 , _itUse = ruseInstant aTractorBeam NoHammer [ ammoCheckI ] diff --git a/src/Dodge/Item/Weapon/BulletGun/Cane.hs b/src/Dodge/Item/Weapon/BulletGun/Cane.hs index af2af41f1..c40a7dd82 100644 --- a/src/Dodge/Item/Weapon/BulletGun/Cane.hs +++ b/src/Dodge/Item/Weapon/BulletGun/Cane.hs @@ -21,7 +21,6 @@ import Dodge.Default --import Dodge.Item.Weapon.InventoryDisplay import Dodge.Item.Weapon.AmmoParams import Dodge.Item.Draw -import Dodge.Item.Weapon.Bullet import Dodge.Item.Weapon.TriggerType import Dodge.SoundLogic.LoadSound import Picture @@ -38,7 +37,7 @@ import LensHelp --import System.Random bangCane :: Item -bangCane = defaultGun +bangCane = defaultBulletWeapon { _itParams = BulletShooter { _muzVel = 0.8 , _rifling = 0.9 @@ -50,12 +49,6 @@ bangCane = defaultGun , _torqueAfter = 0.1 , _randomOffset = 0 } - , _itConsumption = defaultAmmo - { _laType = basicBullet - , _laMax = 1 - , _laReloadTime = 15 - , _laReloadType = ActivePartial 1 - } , _itUse = ruseAmmoParamsRate 6 upHammer [ ammoHammerCheck , useTimeCheck @@ -79,6 +72,8 @@ bangCane = defaultGun } } & itUse . useAim . aimStance .~ OneHand & itType . iyBase .~ BANGCANE + & itConsumption . laMax .~ 1 + & itConsumption . laLoadType .~ ActivePartial 10 1 NoTransfer bangCaneX :: Int -> Item bangCaneX i = bangCane { _itUse = ruseAmmoParamsRate 6 upHammer @@ -144,6 +139,7 @@ rifle = bangCane & itUse . useAim . aimStance .~ TwoHandTwist & itType . iyBase .~ RIFLE & itConsumption . laMax .~ 1 + & itConsumption . laLoadType .~ ActiveEject 5 5 NoTransfer & itUse . useAim . aimWeight .~ 6 & itUse . useAim . aimRange .~ 1 -- & itUse . useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1.5} @@ -152,8 +148,8 @@ repeater :: Item repeater = rifle & itType . iyModules . at ModRifleMag ?~ EMPTYMODULE & itType . iyBase .~ REPEATER - & itConsumption . laReloadType .~ ActiveClear - & itConsumption . laReloadTime .~ 80 + & itConsumption . laLoadType . ejectTime .~ 40 + & itConsumption . laLoadType . insertTime .~ 40 & itConsumption . laMax .~ 15 & itDimension . dimSPic .~ (\it -> noPic $ baseRifleShape <> makeTinClipAt 0 (V3 10 (-2) 0) it @@ -252,14 +248,14 @@ miniGunUse i = ruseInstant (useAmmoParams $ Just 1) NoHammer $ miniGunX :: Int -> Item miniGunX i = defaultAutoGun - { _itConsumption = defaultAmmo - { _laType = basicBullet - , _laMax = 1500 + { _itConsumption = defaultBulletLoadable + { _laMax = 1500 , _laLoaded = 1500 - , _laReloadTime = 200 } + & laLoadType . ejectTime .~ 60 + & laLoadType . insertTime .~ 60 , _itUse = miniGunUse i - & useDelay .~ WarmUpNoDelay {_warmTime = 0,_warmMax = 200} + & useDelay .~ WarmUpNoDelay {_warmTime = 0,_warmMax = 100} & useAim . aimWeight .~ 6 & useAim . aimRange .~ 1 & useAim . aimStance .~ TwoHandTwist diff --git a/src/Dodge/Item/Weapon/BulletGun/Rod.hs b/src/Dodge/Item/Weapon/BulletGun/Rod.hs index 69bffa794..a5aa85892 100644 --- a/src/Dodge/Item/Weapon/BulletGun/Rod.hs +++ b/src/Dodge/Item/Weapon/BulletGun/Rod.hs @@ -22,7 +22,6 @@ import Dodge.Item.Weapon.ExtraEffect --import Dodge.Item.Weapon.InventoryDisplay import Dodge.Item.Weapon.AmmoParams --import Dodge.Item.Draw -import Dodge.Item.Weapon.Bullet import Dodge.Item.Weapon.TriggerType import Dodge.SoundLogic.LoadSound import Picture @@ -38,7 +37,7 @@ import LensHelp --import System.Random bangRod :: Item -bangRod = defaultGun +bangRod = defaultBulletWeapon { _itParams = BulletShooter { _muzVel = 0.8 , _rifling = 1 @@ -69,18 +68,16 @@ bangRod = defaultGun , _dimSPic = \it -> noPic $ baseRodShape <> makeSingleClipAt (V3 5 0 3) it } - , _itConsumption = defaultAmmo - { _laType = basicBullet - , _laMax = 1 - , _laReloadTime = 20 - } } + & itConsumption . laMax .~ 1 + & itConsumption . laLoadType . ejectTime .~ 10 + & itConsumption . laLoadType . insertTime .~ 10 & itType . iyBase .~ BANGROD & itUse . useAim . aimWeight .~ 8 & itUse . useAim . aimRange .~ 1 & itUse . useAim . aimStance .~ OneHand & itUse . useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1.5} - & itConsumption . laType . amBulEff .~ expireAndDamage heavyBulDams + & itConsumption . laAmmoType . amBulEff .~ expireAndDamage heavyBulDams baseRodShape :: Shape baseRodShape = colorSH orange $ upperPrismPoly 3 $ rectXH 20 2 baseAMRShape :: Shape @@ -145,6 +142,7 @@ machineGun = bangRod & useDelay .~ VariableRate {_rateMax = 25, _rateMaxMax = 24, _rateMinMax = 7, _rateTime = 0} ) & itConsumption . laMax .~ 100 - & itConsumption . laReloadTime .~ 75 + & itConsumption . laLoadType . ejectTime .~ 25 + & itConsumption . laLoadType . insertTime .~ 25 & itInvSize .~ 3 & itParams. torqueAfter .~ 0.2 -- not sure if this is necessary? diff --git a/src/Dodge/Item/Weapon/BulletGun/Stick.hs b/src/Dodge/Item/Weapon/BulletGun/Stick.hs index 21230470b..6878eaa58 100644 --- a/src/Dodge/Item/Weapon/BulletGun/Stick.hs +++ b/src/Dodge/Item/Weapon/BulletGun/Stick.hs @@ -18,7 +18,6 @@ import Dodge.Default --import Dodge.Item.Weapon.InventoryDisplay import Dodge.Item.Weapon.AmmoParams --import Dodge.Item.Draw -import Dodge.Item.Weapon.Bullet import Dodge.Item.Weapon.TriggerType import Dodge.SoundLogic.LoadSound import Picture @@ -40,14 +39,8 @@ bangStickSoundChoice it | otherwise = shotgunS bangStick :: Int -> Item -bangStick i = defaultGun - { _itConsumption = defaultAmmo - { _laType = basicBullet - , _laMax = i - , _laReloadTime = 10 - , _laReloadType = ActivePartial 1 - } - , _itUse = ruseAmmoParamsRate 8 upHammer +bangStick i = defaultBulletWeapon + { _itUse = ruseAmmoParamsRate 8 upHammer [ ammoHammerCheck , useTimeCheck , withSoundItemChoiceStart bangStickSoundChoice @@ -84,6 +77,8 @@ bangStick i = defaultGun } } & itType . iyBase .~ BANGSTICK i + & itConsumption . laMax .~ i + & itConsumption . laLoadType .~ ActivePartial 10 1 NoTransfer baseStickShapeX :: Int -> Shape baseStickShapeX i = foldMap f [0..i-1] where @@ -110,14 +105,10 @@ stickClip it = case it ^? itConsumption . laLoaded of revolver :: Item revolver = pistol - { _itConsumption = defaultAmmo - { _laType = basicBullet - , _laMax = 6 - , _laLoaded = 0 - , _laReloadTime = 10 - , _laReloadType = ActivePartial 1 - } - } + & itConsumption .~ + (defaultBulletLoadable + & laMax .~ 6 + & laLoadType .~ ActivePartial 10 1 NoTransfer ) & itDimension . dimSPic .~ (\it -> noPic $ baseStickShape <> revolverClip it) & itType . iyBase .~ REVOLVER @@ -164,18 +155,12 @@ smgAfterHamMods = pistol :: Item pistol = (bangStick 1) - { _itConsumption = defaultAmmo - { _laType = basicBullet - , _laMax = 15 - , _laLoaded = 0 - , _laReloadTime = 70 - , _laReloadType = ActiveClear - } - , _itUse = ruseAmmoParamsRate 6 upHammer - (ammoHammerCheck : pistolAfterHamMods) --- , _itZoom = defaultItZoom --- , _itEquipPict = pictureWeaponAim pistolPic - } & itDimension . dimSPic .~ (\it -> noPic $ baseStickShape <> makeTinClipAt pi (V3 5 2 0) it) + & itConsumption .~ ( defaultBulletLoadable + & laMax .~ 15 + & laLoadType . ejectTime .~ 20 + & laLoadType . insertTime .~ 20 ) + & itUse .~ ruseAmmoParamsRate 6 upHammer (ammoHammerCheck : pistolAfterHamMods) + & itDimension . dimSPic .~ (\it -> noPic $ baseStickShape <> makeTinClipAt pi (V3 5 2 0) it) & itParams %~ ( ( muzVel .~ 0.8 ) . ( rifling .~ 0.8 ) diff --git a/src/Dodge/Item/Weapon/BulletGuns.hs b/src/Dodge/Item/Weapon/BulletGuns.hs index ce4973b88..e64a4a642 100644 --- a/src/Dodge/Item/Weapon/BulletGuns.hs +++ b/src/Dodge/Item/Weapon/BulletGuns.hs @@ -8,7 +8,6 @@ module Dodge.Item.Weapon.BulletGuns , autogunSpread , autoGun , autoGunPic - , longGun , module Dodge.Item.Weapon.BulletGun.Stick , module Dodge.Item.Weapon.BulletGun.Cane , module Dodge.Item.Weapon.BulletGun.Rod @@ -16,7 +15,6 @@ module Dodge.Item.Weapon.BulletGuns import Dodge.Item.Weapon.BulletGun.Stick import Dodge.Item.Weapon.BulletGun.Cane import Dodge.Item.Weapon.BulletGun.Rod -import Dodge.Item.Weapon.ZoomScope --import Dodge.Item.Weapon.BulletGun.Clip import Dodge.Data --import Dodge.ChainEffect @@ -26,7 +24,6 @@ import Dodge.Item.Attachment --import Dodge.Item.Weapon.InventoryDisplay import Dodge.Item.Weapon.AmmoParams import Dodge.Item.Draw -import Dodge.Item.Weapon.Bullet import Dodge.Item.Weapon.TriggerType import Dodge.SoundLogic.LoadSound import Picture @@ -43,12 +40,12 @@ import System.Random autoGun :: Item autoGun = defaultAutoGun - { _itConsumption = defaultAmmo - { _laType = basicBullet - , _laMax = 30 + { _itConsumption = defaultBulletLoadable + { _laMax = 30 , _laLoaded = 30 - , _laReloadTime = 80 } + & laLoadType . ejectTime .~ 40 + & laLoadType . insertTime .~ 40 , _itUse = ruseAmmoParamsRate 4 NoHammer [ ammoCheckI , charFiringStratI @@ -97,14 +94,8 @@ autoGunPic it = noPic $ x = fromIntegral $ _laLoaded $ _itConsumption it bangCone :: Item -bangCone = defaultGun - { _itConsumption = defaultAmmo - { _laType = basicBullet - , _laMax = 5 - , _laReloadTime = 25 - , _laReloadType = ActiveClear - } - , _itUse = ruseAmmoParamsRate 20 upHammer +bangCone = defaultBulletWeapon + { _itUse = ruseAmmoParamsRate 20 upHammer [ ammoCheckI , hammerCheckI , useTimeCheck @@ -140,10 +131,13 @@ bangCone = defaultGun } } & itType . iyBase .~ BANGCONE + & itConsumption . laMax .~ 5 + & itConsumption . laLoadType . ejectTime .~ 10 + & itConsumption . laLoadType . insertTime .~ 10 coneRandItemUpdate :: State StdGen (Item -> Item) coneRandItemUpdate = do wth <- state $ randomR (1,5) - return (\it -> it & itConsumption . laType . amBulWth .~ wth) + return (\it -> it & itConsumption . laAmmoType . amBulWth .~ wth) coneRandItemParams :: State StdGen (ItemParams -> ItemParams) coneRandItemParams = do muzv <- state $ randomR (0.5,1) @@ -167,7 +161,8 @@ blunderbuss = bangCone } } & itConsumption . laMax .~ 25 - & itConsumption . laReloadTime .~ 30 + & itConsumption . laLoadType . ejectTime .~ 15 + & itConsumption . laLoadType . insertTime .~ 15 & itUse . useAim . aimStance .~ TwoHandTwist & itUse . useAim . aimWeight .~ 6 & itType . iyBase .~ BLUNDERBUSS @@ -175,7 +170,8 @@ bigBlunderbuss :: Item bigBlunderbuss = blunderbuss & itType . iyBase .~ BIGBLUNDERBUSS & itConsumption . laMax .~ 50 - & itConsumption . laReloadTime .~ 36 + & itConsumption . laLoadType . ejectTime .~ 18 + & itConsumption . laLoadType . insertTime .~ 18 & itParams . recoil .~ 200 & itParams . torqueAfter .~ 0.3 & itParams . randomOffset .~ 16 @@ -183,7 +179,8 @@ biggerBlunderbuss :: Item biggerBlunderbuss = bigBlunderbuss & itType . iyBase .~ BIGGERBLUNDERBUSS & itConsumption . laMax .~ 75 - & itConsumption . laReloadTime .~ 43 + & itConsumption . laLoadType . ejectTime .~ 20 + & itConsumption . laLoadType . insertTime .~ 20 & itParams . recoil .~ 250 & itParams . torqueAfter .~ 0.5 & itParams . randomOffset .~ 20 @@ -191,7 +188,8 @@ biggestBlunderbuss :: Item biggestBlunderbuss = biggerBlunderbuss & itType . iyBase .~ BIGGESTBLUNDERBUSS & itConsumption . laMax .~ 100 - & itConsumption . laReloadTime .~ 50 + & itConsumption . laLoadType . ejectTime .~ 25 + & itConsumption . laLoadType . insertTime .~ 25 & itParams . recoil .~ 300 & itParams . torqueAfter .~ 0.7 & itParams . randomOffset .~ 24 @@ -199,35 +197,5 @@ biggestBlunderbuss = biggerBlunderbuss grenadeLauncher :: Int -> Item grenadeLauncher _ = bangCone -longGun :: Item -longGun = defaultGun - { _itConsumption = defaultAmmo - { _laType = hvBullet - , _laMax = 1 - , _laLoaded = 1 - , _laReloadTime = 100 - , _laReloadType = PassiveReload skwareFadeTwoSecS - } - , _itUse = ruseAmmoParamsRate 100 upHammer - [ ammoCheckI - , hammerCheckI - , useTimeCheck - , withSoundStart bangEchoS - , useAmmoAmount 1 - , withThickSmokeI - , withTorqueAfter - , withMuzFlareI - ] - & useAim . aimWeight .~ 8 - & useAim . aimRange .~ 1 - & useAim . aimStance .~ TwoHandTwist - & useAim . aimZoom .~ defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5} - & heldScroll .~ zoomLongGun - , _itAttachment = NoItAttachment - , _itScope = ZoomScope (V2 0 0) 0 1 0.1 False --- , _itEffect = itemLaserScopeEffect - } - & itType . iyBase .~ LONGGUN - autogunSpread :: Float autogunSpread = 0.07 diff --git a/src/Dodge/Item/Weapon/Drone.hs b/src/Dodge/Item/Weapon/Drone.hs index db78a415b..0b17ea0e4 100644 --- a/src/Dodge/Item/Weapon/Drone.hs +++ b/src/Dodge/Item/Weapon/Drone.hs @@ -19,14 +19,8 @@ import Control.Lens --import System.Random droneLauncher :: Item -droneLauncher = defaultGun - { _itConsumption = defaultAmmo - { _laType = DroneAmmo { _amString = "LASDRONE" } - , _laMax = 2 - , _laLoaded = 2 - , _laReloadTime = 80 - } - , _itUse = ruseRate 20 aDroneWithItemParams upHammer +droneLauncher = defaultWeapon + { _itUse = ruseRate 20 aDroneWithItemParams upHammer [ ammoCheckI , useTimeCheck , withSoundStart tap4S @@ -37,6 +31,10 @@ droneLauncher = defaultGun & useAim . aimStance .~ TwoHandTwist , _itEffect = NoItEffect } + & itConsumption . laAmmoType .~ DroneAmmo { _amString = "LASDRONE" } + & itConsumption . laMax .~ 2 + & itConsumption . laLoadType . ejectTime .~ 40 + & itConsumption . laLoadType . insertTime .~ 40 & itType . iyBase .~ DRONELAUNCHER lasDronesPic :: Item -> SPic @@ -63,7 +61,7 @@ aDroneWithItemParams it cr w = over props (IM.insert i theShell) w { _prPos = pos , _pjStartPos = pos , _pjVel = rotateV dir (V2 1 0) - , _prDraw = _amPjDraw $ _laType am + , _prDraw = _amPjDraw $ _laAmmoType am , _pjID = i , _pjUpdate = const id } diff --git a/src/Dodge/Item/Weapon/ExtraEffect.hs b/src/Dodge/Item/Weapon/ExtraEffect.hs index 77dd3be7a..ae32bd3a1 100644 --- a/src/Dodge/Item/Weapon/ExtraEffect.hs +++ b/src/Dodge/Item/Weapon/ExtraEffect.hs @@ -186,7 +186,7 @@ targetRBPressUpdate w t & tgActive .~ False targetLaserUpdate :: Item -> Creature -> World -> Targeting -> (World,Targeting) -targetLaserUpdate it cr w t +targetLaserUpdate _ cr w t | crIsAiming cr = (addLaserPic w,t & tgPos .~ fmap fst mp & tgActive .~ True @@ -205,10 +205,10 @@ targetLaserUpdate it cr w t ] , _ptUpdate = ptSimpleTime 1 } - wpammo = _itConsumption it - reloadFrac - | _laLoaded wpammo == 0 = 1 - | otherwise = case _laTransfer wpammo of - Transfer _ rs -> fromIntegral rs / fromIntegral (_laReloadTime wpammo) - NoTransfer -> 1 - col = mixColors reloadFrac (1-reloadFrac) blue red + --wpammo = _itConsumption it +-- reloadFrac +-- | _laLoaded wpammo == 0 = 1 +-- | otherwise = case _laTransfer wpammo of +-- Transfer _ rs -> fromIntegral rs / fromIntegral (_laReloadTime wpammo) +-- NoTransfer -> 1 + col = blue -- mixColors reloadFrac (1-reloadFrac) blue red diff --git a/src/Dodge/Item/Weapon/Launcher.hs b/src/Dodge/Item/Weapon/Launcher.hs index 18bcae28c..5c3c2d02f 100644 --- a/src/Dodge/Item/Weapon/Launcher.hs +++ b/src/Dodge/Item/Weapon/Launcher.hs @@ -34,18 +34,18 @@ import Control.Lens import Control.Applicative launcher :: Item -launcher = defaultGun - { _itConsumption = defaultAmmo - { _laType = ProjectileAmmo +launcher = defaultWeapon + { _itConsumption = defaultLoadable + & laAmmoType .~ ProjectileAmmo { _amPayload = makeExplosionAt , _amString = "EXPLOSIVE SHELL" , _amPjDraw = drawShell , _amPjCreation = fireShell } - , _laMax = 1 - , _laLoaded = 1 - , _laReloadTime = 80 - } + & laMax .~ 1 + & laLoaded .~ 1 + & laLoadType . ejectTime .~ 40 + & laLoadType . insertTime .~ 40 , _itUse = ruseRate 20 usePjCreation upHammer [ hammerCheckI , ammoCheckI @@ -94,14 +94,14 @@ launcherX i = launcher ] usePjCreation :: Item -> Creature -> World -> World -usePjCreation it = _amPjCreation (_laType (_itConsumption it)) it +usePjCreation it = _amPjCreation (_laAmmoType (_itConsumption it)) it usePjCreationX :: Int -> Item -> Creature -> World -> World usePjCreationX i it cr = foldr f - (_amPjCreation (_laType (_itConsumption it)) it cr) + (_amPjCreation (_laAmmoType (_itConsumption it)) it cr) [1..i-1] where - f n = (. _amPjCreation (_laType (_itConsumption it)) it (cr & crDir +~ (2*pi*fromIntegral n / fromIntegral i))) + f n = (. _amPjCreation (_laAmmoType (_itConsumption it)) it (cr & crDir +~ (2*pi*fromIntegral n / fromIntegral i))) launcherPic :: Item -> SPic launcherPic _ = @@ -280,7 +280,7 @@ remoteLauncher = launcher & itType . iyBase .~ REMOTELAUNCHER & itUse . rUse .~ fireRemoteShell & itScope .~ RemoteScope (V2 0 0) 1 True - & itConsumption . laType . amPjDraw .~ drawRemoteShell + & itConsumption . laAmmoType . amPjDraw .~ drawRemoteShell -- TODO consider allowing tweaking rocket speed fireRemoteShell :: Item -> Creature -> World -> World @@ -374,13 +374,13 @@ makeShell it cr theupdate w = w & props %~ IM.insert i Shell , _pjZ = 20 , _pjStartPos = pos , _pjVel = rotateV dir (V2 1 0) - , _prDraw = _amPjDraw $ _laType am + , _prDraw = _amPjDraw $ _laAmmoType am , _pjID = i , _pjUpdate = theupdate , _pjAcc = rotateV dir (V2 3 0) , _pjDir = dir , _pjSpin = 0 - , _pjPayload = _amPayload $ _laType am + , _pjPayload = _amPayload $ _laAmmoType am , _pjTimer = 50 } where diff --git a/src/Dodge/Item/Weapon/Radar.hs b/src/Dodge/Item/Weapon/Radar.hs index 74471ed23..6e6d3ce6e 100644 --- a/src/Dodge/Item/Weapon/Radar.hs +++ b/src/Dodge/Item/Weapon/Radar.hs @@ -22,9 +22,8 @@ import Control.Lens {- | Sends out pulses that display walls. -} clickDetector :: Detector -> Item -clickDetector dt = defaultGun - { _itConsumption = defaultAmmo - , _itUse = ruseRate 20 (detectorEffect dt) upHammer +clickDetector dt = defaultWeapon + { _itUse = ruseRate 20 (detectorEffect dt) upHammer [ ammoUseCheck ] & useAim . aimRange .~ 1 diff --git a/src/Dodge/Item/Weapon/Shatter.hs b/src/Dodge/Item/Weapon/Shatter.hs index 7a9fcf259..6c67b8d4a 100644 --- a/src/Dodge/Item/Weapon/Shatter.hs +++ b/src/Dodge/Item/Weapon/Shatter.hs @@ -27,9 +27,8 @@ import LensHelp import qualified Data.IntMap.Strict as IM shatterGun :: Item -shatterGun = defaultGun +shatterGun = defaultWeapon & itType . iyBase .~ SHATTERGUN - & itConsumption .~ defaultAmmo & itUse .~ ruseRate 10 shootShatter upHammer [ ammoHammerCheck , useTimeCheck diff --git a/src/Dodge/Item/Weapon/SonicGuns.hs b/src/Dodge/Item/Weapon/SonicGuns.hs index 0d57af056..066f59bb8 100644 --- a/src/Dodge/Item/Weapon/SonicGuns.hs +++ b/src/Dodge/Item/Weapon/SonicGuns.hs @@ -30,11 +30,10 @@ import LensHelp sonicGun :: Item sonicGun = defaultAutoGun - { _itConsumption = defaultAmmo - { _laMax = 10 - , _laLoaded = 10 - , _laReloadTime = 80 - } + { _itConsumption = defaultLoadable + & laMax .~ 10 + & laLoadType . ejectTime .~ 40 + & laLoadType . insertTime .~ 40 , _itUse = ruseRate 8 aSonicWave (HasHammer HammerUp) [ ammoHammerCheck , useTimeCheck diff --git a/src/Dodge/Item/Weapon/Spawn.hs b/src/Dodge/Item/Weapon/Spawn.hs index 167c44152..cf1f9ee8f 100644 --- a/src/Dodge/Item/Weapon/Spawn.hs +++ b/src/Dodge/Item/Weapon/Spawn.hs @@ -15,12 +15,11 @@ import Control.Lens {- | Creates a creature next to the creature using the item. -} spawnGun :: Creature -> Item -spawnGun cr = defaultGun - { _itConsumption = defaultAmmo - { _laMax = 1 - , _laLoaded = 1 - , _laReloadTime = 80 - } +spawnGun cr = defaultWeapon + { _itConsumption = defaultLoadable + & laMax .~ 1 + & laLoadType . ejectTime .~ 40 + & laLoadType . insertTime .~ 40 , _itUse = ruseRate 100 (\_ -> spawnCrNextTo cr) upHammer diff --git a/src/Dodge/Item/Weapon/SprayGuns.hs b/src/Dodge/Item/Weapon/SprayGuns.hs index 5abb840c5..082f6db2c 100644 --- a/src/Dodge/Item/Weapon/SprayGuns.hs +++ b/src/Dodge/Item/Weapon/SprayGuns.hs @@ -40,7 +40,7 @@ import System.Random poisonSprayer :: Item poisonSprayer = flameThrower & itType . iyBase .~ POISONSPRAYER - & itConsumption . laType .~ GasAmmo + & itConsumption . laAmmoType .~ GasAmmo { _amString = "POISONGAS" , _amCreateGas = aGasCloud } @@ -68,7 +68,8 @@ flameSpitter :: Item flameSpitter = flameThrower & itType . iyBase .~ FLAMESPITTER & itConsumption . laMax .~ 10 - & itConsumption . laReloadTime .~ 20 + & itConsumption . laLoadType . ejectTime .~ 10 + & itConsumption . laLoadType . insertTime .~ 10 & itParams . sprayNozzles . ix 0 . nzPressure .~ 4 & itUse . useAim . aimStance .~ OneHand & itUse . useDelay .~ FixedRate {_rateMax =12,_rateTime = 0} @@ -116,15 +117,14 @@ flameWall = flameThrower flameThrower :: Item flameThrower = defaultAutoGun - { _itConsumption = defaultAmmo - { _laMax = 250 - , _laLoaded = 0 - , _laReloadTime = 100 - , _laType = GasAmmo + { _itConsumption = defaultLoadable + & laMax .~ 250 + & laAmmoType .~ GasAmmo {_amString = "FLAME" ,_amCreateGas = aFlame } - } + & laLoadType . ejectTime .~ 40 + & laLoadType . insertTime .~ 40 , _itUse = ruseInstant (overNozzles useGasParams) NoHammer [ ammoCheckI , useAmmoAmount 1 @@ -191,7 +191,7 @@ overNozzle eff it cr w nz = wa = min maxa $ max (negate maxa) (_nzCurrentWalkAngle nz + walkamount) useGasParams :: Nozzle -> Item -> Creature -> World -> World -useGasParams nz it cr = _amCreateGas (_laType (_itConsumption it)) (_nzPressure nz) pos dir cr +useGasParams nz it cr = _amCreateGas (_laAmmoType (_itConsumption it)) (_nzPressure nz) pos dir cr where dir = _crDir cr pos = _crPos cr +.+ (_nzLength nz *.* unitVectorAtAngle (_crDir cr)) diff --git a/src/Dodge/Item/Weapon/TriggerType.hs b/src/Dodge/Item/Weapon/TriggerType.hs index bf53c737f..dbb759eee 100644 --- a/src/Dodge/Item/Weapon/TriggerType.hs +++ b/src/Dodge/Item/Weapon/TriggerType.hs @@ -173,15 +173,15 @@ rateIncAB exeffFirst exeffCont eff item cr w itRef = _crInvSel cr pointItem = creatures . ix cid . crInv . ix itRef currentRate = _rateMax (_useDelay (_itUse item)) - repeatFire = _laTransfer (_itConsumption item) == NoTransfer && _rateTime (_useDelay (_itUse item)) == 1 - firstFire = _laTransfer (_itConsumption item) == NoTransfer && _rateTime (_useDelay (_itUse item)) == 0 + repeatFire = _loadProgress (_laLoadType $ _itConsumption item) == NoTransfer && _rateTime (_useDelay (_itUse item)) == 1 + firstFire = _loadProgress (_laLoadType $ _itConsumption item) == NoTransfer && _rateTime (_useDelay (_itUse item)) == 0 {- | Apply effect after a warm up. -} -- note this is quite unsafe, requires the item to have the correct delay type withWarmUp :: SoundID -- ^ warm up sound id -> ChainEffect withWarmUp soundID f item cr w - | _laTransfer (_itConsumption item) /= NoTransfer = w + | _loadProgress (_laLoadType $ _itConsumption item) /= NoTransfer = w | curWarmUp < maxWarmUp = w & pointerToItem . itUse . useDelay . warmTime +~ 2 & soundContinue (CrWeaponSound cid 0) (_crPos cr) soundID (Just 2) @@ -323,7 +323,7 @@ ammoUseCheck f item cr w cid = _crID cr itRef = _crInvSel cr pointerToItem = creatures . ix cid . crInv . ix itRef - fireCondition = _laTransfer (_itConsumption item) == NoTransfer + fireCondition = _loadProgress (_laLoadType $ _itConsumption item) == NoTransfer && _rateTime (_useDelay (_itUse item)) == 0 && _laLoaded (_itConsumption item) > 0 -- reloadCondition = _laLoaded (_itConsumption item) == 0 @@ -359,7 +359,7 @@ shootL f item cr w cid = _crID cr invid = fromJust $ _itInvPos item pointerToItem = creatures . ix cid . crInv . ix invid - fireCondition = _laTransfer (_itConsumption item) == NoTransfer + fireCondition = _loadProgress (_laLoadType $ _itConsumption item) == NoTransfer && _rateTime (_useDelay (_itUse item)) == 0 && _laLoaded (_itConsumption item) > 0 -- reloadCondition = _laLoaded (_itConsumption item) == 0 diff --git a/src/Dodge/Item/Weapon/Utility.hs b/src/Dodge/Item/Weapon/Utility.hs index 4e1817564..f83ceda40 100644 --- a/src/Dodge/Item/Weapon/Utility.hs +++ b/src/Dodge/Item/Weapon/Utility.hs @@ -22,7 +22,7 @@ import Control.Lens --import Control.Monad rewindGun :: Item -rewindGun = defaultGun +rewindGun = defaultLeftItem { _itInvColor = cyan , _itConsumption = ChargeableAmmo { _wpMaxCharge = 250 @@ -63,9 +63,8 @@ useRewindGun _ _ w = case _rewindWorlds w of -- needs to shift this item to the current inventory slot shrinkGun :: Item -shrinkGun = defaultGun - { _itConsumption = defaultAmmo - , _itUse = defaultlUse {_lUse = hammerCheckL useShrinkGun} +shrinkGun = defaultLeftItem + {_itUse = defaultlUse {_lUse = hammerCheckL useShrinkGun} & useHammer .~ upHammer -- , _itFloorPict = shrinkGunPic , _itAttachment = AttachBool True @@ -89,9 +88,8 @@ useShrinkGun it cr w = if _atBool $ _itAttachment it ( (itAttachment . atBool .~ isInUse) . (itCurseStatus .~ cstatus) ) blinkGun :: Item -blinkGun = defaultGun +blinkGun = defaultLeftItem { _itInvColor = cyan - , _itConsumption = defaultAmmo , _itUse = defaultlUse & lUse .~ hammerCheckL (shootL $ const blinkAction) & useHammer .~ upHammer @@ -107,20 +105,20 @@ unsafeBlinkGun = blinkGun & itUse . eqEq . eqViewDist ?~ 400 effectGun :: String -> (Creature -> World -> World) -> Item -effectGun name eff = defaultGun +effectGun name eff = defaultWeapon { _itUse = defaultrUse & rUse .~ const eff & useMods .~ [hammerCheckI] } & itType . iyBase .~ EFFGUN name autoEffectGun :: String -> (Creature -> World -> World) -> Item -autoEffectGun name eff = defaultGun +autoEffectGun name eff = defaultWeapon { _itUse = defaultrUse {_rUse = const eff} } & itType . iyBase .~ AUTOEFFGUN name forceFieldGun :: Item -forceFieldGun = defaultGun - { _itConsumption = defaultAmmo & laType .~ ForceFieldAmmo forceField +forceFieldGun = defaultWeapon + { _itConsumption = defaultLoadable & laAmmoType .~ ForceFieldAmmo forceField , _itUse = ruseInstant useForceFieldGun (HasHammer HammerUp) [ hammerCheckI , ammoCheckI , useAmmoAmount 1] -- , _itFloorPict = \_ -> (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-4,-4),(-4,4),(4,4),(4,0),(0,0),(0,-4)] diff --git a/src/Dodge/Reloading.hs b/src/Dodge/Reloading.hs index 67baf0ce2..c24623ebd 100644 --- a/src/Dodge/Reloading.hs +++ b/src/Dodge/Reloading.hs @@ -1,32 +1,15 @@ module Dodge.Reloading ( stepReloading - , tryStartReloading +-- , tryStartReloading , crStopReloading + , crStartReloading ) where import Dodge.Data -import Dodge.Base.Arithmetic +--import Dodge.Base.Arithmetic --import qualified Data.IntMap.Strict as IM import Control.Lens - -tryStartReloading :: Creature -> World -> Maybe World -tryStartReloading cr w = case cr ^? crInv . ix (_crInvSel cr) . itConsumption of - Just LoadableAmmo {_laMax = ma, _laLoaded = la, _laReloadTime = rtime, _laReloadType = rtype, _laTransfer = NoTransfer} - | ma > la && rtype == ActiveClear -> Just $ w & creatures . ix (_crID cr) %~ clearload - | ma > la && isActivePartial rtype -> Just $ w & creatures . ix (_crID cr) %~ partialload - where - isActivePartial ActivePartial {} = True - isActivePartial _ = False - clearload cr' = cr' - & crInv . ix (_crInvSel cr) . itConsumption . laLoaded .~ 0 - & crInv . ix (_crInvSel cr) . itConsumption . laTransfer .~ Transfer ma rtime - & crStance . posture .~ Reloading - partialload cr' = cr' - & crInv . ix (_crInvSel cr) . itConsumption . laTransfer - .~ Transfer (min (ma - la) (_partialReloadAmount rtype)) rtime - & crStance . posture .~ Reloading - _ -> Nothing - +import Data.Maybe ---- TODO clean this up, rethink datatypes --icTryStartReloading :: Item -> Maybe Item @@ -43,24 +26,51 @@ tryStartReloading cr w = case cr ^? crInv . ix (_crInvSel cr) . itConsumption of -- else id -- else Nothing +crStartReloading :: Creature -> World -> World +crStartReloading cr = creatures . ix (_crID cr) . crStance . posture .~ Reloading + crStopReloading :: Creature -> Creature crStopReloading cr = cr & crStance . posture .~ AtEase --- ugly TODO cleanup +startInsertAmmo :: ItemConsumption -> ItemConsumption +startInsertAmmo ic = ic & laLoadType . loadProgress .~ Insert intime inamount + where + intime = _insertTime (_laLoadType ic) + inamount = maybe id min (ic ^? laLoadType . loadAmount) (_laMax ic - _laLoaded ic) + +startEjectAmmo :: ItemConsumption -> ItemConsumption +startEjectAmmo ic = ic & laLoadType . loadProgress .~ Eject (_ejectTime $ _laLoadType ic) + +loadAmmo :: Int -> ItemConsumption -> ItemConsumption +loadAmmo inamount ic = ic + & laLoaded +~ inamount + & laLoadType . loadProgress .~ NoTransfer + stepReloading :: Creature -> Creature -stepReloading cr = case cr ^? crInv . ix isel . itConsumption . laTransfer of - Just (Transfer x 0) -> cr - & crInv . ix isel %~ loadItem x - & crStance . posture .~ AtEase - Just Transfer {} -> cr - & crInv . ix isel . itConsumption . laTransfer . transferTime %~ decreaseToZero +stepReloading cr = case _posture (_crStance cr) of + Reloading -> fromMaybe (cr & crStance . posture .~ AtEase) + (cr & crInv . ix (_crInvSel cr) . itConsumption %%~ stepReloading') _ -> cr - where - isel = _crInvSel cr - -loadItem :: Int -> Item -> Item -loadItem x = itConsumption %~ (set laTransfer NoTransfer . (laLoaded +~ x)) +stepReloading' :: ItemConsumption -> Maybe ItemConsumption +stepReloading' ic = do + ltype <- ic ^? laLoadType + lprog <- ltype ^? loadProgress + case lprog of + Eject x + | x > 0 -> Just $ ic & laLoadType . loadProgress . ejectProgress -~ 1 + | otherwise -> Just $ ic & startInsertAmmo + Insert x inamount + | x > 0 -> Just $ ic & laLoadType . loadProgress . insertProgress -~ 1 + | otherwise -> Just $ ic & loadAmmo inamount + NoTransfer + | _laLoaded ic >= _laMax ic + -> Nothing + | otherwise -> case ltype of + ActiveEject {} -> Just $ ic & startEjectAmmo + ActivePartial {} -> Just $ ic & startInsertAmmo + _ -> Nothing + --{- | Start reloading if clip is empty. -} --crAutoReload :: Creature -> Creature --crAutoReload cr = case cr ^? ptrItConsumption' . ammoLoaded of