Hello! This is mostly general programming question.
I am trying to implement modifiers. I.e., some coefficients that can modify a playable unit's actual stats: HP, speed, damage, etc. They can be added and removed, adding their strength together.
I am inexperienced in programming. And I need help on what data structure to use.
What I have in mind now:
1. One idea is Dictionary type, something like:
var damage_modifier : Dictionary = {
concerned_state = "Attack",
parent_ability = "Blood lust",
value = -0.1,
}
But I'd like to proof that this Dictionary always has the same set of fields (without controlling it manually all the time). And I think, Dictionaries can't do that... Or is there a way?
2. Another idea is a new modifier class, naturally, instance it every time I have to add modifier, add_child() to the Unit, add to some all_modifiers array, and then remove when modifier expires:
class Modifier:
var concerned_state : String
var parent_ability : String
var value_add : int
var value_multiply : float
func update_duration():
pass
func get_modifier_value():
pass
# etc...
But... If I declare a class in Godot, won't it be a extension of Node always? Having tens of units, each with tens of modifier child Nodes, will probably hurt performance, right? Or not? Or am I optimizing too early?
So. Is there a way maybe between this and that? Strict set of fields like variables in a class, but lightweight like a simple Dictionary?..
PS: Also, I am not sure where to declare the class. If it is an inner class of some ModifiersComponent of a Unit, then every unit will have it and declare it. Is it OK?.. I think, not?.. Or can I declare a new class somewhere, without making it an inner class?..
Please, help me understand.