feat(xanthous): Add configurable natural attacks

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
This commit is contained in:
Griffin Smith 2021-06-18 12:42:42 -04:00 committed by grfn
parent 88b0d0eecc
commit fb5bec8d95
7 changed files with 69 additions and 12 deletions

View file

@ -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