B5: Inventory and pickups
Five slots plus the always-carried boathook (selection 0), ammunition carried apart from the slots, and items lying in the world as pickup entities. All changes are made by the server from commands: interact picks up the nearest pickup in reach, drop (new BUTTON_DROP) leaves the held stack at the feet, and both act once per press. A full inventory swaps the held item. Consumables and thrown weapons stack; ammunition stops at its cap and leaves the rest on the ground. An eliminated player drops everything on a ring around where they fell, and the simulation now emits an "eliminated" event when health reaches 0. Item definitions are ItemDef resources built by ItemCatalog from the tables in Tuning (WEAPONS, ITEMS and the new AMMO), so a new item is a data change only. Closes #19 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
## 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.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.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
|
||||
Reference in New Issue
Block a user