Eight slot weapons: the six from the design plus the rivet repeater (fast, short-range automatic) and the harpoon gun (slow heavy bolt, 2.5x damage to built pieces). Four quality tiers, Rusted to Captain's, scale damage and reload time. The line thrower now yanks the shooter towards where its line lands, through a data field (pull_speed) any weapon can use. Four consumables: sailcloth bandage (heals to 75), brine tonic, cork vest and the new tar patch. Fire with one held starts using it if it would help; it takes effect after its use time. Changing slot, dropping, sprinting, swimming or elimination interrupts it and uses nothing up. All checks run on the server. A data-validation test covers every weapon, tier, consumable and ammunition type, including unknown stat keys, name format and that every ammo type is used. The GDD's weapons section lists the roster. Closes #21 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
90 lines
2.9 KiB
GDScript
90 lines
2.9 KiB
GDScript
## 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)
|