Commit before changing module system to Map

This commit is contained in:
2022-02-21 07:50:15 +00:00
parent 779e076c93
commit 724ee21afc
25 changed files with 171 additions and 86 deletions
+5 -4
View File
@@ -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
+34 -2
View File
@@ -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)
]
+1
View File
@@ -94,6 +94,7 @@ data CombineType
| FUELCELL
| PORTABLEFUSION
-- Modules
-- bullet
| INCENDIARYMODULE
| BOUNCEMODULE
| NoCombineType
+8 -1
View File
@@ -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
+8 -2
View File
@@ -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')
+6 -2
View File
@@ -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
+12
View File
@@ -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
+9 -3
View File
@@ -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
+3 -3
View File
@@ -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
}
+1 -1
View File
@@ -43,7 +43,7 @@ bezierGun = defaultGun
, _itEffect = rbSetTarget
-- , _itZoom = defaultItZoom
, _itConsumption = defaultAmmo
{ _ammoMax = 50
{ _ammoBaseMax = 50
}
}
+1 -1
View File
@@ -115,7 +115,7 @@ boosterGun = defaultGun
, _itType = BOOSTER
, _itInvColor = cyan
, _itConsumption = defaultAmmo
{ _ammoMax = 100
{ _ammoBaseMax = 100
, _ammoLoaded = 100
, _reloadTime = 20
}
+11 -7
View File
@@ -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
+2 -2
View File
@@ -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
)
+4 -4
View File
@@ -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
+12 -12
View File
@@ -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
+1 -1
View File
@@ -24,7 +24,7 @@ lasDrones = defaultGun
, _itType = DRONELAUNCHER
, _itConsumption = defaultAmmo
{ _aoType = DroneAmmo { _amString = "LASDRONE" }
, _ammoMax = 2
, _ammoBaseMax = 2
, _ammoLoaded = 2
, _reloadTime = 80
}
+7 -2
View File
@@ -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]
+2 -2
View File
@@ -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
}
+2 -2
View File
@@ -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
}
+1 -1
View File
@@ -33,7 +33,7 @@ sonicGun = defaultAutoGun
{ _itName = "SONICGUN"
, _itType = SONICGUN
, _itConsumption = defaultAmmo
{ _ammoMax = 10
{ _ammoBaseMax = 10
, _ammoLoaded = 10
, _reloadTime = 80
}
+1 -1
View File
@@ -18,7 +18,7 @@ spawnGun :: Creature -> Item
spawnGun cr = defaultGun
{ _itName = "SPAWNER"
, _itConsumption = defaultAmmo
{ _ammoMax = 1
{ _ammoBaseMax = 1
, _ammoLoaded = 1
, _reloadTime = 80
}
+2 -2
View File
@@ -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
}
+3 -3
View File
@@ -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'
+2 -1
View File
@@ -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)
+33 -27
View File
@@ -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)