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>
This commit is contained in:
2026-11-11 17:26:04 -05:00
co-authored by Claude Opus 5.5
parent ed46b6e19f
commit 5d2a2bbc31
12 changed files with 434 additions and 22 deletions
+49
View File
@@ -0,0 +1,49 @@
## Using bandages, tonics, vests and patches. Fire with a consumable held starts using
## it, if it would do something: heal below its cap, or add armor below the maximum.
## It takes effect after the item's use time and uses up one from the stack.
##
## The server checks everything. Changing slot, dropping or swapping the item,
## sprinting, swimming or being eliminated interrupts it, and nothing is used up.
class_name Consumables
extends RefCounted
## True if using the item now would change anything.
static func would_help(player: SimEntity, def: ItemDef) -> bool:
if def.heal > 0 and player.health < mini(def.heal_cap, Tuning.PLAYER_MAX_HEALTH):
return true
return def.armor > 0 and player.armor < Tuning.PLAYER_MAX_ARMOR
## Starts using the held consumable. Returns true if it started.
static func start(sim: Simulation, player: SimEntity) -> bool:
var def: ItemDef = Inventory.held_def(player)
if def == null or def.kind != ItemDef.CONSUMABLE or player.use_ticks > 0:
return false
if player.action_cooldown > 0 or not would_help(player, def):
return false
player.use_ticks = maxi(def.use_ticks(), 1)
sim.events.append({"type": "use_started", "player": player.id, "item": def.code})
return true
## Advances a use in progress. Called every tick for a player on foot.
static func update(sim: Simulation, player: SimEntity, command: PlayerCommand) -> void:
if player.use_ticks <= 0:
return
var def: ItemDef = Inventory.held_def(player)
var sprinting: bool = command != null and command.is_pressed(PlayerCommand.BUTTON_SPRINT) and command.move_vector().length() > 0.0
if def == null or def.kind != ItemDef.CONSUMABLE or sprinting or player.swimming or player.health <= 0:
player.use_ticks = 0
sim.events.append({"type": "use_cancelled", "player": player.id})
return
player.use_ticks -= 1
if player.use_ticks > 0:
return
if def.heal > 0:
var cap: int = mini(def.heal_cap, Tuning.PLAYER_MAX_HEALTH)
player.health = maxi(player.health, mini(player.health + def.heal, cap))
if def.armor > 0:
player.armor = mini(player.armor + def.armor, Tuning.PLAYER_MAX_ARMOR)
Inventory.take_from_slot(player, Inventory.held_slot(player))
sim.events.append({"type": "item_used", "player": player.id, "item": def.code})
+1
View File
@@ -0,0 +1 @@
uid://bds3m0j8gf5ah
+4
View File
@@ -34,6 +34,7 @@ static func reset(player: SimEntity) -> void:
player.ammo.fill(0)
player.selected = 0
player.reload_ticks = 0
player.use_ticks = 0
## Index into SimEntity.ammo for an ammunition item code, or -1.
@@ -69,6 +70,7 @@ static func select(player: SimEntity, selection: int) -> void:
return
player.selected = selection
player.reload_ticks = 0
player.use_ticks = 0
player.action_cooldown = maxi(player.action_cooldown, roundi(Tuning.SWAP_SECONDS * Tuning.TICK_RATE_HZ))
@@ -158,6 +160,7 @@ static func interact(sim: Simulation, player: SimEntity) -> int:
var moved: int = mini(def.stack, pickup.item_count)
_fill(player, slot, pickup.item, moved, pickup.item_rounds, pickup.item_tier)
player.reload_ticks = 0
player.use_ticks = 0
taken = moved
_take_from_pickup(sim, pickup, taken)
var dropped: int = spawn_pickup(sim, spot, old[0], old[1], old[2], old[3])
@@ -181,6 +184,7 @@ static func drop_held(sim: Simulation, player: SimEntity) -> int:
sim.events.append({"type": "dropped", "player": player.id, "pickup": id, "item": player.slot_items[slot], "count": player.slot_counts[slot]})
_clear(player, slot)
player.reload_ticks = 0
player.use_ticks = 0
return id
+4
View File
@@ -59,6 +59,8 @@ static func _build() -> void:
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)
@@ -99,6 +101,8 @@ static func _weapon_def(id: String, stats: Dictionary, ammo_code: int) -> ItemDe
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
+14 -2
View File
@@ -30,6 +30,10 @@ const AMMO: int = 2
@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
@@ -40,6 +44,8 @@ const AMMO: int = 2
@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
@@ -61,8 +67,14 @@ 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)
## 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:
+2
View File
@@ -44,6 +44,8 @@ var slot_tiers: PackedInt32Array = PackedInt32Array()
var ammo: PackedInt32Array = PackedInt32Array()
## Ticks left on a reload of the held weapon; 0 when not reloading.
var reload_ticks: int = 0
## Ticks left using a consumable from the held slot; 0 when not using one.
var use_ticks: int = 0
## Extra spread from recent shots, in degrees.
var bloom: float = 0.0
## Buttons held last tick, so pick up and drop act once per press.
+7 -1
View File
@@ -162,6 +162,7 @@ func _apply_command(player: SimEntity, command: PlayerCommand) -> void:
if player.action_cooldown > 0:
player.action_cooldown -= 1
Weapons.update(player)
Consumables.update(self, player, command)
var held: int = command.buttons if command != null else 0
var pressed: int = held & ~player.prev_buttons
player.prev_buttons = held
@@ -184,7 +185,11 @@ func _apply_command(player: SimEntity, command: PlayerCommand) -> void:
if player.selected == BOATHOOK_SLOT:
Harvest.swing(player, ground, props, events, structures)
else:
Weapons.fire(self, player, command.is_pressed(PlayerCommand.BUTTON_AIM))
var def: ItemDef = Inventory.held_def(player)
if def != null and def.kind == ItemDef.CONSUMABLE:
Consumables.start(self, player)
else:
Weapons.fire(self, player, command.is_pressed(PlayerCommand.BUTTON_AIM))
## Marks players whose health reached 0 as eliminated, and drops what they carried.
@@ -249,6 +254,7 @@ func state_hash() -> String:
for array: PackedInt32Array in [entity.slot_items, entity.slot_counts, entity.slot_rounds, entity.slot_tiers, entity.ammo]:
buffer.put_data(array.to_byte_array())
buffer.put_32(entity.reload_ticks)
buffer.put_32(entity.use_ticks)
buffer.put_64(roundi(entity.bloom * 1000.0))
buffer.put_32(entity.prev_buttons)
buffer.put_u8(1 if entity.eliminated else 0)
+32 -5
View File
@@ -246,6 +246,7 @@ const AMMO: Dictionary = {
"cartridges": {"cap": 300, "pickup": 30},
"heavy_balls": {"cap": 30, "pickup": 6},
"lines": {"cap": 12, "pickup": 3},
"harpoons": {"cap": 10, "pickup": 3},
}
# Weapons. Falloff is linear from full damage at `range_full` to `falloff_min`
@@ -254,6 +255,8 @@ const AMMO: Dictionary = {
# degrees, which decays at BLOOM_DECAY_DEGREES_PER_SECOND while the weapon is ready. `projectile_speed` 0 means
# hitscan; otherwise shots fly at that speed under `projectile_gravity`. `ammo` names
# an AMMO type; a weapon with `stack` above 1 is thrown and is its own ammunition.
# `pull_speed` yanks the shooter towards where the shot lands, at that speed.
# `structure_factor` scales damage to built pieces and props (default 1).
const WEAPONS: Dictionary = {
"boathook": {
"damage": 20, "fire_rate": 1.5, "magazine": 0, "reload": 0.0,
@@ -275,6 +278,11 @@ const WEAPONS: Dictionary = {
"range_full": 30.0, "range_max": 80.0, "falloff_min": 0.5, "rarity": 0,
"spread": 0.8, "bloom": 0.6, "ammo": "cartridges", "headshot": 2.0,
},
"rivet_repeater": {
"damage": 17, "fire_rate": 11.0, "magazine": 35, "reload": 2.0,
"range_full": 12.0, "range_max": 45.0, "falloff_min": 0.4, "rarity": 0,
"spread": 2.4, "bloom": 0.25, "ammo": "cartridges", "headshot": 1.5,
},
"whalers_longgun": {
"damage": 105, "fire_rate": 0.5, "magazine": 1, "reload": 2.6,
"range_full": 120.0, "range_max": 350.0, "falloff_min": 0.7, "rarity": 2,
@@ -285,7 +293,13 @@ const WEAPONS: Dictionary = {
"damage": 0, "fire_rate": 0.6, "magazine": 3, "reload": 3.0,
"range_full": 45.0, "range_max": 45.0, "falloff_min": 1.0, "rarity": 2,
"spread": 0.0, "bloom": 0.0, "ammo": "lines",
"projectile_speed": 90.0, "projectile_gravity": 4.0,
"projectile_speed": 90.0, "projectile_gravity": 4.0, "pull_speed": 18.0,
},
"harpoon_gun": {
"damage": 70, "fire_rate": 0.9, "magazine": 1, "reload": 1.8,
"range_full": 25.0, "range_max": 70.0, "falloff_min": 0.6, "rarity": 1,
"spread": 0.6, "bloom": 0.0, "ammo": "harpoons", "headshot": 1.5,
"projectile_speed": 120.0, "projectile_gravity": 6.0, "structure_factor": 2.5,
},
"powder_keg": {
"damage": 80, "structure_damage": 400, "blast_radius": 6.0, "fuse": 3.0,
@@ -307,10 +321,23 @@ const HEADSHOT_MULTIPLIER: float = 1.5
const HEAD_HEIGHT: float = 0.35
## Shots against built pieces and props do this fraction of their player damage.
const WEAPON_STRUCTURE_FACTOR: float = 1.0
## Quality tiers, lowest first. Loot rolls a tier for each weapon it spawns. `damage`
## multiplies every hit and `reload` multiplies the reload time.
const WEAPON_TIERS: Array[Dictionary] = [
{"name": "rusted", "damage": 1.0, "reload": 1.0},
{"name": "seaworthy", "damage": 1.08, "reload": 0.95},
{"name": "brass_fitted", "damage": 1.16, "reload": 0.9},
{"name": "captains", "damage": 1.25, "reload": 0.85},
]
## A line pull also lifts the puller this fast, so it clears the ground.
const LINE_PULL_LIFT: float = 4.0
# Consumables
# Consumables. Fire with one held starts using it; it takes effect after `use_seconds`
# unless interrupted. `heal` restores health up to `heal_cap` (default full), `armor`
# adds armor up to PLAYER_MAX_ARMOR. An item that would do nothing can't be started.
const ITEMS: Dictionary = {
"sailcloth_bandage": {"heal": 25, "use_seconds": 3.0, "stack": 6},
"brine_tonic": {"heal": 60, "use_seconds": 8.0, "stack": 3},
"cork_vest": {"armor": 50, "use_seconds": 5.0, "stack": 2},
"sailcloth_bandage": {"heal": 25, "heal_cap": 75, "use_seconds": 3.0, "stack": 6, "rarity": 0},
"brine_tonic": {"heal": 60, "use_seconds": 8.0, "stack": 3, "rarity": 1},
"cork_vest": {"armor": 50, "use_seconds": 5.0, "stack": 2, "rarity": 1},
"tar_patch": {"armor": 20, "use_seconds": 2.0, "stack": 5, "rarity": 0},
}
+20 -6
View File
@@ -64,7 +64,7 @@ static func start_reload(player: SimEntity) -> bool:
return false
if player.ammo[Inventory.ammo_index(def.ammo_code)] <= 0:
return false
player.reload_ticks = maxi(def.reload_ticks(), 1)
player.reload_ticks = maxi(def.reload_ticks(player.slot_tiers[slot]), 1)
return true
@@ -207,6 +207,8 @@ static func body_box(player: SimEntity) -> AABB:
## Applies a pellet's hit. `distance` is from where the shot started.
static func _apply_hit(sim: Simulation, attacker: int, def: ItemDef, tier: int, hit: Hit, distance: float) -> void:
sim.events.append({"type": "impact", "player": attacker, "item": def.code, "point": hit.point, "hit": hit.kind, "target": hit.target})
if def.pull_speed > 0.0 and hit.kind != HIT_NONE:
_pull(sim, sim.entities.find(attacker), hit.point, def.pull_speed)
if def.damage <= 0:
return
var amount: float = def.damage_at(distance) * tier_multiplier(tier)
@@ -216,15 +218,27 @@ static func _apply_hit(sim: Simulation, attacker: int, def: ItemDef, tier: int,
amount *= def.headshot_multiplier
damage_player(sim, sim.entities.find(hit.target), roundi(amount), attacker, hit.headshot)
HIT_PIECE:
sim.damage_piece(hit.target, roundi(amount * Tuning.WEAPON_STRUCTURE_FACTOR), "weapon")
sim.damage_piece(hit.target, roundi(amount * def.structure_factor), "weapon")
HIT_PROP:
if sim.damage_prop(hit.target, roundi(amount * Tuning.WEAPON_STRUCTURE_FACTOR)):
if sim.damage_prop(hit.target, roundi(amount * def.structure_factor)):
sim.events.append({"type": "prop_destroyed", "prop": hit.target})
## Damage multiplier for a quality tier. Tiers arrive with the weapon roster (B7).
static func tier_multiplier(_tier: int) -> float:
return 1.0
## Damage multiplier for a quality tier, from Tuning.WEAPON_TIERS.
static func tier_multiplier(tier: int) -> float:
return float(ItemDef.tier_stats(tier)["damage"])
## Yanks a player on foot towards `point`, lifting them off the ground.
static func _pull(sim: Simulation, player: SimEntity, point: Vector3, speed: float) -> void:
if player == null or player.eliminated or player.drop_state != Drop.NONE or player.swimming:
return
var direction: Vector3 = point - Harvest.eye(player)
if direction.length_squared() < 0.0001:
return
player.velocity = direction.normalized() * speed + Vector3(0.0, Tuning.LINE_PULL_LIFT, 0.0)
player.on_ground = false
sim.events.append({"type": "line_pull", "player": player.id, "point": point})
## Takes `amount` from armor, then health. Returns the damage actually done.