about summary refs log tree commit diff
path: root/users/grfn/xanthous/src/Xanthous/Entities/Creature.hs
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2021-11-24T22·10-0500
committergrfn <grfn@gws.fyi>2021-11-25T17·31+0000
commit4b11859d046b470a87d73edc8447ed73a3f7a6da (patch)
tree5824920ffba3d90a87ce491055ec333af9e675c4 /users/grfn/xanthous/src/Xanthous/Entities/Creature.hs
parentbf4d8ab603a754c326d946e1a51c6ff641142e56 (diff)
feat(gs/xanthous): Allow generating creatures with items r/3097
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
Diffstat (limited to 'users/grfn/xanthous/src/Xanthous/Entities/Creature.hs')
-rw-r--r--users/grfn/xanthous/src/Xanthous/Entities/Creature.hs26
1 files changed, 4 insertions, 22 deletions
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