July 12, 2009 at 11:29 pm
This feels like something that's probably been invented, given a nice name, and had important-looking papers written about it. I'm just not sure exactly what it is.
Take a look at Blizzard's modern games: Warcraft, Diablo, and Starcraft. They all involve various numbers of characters with attributes and abilities and whatnot. Pretty much every aspect of a character can be modified by buffs, talents, consumable items, researched tech, etc. These modifications can do pretty much anything, from granting a character infinite breath underwater to making a fireball spell bounce on the ground multiple times to unlocking or preventing the use of entire abilities. Sometimes the modifications stack, increasing effectiveness with each level in the stack. Sometimes different modifications impact the same aspect of the character (you might have five different equipped items increasing a character's agility, plus three different buffs cast on him that also increase agility).
The problem that I want a solution for is how do you support this logic. Essentially, an entity (like a character) wants to ask an arbitrary set of objects to mutate some property or a set of properties that the entity exposes.
The Chain of Responsibility pattern is the closest I can find. You create some sort of request object ("What should my agility be?") and then toss it down a chain of objects that say they can mess with agility. They each get an opportunity to mutate it, and then once the chain is complete the request has been resolved.
It seems to me, however, that the desired cases want something a bit more than that. Depending on some conditions, the behavior of the objects in the chain could be different. You might want to sum up the values of agility producing objects, or select only the highest speed buff from objects that present different speed values.
It's things like the extra combinatorial logic that's kind of tripping me up. Anybody know of anything that would fit the bill, or am I looking at just an ad hoc augmentation and specialization of the Chain of Responsibility pattern?
Edit: Actually, maybe the mediator pattern? I dunno, I'm tired.