game: add weapon mod system

This commit is contained in:
2025-08-21 19:49:07 +02:00
parent 3e12c386c2
commit 1d75a850bf
5 changed files with 71 additions and 5 deletions

View File

@@ -0,0 +1,36 @@
class_name WeaponModBase
extends Resource
enum ModType { ADDITIVE, MULTIPLICATIVE, ABSOLUTE, BOOL }
@export var name: String = "Unnamed mod"
@export var description: String = ""
@export var icon: Texture2D
@export var mod_property: String
@export var mod_value: float
@export var mod_value_bool: bool = false
@export var mod_type: ModType = ModType.MULTIPLICATIVE
@export var mod_extra_tags: Array[WeaponBase.WeaponTag] = []
static func get_calculated(weapon: WeaponBase, key: String) -> Variant:
assert(
weapon.has_property(key),
"tried calculate property '%s' where base value does not exist on %s" % [key, weapon]
)
var base_value = weapon.get(key)
var add = 0.0
var mul = 1.0
for mod in weapon.modifiers:
if mod.mod_property == key:
match mod.mod_type:
ModType.ADDITIVE:
add += mod.mod_value
ModType.MULTIPLICATIVE:
mul *= mod.mod_value
ModType.ABSOLUTE:
return mod.mod_value
ModType.BOOL:
return mod.mod_value_bool
return (base_value + add) * mul