Log inGet started
Package

BossSpawn.component

Newest version

README.md

BossSpawn

Puts one networked pixelBosses boss in a scene, the same one on every peer. Put it on a plain entity in a scene build (not entity.spawnSynced): its position is where the boss's feet stand, and its fields say which boss and its arena. It needs no sibling components; the boss it spawns is a separate entity carrying a pixelBosses.Boss2D.

local s = entity.spawn("BossSpawn_lair", { position = { 18, 1, 0 } })
s.component.add("pixelBosses.BossSpawn", { bossName = "Boss_lair", kind = "thornKnight",
    arenaMinX = 1, arenaMinY = 1, arenaMaxX = 23, arenaMaxY = 11, maxHealth = 12 })
-- in play, on any peer:
local id = s.component.get("pixelBosses.BossSpawn"):bossId()   -- or require("pixelBosses.api").byName("Boss_lair")
  • Spawn once: in play, after the room answers this peer's join and settle seconds pass, each peer looks for the boss by bossName. If the room already holds it, that is the boss. If not, the lowest peer id in the room spawns it with entity.spawnSynced and adds the Boss2D, so its synced state, health and moves reach every peer. A peer further down the order waits settle + rank * Bosses.SPAWN_STAGGER seconds before spawning, in case the lowest peer never does. If two ever exist, the owner of each one but the lowest id despawns its own.
  • Late joiners receive the existing boss from the room. The owner leaving hands it to a peer that stays (the engine's ownership handover), with its health kept. Re-entering play finds the boss the room still holds, or spawns a fresh one when the room is empty: never a duplicate.
  • Edit mode: shows and spawns nothing.
  • Why: a boss spawned with entity.spawnSynced inside a scene build reached a peer that entered play second without a replication record, so its fight never synced there.

Fields (all per peer, not synced): bossName (empty = this entity's name + _boss), kind, arenaMinX, arenaMinY, arenaMaxX, arenaMaxY, maxHealth (0 = the kind's default), settle. Methods: bossId() (nil until the boss exists on this peer), boss() (its Boss2D), name(). The decision itself is pixelBosses.api _spawnPlan, a pure function the tests drive.