• Advertisement
Sign in to follow this  

Modifiers on items

This topic is 1427 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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,

Share this post


Link to post
Share on other sites
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: [tt]void Modify(Entity e);[/tt]

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement