Files
tidewall/src/sim/item_catalog.gd
T
claudeandClaude Opus 5.5 5d2a2bbc31 B7: Weapon roster and consumables
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>
2026-11-11 17:26:04 -05:00

110 lines
3.5 KiB
GDScript

## Every carryable item, built once from Tuning.WEAPONS, Tuning.ITEMS and Tuning.AMMO.
## Codes run weapons first (in table order, without the boathook, which is always
## carried and never in a slot), then consumables, then ammunition.
class_name ItemCatalog
extends RefCounted
const NONE: int = -1
## The weapon every player always holds in selection 0. Not an inventory item.
const BOATHOOK: String = "boathook"
static var _defs: Array[ItemDef] = []
static var _by_id: Dictionary = {}
static func all() -> Array[ItemDef]:
if _defs.is_empty():
_build()
return _defs
static func count() -> int:
return all().size()
## The definition for a code, or null if the code is out of range.
static func get_def(code: int) -> ItemDef:
var defs: Array[ItemDef] = all()
if code < 0 or code >= defs.size():
return null
return defs[code]
## The code for an item ID, or NONE.
static func code_of(id: String) -> int:
all()
return int(_by_id.get(id, NONE))
## The boathook's stats, built the same way as any other weapon.
static func boathook() -> ItemDef:
return _weapon_def(BOATHOOK, Tuning.WEAPONS[BOATHOOK], NONE)
static func _build() -> void:
var ammo_ids: Array = Tuning.AMMO.keys()
var first_ammo: int = Tuning.WEAPONS.size() - 1 + Tuning.ITEMS.size()
for id: String in Tuning.WEAPONS:
if id == BOATHOOK:
continue
var stats: Dictionary = Tuning.WEAPONS[id]
var ammo_code: int = NONE
if stats.has("ammo"):
ammo_code = first_ammo + ammo_ids.find(stats["ammo"])
_add(_weapon_def(id, stats, ammo_code))
for id: String in Tuning.ITEMS:
var stats: Dictionary = Tuning.ITEMS[id]
var def: ItemDef = ItemDef.new()
def.id = id
def.kind = ItemDef.CONSUMABLE
def.stack = int(stats.get("stack", 1))
def.heal = int(stats.get("heal", 0))
def.heal_cap = int(stats.get("heal_cap", Tuning.PLAYER_MAX_HEALTH))
def.rarity = int(stats.get("rarity", 0))
def.armor = int(stats.get("armor", 0))
def.use_seconds = float(stats.get("use_seconds", 0.0))
_add(def)
for id: String in ammo_ids:
var stats: Dictionary = Tuning.AMMO[id]
var def: ItemDef = ItemDef.new()
def.id = id
def.kind = ItemDef.AMMO
def.cap = int(stats["cap"])
def.pickup_amount = int(stats["pickup"])
def.stack = def.cap
_add(def)
static func _add(def: ItemDef) -> void:
def.code = _defs.size()
_defs.append(def)
_by_id[def.id] = def.code
static func _weapon_def(id: String, stats: Dictionary, ammo_code: int) -> ItemDef:
var def: ItemDef = ItemDef.new()
def.id = id
def.kind = ItemDef.WEAPON
def.stack = int(stats.get("stack", 1))
def.thrown = def.stack > 1
def.damage = int(stats["damage"])
def.pellets = int(stats.get("pellets", 1))
def.fire_rate = float(stats["fire_rate"])
def.magazine = int(stats["magazine"])
def.reload_seconds = float(stats.get("reload", 0.0))
def.range_full = float(stats["range_full"])
def.range_max = float(stats["range_max"])
def.falloff_min = float(stats["falloff_min"])
def.rarity = int(stats["rarity"])
def.spread_degrees = float(stats.get("spread", 0.0))
def.aim_spread_factor = float(stats.get("aim_spread", Tuning.AIM_SPREAD_FACTOR))
def.bloom_degrees = float(stats.get("bloom", 0.0))
def.headshot_multiplier = float(stats.get("headshot", Tuning.HEADSHOT_MULTIPLIER))
def.structure_damage = int(stats.get("structure_damage", 0))
def.structure_factor = float(stats.get("structure_factor", Tuning.WEAPON_STRUCTURE_FACTOR))
def.pull_speed = float(stats.get("pull_speed", 0.0))
def.projectile_speed = float(stats.get("projectile_speed", 0.0))
def.projectile_gravity = float(stats.get("projectile_gravity", 0.0))
def.ammo_code = ammo_code
return def