## 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