B9: Loot tables and containers
Seeded loot at every point of interest's loot markers, rolled once per match from the "loot" stream by LootSet.plan() and placed by Simulation.place_loot(). - Each marker holds a sea chest (chance by location) or floor loot (rolls on the location's weapon/consumable/ammo/nothing weights). Weapons roll a tier from the location's tier weights and come with their ammunition; chests hold a weapon (best of two tier rolls), a consumable and spare ammunition. - Interact opens the nearest closed chest in reach unless a pickup is nearer, and spills its contents as pickups. - Washed-up crate props hold one roll of the crate table and spill it when broken by any means. - If the rolls leave fewer POI weapons than LOOT_MIN_POI_WEAPONS (one per player in a full lobby), extra weapon rolls top up floor spots. - Chest and crate state is part of state_hash(). ServerLoop places loot. Tests: test_loot (12), including a statistics run of 1,000 loot seeds over four generated islands that checks tier shares against the tables, that shrines beat hamlets, and that every match has a weapon per player at POIs and 1.25 per player counting crates. Closes #23 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+42
-1
@@ -33,6 +33,9 @@ var structures: StructureSet = StructureSet.new()
|
||||
## The sky barge, from start_drop() on. Null in matches and tests that start on foot.
|
||||
var drop: Drop = null
|
||||
|
||||
## Floor loot, sea chests and crate contents. Empty until place_loot().
|
||||
var loot: LootSet = LootSet.new()
|
||||
|
||||
## Items lying in the world, as entity IDs in ascending order. See Inventory.
|
||||
var pickups: Array[int] = []
|
||||
## Shots in flight, as entity IDs in ascending order. See Weapons.
|
||||
@@ -44,6 +47,8 @@ var events: Array[Dictionary] = []
|
||||
|
||||
## Player entity ID -> { command tick -> PlayerCommand }
|
||||
var _pending: Dictionary = {}
|
||||
## How many entries of props.destroyed have been checked for crate loot.
|
||||
var _destroyed_checked: int = 0
|
||||
## Player entity IDs, ascending.
|
||||
var _players: Array[int] = []
|
||||
|
||||
@@ -115,6 +120,26 @@ func start_drop() -> void:
|
||||
Drop.board(entities.find(player_id), drop.barge_position(tick))
|
||||
|
||||
|
||||
## Rolls the match's loot from the "loot" stream and puts the floor loot in the world.
|
||||
## Chests and crates spill theirs when opened or broken. Does nothing on a test ground
|
||||
## with no island, and only works once.
|
||||
func place_loot() -> void:
|
||||
if island == null or loot.floor_spots.size() + loot.chest_positions.size() + loot.crate_contents.size() > 0:
|
||||
return
|
||||
loot = LootSet.plan(rng.stream("loot"), pois.loot_markers(), crate_spill_points(props))
|
||||
loot.place_floor(self)
|
||||
|
||||
|
||||
## Each crate prop's index mapped to where its loot spills: the middle of its base.
|
||||
static func crate_spill_points(prop_set: PropSet) -> Dictionary:
|
||||
var points: Dictionary = {}
|
||||
for prop: int in prop_set.count():
|
||||
if prop_set.kind_name(prop) == LootSet.CRATE_KIND and prop_set.is_standing(prop):
|
||||
var box: AABB = prop_set.boxes[prop]
|
||||
points[prop] = Vector3(box.get_center().x, box.position.y, box.get_center().z)
|
||||
return points
|
||||
|
||||
|
||||
## Advances the simulation by one tick.
|
||||
func step() -> void:
|
||||
events.clear()
|
||||
@@ -133,6 +158,7 @@ func step() -> void:
|
||||
else:
|
||||
_apply_command(player, command)
|
||||
Weapons.advance_projectiles(self)
|
||||
_spill_broken_crates()
|
||||
_check_eliminations()
|
||||
if drop != null and not drop.finished and drop.is_over(tick + 1):
|
||||
# The end of the route: everyone still aboard goes over the side.
|
||||
@@ -170,7 +196,8 @@ func _apply_command(player: SimEntity, command: PlayerCommand) -> void:
|
||||
Inventory.select(player, command.selection)
|
||||
if Harvest.can_swing(player):
|
||||
if pressed & PlayerCommand.BUTTON_INTERACT:
|
||||
Inventory.interact(self, player)
|
||||
if loot.open_nearest(self, player) < 0:
|
||||
Inventory.interact(self, player)
|
||||
if pressed & PlayerCommand.BUTTON_DROP:
|
||||
Inventory.drop_held(self, player)
|
||||
if command != null and command.is_pressed(PlayerCommand.BUTTON_RELOAD):
|
||||
@@ -192,6 +219,19 @@ func _apply_command(player: SimEntity, command: PlayerCommand) -> void:
|
||||
Weapons.fire(self, player, command.is_pressed(PlayerCommand.BUTTON_AIM))
|
||||
|
||||
|
||||
## Spills the loot of every crate destroyed since the last check, however it broke.
|
||||
func _spill_broken_crates() -> void:
|
||||
while _destroyed_checked < props.destroyed.size():
|
||||
var prop: int = props.destroyed[_destroyed_checked]
|
||||
_destroyed_checked += 1
|
||||
if not loot.crate_contents.has(prop):
|
||||
continue
|
||||
var box: AABB = props.boxes[prop]
|
||||
var at: Vector3 = Vector3(box.get_center().x, box.position.y, box.get_center().z)
|
||||
var ids: Array[int] = loot.spill_crate(self, prop, at)
|
||||
events.append({"type": "crate_spilled", "prop": prop, "pickups": ids})
|
||||
|
||||
|
||||
## Marks players whose health reached 0 as eliminated, and drops what they carried.
|
||||
func _check_eliminations() -> void:
|
||||
for player_id: int in _players:
|
||||
@@ -282,6 +322,7 @@ func state_hash() -> String:
|
||||
buffer.put_64(props.count())
|
||||
buffer.put_data(props.health.to_byte_array())
|
||||
structures.write_state(buffer)
|
||||
loot.write_state(buffer)
|
||||
|
||||
var hasher: HashingContext = HashingContext.new()
|
||||
hasher.start(HashingContext.HASH_SHA256)
|
||||
|
||||
Reference in New Issue
Block a user