Configurable weapon system: assigning instances of varying types at runtime

I’m working on a configurable weapon system that takes three parts: a fire pattern(an arc like a shotgun blast, three projectiles in a row, circluar pattern etc.), an ammo type (bullet, rocket, cheese etc.) and a weapon mod, which overwrites things like damage or rate of fire. I thought it would be a fairly simple task but i’m running into problems. I must be still half asleep or something…

My initial design is to have a ConfigurableWeapon class that has three fields: pattern, ammoType and mod. These fields are types of abstract class that you would inherit from for individual ammo types etc. The user would pick what they wanted from a list, then when the game starts the weapon would be set up. Also, the A.I. controlled enemies would use the same system, with pre-specified settings per enemy prefab.

I thought I would use a static helper class that has a dictionary that stores an enum as a key, and the type to be added as a value, then return new instances as needed but I can’t for the life of me get anything working this morning!

There’s probably a more elegant way of doing this, or i’m overlooking something obvious, so any suggestions would be appreciated.

I can post the code if needed, but seeming as i’m still trying to figure out the design it’s mostly just abstract class definitions and some inherited testing classes.

Alright so after some lunch and caffeine I took another look at my design and decided I was doing it backwards. What I’ve done now is rather than trying to pull instances into the weapon when fired, instead store the firing patterns in a static dictionary in a manager class and using enums stored in the weapon, look up the appropriate pattern and pass it a reference to an ammo type stored in a different dictionary (also in the manager class) to be instantiated. Works so far, if a little obtuse.

I’ll leave this up as an answer for now but if anyone has a more elegant way, i’d be interested in hearing it!

Thanks for your help Fattie, I decided to just go with prefab ammo types for simplicity, makes things easier in that regard.

Now I just need to add the weapon mod part and I can start blowing things up in all manner of entertaining ways!