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:
2026-11-11 17:19:45 -05:00
co-authored by Claude Opus 5.5
parent ced13f1f42
commit e58d6140cc
12 changed files with 800 additions and 3 deletions
+77
View File
@@ -0,0 +1,77 @@
## 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
## 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
@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)
func reload_ticks() -> int:
return roundi(reload_seconds * Tuning.TICK_RATE_HZ)
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)