core icon indicating copy to clipboard operation
core copied to clipboard

Option for defaulting an attribute to zero on attribute formula

Open marcelomoreli opened this issue 6 years ago • 2 comments

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!

marcelomoreli avatar Mar 13 '19 22:03 marcelomoreli

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.

seanohue avatar Mar 13 '19 23:03 seanohue

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.

shawncplus avatar Mar 14 '19 01:03 shawncplus