Make ammo magazines into own item type
This commit is contained in:
+33
-37
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -12,3 +12,4 @@ itemInvColor itm = case itm ^. itType . iyBase of
|
||||
CONSUMABLE {} -> blue
|
||||
CRAFT {} -> green
|
||||
ATTACH {} -> orange
|
||||
AMMOMAG {} -> greyN 0.5
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user