Modifiers on items

Started by
1 comment, last by DejaimeNeto 10 years, 1 month ago

Hi, i am fiddling around with an old abandoned game project I wrote. I want to add modifiers on my weapons such as +10 to +20 damage or +4 to strength. I am already using an enum for attributes such as the players strength and dexterity or weapon requirements. Another enum for magic alignment such as fire and ice for spells and resistance. The weapon damage itself, gold cost, speed, etc are just fields within the weapon class.

I am looking for a clean way to add modifiers to my items. I was thinking of creating a new enum with all the attributes, magical alignments, players stats, damage, etc and use that enum in a struct with a value field to modify the corresponding thing to modify. However, I don't see this as a very clean way. Can anyone suggest a nice and elegant way to create such a modifier that has the ability to change all kind of different character stats?

Thank you,

Advertisement
An enum is maybe not a bad way of doing it, I would say it depends on the number of things that would need to be included in the enum - if it's a lot of things and/or if the list of things to enumerate is tricky to keep in-sync with the attributes in the entity then it may be less appropriate.

Another way of doing it is to attach a modifier as a delegate/interface with a signature something like: void Modify(Entity e);

You could then attach modifiers e.g. weapon.AddModifier( new DamageModifier(10) );

I'd probably use a vector of modifiers in my actors, and these modifiers would have their own type, data, duration and possibly override rules (like in only one dmg modifier at a time).

So all you'd need to do is add a new modifier to the that vector through a add function, and maybe remove any expired ones when updating the actor.

This topic is closed to new replies.

Advertisement