From 91f11e43c83f5bd810800e044d609728d2c796d4 Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 8 Jan 2025 16:18:44 +0000 Subject: [PATCH] Handle warmdown of minigun with inventory effect --- src/Dodge/Creature/State.hs | 28 +++++++++++++--------------- src/Dodge/Data/Item/Effect.hs | 2 ++ src/Dodge/ItEffect.hs | 4 ++++ src/Dodge/Item/Held/Cane.hs | 2 ++ 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/Dodge/Creature/State.hs b/src/Dodge/Creature/State.hs index 04c9aca79..5c2b57962 100644 --- a/src/Dodge/Creature/State.hs +++ b/src/Dodge/Creature/State.hs @@ -3,8 +3,6 @@ module Dodge.Creature.State ( doDamage, ) where ---import Dodge.Inventory.SelectionList ---import Dodge.Item.Location import Control.Applicative import Dodge.HeldUse import Control.Monad @@ -69,7 +67,7 @@ crUpdate f = , internalCreatureUpdate , f , footstepSideEffect - , updateInv -- upInv must be called before invSideEff 22.05.23 +-- , updateInv -- upInv must be called before invSideEff 22.05.23 , invRootItemEffs , invSideEff -- , equipmentEffects @@ -106,26 +104,25 @@ checkDeath cr w -- hack to get around player creature being killed but left with more than 0 hp | otherwise = cWorld . lWorld . creatures . at (_crID cr) .~ Nothing +-- could look at the amount of damage here (given by maxDamage) too corpseOrGib :: Creature -> World -> World -corpseOrGib cr = case maxDamageType (_csDamage (_crState cr)) of - Just (FLAMING, _) -> plNew (cWorld . lWorld . corpses) cpID (thecorpse & cpSPic %~ scorchSPic) - Just (ELECTRICAL, _) -> plNew (cWorld . lWorld . corpses) cpID thecorpse - Just (POISONDAM, _) -> plNew (cWorld . lWorld . corpses) cpID (thecorpse & cpSPic %~ poisonSPic) +corpseOrGib cr = case cr ^? crState . csDamage . to maxDamageType . _Just . _1 of + Just FLAMING -> plNew (cWorld . lWorld . corpses) cpID (thecorpse & cpSPic %~ scorchSPic) + Just ELECTRICAL -> plNew (cWorld . lWorld . corpses) cpID thecorpse + Just POISONDAM -> plNew (cWorld . lWorld . corpses) cpID (thecorpse & cpSPic %~ poisonSPic) _ | _crPastDamage cr > 200 -> addCrGibs cr _ -> plNew (cWorld . lWorld . corpses) cpID thecorpse where thecorpse = makeDefaultCorpse cr scorchSPic :: SPic -> SPic -scorchSPic = over _1 $ overColSH (mixColors 0.9 0.1 black . normalizeColor) +scorchSPic = _1 %~ overColSH (mixColors 0.9 0.1 black . normalizeColor) poisonSPic :: SPic -> SPic -poisonSPic = over _1 $ overColSH (mixColors 0.5 0.5 green . normalizeColor) +poisonSPic = _1 %~ overColSH (mixColors 0.5 0.5 green . normalizeColor) internalCreatureUpdate :: Creature -> World -> World -internalCreatureUpdate cr = - cWorld . lWorld . creatures . ix (_crID cr) - %~ updateMovement +internalCreatureUpdate cr = cWorld . lWorld . creatures . ix (_crID cr) %~ updateMovement {- | Drop items according to the creature state. TODO make sure this doesn't mess up any ItemPosition @@ -159,9 +156,10 @@ applyPastDamages cr w | otherwise = w -- a map updating all inventory items -updateInv :: Creature -> World -> World -updateInv cr = cWorld . lWorld . creatures . ix (_crID cr) . crInv . each - . itUse . heldDelay . warmTime %~ (max 0 . subtract 1) +--updateInv :: Creature -> World -> World +--updateInv cr =id +--updateInv cr = cWorld . lWorld . creatures . ix (_crID cr) . crInv . each +-- . itUse . heldDelay . warmTime %~ (max 0 . subtract 1) -- a loop going over all inventory items invSideEff :: Creature -> World -> World diff --git a/src/Dodge/Data/Item/Effect.hs b/src/Dodge/Data/Item/Effect.hs index 83ec23b03..de75b271c 100644 --- a/src/Dodge/Data/Item/Effect.hs +++ b/src/Dodge/Data/Item/Effect.hs @@ -30,6 +30,8 @@ data ItInvEffect | ItemUseToggle BlBl | ItemCancelExamineInventory | ItemCopierUpdate + | ItemReduceWarmTime + | ItemSetWarmTime Int deriving (Eq, Ord, Show, Read) --Generic, Flat) data ItDropEffect = NoDropEffect diff --git a/src/Dodge/ItEffect.hs b/src/Dodge/ItEffect.hs index 99a46bd4f..9e9ed59e6 100644 --- a/src/Dodge/ItEffect.hs +++ b/src/Dodge/ItEffect.hs @@ -25,6 +25,10 @@ doInvEffect = \case pointerToItemID (itm ^. itID) . itUse . useToggle %~ doBlBl f ItemCancelExamineInventory -> \_ _ -> cancelExamineInventory ItemCopierUpdate -> copierItemUpdate + ItemReduceWarmTime -> \itm _ -> pointerToItem itm . itUse . heldDelay . warmTime + %~ (max 0 . subtract 1) + ItemSetWarmTime x -> \itm _ -> pointerToItem itm . itUse . heldDelay . warmTime + .~ x copierItemUpdate :: Item -> Creature -> World -> World copierItemUpdate itm cr w = fromMaybe w $ do diff --git a/src/Dodge/Item/Held/Cane.hs b/src/Dodge/Item/Held/Cane.hs index 1b9f76c6a..8c0d86e46 100644 --- a/src/Dodge/Item/Held/Cane.hs +++ b/src/Dodge/Item/Held/Cane.hs @@ -112,3 +112,5 @@ miniGunX i = & itUse . heldParams . randomOffset .~ 10 & itUse . heldParams . rifling .~ UniRandFloat 0.8 0.9 & itType .~ HELD (MINIGUNX i) + & itEffect . ieInv .~ ItemReduceWarmTime + & itEffect . ieOnDrop .~ ItemSetWarmTime 0