When you load this item from JSON, you string together a matching pattern of polymorphic effect nodes, each with their own Apply
method., something like this:
public class StatCheckEffect implements ItemEffect {
public Stat stat;
public int threshold;
public ItemEffect[] effectsIfMet;
public ItemEffect[] effectsIfNotMet;
public void Apply(Character char) {
if (char.GetStat(stat) >= threshold) {
for(ItemEffect effect : effectsIfMet)
effect.Apply(char);
} else {
for(ItemEffect effect : effectsIfNotMet)
effect.Apply(char);
}
}
}
public class StatBoostEffect implements ItemEffect {
public Stat stat;
public int value;
public void Apply(Character char) {
char.ModifyStat(stat, value);
}
}
When the item is equipped, or whenyou run the Apply()
methods on all its top-level effects. When the character's status changes in a way that might affect equipment properties, you reset the character's stats to base and re-run the Apply()
methods of all equipped gear to find the new net result. (More sophisticated caching to avoid redundant processing is possible, but do it the simple way first to check if you really need the added complexity)