## One kind of carried item: a weapon, a consumable or an ammunition type. Built by ## ItemCatalog from the tables in Tuning, so adding an item is a data change only. class_name ItemDef extends Resource const WEAPON: int = 0 const CONSUMABLE: int = 1 const AMMO: int = 2 ## Index in ItemCatalog.all(). Stable for a given Tuning table. @export var code: int = -1 ## Key in Tuning.WEAPONS, Tuning.ITEMS or Tuning.AMMO. @export var id: String = "" @export var kind: int = WEAPON ## How many fit in one slot. Weapons that aren't thrown stack to 1. @export var stack: int = 1 @export_group("Weapon") @export var damage: int = 0 @export var pellets: int = 1 @export var fire_rate: float = 1.0 @export var magazine: int = 0 @export var reload_seconds: float = 0.0 @export var range_full: float = 0.0 @export var range_max: float = 0.0 @export var falloff_min: float = 1.0 @export var rarity: int = 0 @export var spread_degrees: float = 0.0 @export var aim_spread_factor: float = 1.0 @export var bloom_degrees: float = 0.0 @export var headshot_multiplier: float = 1.0 @export var structure_damage: int = 0 ## Multiplies damage to built pieces and props. @export var structure_factor: float = 1.0 ## Speed the shooter is pulled towards where a shot lands; 0 for none. @export var pull_speed: float = 0.0 ## 0 means hitscan. @export var projectile_speed: float = 0.0 @export var projectile_gravity: float = 0.0 ## ItemCatalog code of the ammunition this weapon loads, or -1 if none. @export var ammo_code: int = -1 ## Thrown weapons are their own ammunition: the slot count is what's left. @export var thrown: bool = false @export_group("Consumable") @export var heal: int = 0 ## Healing stops at this much health. @export var heal_cap: int = 0 @export var armor: int = 0 @export var use_seconds: float = 0.0 @export_group("Ammunition") @export var cap: int = 0 @export var pickup_amount: int = 0 func is_weapon() -> bool: return kind == WEAPON func uses_magazine() -> bool: return kind == WEAPON and magazine > 0 and not thrown ## Ticks between shots at this weapon's fire rate. func fire_interval_ticks() -> int: return maxi(ceili(Tuning.TICK_RATE_HZ / fire_rate), 1) ## Reload time in ticks for a weapon of quality `tier`. func reload_ticks(tier: int = 0) -> int: return roundi(reload_seconds * Tuning.TICK_RATE_HZ * float(tier_stats(tier)["reload"])) ## The Tuning.WEAPON_TIERS entry for `tier`, clamped into range. static func tier_stats(tier: int) -> Dictionary: return Tuning.WEAPON_TIERS[clampi(tier, 0, Tuning.WEAPON_TIERS.size() - 1)] func use_ticks() -> int: return roundi(use_seconds * Tuning.TICK_RATE_HZ) ## Damage of one pellet at `distance` metres, before headshots and tiers. func damage_at(distance: float) -> float: if distance <= range_full or range_max <= range_full: return float(damage) var t: float = clampf((distance - range_full) / (range_max - range_full), 0.0, 1.0) return float(damage) * lerpf(1.0, falloff_min, t)