Jump to content
  • Advertisement
Sign in to follow this  
CelticSir

C# C# design pattern for abilities that affect an object?

Recommended Posts

Posted (edited)

I asked else where on other websites for this and never got answers, I am struggling to know how to do a design pattern for abilities that you can swap in and out that affect the given object's stats.

 

Lets take a weapon like a gun as an example. Of which can have a number of attachments that affect its aim, fire rate, magazine count etc. You can add/remove the attachments. 

I can setup something like that pretty easily (although its very tedious) by creating each attachment and setting its data to what it affects. But then i ran into problems for putting restrictions in place, because then i need a unique one for each weapon they are restricted to. For example:

Scope A only attaches to gun A , C, D
Magazine A attaches only to gun B , C

When i have these specific restrictions - my tedious approach of hard writing it kinda falls apart. So i need a design pattern where this will work easily.

What is the correct way to design this in C# ? I can't figure out a clean system for this at all. 

Edited by CelticSir

Share this post


Link to post
Share on other sites
Advertisement
On 8/19/2019 at 4:02 AM, ChaosEngine said:

What you're asking for is essentially double dispatch, and there isn't a clean way to represent this in C#.

 

Have a read of this

 

 

Thanks for the link :) Never heard of double dispatch. Will read up on it !

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!