about summary refs log tree commit diff
path: root/users/grfn/xanthous/src/Xanthous/AI
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2021-06-18T16·42-0400
committergrfn <grfn@gws.fyi>2021-06-18T17·51+0000
commitfb5bec8d952b57fe4afa0d842ee606cf4e548563 (patch)
tree8bde10c0136c5913ef8f3afd2c2b3beba1571c47 /users/grfn/xanthous/src/Xanthous/AI
parent88b0d0eecc8ea87e848f2e78ebae08f3361dbeaa (diff)
feat(xanthous): Add configurable natural attacks r/2674
Allow configuring the natural attacks (eg, part of their body rather
than an item) of a creature. Each attack has a description and a damage
associated with it.

Change-Id: I69698a8ac4ee2da91e4c88e419593627519522a5
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3220
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/grfn/xanthous/src/Xanthous/AI')
-rw-r--r--users/grfn/xanthous/src/Xanthous/AI/Gormlak.hs19
1 files changed, 15 insertions, 4 deletions
diff --git a/users/grfn/xanthous/src/Xanthous/AI/Gormlak.hs b/users/grfn/xanthous/src/Xanthous/AI/Gormlak.hs
index a7938c12254c..59be5383de55 100644
--- a/users/grfn/xanthous/src/Xanthous/AI/Gormlak.hs
+++ b/users/grfn/xanthous/src/Xanthous/AI/Gormlak.hs
@@ -24,7 +24,10 @@ import           Xanthous.Entities.Creature.Hippocampus
 import           Xanthous.Entities.Character (Character)
 import qualified Xanthous.Entities.Character as Character
 import qualified Xanthous.Entities.RawTypes as Raw
-import           Xanthous.Entities.RawTypes (CreatureType, HasLanguage (language), getLanguage)
+import           Xanthous.Entities.RawTypes
+                 ( CreatureType, HasLanguage(language), getLanguage
+                 , HasAttacks (attacks)
+                 )
 import           Xanthous.Game.State
 import           Xanthous.Game.Lenses
                  ( entitiesCollision, collisionAt
@@ -36,6 +39,7 @@ import           Xanthous.Random
 import           Xanthous.Monad (say)
 import           Xanthous.Generators.Speech (word)
 import qualified Linear.Metric as Metric
+import qualified Xanthous.Messages as Messages
 --------------------------------------------------------------------------------
 
 --  TODO move the following two classes to a more central location
@@ -86,7 +90,7 @@ stepGormlak ticks pe@(Positioned pos creature) = do
          $ creature ^. field @"_hippocampus" . destination
   let progress' =
         dest ^. destinationProgress
-        + creature ^. field @"_creatureType" . Raw.speed . invertedRate |*| ticks
+        + creatureType ^. Raw.speed . invertedRate |*| ticks
   if progress' < 1
     then pure
          $ pe'
@@ -106,10 +110,17 @@ stepGormlak ticks pe@(Positioned pos creature) = do
           when (any (entityIs @Character) ents) attackCharacter
           pure pe'
   where
+    creatureType = creature ^. field @"_creatureType"
     vision = visionRadius creature
     attackCharacter = do
-      say ["combat", "creatureAttack"] $ object [ "creature" A..= creature ]
-      character %= Character.damage 1
+      attack <- choose $ 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)
 
     yellAtCharacter = for_ (creature ^. field @"_creatureType" . language)
       $ \lang -> do