RanvierMUD / core

Core engine code for Ranvier
https://ranviermud.com
MIT License
45 stars 40 forks source link

Allow for composite behaviors #19

Open shawncplus opened 7 years ago

shawncplus commented 7 years ago

There are currently 2 tiers of scripting for entities: a script, one-off and specific for a single entity; and behaviors shareable/configurable chunk of code.

The use case for composite behaviors is the following:

I have 3 types of town guard: gate guard, tower archers, and cityguards. I want all guards to wander, I want them all to attack any npc from a different area that is currently attacking an npc in this area or a player. The wander configurations differ between the archers and the cityguards but regardless they both wander, but the "aggro" behavior config is the same between them and quite complex.

Currently to accomplish this I would have to copy and paste the behavior configuration for each guard. Hence the need for "composite behaviors".

Currently behaviors live in behaviors/<entity type>/<name.js> a new file would need to be created in `behaviors//composites.yml"

Example composites.yml file:

# name of composite behavior
ranvier-guard:
  # list of behavior configurations (essentially exactly what you would otherwise put in the `behaviors` setting for a single entity
  ranvier-wander:
    areaRestricted: true
  ranvier-aggro:
    players: false
    # attack any NPC that is not from this area that wanders into it (unless it is a follower of a player)
    areaDefender: true
    # attack anything attacking an npc with the entityRef in this list, i.e., they are teammates with these npcs
    teammates: [ "somearea:cityguard", "somearea:archer-guard", "somearea:gateguard" ]

When using this composite behavior it would be like any other behavior, example in npcs.yml


- id: cityguard
  name: Cityguard
  behaviors:
    # cityguard doesn't need any extra configuration on top of ranvier-guard
    ranvier-guard: true
- id: archer-guard
  name: Tower Archer
  behaviors:
    # the tower archer wanders only along the tower wall
    ranvier-guard:
      ranvier-wander:
        restrictTo: [ "somearea:towerwall-1", "somearea:towerwall-2", "somearea:towerwall-3" ]
- id: gateguard
  name: City Gate Guard
  behaviors:
    # the gate guard doesn't wander from their room
    ranvier-guard:
      ranvier-wander:
        disabled: true
samjaninf commented 7 years ago

Hmmm, If I recall correctly I suggested something similar to this behavior with mob type inheritance. SO You could have a basic guard mob with the aggro, wander and the guard behaviors. Then you just clone the basic guard three times as the archer, city and gate guard, it comes with the basic stats and behaviors already assigned to basic guard as that would be it's prototype/parent. Then just change the wander areaRestricted on the archer.

shawncplus commented 7 years ago

@samjaninf this could technically be done right now with no changes necessary by using YAML anchors but I'd rather have it codified than depend on a YAML feature