I’m planning out an rpg game with weapons that will be given random affixes that can give boosts to the weapons like extra damage, extra speed, or extra mana and stuff. What would be the best way to implement this with modules system and make it easily accessible as well as expandable?
Let’s say I have an affix “Heavy” and it applies to a weapon called “Sword.” Now the name is “Heavy Sword” and the base damage for “Sword” is 5. Now the “Heavy” affix makes the player walk 15% slower but multiplies the sword’s damage by 2. This can easily be done, but I stumped on a way to make it where you can easily add affixes and add its effects and boosts to each weapon. I have a damage module, so maybe add something there? I was also thinking there might be affixes that arent related to damaging or stats, and instead it maybe spawns stuff in? How would I do that. Any help or responses is really appreciated!
Bumping this thread because i’m still stumped!
An OOP-based implmentation could work well here.
I would store the affix as a value in the item itself.
Let’s say you have a class Weapon (going to use unfinished here).
local Weapon = {}
Weapon.__index = Weapon
function Weapon.init(self, name, damage, affix, ...)
local w = {}
setmetatable(w, Weapon)
w.name = name
w.damage = damage
w.affix = affix
...
return w
end
return Weapon
local Affix = {}
Affix.__index = Affix
function Affix.init(self, name, effect, ...)
local a = {}
setmetatable(a, Affix)
a.name = name
a.effect = effect
...
return a
end
A possible route would be to make Affix a class of its own that contained information about how it modifies the attributes of an object of class Weapon.
This could be done in numerous ways, such as storing a dictionary in an object of class Affix that the tied Weapon references to find out how its stats are modified.