Modularise code concerning items

This commit is contained in:
2021-03-12 02:29:24 +01:00
parent 9bdc6fddd7
commit 22275beb89
9 changed files with 339 additions and 292 deletions
+34
View File
@@ -0,0 +1,34 @@
module Dodge.Item.Consumable
where
import Dodge.Data
import Dodge.Base
import Dodge.Prototypes
import Dodge.SoundLogic
import Dodge.Item.Draw
import Picture
import Control.Lens
import qualified Data.IntMap.Strict as IM
medkit :: Int -> Item
medkit i = basicConsumable
{ _itIdentity = Medkit25
, _itName = "MEDKIT" ++ show i
, _itMaxStack = 9
, _itAmount = 1
, _cnEffect = heal i
, _itFloorPict = onLayer FlItLayer $ color blue $ circleSolid 3
, _itEquipPict = drawWeapon $ color blue $ circleSolid 3
, _itID = Nothing
}
heal25 :: Int -> World -> Maybe World
heal25 = heal 25
heal :: Int -> Int -> World -> Maybe World
heal hp n w | _crHP (_creatures w IM.! n) >= 10000 = Nothing
| otherwise = Just $ soundOnce healSound
$ over (creatures . ix n . crHP) ((\x-> min x 10000). (+ hp) ) w