2.8: relay bought/consumed items (stored for joiners), crash damage, job values, traffic (world authority only); tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-27 14:58:47 +02:00
co-authored by Claude Opus 5.5
parent b9c7d33294
commit 6f8474d66b
5 changed files with 85 additions and 4 deletions
+36
View File
@@ -30,6 +30,12 @@ public sealed class WorldState
/// <summary>Von Admins gespawnte Items (SpawnItem-Nachrichten, Base64), damit später Beitretende sie auch haben.</summary>
public List<string> Spawns { get; set; } = new();
public const int MaxSpawns = 2000;
/// <summary>Seit dem letzten Spielstand gekaufte/ausgepackte Items (ItemAppeared, Base64) - stecken danach im Spielstand.</summary>
public List<string> Appeared { get; set; } = new();
/// <summary>Seit dem letzten Spielstand verbrauchte Items (Objekt-IDs).</summary>
public List<int> Destroyed { get; set; } = new();
public const int MaxAppeared = 2000;
public const int MaxDestroyed = 5000;
public bool Dirty { get; private set; }
@@ -61,12 +67,16 @@ public sealed class WorldState
MoneyDelta = 0f;
Doors.Clear();
Vars.Clear();
Appeared.Clear();
Destroyed.Clear();
Dirty = true;
}
public void Reset()
{
Spawns.Clear();
Appeared.Clear();
Destroyed.Clear();
Objects.Clear();
Events.Clear();
PlayerPositions.Clear();
@@ -172,6 +182,21 @@ public sealed class WorldState
Dirty = true;
}
public void AddAppeared(byte[] payload)
{
if (Appeared.Count >= MaxAppeared) return;
Appeared.Add(Convert.ToBase64String(payload));
Dirty = true;
}
public void AddDestroyed(int id)
{
if (Destroyed.Count >= MaxDestroyed || Destroyed.Contains(id)) return;
Destroyed.Add(id);
Objects.Remove(id);
Dirty = true;
}
public void AddFsmEvent(byte[] payload)
{
if (Events.Count >= MaxEvents) return;
@@ -244,6 +269,17 @@ public sealed class WorldState
w.Write(bytes.Length);
w.Write(bytes);
}
// Gekaufte Items: int n, je [int Länge, ItemAppeared-Payload]; verbrauchte: int n, je int ID
w.Write(Appeared.Count);
foreach (string a in Appeared)
{
byte[] bytes = Convert.FromBase64String(a);
w.Write(bytes.Length);
w.Write(bytes);
}
w.Write(Destroyed.Count);
foreach (int id in Destroyed) w.Write(id);
});
}
}