From 4b11859d046b470a87d73edc8447ed73a3f7a6da Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Wed, 24 Nov 2021 17:10:47 -0500 Subject: feat(gs/xanthous): Allow generating creatures with items Add an `equippedItems` field to the CreatureType raw, which provides a chance for generating that creature with an item equipped, which goes into a new `inventory` field on the creature entity itself. Currently the creature doesn't actually *use* this equipped item, but it's a step. This commit also adds a broken-dagger equipped 90% of the time to the "husk" creature. Change-Id: I6416c0678ba7bc1b002c5ce6119f7dc97dd86437 --- .../xanthous/src/Xanthous/Entities/Creature.hs | 26 ++++------------------ 1 file changed, 4 insertions(+), 22 deletions(-) (limited to 'users/grfn/xanthous/src/Xanthous/Entities/Creature.hs') diff --git a/users/grfn/xanthous/src/Xanthous/Entities/Creature.hs b/users/grfn/xanthous/src/Xanthous/Entities/Creature.hs index 98dd4dd83331..3af2cafe3349 100644 --- a/users/grfn/xanthous/src/Xanthous/Entities/Creature.hs +++ b/users/grfn/xanthous/src/Xanthous/Entities/Creature.hs @@ -8,10 +8,9 @@ module Xanthous.Entities.Creature , creatureType , hitpoints , hippocampus + , inventory -- ** Creature functions - , newWithType - , newOnLevelWithType , damage , isDead , visionRadius @@ -33,7 +32,6 @@ import Xanthous.Prelude import Test.QuickCheck import Data.Aeson.Generic.DerivingVia import Data.Aeson (ToJSON, FromJSON) -import Control.Monad.Random (MonadRandom) -------------------------------------------------------------------------------- import Xanthous.AI.Gormlak import Xanthous.Entities.RawTypes hiding @@ -44,12 +42,14 @@ import Xanthous.Data import Xanthous.Data.Entities import Xanthous.Entities.Creature.Hippocampus import Xanthous.Util.QuickCheck (GenericArbitrary(..)) +import Xanthous.Entities.Common (Inventory) -------------------------------------------------------------------------------- data Creature = Creature { _creatureType :: !CreatureType , _hitpoints :: !Hitpoints , _hippocampus :: !Hippocampus + , _inventory :: !Inventory } deriving stock (Eq, Show, Ord, Generic) deriving anyclass (NFData, CoArbitrary, Function) @@ -58,7 +58,7 @@ data Creature = Creature deriving (ToJSON, FromJSON) via WithOptions '[ FieldLabelModifier '[Drop 1] ] Creature -makeLenses ''Creature +makeFieldsNoPrefix ''Creature instance HasVisionRadius Creature where visionRadius = const 50 -- TODO @@ -76,24 +76,6 @@ instance Entity Creature where -------------------------------------------------------------------------------- -newOnLevelWithType - :: MonadRandom m - => Word -- ^ Level number, starting at 0 - -> CreatureType - -> m (Maybe Creature) -newOnLevelWithType levelNumber cType - | maybe True (canGenerate levelNumber) $ cType ^. generateParams - = Just <$> newWithType cType - | otherwise - = pure Nothing - - -newWithType :: MonadRandom m => CreatureType -> m Creature -newWithType _creatureType = - let _hitpoints = _creatureType ^. maxHitpoints - _hippocampus = initialHippocampus - in pure Creature {..} - damage :: Hitpoints -> Creature -> Creature damage amount = hitpoints %~ \hp -> if hp <= amount -- cgit 1.4.1