about summary refs log tree commit diff
path: root/users/grfn/xanthous/src/Xanthous/App.hs
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2021-11-25T15·14-0500
committergrfn <grfn@gws.fyi>2021-11-25T17·31+0000
commit604319850c4b875fb8cdb9c1e7ca34f013993f20 (patch)
treea8db077291eaf3cf0b6f7511e2c32012f278c477 /users/grfn/xanthous/src/Xanthous/App.hs
parenta3d220b631d264f4950f17057e60d8908f0783a2 (diff)
feat(gs/xanthous): Creatures drop their items when they die r/3099
When a creature is killed, it now drops all the contents of its
inventory on the ground.

Change-Id: Ie95c397308ba2c9861f10e58b99c91c9cc759c56
Diffstat (limited to 'users/grfn/xanthous/src/Xanthous/App.hs')
-rw-r--r--users/grfn/xanthous/src/Xanthous/App.hs16
1 files changed, 14 insertions, 2 deletions
diff --git a/users/grfn/xanthous/src/Xanthous/App.hs b/users/grfn/xanthous/src/Xanthous/App.hs
index b29614383b..a251833955 100644
--- a/users/grfn/xanthous/src/Xanthous/App.hs
+++ b/users/grfn/xanthous/src/Xanthous/App.hs
@@ -48,17 +48,18 @@ import           Xanthous.Game.Draw (drawGame)
 import           Xanthous.Game.Prompt hiding (Fire)
 import qualified Xanthous.Messages as Messages
 import           Xanthous.Random
-import           Xanthous.Util (removeVectorIndex)
+import           Xanthous.Util (removeVectorIndex, useListOf)
 import           Xanthous.Util.Inflection (toSentence)
 import           Xanthous.Physics (throwDistance, bluntThrowDamage)
 import           Xanthous.Data.EntityMap.Graphics (lineOfSight)
 import           Xanthous.Data.EntityMap (EntityID)
 --------------------------------------------------------------------------------
+--------------------------------------------------------------------------------
 import           Xanthous.Entities.Common
                  ( InventoryPosition, describeInventoryPosition, backpack
                  , wieldableItem, wieldedItems, wielded, itemsWithPosition
                  , removeItemFromPosition, asWieldedItem, inRightHand
-                 , wieldedItem
+                 , wieldedItem, items
                  )
 import qualified Xanthous.Entities.Character as Character
 import           Xanthous.Entities.Character hiding (pickUpItem)
@@ -462,7 +463,18 @@ damageCreature (creatureID, creature) dam = do
   if Creature.isDead creature'
     then do
       say ["combat", "killed"] msgParams
+      floorItems <- useListOf
+                   $ entities
+                   . ix creatureID
+                   . positioned
+                   . _SomeEntity @Creature
+                   . inventory
+                   . items
+      mCreaturePos <- preuse $ entities . ix creatureID . position
       entities . at creatureID .= Nothing
+      for_ mCreaturePos $ \creaturePos ->
+        entities . EntityMap.atPosition creaturePos
+          %= (<> fromList (SomeEntity <$> floorItems))
     else entities . ix creatureID . positioned .= SomeEntity creature'
   pure creature'