fix: an event's teardown removes a boss's adds (D287)
All checks were successful
PR Checks / plugin-checks (pull_request) Successful in -1m33s
All checks were successful
PR Checks / plugin-checks (pull_request) Successful in -1m33s
The walk found an event run's boss adds outliving the run: teardown removes what a step placed by net id, and the adds RunicNPC spawned for a boss's phase are in no step's ledger. RunicNPC now keeps each boss's live adds by the boss's net id, after the boss dies too, and RunicNpc_Despawn(<boss net id>) removes them with it, which is the call the bridge's teardown makes. An add leaves the set when it dies. Walked on the Oxide rig: event 36, run 65 placed the boss, its phase summoned two adds owned by run:65, the boss was killed, the event advanced on rust.boss.killed, and the run's cleanup removed both adds. New harness check s6.boss.despawnTakesAdds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E14m6SuuY6i1vASFeGDBeY
This commit is contained in:
@@ -3212,6 +3212,10 @@ namespace Oxide.Plugins
|
||||
Index(npc, false);
|
||||
if (npc.IsBoss)
|
||||
ClearBar(npc);
|
||||
if (_addsOf.Count > 0)
|
||||
foreach (ulong boss in _addsOf.Keys.ToList())
|
||||
if (_addsOf[boss].Remove(npc) && _addsOf[boss].Count == 0)
|
||||
_addsOf.Remove(boss);
|
||||
|
||||
if (npc.PlacementId != null)
|
||||
{
|
||||
@@ -3542,6 +3546,12 @@ namespace Oxide.Plugins
|
||||
/// <summary>The bosses alive now.</summary>
|
||||
private readonly HashSet<RunicNpcPlayer> _bosses = new HashSet<RunicNpcPlayer>();
|
||||
|
||||
/// <summary>
|
||||
/// Each boss's live adds, by the boss's net id, kept after the boss dies (D287) so that despawning
|
||||
/// the boss's id removes them too. An add leaves its set when it dies or despawns.
|
||||
/// </summary>
|
||||
private readonly Dictionary<ulong, HashSet<RunicNpcPlayer>> _addsOf = new Dictionary<ulong, HashSet<RunicNpcPlayer>>();
|
||||
|
||||
/// <summary>Whose bar each player sees, by Steam id: one boss at a time, the nearest that qualifies (D274).</summary>
|
||||
private readonly Dictionary<ulong, RunicNpcPlayer> _barShown = new Dictionary<ulong, RunicNpcPlayer>();
|
||||
|
||||
@@ -3692,6 +3702,7 @@ namespace Oxide.Plugins
|
||||
|
||||
Vector3 centre = boss.transform.position;
|
||||
string owner = boss.Owner;
|
||||
ulong bossId = boss.NetId;
|
||||
var attackers = boss.Contributors.Keys.ToList();
|
||||
float turn = UnityEngine.Random.value * Mathf.PI * 2f;
|
||||
int i = 0;
|
||||
@@ -3712,12 +3723,18 @@ namespace Oxide.Plugins
|
||||
if (add == null)
|
||||
PrintWarning($"{boss.RnName} ({boss.ProfileName}): add {i + 1} of {adds.Count} ('{adds.Profile}') not placed: {error}");
|
||||
else
|
||||
{
|
||||
HashSet<RunicNpcPlayer> mine;
|
||||
if (!_addsOf.TryGetValue(bossId, out mine))
|
||||
_addsOf[bossId] = mine = new HashSet<RunicNpcPlayer>();
|
||||
mine.Add(add);
|
||||
foreach (ulong id in attackers)
|
||||
{
|
||||
BasePlayer who = BasePlayer.FindByID(id);
|
||||
if (who != null && who.IsAlive() && Vector3.Distance(who.transform.position, add.transform.position) <= 100f)
|
||||
Learn(add, who, true);
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
if (i < adds.Count)
|
||||
@@ -4251,10 +4268,25 @@ namespace Oxide.Plugins
|
||||
return npc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes one NPC, and for a boss the adds it summoned, alive or not (D287): an event's teardown
|
||||
/// removes what its step placed by net id, and a boss's adds are in no step's ledger. The boss may
|
||||
/// already be dead; its adds are still found by its net id.
|
||||
/// </summary>
|
||||
private int RunicNpc_Despawn(ulong netId)
|
||||
{
|
||||
var gone = new List<RunicNpcPlayer>();
|
||||
RunicNpcPlayer npc;
|
||||
return _npcs.TryGetValue(netId, out npc) ? Despawn(new[] { npc }) : 0;
|
||||
if (_npcs.TryGetValue(netId, out npc))
|
||||
gone.Add(npc);
|
||||
HashSet<RunicNpcPlayer> adds;
|
||||
if (_addsOf.TryGetValue(netId, out adds))
|
||||
{
|
||||
gone.AddRange(adds);
|
||||
_addsOf.Remove(netId);
|
||||
}
|
||||
|
||||
return Despawn(gone);
|
||||
}
|
||||
|
||||
private int RunicNpc_DespawnOwner(string owner) => owner == null ? 0 : Despawn(_npcs.Values.Where(n => n.Owner == owner));
|
||||
|
||||
Reference in New Issue
Block a user