Make ammo magazines into own item type

This commit is contained in:
2024-06-22 12:03:32 +01:00
parent 35a56eef56
commit 8e127f0603
17 changed files with 258 additions and 255 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ updateBulVel bt = case _buTrajectory bt of
shootBullet :: Item -> Creature -> World -> World
shootBullet it cr w = fromMaybe (error "cannot find bullet ammo when expected to") $ do
invid <- it ^? itLocation . ipInvID
thebullet <- cr ^? crInv . ix (invid + 1) . itUse . attachParams . ammoParams . ampBullet
thebullet <- cr ^? crInv . ix (invid + 1) . itUse . amagParams . ampBullet
return $ w & cWorld . lWorld . instantBullets
.:~ ( thebullet
& buPos .~ _crPos cr
+8 -8
View File
@@ -12,19 +12,19 @@ moduleModification imt = case imt of
EMPTYMODULE -> id
-- BELTMAG -> itUse . heldConsumption . laSource . _InternalSource . iaMax .~ 150
MAGNETMAG -> itUse . heldDelay . rateMax .~ 4
BULPAY BulFlak -> (itUse . attachParams . ammoParams . ampBullet . buSpawn .~ BulFlak)
. (itUse . attachParams . ammoParams . ampBullet . buTimer .~ 3)
BULPAY thepayload -> itUse . attachParams . ammoParams . ampBullet . buSpawn .~ thepayload
BULBODY thebody -> itUse . attachParams . ammoParams . ampBullet . buEffect .~ thebody
BULPAY BulFlak -> (itUse . amagParams . ampBullet . buSpawn .~ BulFlak)
. (itUse . amagParams . ampBullet . buTimer .~ 3)
BULPAY thepayload -> itUse . amagParams . ampBullet . buSpawn .~ thepayload
BULBODY thebody -> itUse . amagParams . ampBullet . buEffect .~ thebody
TARGET {} -> id -- itUse . useTargeting ?~ t
BULTRAJ BasicBulletTrajectoryType -> id
BULTRAJ MagnetTrajectoryType ->
(itUse . attachParams . ammoParams . ampBullet . buTrajectory .~ MagnetTrajectory 0)
. (itUse . attachParams . ammoParams . ampBullet . buVel .~ V2 10 0)
(itUse . amagParams . ampBullet . buTrajectory .~ MagnetTrajectory 0)
. (itUse . amagParams . ampBullet . buVel .~ V2 10 0)
BULTRAJ FlechetteTrajectoryType ->
itUse . attachParams . ammoParams . ampBullet . buTrajectory .~ FlechetteTrajectory 0
itUse . amagParams . ampBullet . buTrajectory .~ FlechetteTrajectory 0
BULTRAJ BezierTrajectoryType ->
itUse . attachParams . ammoParams . ampBullet . buTrajectory .~ BezierTrajectory 0 0 0
itUse . amagParams . ampBullet . buTrajectory .~ BezierTrajectory 0 0 0
INCENDLAS -> itParams . lasBeam .~ BeamCombine FlameBeamCombine
SPLITLAS -> itParams . lasBeam .~ BeamCombine SplitBeamCombine
STATICLAS ->
+1
View File
@@ -43,6 +43,7 @@ itemEffect cr it w = case it ^. itUse of
(ConsumeUse eff _) -> useC eff it cr $ rmInvItem (_crID cr) itRef w
CraftUse{} -> w
AttachUse{} -> w
AmmoMagUse{} -> w
where
itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
hammerTest f = case _crHammerPosition cr of
+1 -1
View File
@@ -174,7 +174,7 @@ reloadOverride :: Creature -> Creature
reloadOverride cr = fromMaybe cr $ do
guard $ cr ^. crStance . posture == Aiming
itRef <- cr ^? crManipulation . manObject . inInventory . ispItem
guard $ cr ^? crInv . ix (itRef + 1) . itUse . attachParams . ammoLoadStatus . iaLoaded == Just 0
guard $ cr ^? crInv . ix (itRef + 1) . itUse . amagLoadStatus . iaLoaded == Just 0
return $ cr & crActionPlan . apStrategy .~ StrategyActions Reload reloadActions
where
reloadActions =
+1 -1
View File
@@ -42,7 +42,7 @@ crIsReloading cr = case cr ^? crManipulation . manObject . inInventory . iselAct
crWeaponReady :: Creature -> Bool
crWeaponReady cr = fromMaybe False $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
x <- cr ^? crInv . ix (i + 1) . itUse . attachParams . ammoLoadStatus . iaLoaded
x <- cr ^? crInv . ix (i + 1) . itUse . amagLoadStatus . iaLoaded
return (x > 0)
crCanSeeCr :: Creature -> (World, Creature) -> Bool
+4 -4
View File
@@ -90,13 +90,13 @@ data ItemBaseType
| CONSUMABLE {_ibtConsumable :: ConsumableItemType}
| CRAFT CraftType
| ATTACH {_ibtAttach :: AttachType}
| AMMOMAG {_ibtAmmoMag :: AmmoMagType}
deriving (Eq, Ord, Show, Read)
--deriving (Eq, Ord, Show, Read) --Generic, Flat)
data AttachType
= SCROLLATTACH ScrollAttachType
| AMMOATTACH AmmoAttachType
| TARGETATTACH {_ibtAttachTarget :: TargetType}
-- | BULPAYLOADATTACH
-- | BULTRAJECTORYATTACH
@@ -106,11 +106,11 @@ data ScrollAttachType
= ZOOMSCOPE
deriving (Eq, Ord, Show, Read)
data AmmoAttachType
data AmmoMagType
= REVOLVEMAG
| TINMAG
| DRUMMAG
| BULLETBELT
| BELTMAG
| SHELLMAG
deriving (Eq, Ord, Show, Read)
@@ -246,7 +246,7 @@ makeLenses ''AttachType
deriveJSON defaultOptions ''Stack
deriveJSON defaultOptions ''CraftType
deriveJSON defaultOptions ''ConsumableItemType
deriveJSON defaultOptions ''AmmoAttachType
deriveJSON defaultOptions ''AmmoMagType
deriveJSON defaultOptions ''ScrollAttachType
deriveJSON defaultOptions ''AttachType
deriveJSON defaultOptions ''Detector
+3 -4
View File
@@ -55,6 +55,9 @@ data ItemUse
{_useAmount :: ItAmount}
| AttachUse
{_attachParams :: AttachParams}
| AmmoMagUse
{ _amagLoadStatus :: InternalAmmo
, _amagParams :: AmmoParams }
--deriving (Eq, Show, Read) --Generic, Flat)
data HeldParams
@@ -69,10 +72,6 @@ data HeldParams
data AttachParams
= ScrollAttachParams {_scrollAttachParams :: ScrollAttachParams}
| AmmoAttachParams
{_ammoLoadStatus :: InternalAmmo
,_ammoParams :: AmmoParams
}
| TargetAttachParams
data AmmoParams = BulletParams {_ampBullet :: Bullet}
+1 -1
View File
@@ -372,7 +372,7 @@ useMod hm = case hm of
invid <- cr ^? crManipulation . manObject . inInventory . ispItem
return $ cr & crDir %~ tweenAngles x (_crOldDir cr)
& crPos %~ alongSegBy x (_crOldPos cr)
& crInv . ix (invid + 1) . itUse . attachParams . ammoParams . ampBullet . buDelayFraction .~ x
& crInv . ix (invid + 1) . itUse . amagParams . ampBullet . buDelayFraction .~ x
lasWideRate :: Int
lasWideRate = 2
+9 -4
View File
@@ -24,14 +24,19 @@ itemFromBase ibt = case ibt of
CONSUMABLE et -> itemFromConsumableType et
CRAFT cr -> makeTypeCraft cr
ATTACH at -> itemFromAttachType at
AMMOMAG t -> itemFromAmmoMag t
itemFromAmmoMag :: AmmoMagType -> Item
itemFromAmmoMag at = case at of
DRUMMAG -> drumMag
TINMAG -> tinMag
REVOLVEMAG -> revolveMag
BELTMAG -> beltMag
SHELLMAG -> shellMag
itemFromAttachType :: AttachType -> Item
itemFromAttachType at = case at of
SCROLLATTACH ZOOMSCOPE -> zoomScope
AMMOATTACH DRUMMAG -> drumMag
AMMOATTACH TINMAG -> tinMag
AMMOATTACH REVOLVEMAG -> revolveMag
AMMOATTACH BULLETBELT -> beltMag
TARGETATTACH tt -> targetingScope tt
+33 -37
View File
@@ -1,65 +1,61 @@
module Dodge.Item.Ammo where
import Dodge.Item.Weapon.Bullet
import Control.Lens
import Dodge.Data.World
import Dodge.Default.Item
import Dodge.Item.Weapon.Bullet
import Dodge.Reloading.Action
tinMag :: Item
tinMag =
defaultHeldItem & itType . iyBase .~ ATTACH (AMMOATTACH TINMAG)
defaultHeldItem & itType . iyBase .~ AMMOMAG TINMAG
& itType . iyModules . at ModBulletPayload ?~ EMPTYMODULE
& itType . iyModules . at ModBulletTrajectory ?~ EMPTYMODULE
& itUse
.~ AttachUse
{ _attachParams =
AmmoAttachParams
{ _ammoParams = BulletParams defaultBullet
, _ammoLoadStatus =
InternalAmmo
{ _iaMax = 15
, _iaLoaded = 15
, _iaPrimed = True
, _iaCycle = [loadEject 10, loadInsert 10, loadPrime 10]
, _iaProgress = Nothing
}
.~ AmmoMagUse
{ _amagParams = BulletParams defaultBullet
, _amagLoadStatus =
InternalAmmo
{ _iaMax = 15
, _iaLoaded = 15
, _iaPrimed = True
, _iaCycle = [loadEject 10, loadInsert 10, loadPrime 10]
, _iaProgress = Nothing
}
}
revolveMag :: Item
revolveMag = tinMag
& itType . iyBase .~ ATTACH (AMMOATTACH REVOLVEMAG)
& itUse . attachParams . ammoLoadStatus . iaMax .~ 6
& itUse . attachParams . ammoLoadStatus . iaLoaded .~ 6
& itUse . attachParams . ammoLoadStatus . iaCycle .~ [loadPartialInsert 10 1]
revolveMag =
tinMag
& itType . iyBase .~ AMMOMAG REVOLVEMAG
& itUse . amagLoadStatus . iaMax .~ 6
& itUse . amagLoadStatus . iaLoaded .~ 6
& itUse . amagLoadStatus . iaCycle .~ [loadPartialInsert 10 1]
drumMag :: Item
drumMag =
tinMag & itType . iyBase .~ ATTACH (AMMOATTACH DRUMMAG)
& itUse . attachParams . ammoLoadStatus . iaMax .~ 30
tinMag & itType . iyBase . ibtAmmoMag .~ DRUMMAG
& itUse . amagLoadStatus . iaLoaded .~ 30
& itUse . amagLoadStatus . iaMax .~ 30
beltMag :: Item
beltMag =
tinMag & itType . iyBase .~ ATTACH (AMMOATTACH BULLETBELT)
& itUse . attachParams . ammoLoadStatus . iaMax .~ 2000
tinMag & itType . iyBase . ibtAmmoMag .~ BELTMAG
& itUse . amagLoadStatus . iaLoaded .~ 10000
& itUse . amagLoadStatus . iaMax .~ 20000
shellMag :: Item
shellMag =
defaultHeldItem & itType . iyBase .~ ATTACH (AMMOATTACH SHELLMAG)
defaultHeldItem & itType . iyBase .~ AMMOMAG SHELLMAG
& itUse
.~ AttachUse
{ _attachParams =
AmmoAttachParams
{ _ammoParams = BulletParams defaultBullet
, _ammoLoadStatus =
InternalAmmo
{ _iaMax = 15
, _iaLoaded = 15
, _iaPrimed = True
, _iaCycle = [loadEject 10, loadInsert 10, loadPrime 10]
, _iaProgress = Nothing
}
.~ AmmoMagUse
{ _amagParams = BulletParams defaultBullet
, _amagLoadStatus =
InternalAmmo
{ _iaMax = 15
, _iaLoaded = 15
, _iaPrimed = True
, _iaCycle = [loadEject 10, loadInsert 10, loadPrime 10]
, _iaProgress = Nothing
}
}
+3 -2
View File
@@ -82,11 +82,11 @@ itemBaseName it = case _iyBase $ _itType it of
EQUIP eit -> showEquipItem eit
CONSUMABLE cit -> show cit
ATTACH ait -> showAttachItem ait
AMMOMAG ait -> show ait
showAttachItem :: AttachType -> String
showAttachItem t = case t of
SCROLLATTACH x -> show x
AMMOATTACH x -> show x
TARGETATTACH x -> show x
showEquipItem :: EquipItemType -> String
@@ -124,6 +124,7 @@ itemNumberDisplay cr itm = case iu of
CraftUse x -> [show $ x ^. getItAmount]
ConsumeUse {_useAmount = x} -> [show $ x ^. getItAmount]
AttachUse {} -> [showReloadProgress cr itm]
AmmoMagUse {} -> [showReloadProgress cr itm]
-- this could be cleaner here...
where
iu = itm ^?! itUse
@@ -153,7 +154,7 @@ showEquipmentNumber _ itm = case _eeUse ee of
showReloadProgress :: Creature -> Item -> String
showReloadProgress _ itm = fromMaybe [] $ do
ia <- itm ^? itUse . attachParams . ammoLoadStatus
ia <- itm ^? itUse . amagLoadStatus
return $ case ia ^? iaProgress . _Just . ix 0 of
Nothing -> maybe "" show $ ia ^? iaLoaded
Just la -> showLoadActionType la ia
+1
View File
@@ -24,6 +24,7 @@ itemSPic it =
EQUIP et -> equipItemSPic et it
CONSUMABLE{} -> defSPic
ATTACH {} -> defSPic
AMMOMAG {} -> defSPic
equipItemSPic :: EquipItemType -> Item -> SPic
equipItemSPic et _ = case et of
+1
View File
@@ -12,3 +12,4 @@ itemInvColor itm = case itm ^. itType . iyBase of
CONSUMABLE {} -> blue
CRAFT {} -> green
ATTACH {} -> orange
AMMOMAG {} -> greyN 0.5
+6 -6
View File
@@ -143,7 +143,7 @@ withThickSmokeI eff item cr w =
ammoCheckI :: ChainEffect
ammoCheckI eff itm cr w = fromMaybe (failsound w) $ do
invid <- itm ^? itLocation . ipInvID
x <- cr ^? crInv . ix (invid + 1) . itUse . attachParams . ammoLoadStatus . iaLoaded
x <- cr ^? crInv . ix (invid + 1) . itUse . amagLoadStatus . iaLoaded
guard $ x > 0
return $ eff itm cr $ w & cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading
where
@@ -341,13 +341,13 @@ useAllAmmo eff item cr = fromMaybe id $ do
invid <- item ^? itLocation . ipInvID
return $ eff item cr
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix (invid + 1)
. itUse . attachParams . ammoLoadStatus . iaLoaded .~ 0)
. itUse . amagLoadStatus . iaLoaded .~ 0)
useAmmoUpTo :: Int -> ChainEffect
useAmmoUpTo amAmount eff itm cr = fromMaybe id $ do
invid <- itm ^? itLocation . ipInvID
return $ eff itm cr
. ( cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix (invid + 1) . itUse . attachParams . ammoLoadStatus . iaLoaded
. ( cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix (invid + 1) . itUse . amagLoadStatus . iaLoaded
%~ (max 0 . subtract amAmount)
)
@@ -359,7 +359,7 @@ useAmmoAmount amAmount eff item cr =
itref = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change
useAmmoAmount' :: Int -> Int -> IM.IntMap Item -> IM.IntMap Item
useAmmoAmount' itref x inv = inv & ix (itref + 1) . itUse . attachParams . ammoLoadStatus . iaLoaded -~ x
useAmmoAmount' itref x inv = inv & ix (itref + 1) . itUse . amagLoadStatus . iaLoaded -~ x
-- . crInv . ix itRef . itUse . heldConsumption . laSource
@@ -665,7 +665,7 @@ duplicateLoaded eff it cr w = foldr f w (take numbul [1::Int .. ])
f _ = eff it cr
numbul = fromMaybe 0 $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
cr ^? crInv . ix (i+1) . itUse . attachParams . ammoLoadStatus . iaLoaded
cr ^? crInv . ix (i+1) . itUse . amagLoadStatus . iaLoaded
duplicateNumBarrels :: Int -> ChainEffect
duplicateNumBarrels n eff itm cr w = foldr f w (take n $ itm ^?! itUse . heldAim . aimMuzzles)
@@ -687,7 +687,7 @@ duplicateLoadedBarrels eff itm cr = duplicateNumBarrels numbul eff itm cr
numbul :: Int
numbul = fromMaybe 0 $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
cr ^? crInv . ix (i+1) . itUse . attachParams . ammoLoadStatus . iaLoaded
cr ^? crInv . ix (i+1) . itUse . amagLoadStatus . iaLoaded
duplicateOffsetsFocus :: [Float] -> ChainEffect
duplicateOffsetsFocus xs eff item cr w = foldr f w poss
+6 -6
View File
@@ -17,7 +17,7 @@ crCancelReloading cr =
updateProgress = fromMaybe id $ do
InInventory (SelItem i _) <- cr ^? crManipulation . manObject
return $
crInv . ix (i + 1) . itUse . attachParams . ammoLoadStatus . iaProgress
crInv . ix (i + 1) . itUse . amagLoadStatus . iaProgress
%~ const Nothing
stepReloading :: Creature -> Creature
@@ -27,14 +27,14 @@ stepReloading cr = case cr ^? crManipulation . manObject . inInventory of
cr & crManipulation . manObject . inInventory . iselAction . actionProgress -~ 1
| otherwise ->
cr
& crInv . ix (i + 1) . itUse . attachParams . ammoLoadStatus %~ doLoadAction la
& crInv . ix (i + 1) . itUse . attachParams . ammoLoadStatus %~ rotateActionProgress
& crInv . ix (i + 1) . itUse . amagLoadStatus %~ doLoadAction la
& crInv . ix (i + 1) . itUse . amagLoadStatus %~ rotateActionProgress
& tryNextLoadAction
_ -> cr
tryNextLoadAction :: Creature -> Creature
tryNextLoadAction cr = case cr ^? crManipulation . manObject . inInventory of
Just (SelItem i _) -> case cr ^? crInv . ix (i + 1) . itUse . attachParams . ammoLoadStatus . iaProgress . _Just . ix 0 of
Just (SelItem i _) -> case cr ^? crInv . ix (i + 1) . itUse . amagLoadStatus . iaProgress . _Just . ix 0 of
Nothing -> cr & crManipulation . manObject . inInventory . iselAction .~ NoInvSelAction
Just la ->
cr & crManipulation . manObject . inInventory . iselAction . actionProgress .~ _actionTime la
@@ -49,7 +49,7 @@ crReload cr = case cr ^? crManipulation . manObject . inInventory . iselAction o
tryStartLoading :: Creature -> Creature
tryStartLoading cr = fromMaybe cr $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
ia <- cr ^? crInv . ix (i + 1) . itUse . attachParams . ammoLoadStatus
ia <- cr ^? crInv . ix (i + 1) . itUse . amagLoadStatus
return $ startLoading ia cr
-- case as of
@@ -66,7 +66,7 @@ startLoading ic cr = case ic ^? iaProgress . _Just . ix 0 of
i <- cr ^? crManipulation . manObject . inInventory . ispItem
return $
cr & startLoadingStep la
& crInv . ix i . itUse . attachParams . ammoLoadStatus . iaProgress ?~ (la : las)
& crInv . ix i . itUse . amagLoadStatus . iaProgress ?~ (la : las)
startLoadingStep :: LoadAction -> Creature -> Creature
startLoadingStep la cr = cr & crManipulation . manObject . inInventory . iselAction .~ ReloadAction (_actionTime la) la