Files
gamedev-the-steward/simulation/definitions/ItemDefinition.gd
T
2026-08-12 20:06:51 +02:00

47 lines
1.6 KiB
GDScript

class_name ItemDefinition
extends Resource
const CATEGORY_RESOURCE := &"resource"
const CATEGORY_WEAPON := SimulationIds.ITEM_CATEGORY_WEAPON
const VALID_CATEGORIES := [CATEGORY_RESOURCE, CATEGORY_WEAPON]
@export var item_id: StringName
@export var display_name: String
@export var category: StringName = CATEGORY_RESOURCE
@export var equip_slot: StringName
@export_range(0.0, 1000.0, 0.1) var damage := 0.0
@export_range(0.0, 50.0, 0.1) var reach := 0.0
@export_range(0.0, 5.0, 0.05) var attack_cooldown := 0.0
func validate() -> Array[String]:
var errors: Array[String] = []
if item_id.is_empty():
errors.append("item_id is empty")
if display_name.is_empty():
errors.append("display_name is empty for '%s'" % item_id)
if category not in VALID_CATEGORIES:
errors.append("category '%s' is invalid for '%s'" % [category, item_id])
elif category == CATEGORY_WEAPON:
if equip_slot != SimulationIds.EQUIP_SLOT_HAND:
errors.append(
"weapon '%s' must equip in '%s'" % [item_id, SimulationIds.EQUIP_SLOT_HAND]
)
if not is_finite(damage) or damage <= 0.0:
errors.append("damage must be positive for '%s'" % item_id)
if not is_finite(reach) or reach <= 0.0:
errors.append("reach must be positive for '%s'" % item_id)
if not is_finite(attack_cooldown) or attack_cooldown <= 0.0:
errors.append("attack_cooldown must be positive for '%s'" % item_id)
elif not equip_slot.is_empty():
errors.append("resource item '%s' cannot declare equip_slot '%s'" % [item_id, equip_slot])
return errors
func is_weapon() -> bool:
return category == CATEGORY_WEAPON
func is_resource() -> bool:
return category == CATEGORY_RESOURCE