Randoloot/scripts/items/item_stat_modifier.gd
2026-10-11 20:57:00 +02:00

25 lines
1000 B
GDScript

extends Resource
class_name ItemStatModifier
@export var stat_key: String = ""
@export var value: float = 0.0
@export var affix: ItemAffixDefinition
# Fixed-value affixes and legacy modifiers have no roll quality to highlight.
func get_roll_quality(level: int) -> int:
if affix == null:
return 0
var bounds := affix.get_value_range(level)
if is_equal_approx(bounds.x, bounds.y):
return 0
var fraction := clampf((value - bounds.x) / (bounds.y - bounds.x), 0.0, 1.0)
if fraction >= 0.9 - 0.000001:
return 2
return 1 if fraction >= 0.75 - 0.000001 else 0
func get_display_text() -> String:
var label := affix.display_name if affix else ItemInstance.stat_name(stat_key)
var suffix := affix.unit if affix else ("%" if stat_key.ends_with("_percent") else "/s")
var displayed_value := value * ItemInstance.ENERGY_REGENERATION_BONUS_MULTIPLIER if stat_key == "energy_regeneration" else value
return "%s: %s%.2f %s" % [label, "+" if displayed_value >= 0.0 else "", displayed_value, suffix]