From 724ee21afc3cff6688c2f1828f5940d127ae3db7 Mon Sep 17 00:00:00 2001 From: justin Date: Mon, 21 Feb 2022 07:50:15 +0000 Subject: [PATCH] Commit before changing module system to Map --- src/Dodge/Combine.hs | 9 ++-- src/Dodge/Combine/Combinations.hs | 36 +++++++++++++- src/Dodge/Combine/Data.hs | 1 + src/Dodge/Data.hs | 9 +++- src/Dodge/Default.hs | 10 +++- src/Dodge/Default/Weapon.hs | 8 ++- src/Dodge/Item/MaxAmmo.hs | 12 +++++ src/Dodge/Item/Weapon/AmmoParams.hs | 12 +++-- src/Dodge/Item/Weapon/BatteryGuns.hs | 6 +-- src/Dodge/Item/Weapon/Bezier.hs | 2 +- src/Dodge/Item/Weapon/Booster.hs | 2 +- src/Dodge/Item/Weapon/BulletGun/Cane.hs | 18 ++++--- src/Dodge/Item/Weapon/BulletGun/Rod.hs | 4 +- src/Dodge/Item/Weapon/BulletGun/Stick.hs | 8 +-- src/Dodge/Item/Weapon/BulletGuns.hs | 24 ++++----- src/Dodge/Item/Weapon/Drone.hs | 2 +- src/Dodge/Item/Weapon/InventoryDisplay.hs | 9 +++- src/Dodge/Item/Weapon/Launcher.hs | 4 +- src/Dodge/Item/Weapon/Radar.hs | 4 +- src/Dodge/Item/Weapon/SonicGuns.hs | 2 +- src/Dodge/Item/Weapon/Spawn.hs | 2 +- src/Dodge/Item/Weapon/SprayGuns.hs | 4 +- src/Dodge/Item/Weapon/Utility.hs | 6 +-- src/Dodge/Module.hs | 3 +- src/Dodge/Reloading.hs | 60 +++++++++++++---------- 25 files changed, 171 insertions(+), 86 deletions(-) create mode 100644 src/Dodge/Item/MaxAmmo.hs diff --git a/src/Dodge/Combine.hs b/src/Dodge/Combine.hs index 76f73ec72..f758d0169 100644 --- a/src/Dodge/Combine.hs +++ b/src/Dodge/Combine.hs @@ -72,15 +72,16 @@ addModules (ps,it) = (is , ) <$> [ (it & itModules .~ themodules,s) | (themodule g ims (ims',s) = map (second (s++)) $ combineModules ims ims' combineModules :: ItemModules -> ItemModules -> [(ItemModules,[String])] -combineModules (ItemModules a1) (ItemModules a2) - = [(ItemModules a,ss) | (a,ss) <- combineModule a1 a2] +combineModules (ItemModules a1 b1) (ItemModules a2 b2) + = [(ItemModules a b,as++bs) | (a,as) <- combineModule a1 a2 + , (b,bs) <- combineModule b1 b2] combineModule :: ItemModule a -> ItemModule a -> [(ItemModule a,[String])] -combineModule (ItemModule _ ss _) BlockedModule = [(BlockedModule, "WARNING:REMOVES":ss)] +combineModule ItemModule{_modName=ss} BlockedModule = [(BlockedModule, "WARNING:REMOVES":ss)] combineModule _ BlockedModule = [(BlockedModule, [])] combineModule BlockedModule m = [(m,[])] combineModule DefaultModule m = [(m,[])] -combineModule (ItemModule _ ss _) m@ItemModule{} = [(m,"WARNING:REMOVES":ss)] +combineModule ItemModule{_modName=ss} m@ItemModule{} = [(m,"WARNING:REMOVES":ss)] combineModule m _ = [(m,[])] toggleCombineInv :: World -> World diff --git a/src/Dodge/Combine/Combinations.hs b/src/Dodge/Combine/Combinations.hs index c31856911..72f02553f 100644 --- a/src/Dodge/Combine/Combinations.hs +++ b/src/Dodge/Combine/Combinations.hs @@ -70,17 +70,49 @@ itemCombinations = ++ [ po [itype,mtype] $ it & itModules . modHitEffect .~ m | (itype,it) <- firearmTypes , (mtype,m) <- bulletModules ] + ++ [ po (itype : ctypes) $ it & itModules . modRifleMag .~ m + | (itype,it) <- rifleMagTypes , (ctypes,m) <- rifleMagModules + ] where p = (,) po xs it = (map o xs,it) o = (1,) +rifleMagTypes :: [(CombineType,Item)] +rifleMagTypes + = [(REPEATER,repeater) + ,(AUTORIFLE,autoRifle) + ,(BURSTRIFLE,burstRifle) + ,(FASTBURSTRIFLE,fastBurstRifle) + ] +rifleMagModules :: [([CombineType],ItemModule RifleMag)] +rifleMagModules = + [([DRUM,HARDWARE], ItemModule DrumMag ["+DRUM MAGAZINE"] 1 id) + ,([MOTOR,HARDWARE], ItemModule BeltMag ["+BELT MAGAZINE"] 1 id) + ,([MAGNET,HARDWARE],ItemModule MagnetMag ["+MAGNET MAGAZINE"] 1 id) + ] + firearmTypes :: [(CombineType,Item)] firearmTypes = [(BANGSTICK i,bangStick i) | i <- [1..9] ] ++ [(BANGCANEX i,bangCaneX i) | i <- [1..6] ] + ++ [(REVOLVERX i,revolverX i) | i <- [1..5] ] + ++ [(MINIGUNX i,miniGunX i) | i <- [3..16] ] + ++ [(BANGCANE,bangCane) + ,(PISTOL,pistol) + ,(AUTOPISTOL,autoPistol) + ,(SMG,smg) + ,(MACHINEPISTOL,machinePistol) + ,(REVOLVER,revolver) + ,(RIFLE,rifle) + ,(REPEATER,repeater) + ,(AUTORIFLE,autoRifle) + ,(BURSTRIFLE,burstRifle) + ,(FASTBURSTRIFLE,fastBurstRifle) + ,(COMPLETEBURSTRIFLE,completeBurstRifle) + ] bulletModules :: [(CombineType,ItemModule HitEffect)] bulletModules = - [(INCENDIARYMODULE, ItemModule (destroyOnImpact bulIncCr bulIncWall) ["+INCENDIARY"] 1 ) - ,(BOUNCEMODULE, ItemModule (destroyOnImpact bulBounceArmCr' bulBounceWall) ["+BOUNCE"] 1 ) + [(INCENDIARYMODULE, ItemModule (destroyOnImpact bulIncCr bulIncWall) ["+INCENDIARY"] 1 id) + ,(BOUNCEMODULE, ItemModule (destroyOnImpact bulBounceArmCr' bulBounceWall) ["+BOUNCE"] 1 id) ] diff --git a/src/Dodge/Combine/Data.hs b/src/Dodge/Combine/Data.hs index c42ead7b9..944279b05 100644 --- a/src/Dodge/Combine/Data.hs +++ b/src/Dodge/Combine/Data.hs @@ -94,6 +94,7 @@ data CombineType | FUELCELL | PORTABLEFUSION -- Modules + -- bullet | INCENDIARYMODULE | BOUNCEMODULE | NoCombineType diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 0c24808bb..bd36c70d7 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -342,7 +342,7 @@ _itUseAimStance = _aimStance . _useAim . _itUse data ItemConsumption = LoadableAmmo { _aoType :: AmmoType - , _ammoMax :: Int + , _ammoBaseMax :: Int , _ammoLoaded :: Int , _reloadTime :: Int , _reloadState :: Maybe' Int @@ -380,7 +380,13 @@ data Item data ItemModules = ItemModules { _modHitEffect :: ItemModule HitEffect + , _modRifleMag :: ItemModule RifleMag } +data RifleMag = DrumMag | BeltMag | MagnetMag + +data ModuleSlot + = ModBullet + | ModRifleMag data ItemModule a = BlockedModule @@ -389,6 +395,7 @@ data ItemModule a { _theModule :: a , _modName :: [String] , _modSize :: Int + , _modModification :: Item -> Item } data ItemDimension = ItemDimension diff --git a/src/Dodge/Default.hs b/src/Dodge/Default.hs index 748aa2948..25e7fefec 100644 --- a/src/Dodge/Default.hs +++ b/src/Dodge/Default.hs @@ -154,7 +154,10 @@ defaultEquipment = Item , _itParams = NoParams , _itTweaks = NoTweaks , _itTargeting = Nothing - , _itModules = ItemModules BlockedModule + , _itModules = ItemModules + { _modHitEffect = BlockedModule + , _modRifleMag = BlockedModule + } } defaultItZoom :: ItZoom defaultItZoom = ItZoom 20 0.2 1 @@ -178,7 +181,10 @@ defaultConsumable = Item , _itParams = NoParams , _itDimension = defItDimCol blue , _itTweaks = NoTweaks - , _itModules = ItemModules BlockedModule + , _itModules = ItemModules + { _modHitEffect = BlockedModule + , _modRifleMag = BlockedModule + } } defaultApplyDamage :: [DamageType] -> Creature -> (World -> World, Creature) defaultApplyDamage ds cr = (id, doPoisonDam $ foldl' (flip $ \d c -> snd $ applyIndividualDamage d c) cr ds') diff --git a/src/Dodge/Default/Weapon.hs b/src/Dodge/Default/Weapon.hs index 17a178133..ec276f4fd 100644 --- a/src/Dodge/Default/Weapon.hs +++ b/src/Dodge/Default/Weapon.hs @@ -16,7 +16,7 @@ import Control.Lens defaultAmmo :: ItemConsumption defaultAmmo = LoadableAmmo { _aoType = GenericAmmo - , _ammoMax = 15 + , _ammoBaseMax = 15 , _ammoLoaded = 0 , _reloadTime = 40 , _reloadState = Nothing' @@ -102,6 +102,7 @@ defaultGun = Item , _itTweaks = NoTweaks , _itModules = ItemModules { _modHitEffect = DefaultModule + , _modRifleMag = BlockedModule } } defaultCraftable :: Item @@ -125,7 +126,10 @@ defaultCraftable = Item , _itParams = NoParams , _itDimension = defItDimCol green , _itTweaks = NoTweaks - , _itModules = ItemModules BlockedModule + , _itModules = ItemModules + { _modHitEffect = BlockedModule + , _modRifleMag = BlockedModule + } } defItDim :: ItemDimension defItDim = ItemDimension diff --git a/src/Dodge/Item/MaxAmmo.hs b/src/Dodge/Item/MaxAmmo.hs new file mode 100644 index 000000000..eb6ae41e0 --- /dev/null +++ b/src/Dodge/Item/MaxAmmo.hs @@ -0,0 +1,12 @@ +module Dodge.Item.MaxAmmo where +import Dodge.Data + +import Control.Lens + +itMaxAmmo :: Item -> Int +itMaxAmmo it = _ammoBaseMax (_itConsumption it) + + maybe 0 f (it ^? itModules . modRifleMag . theModule) + where + f DrumMag = 45 + f BeltMag = 135 + f MagnetMag = 0 diff --git a/src/Dodge/Item/Weapon/AmmoParams.hs b/src/Dodge/Item/Weapon/AmmoParams.hs index 500f1a1f1..7a03c3037 100644 --- a/src/Dodge/Item/Weapon/AmmoParams.hs +++ b/src/Dodge/Item/Weapon/AmmoParams.hs @@ -7,6 +7,7 @@ module Dodge.Item.Weapon.AmmoParams , fractionLoadedAmmo2 ) where import Dodge.Data +import Dodge.Item.MaxAmmo import Dodge.Particle.Bullet.Spawn import Dodge.Creature.HandPos import Dodge.WorldEvent.HitEffect @@ -54,9 +55,13 @@ useAmmoParams it cr = withVelWthHiteff useAmmoParamsVelMod :: Float -> Item -> Creature -> World -> World useAmmoParamsVelMod vfact it = withDelayedVelWthHiteff vfact (_amBulVel b) (_rifling $ _itParams it) - (_amBulWth b) (_amBulEff b) + (_amBulWth b) +-- (_amBulEff b) + bulHitEff where b = _aoType $ _itConsumption it + bulHitEff = fromMaybe (destroyOnImpact bulHitCr bulHitWall) + $ it ^? itModules . modHitEffect . theModule {- | Creates a bullet with a given velocity, width, and 'HitEffect' -} withVelWthHiteff @@ -98,7 +103,8 @@ loadedAmmo it | otherwise = 0 fractionLoadedAmmo :: Item -> Float -fractionLoadedAmmo it = fromIntegral (loadedAmmo it) / fromIntegral (_ammoMax (_itConsumption it)) +fractionLoadedAmmo it = fromIntegral (loadedAmmo it) / fromIntegral (itMaxAmmo it) fractionLoadedAmmo2 :: Item -> Float -fractionLoadedAmmo2 it = 1 - (1 - fromIntegral (loadedAmmo it) / fromIntegral (_ammoMax (_itConsumption it)))**2 +fractionLoadedAmmo2 it = 1 - + (1 - fromIntegral (loadedAmmo it) / fromIntegral (itMaxAmmo it))**2 diff --git a/src/Dodge/Item/Weapon/BatteryGuns.hs b/src/Dodge/Item/Weapon/BatteryGuns.hs index 89aeaafa9..f9977f143 100644 --- a/src/Dodge/Item/Weapon/BatteryGuns.hs +++ b/src/Dodge/Item/Weapon/BatteryGuns.hs @@ -35,7 +35,7 @@ teslaGun = defaultGun { _itName = "TESLA" , _itType = TESLAGUN , _itConsumption = defaultAmmo - { _ammoMax = 200 + { _ammoBaseMax = 200 , _ammoLoaded = 200 , _reloadTime = 80 } @@ -69,7 +69,7 @@ lasGun = defaultAutoGun { _itName = "LASGUN" , _itType = LASGUN , _itConsumption = defaultAmmo - { _ammoMax = 200 + { _ammoBaseMax = 200 , _ammoLoaded = 200 , _reloadTime = 80 } @@ -129,7 +129,7 @@ tractorGun = lasGun { _itName = "TRACTORGUN" , _itType = TRACTORGUN , _itConsumption = defaultAmmo - { _ammoMax = 10000 + { _ammoBaseMax = 10000 , _ammoLoaded = 10000 , _reloadTime = 40 } diff --git a/src/Dodge/Item/Weapon/Bezier.hs b/src/Dodge/Item/Weapon/Bezier.hs index 91c904a2a..1b4acee94 100644 --- a/src/Dodge/Item/Weapon/Bezier.hs +++ b/src/Dodge/Item/Weapon/Bezier.hs @@ -43,7 +43,7 @@ bezierGun = defaultGun , _itEffect = rbSetTarget -- , _itZoom = defaultItZoom , _itConsumption = defaultAmmo - { _ammoMax = 50 + { _ammoBaseMax = 50 } } diff --git a/src/Dodge/Item/Weapon/Booster.hs b/src/Dodge/Item/Weapon/Booster.hs index 528029745..dbbed18c1 100644 --- a/src/Dodge/Item/Weapon/Booster.hs +++ b/src/Dodge/Item/Weapon/Booster.hs @@ -115,7 +115,7 @@ boosterGun = defaultGun , _itType = BOOSTER , _itInvColor = cyan , _itConsumption = defaultAmmo - { _ammoMax = 100 + { _ammoBaseMax = 100 , _ammoLoaded = 100 , _reloadTime = 20 } diff --git a/src/Dodge/Item/Weapon/BulletGun/Cane.hs b/src/Dodge/Item/Weapon/BulletGun/Cane.hs index 5a3731058..291be0d7a 100644 --- a/src/Dodge/Item/Weapon/BulletGun/Cane.hs +++ b/src/Dodge/Item/Weapon/BulletGun/Cane.hs @@ -53,7 +53,7 @@ bangCane = defaultGun } , _itConsumption = defaultAmmo { _aoType = basicBullet - , _ammoMax = 1 + , _ammoBaseMax = 1 , _reloadTime = 20 , _reloadType = ActivePartial 1 } @@ -115,7 +115,7 @@ bangCaneX i = bangCane & itUse . useAim . aimRange .~ 1 & itUse . useAim . aimStance .~ TwoHandFlat & itUse . useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1.5} - & itConsumption . ammoMax .~ i + & itConsumption . ammoBaseMax .~ i & itParams . gunBarrels .~ MultiBarrel {_brlSpread = AlignedBarrels ,_brlNum = i @@ -145,21 +145,23 @@ rifle = bangCane , _dimSPic = \it -> noPic $ baseRifleShape <> makeSingleClipAt (V3 5 0 3) it } - , _itModules = ItemModules - { _modHitEffect = DefaultModule } } & itUse . useAim . aimStance .~ TwoHandTwist & itName .~ "RIFLE" & itType .~ RIFLE - & itConsumption . ammoMax .~ 1 + & itConsumption . ammoBaseMax .~ 1 repeater :: Item repeater = rifle + & itModules .~ ItemModules + { _modHitEffect = DefaultModule + , _modRifleMag = DefaultModule + } & itName .~ "REPEATER" & itType .~ REPEATER & itConsumption . reloadType .~ ActiveClear & itConsumption . reloadTime .~ 80 - & itConsumption . ammoMax .~ 15 + & itConsumption . ammoBaseMax .~ 15 & itDimension . dimSPic .~ (\it -> noPic $ baseRifleShape <> makeTinClipAt 0 (V3 10 (-2) 0) it ) @@ -216,6 +218,7 @@ completeBurstRifle :: Item completeBurstRifle = repeater & itName .~ "COMPLETEBURSTRIFLE" & itType .~ COMPLETEBURSTRIFLE + & itModules . modRifleMag .~ BlockedModule & itParams . gunBarrels . brlInaccuracy .~ 0.1 & itUse . useDelay . rateMax .~ 28 & itUse . useMods .~ @@ -263,7 +266,7 @@ miniGunX i = defaultAutoGun , _itType = MINIGUNX i , _itConsumption = defaultAmmo { _aoType = basicBullet - , _ammoMax = 1500 + , _ammoBaseMax = 1500 , _ammoLoaded = 1500 , _reloadTime = 200 } @@ -291,6 +294,7 @@ miniGunX i = defaultAutoGun ["*" ++ replicate 13 ' ' ++ "*" ,"* " ++ fromMaybe " " (maybeWarmupStatus it) ++ " *" ,"*" ++ replicate 13 ' ' ++ "*" ] + ++ moduleStrings it , _itDimension = ItemDimension { _dimRad = 20 , _dimCenter = V3 5 0 0 diff --git a/src/Dodge/Item/Weapon/BulletGun/Rod.hs b/src/Dodge/Item/Weapon/BulletGun/Rod.hs index fe30dab62..248c3580f 100644 --- a/src/Dodge/Item/Weapon/BulletGun/Rod.hs +++ b/src/Dodge/Item/Weapon/BulletGun/Rod.hs @@ -65,7 +65,7 @@ bangRod = defaultGun } , _itConsumption = defaultAmmo { _aoType = basicBullet - , _ammoMax = 1 + , _ammoBaseMax = 1 , _reloadTime = 20 , _reloadType = ActiveClear } @@ -101,7 +101,7 @@ amr :: Item amr = elephantGun & itName .~ "AMR" & itType .~ AMR - & itConsumption . ammoMax .~ 15 + & itConsumption . ammoBaseMax .~ 15 & itDimension . dimSPic .~ (\it -> noPic $ baseAMRShape <> makeTinClipAt 0 (V3 10 (-2) 0) it ) diff --git a/src/Dodge/Item/Weapon/BulletGun/Stick.hs b/src/Dodge/Item/Weapon/BulletGun/Stick.hs index ff8565874..c1666a807 100644 --- a/src/Dodge/Item/Weapon/BulletGun/Stick.hs +++ b/src/Dodge/Item/Weapon/BulletGun/Stick.hs @@ -48,7 +48,7 @@ bangStick i = defaultGun , _itType = BANGSTICK i , _itConsumption = defaultAmmo { _aoType = basicBullet - , _ammoMax = i + , _ammoBaseMax = i , _reloadTime = 15 , _reloadType = ActivePartial 1 } @@ -119,7 +119,7 @@ revolver = pistol , _itType = REVOLVER , _itConsumption = defaultAmmo { _aoType = basicBullet - , _ammoMax = 6 + , _ammoBaseMax = 6 , _ammoLoaded = 0 , _reloadTime = 15 , _reloadType = ActivePartial 1 @@ -174,7 +174,7 @@ pistol = (bangStick 1) , _itType = PISTOL , _itConsumption = defaultAmmo { _aoType = basicBullet - , _ammoMax = 15 + , _ammoBaseMax = 15 , _ammoLoaded = 0 , _reloadTime = 70 , _reloadType = ActiveClear @@ -233,4 +233,4 @@ revolverX i = revolver , torqueAfterI 0.2 , withRecoilI 10 ] - } & itConsumption . ammoMax .~ i * 6 + } & itConsumption . ammoBaseMax .~ i * 6 diff --git a/src/Dodge/Item/Weapon/BulletGuns.hs b/src/Dodge/Item/Weapon/BulletGuns.hs index b3e27a752..d4966aaa0 100644 --- a/src/Dodge/Item/Weapon/BulletGuns.hs +++ b/src/Dodge/Item/Weapon/BulletGuns.hs @@ -55,7 +55,7 @@ autoGun = defaultAutoGun , _itType = AUTOGUN , _itConsumption = defaultAmmo { _aoType = basicBullet - , _ammoMax = 30 + , _ammoBaseMax = 30 , _ammoLoaded = 30 , _reloadTime = 80 } @@ -109,7 +109,7 @@ bangCone = defaultGun , _itType = BANGCONE , _itConsumption = defaultAmmo { _aoType = basicBullet - , _ammoMax = 5 + , _ammoBaseMax = 5 , _reloadTime = 25 , _reloadType = ActiveClear } @@ -194,7 +194,7 @@ blunderbuss = bangCone <> upperPrismPoly 6 (rectNSEW 4 (-4) 30 20) } } - & itConsumption . ammoMax .~ 25 + & itConsumption . ammoBaseMax .~ 25 & itConsumption . reloadTime .~ 30 bigBlunderbuss :: Item bigBlunderbuss = blunderbuss @@ -218,7 +218,7 @@ bigBlunderbuss = blunderbuss & useAim . aimStance .~ TwoHandTwist & useAim . aimSpeed .~ 0.4 } - & itConsumption . ammoMax .~ 50 + & itConsumption . ammoBaseMax .~ 50 & itConsumption . reloadTime .~ 36 biggerBlunderbuss :: Item biggerBlunderbuss = bigBlunderbuss @@ -242,7 +242,7 @@ biggerBlunderbuss = bigBlunderbuss & useAim . aimStance .~ TwoHandTwist & useAim . aimSpeed .~ 0.4 } - & itConsumption . ammoMax .~ 75 + & itConsumption . ammoBaseMax .~ 75 & itConsumption . reloadTime .~ 43 biggestBlunderbuss :: Item biggestBlunderbuss = biggerBlunderbuss @@ -266,7 +266,7 @@ biggestBlunderbuss = biggerBlunderbuss & useAim . aimStance .~ TwoHandTwist & useAim . aimSpeed .~ 0.4 } - & itConsumption . ammoMax .~ 100 + & itConsumption . ammoBaseMax .~ 100 & itConsumption . reloadTime .~ 50 grapeShotCannon :: Item @@ -291,7 +291,7 @@ grapeShotCannon = blunderbuss & useAim . aimStance .~ TwoHandTwist & useAim . aimSpeed .~ 0.4 } - & itConsumption . ammoMax .~ 15 + & itConsumption . ammoBaseMax .~ 15 & itConsumption . reloadTime .~ 30 grenadeLauncher :: Int -> Item @@ -305,7 +305,7 @@ hvAutoGun = defaultAutoGun , _itType = HVAUTOGUN , _itConsumption = defaultAmmo { _aoType = hvBullet - , _ammoMax = 100 + , _ammoBaseMax = 100 , _ammoLoaded = 100 , _reloadTime = 200 } @@ -334,7 +334,7 @@ ltAutoGun = defaultAutoGun , _itType = LTAUTOGUN , _itConsumption = defaultAmmo { _aoType = basicBullet - , _ammoMax = 15 + , _ammoBaseMax = 15 , _ammoLoaded = 0 , _reloadTime = 90 } @@ -363,7 +363,7 @@ spreadGun = defaultGun , _itType = SPREADGUN , _itConsumption = defaultAmmo { _aoType = basicBullet - , _ammoMax = 5 + , _ammoBaseMax = 5 , _ammoLoaded = 5 , _reloadTime = 80 } @@ -396,7 +396,7 @@ multGun = defaultGun , _itType = MULTGUN , _itConsumption = defaultAmmo { _aoType = basicBullet - , _ammoMax = 5 + , _ammoBaseMax = 5 , _ammoLoaded = 2 , _reloadTime = 10 , _reloadType = ActivePartial 1 @@ -434,7 +434,7 @@ longGun = defaultGun , _itType = LONGGUN , _itConsumption = defaultAmmo { _aoType = hvBullet - , _ammoMax = 1 + , _ammoBaseMax = 1 , _ammoLoaded = 1 , _reloadTime = 100 , _reloadType = PassiveReload skwareFadeTwoSecS diff --git a/src/Dodge/Item/Weapon/Drone.hs b/src/Dodge/Item/Weapon/Drone.hs index 27c32ab48..930257af1 100644 --- a/src/Dodge/Item/Weapon/Drone.hs +++ b/src/Dodge/Item/Weapon/Drone.hs @@ -24,7 +24,7 @@ lasDrones = defaultGun , _itType = DRONELAUNCHER , _itConsumption = defaultAmmo { _aoType = DroneAmmo { _amString = "LASDRONE" } - , _ammoMax = 2 + , _ammoBaseMax = 2 , _ammoLoaded = 2 , _reloadTime = 80 } diff --git a/src/Dodge/Item/Weapon/InventoryDisplay.hs b/src/Dodge/Item/Weapon/InventoryDisplay.hs index 105c88e4a..3c22225e1 100644 --- a/src/Dodge/Item/Weapon/InventoryDisplay.hs +++ b/src/Dodge/Item/Weapon/InventoryDisplay.hs @@ -5,6 +5,7 @@ module Dodge.Item.Weapon.InventoryDisplay ( basicItemDisplay , maybeWarmupStatus , maybeRateStatus + , moduleStrings ) where import Dodge.Data import Padding @@ -17,9 +18,8 @@ import Control.Lens basicItemDisplay :: Item -> [String] basicItemDisplay it = Prelude.take (itSlotsTaken it) $ (midPadL 15 ' ' thename (' ' : thenumber) ++ theparam) - : moduleStrings ++ repeat "*" + : moduleStrings it ++ repeat "*" where - moduleStrings = fromMaybe [] $ it ^? itModules . modHitEffect . modName thename = _itName it thenumber = case it ^? itConsumption of Just am@LoadableAmmo{} -> case _reloadState am of @@ -37,6 +37,11 @@ basicItemDisplay it = Prelude.take (itSlotsTaken it) $ -- , maybeRateStatus ] +moduleStrings :: Item -> [String] +moduleStrings it = map (" " ++) + $ (fromMaybe [] $ it ^? itModules . modHitEffect . modName) + ++ (fromMaybe [] $ it ^? itModules . modRifleMag . modName) + maybeModeStatus :: Item -> Maybe String maybeModeStatus it = case it ^? itAttachment of Just ItCharMode {_itCharMode = (c :<| _)} -> Just [' ',c] diff --git a/src/Dodge/Item/Weapon/Launcher.hs b/src/Dodge/Item/Weapon/Launcher.hs index 0497ba1a1..d23b83488 100644 --- a/src/Dodge/Item/Weapon/Launcher.hs +++ b/src/Dodge/Item/Weapon/Launcher.hs @@ -44,7 +44,7 @@ launcher = defaultGun , _amString = "EXPLOSIVE SHELL" , _amPjDraw = shellPic } - , _ammoMax = 30 + , _ammoBaseMax = 30 , _ammoLoaded = 30 , _reloadTime = 80 } @@ -271,7 +271,7 @@ remoteLauncher = launcher , _amString = "" , _amPjDraw = shellPic } - , _ammoMax = 30 + , _ammoBaseMax = 30 , _ammoLoaded = 30 , _reloadTime = 80 } diff --git a/src/Dodge/Item/Weapon/Radar.hs b/src/Dodge/Item/Weapon/Radar.hs index 6fd17cd8e..1269e6864 100644 --- a/src/Dodge/Item/Weapon/Radar.hs +++ b/src/Dodge/Item/Weapon/Radar.hs @@ -22,7 +22,7 @@ radar = defaultGun { _itName = "RADAR" , _itType = RADAR , _itConsumption = defaultAmmo - { _ammoMax = 100 + { _ammoBaseMax = 100 , _ammoLoaded = 100 , _reloadTime = 200 } @@ -41,7 +41,7 @@ sonar = defaultGun { _itName = "SONAR" , _itType = RADAR , _itConsumption = defaultAmmo - { _ammoMax = 100 + { _ammoBaseMax = 100 , _ammoLoaded = 100 , _reloadTime = 200 } diff --git a/src/Dodge/Item/Weapon/SonicGuns.hs b/src/Dodge/Item/Weapon/SonicGuns.hs index d4326613e..b69957899 100644 --- a/src/Dodge/Item/Weapon/SonicGuns.hs +++ b/src/Dodge/Item/Weapon/SonicGuns.hs @@ -33,7 +33,7 @@ sonicGun = defaultAutoGun { _itName = "SONICGUN" , _itType = SONICGUN , _itConsumption = defaultAmmo - { _ammoMax = 10 + { _ammoBaseMax = 10 , _ammoLoaded = 10 , _reloadTime = 80 } diff --git a/src/Dodge/Item/Weapon/Spawn.hs b/src/Dodge/Item/Weapon/Spawn.hs index 9e0633e61..7ba635d27 100644 --- a/src/Dodge/Item/Weapon/Spawn.hs +++ b/src/Dodge/Item/Weapon/Spawn.hs @@ -18,7 +18,7 @@ spawnGun :: Creature -> Item spawnGun cr = defaultGun { _itName = "SPAWNER" , _itConsumption = defaultAmmo - { _ammoMax = 1 + { _ammoBaseMax = 1 , _ammoLoaded = 1 , _reloadTime = 80 } diff --git a/src/Dodge/Item/Weapon/SprayGuns.hs b/src/Dodge/Item/Weapon/SprayGuns.hs index 6743fb7db..1024730eb 100644 --- a/src/Dodge/Item/Weapon/SprayGuns.hs +++ b/src/Dodge/Item/Weapon/SprayGuns.hs @@ -38,7 +38,7 @@ poisonSprayer = defaultAutoGun { _itName = "POISON" , _itType = SPRAYER , _itConsumption = defaultAmmo - { _ammoMax = 500 + { _ammoBaseMax = 500 , _ammoLoaded = 500 , _reloadTime = 100 } @@ -92,7 +92,7 @@ flamer = defaultAutoGun { _itName = "FLAMER" , _itType = SQUIRTER , _itConsumption = defaultAmmo - { _ammoMax = 250 + { _ammoBaseMax = 250 , _ammoLoaded = 250 , _reloadTime = 100 } diff --git a/src/Dodge/Item/Weapon/Utility.hs b/src/Dodge/Item/Weapon/Utility.hs index 91f50123a..6c78edafe 100644 --- a/src/Dodge/Item/Weapon/Utility.hs +++ b/src/Dodge/Item/Weapon/Utility.hs @@ -60,7 +60,7 @@ shrinkGun = defaultGun { _itName = "SHRINKER" , _itType = SHRINKER , _itConsumption = defaultAmmo - { _ammoMax = 100 + { _ammoBaseMax = 100 , _ammoLoaded = 100 , _reloadTime = 20 } @@ -91,7 +91,7 @@ blinkGun = defaultGun , _itType = BLINKER , _itInvColor = cyan , _itConsumption = defaultAmmo - { _ammoMax = 100 + { _ammoBaseMax = 100 , _ammoLoaded = 100 , _reloadTime = 20 } @@ -123,7 +123,7 @@ forceFieldGun = defaultGun { _itName = "FORCEFIELD" , _itType = FORCEFIELD , _itConsumption = defaultAmmo - { _ammoMax = 100 + { _ammoBaseMax = 100 , _ammoLoaded = 100 , _reloadTime = 40 , _reloadState = Nothing' diff --git a/src/Dodge/Module.hs b/src/Dodge/Module.hs index 751a935cd..38a172a79 100644 --- a/src/Dodge/Module.hs +++ b/src/Dodge/Module.hs @@ -6,4 +6,5 @@ import Control.Lens import Data.Maybe moduleSizes :: Item -> Int -moduleSizes it = fromMaybe 0 $ it ^? itModules . modHitEffect . modSize +moduleSizes it = (fromMaybe 0 $ it ^? itModules . modHitEffect . modSize) + + (fromMaybe 0 $ it ^? itModules . modRifleMag . modSize) diff --git a/src/Dodge/Reloading.hs b/src/Dodge/Reloading.hs index 2c05d5fc9..d36672e07 100644 --- a/src/Dodge/Reloading.hs +++ b/src/Dodge/Reloading.hs @@ -1,21 +1,25 @@ module Dodge.Reloading where import Dodge.Data import Dodge.Base +import Dodge.Item.MaxAmmo --import qualified Data.IntMap.Strict as IM -import Data.Maybe +--import Data.Maybe import Control.Lens + startReloadingWeapon :: Creature -> World -> Maybe World -startReloadingWeapon cr = (creatures . ix (_crID cr) . crInv . ix (_crInvSel cr) . itConsumption) +startReloadingWeapon cr = (creatures . ix (_crID cr) . crInv . ix (_crInvSel cr)) icTryStartReloading -icTryStartReloading :: ItemConsumption -> Maybe ItemConsumption -icTryStartReloading am - | _ammoLoaded am < _ammoMax am && _reloadState am == Nothing' - = Just $ am & reloadState .~ Just' (_reloadTime am) - & if _reloadType am == ActiveClear then ammoLoaded .~ 0 else id +icTryStartReloading :: Item -> Maybe Item +icTryStartReloading it + | _ammoLoaded am < itMaxAmmo it && _reloadState am == Nothing' + = Just $ it & itConsumption . reloadState .~ Just' (_reloadTime am) + & if _reloadType am == ActiveClear then itConsumption . ammoLoaded .~ 0 else id | otherwise = Nothing + where + am = _itConsumption it crStopReloading :: Creature -> Creature crStopReloading cr = cr & crInv . ix (_crInvSel cr) . itConsumption . reloadState .~ Nothing' @@ -25,29 +29,31 @@ crUpCrUp f cr = creatures . ix (_crID cr) %~ f stepReloading :: Creature -> Creature stepReloading cr = case cr ^? crInv . ix isel . itConsumption . reloadState . _Just' of - Just 0 -> cr & crInv . ix isel . itConsumption %~ doload + Just 0 -> cr & crInv . ix isel %~ doload Just _ -> cr & crInv . ix isel . itConsumption . reloadState . _Just' %~ decreaseToZero Nothing -> cr where isel = _crInvSel cr - doload itcon = case _reloadType itcon of + doload it = case _reloadType itcon of ActivePartial x - | x + _ammoLoaded itcon < _ammoMax itcon -> itcon & ammoLoaded %~ (+ x) - & reloadState .~ Just' (_reloadTime itcon) - | otherwise -> itcon & ammoLoaded .~ _ammoMax itcon - & reloadState .~ Nothing' - _ -> itcon & ammoLoaded .~ _ammoMax itcon - & reloadState .~ Nothing' + | x + _ammoLoaded itcon < itMaxAmmo it -> it & itConsumption . ammoLoaded %~ (+ x) + & itConsumption . reloadState .~ Just' (_reloadTime itcon) + | otherwise -> it & itConsumption . ammoLoaded .~ itMaxAmmo it + & itConsumption . reloadState .~ Nothing' + _ -> it & itConsumption . ammoLoaded .~ itMaxAmmo it + & itConsumption . reloadState .~ Nothing' + where + itcon = _itConsumption it -{- | Start reloading if clip is empty. -} -crAutoReload :: Creature -> Creature -crAutoReload cr = case cr ^? ptrItConsumption' . ammoLoaded of - Just 0 | _posture (_crStance cr) /= Aiming - -> cr & ptrItConsumption . reloadState .~ strictify reloadT - & ptrItConsumption . ammoLoaded %~ (`fromMaybe` maxA) - _ -> cr - where - ptrItConsumption = crInv . ix (_crInvSel cr) . itConsumption - ptrItConsumption' = crInv . ix (_crInvSel cr) . itConsumption - reloadT = cr ^? ptrItConsumption' . reloadTime - maxA = cr ^? ptrItConsumption' . ammoMax +--{- | Start reloading if clip is empty. -} +--crAutoReload :: Creature -> Creature +--crAutoReload cr = case cr ^? ptrItConsumption' . ammoLoaded of +-- Just 0 | _posture (_crStance cr) /= Aiming +-- -> cr & ptrItConsumption . reloadState .~ strictify reloadT +-- & ptrItConsumption . ammoLoaded %~ (`fromMaybe` maxA) +-- _ -> cr +-- where +-- ptrItConsumption = crInv . ix (_crInvSel cr) . itConsumption +-- ptrItConsumption' = crInv . ix (_crInvSel cr) . itConsumption +-- reloadT = cr ^? ptrItConsumption' . reloadTime +-- maxA = fmap itMaxAmmo $ cr ^? crInv . ix (_crInvSel cr)