about summary refs log tree commit diff
path: root/users/grfn/xanthous/src/Xanthous
diff options
context:
space:
mode:
Diffstat (limited to 'users/grfn/xanthous/src/Xanthous')
-rw-r--r--users/grfn/xanthous/src/Xanthous/AI/Gormlak.hs38
-rw-r--r--users/grfn/xanthous/src/Xanthous/Entities/RawTypes.hs12
-rw-r--r--users/grfn/xanthous/src/Xanthous/Entities/Raws/broken-dagger.yaml3
-rw-r--r--users/grfn/xanthous/src/Xanthous/Entities/Raws/stick.yaml4
-rw-r--r--users/grfn/xanthous/src/Xanthous/messages.yaml4
5 files changed, 50 insertions, 11 deletions
diff --git a/users/grfn/xanthous/src/Xanthous/AI/Gormlak.hs b/users/grfn/xanthous/src/Xanthous/AI/Gormlak.hs
index c75c6d9163ec..1f2b513ffe0e 100644
--- a/users/grfn/xanthous/src/Xanthous/AI/Gormlak.hs
+++ b/users/grfn/xanthous/src/Xanthous/AI/Gormlak.hs
@@ -26,8 +26,10 @@ import qualified Xanthous.Entities.Character as Character
 import qualified Xanthous.Entities.RawTypes as Raw
 import           Xanthous.Entities.RawTypes
                  ( CreatureType, HasLanguage(language), getLanguage
-                 , HasAttacks (attacks)
+                 , HasAttacks (attacks), creatureAttackMessage
                  )
+import           Xanthous.Entities.Common
+                 ( wielded, Inventory, wieldedItems, WieldedItem (WieldedItem) )
 import           Xanthous.Game.State
 import           Xanthous.Game.Lenses
                  ( entitiesCollision, collisionAt
@@ -36,7 +38,7 @@ import           Xanthous.Game.Lenses
                  )
 import           Xanthous.Data.EntityMap.Graphics (linesOfSight, canSee)
 import           Xanthous.Random
-import           Xanthous.Monad (say)
+import           Xanthous.Monad (say, message)
 import           Xanthous.Generators.Speech (word)
 import qualified Linear.Metric as Metric
 import qualified Xanthous.Messages as Messages
@@ -50,6 +52,7 @@ type IsCreature entity =
   ( HasVisionRadius entity
   , HasField "_hippocampus" entity entity Hippocampus Hippocampus
   , HasField "_creatureType" entity entity CreatureType CreatureType
+  , HasField "_inventory" entity entity Inventory Inventory
   , A.ToJSON entity
   )
 
@@ -113,14 +116,26 @@ stepGormlak ticks pe@(Positioned pos creature) = do
   where
     vision = visionRadius creature
     attackCharacter = do
-      attack <- choose $ creature ^. creatureType . attacks
-      attackDescription <- Messages.render (attack ^. Raw.description)
-                          $ object []
-      say ["combat", "creatureAttack"]
-        $ object [ "creature" A..= creature
-                 , "attackDescription" A..= attackDescription
-                 ]
-      character %= Character.damage (attack ^. Raw.damage)
+      dmg <- case creature ^? inventory . wielded . wieldedItems of
+        Just (WieldedItem item wi) -> do
+          let msg = fromMaybe
+                    (Messages.lookup ["combat", "creatureAttack", "genericWeapon"])
+                    $ wi ^. creatureAttackMessage
+          message msg $ object [ "creature" A..= creature
+                               , "item" A..= item
+                               ]
+          pure $ wi ^. Raw.damage
+        Nothing -> do
+          attack <- choose $ creature ^. creatureType . attacks
+          attackDescription <- Messages.render (attack ^. Raw.description)
+                              $ object []
+          say ["combat", "creatureAttack", "natural"]
+              $ object [ "creature" A..= creature
+                       , "attackDescription" A..= attackDescription
+                       ]
+          pure $ attack ^. Raw.damage
+
+      character %= Character.damage dmg
 
     yellAtCharacter = for_ (creature ^. creatureType . language)
       $ \lang -> do
@@ -171,6 +186,9 @@ hippocampus = field @"_hippocampus"
 creatureType :: HasField "_creatureType" s t a b => Lens s t a b
 creatureType = field @"_creatureType"
 
+inventory :: HasField "_inventory" s t a b => Lens s t a b
+inventory = field @"_inventory"
+
 --------------------------------------------------------------------------------
 
 -- instance Brain Creature where
diff --git a/users/grfn/xanthous/src/Xanthous/Entities/RawTypes.hs b/users/grfn/xanthous/src/Xanthous/Entities/RawTypes.hs
index 8453a0533610..9f5cabecdca7 100644
--- a/users/grfn/xanthous/src/Xanthous/Entities/RawTypes.hs
+++ b/users/grfn/xanthous/src/Xanthous/Entities/RawTypes.hs
@@ -34,6 +34,7 @@ module Xanthous.Entities.RawTypes
   , HasAttacks(..)
   , HasChance(..)
   , HasChar(..)
+  , HasCreatureAttackMessage(..)
   , HasDamage(..)
   , HasDensity(..)
   , HasDescription(..)
@@ -200,6 +201,17 @@ makeFieldsNoPrefix ''EdibleItem
 data WieldableItem = WieldableItem
   { _damage :: !Hitpoints
   , _attackMessage :: !(Maybe Message)
+    -- | Message to use when a creature is using this item to attack the
+    -- character.
+    --
+    -- Grammatically, should be of the form "The creature slashes you with its
+    -- dagger".
+    --
+    -- = Parameters
+    --
+    -- [@creature@ (type: 'Creature')] The creature doing the attacking
+    -- [@item@ (type: 'Item')] The item itself
+  , _creatureAttackMessage :: !(Maybe Message)
   }
   deriving stock (Show, Eq, Ord, Generic)
   deriving anyclass (NFData, CoArbitrary, Function)
diff --git a/users/grfn/xanthous/src/Xanthous/Entities/Raws/broken-dagger.yaml b/users/grfn/xanthous/src/Xanthous/Entities/Raws/broken-dagger.yaml
index e32ba214a746..2d30e6986b6e 100644
--- a/users/grfn/xanthous/src/Xanthous/Entities/Raws/broken-dagger.yaml
+++ b/users/grfn/xanthous/src/Xanthous/Entities/Raws/broken-dagger.yaml
@@ -11,6 +11,9 @@ Item:
     attackMessage:
       - You slash at the {{creature.creatureType.name}} with your dagger.
       - You stab the {{creature.creatureType.name}} with your dagger.
+    creatureAttackMessage:
+      - The {{creature.creatureType.name}} slashes at you with its dagger.
+      - The {{creature.creatureType.name}} stabs you with its dagger.
   # Just the steel, not the handle, for now
   density: [7750 , 8050000]
   # 15cm – 45cm
diff --git a/users/grfn/xanthous/src/Xanthous/Entities/Raws/stick.yaml b/users/grfn/xanthous/src/Xanthous/Entities/Raws/stick.yaml
index 4100808ca071..a7eae9c36666 100644
--- a/users/grfn/xanthous/src/Xanthous/Entities/Raws/stick.yaml
+++ b/users/grfn/xanthous/src/Xanthous/Entities/Raws/stick.yaml
@@ -12,6 +12,10 @@ Item:
       - You bonk the {{creature.creatureType.name}} over the head with your stick.
       - You bash the {{creature.creatureType.name}} on the noggin with your stick.
       - You whack the {{creature.creatureType.name}} with your stick.
+    creatureAttackMessage:
+      - The {{creature.creatureType.name}} bonks you over the head with its stick.
+      - The {{creature.creatureType.name}} bashes you on the noggin with its stick.
+      - The {{creature.creatureType.name}} whacks you with its stick.
   # https://www.sciencedirect.com/topics/agricultural-and-biological-sciences/wood-density
   # it's a hard stick. so it's dense wood.
   density: 890000 # g/m³
diff --git a/users/grfn/xanthous/src/Xanthous/messages.yaml b/users/grfn/xanthous/src/Xanthous/messages.yaml
index d207a73bf663..27ee841dd9db 100644
--- a/users/grfn/xanthous/src/Xanthous/messages.yaml
+++ b/users/grfn/xanthous/src/Xanthous/messages.yaml
@@ -80,7 +80,9 @@ combat:
     generic:
       - You hit the {{creature.creatureType.name}}.
       - You attack the {{creature.creatureType.name}}.
-  creatureAttack: The {{creature.creatureType.name}} {{attackDescription}}
+  creatureAttack:
+    natural: The {{creature.creatureType.name}} {{attackDescription}}.
+    genericWeapon: The {{creature.creatureType.name}} attacks you with its {{item.itemType.name}}.
   killed:
     - You kill the {{creature.creatureType.name}}!
     - You've killed the {{creature.creatureType.name}}!