core
core copied to clipboard
Option for defaulting an attribute to zero on attribute formula
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!
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.
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.