RanvierMUD / core

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

Option for defaulting an attribute to zero on attribute formula #64

Open marcelomoreli opened 5 years ago

marcelomoreli commented 5 years ago

Today if you try to create an attribute (i.e: health) and have different formulas with different attributes based on class / char type or anything else fails if the entity doesn't have all the attributes.

Example: Let's suppose NPC health is 10 strength (100 bare_hand_damage) and Non-Npc health: level vitality

where NPCs doesn't have vitality and Players don't have bare_hand_damage, it fails.

A suggestion discussed in slack would be a toggle option on ./ranvier with something like state.AttributeFactory.setAllowSomethingSomethingRequires(true);

Thanks!

seanohue commented 5 years ago

Vue has similar API for validating props. In this case perhaps the "requires" property for a computed attribute would be an object instead of an array with something like:

{
  requires: {
    bare_hand_damage: 1,
    vitality: 1
  }
}

where the properties are their defaults in case the attributes don't exist.

shawncplus commented 5 years ago

hmmm, I like this idea a lot. It wouldn't break backwards compatibility if I supported either the array ['vitality', 'foobar'] or a "with defaults" format like your example.

I tend to really dislike those global .setRandomThingGloballyMagic() things because looking at certain code you have to keep both possibilities in your head if it's on or not which is frustrating.