reset-world restores the original save (reset point in data/save_original), set-reset-point; per-player needs stored and returned; tests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,8 @@ public sealed class WorldState
|
||||
public Dictionary<int, ObjectPose> Objects { get; set; } = new();
|
||||
/// <summary>FsmEvent-Payloads (Base64) in der Reihenfolge, in der sie passiert sind.</summary>
|
||||
public List<string> Events { get; set; } = new();
|
||||
/// <summary>SteamID64 -> eigene Bedürfnisse (Hunger, Durst, Stress ...), Name -> Wert.</summary>
|
||||
public Dictionary<string, Dictionary<string, float>> PlayerNeeds { get; set; } = new();
|
||||
/// <summary>SteamID64 -> letzte Position.</summary>
|
||||
public Dictionary<string, float[]> PlayerPositions { get; set; } = new();
|
||||
/// <summary>Summe aller Geldänderungen seit dem Ausgangs-Spielstand (gemeinsame Kasse).</summary>
|
||||
@@ -74,6 +76,7 @@ public sealed class WorldState
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
PlayerNeeds.Clear();
|
||||
Spawns.Clear();
|
||||
Appeared.Clear();
|
||||
Destroyed.Clear();
|
||||
@@ -215,6 +218,30 @@ public sealed class WorldState
|
||||
Dirty = true;
|
||||
}
|
||||
|
||||
/// <summary>PlayerNeeds: int n, je [string Name, float Wert]. Werte werden begrenzt, Unsinn verworfen.</summary>
|
||||
public void ApplyNeeds(string steamId, byte[] payload)
|
||||
{
|
||||
if (string.IsNullOrEmpty(steamId) || payload.Length > 1024) return;
|
||||
try
|
||||
{
|
||||
using var r = new BinaryReader(new MemoryStream(payload));
|
||||
int count = r.ReadInt32();
|
||||
if (count < 0 || count > 16) return;
|
||||
var needs = new Dictionary<string, float>();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
string name = r.ReadString();
|
||||
float value = r.ReadSingle();
|
||||
if (name.Length == 0 || name.Length > 40 || !float.IsFinite(value)) continue;
|
||||
needs[name] = Math.Clamp(value, -1000f, 1000f);
|
||||
}
|
||||
if (needs.Count == 0) return;
|
||||
PlayerNeeds[steamId] = needs;
|
||||
Dirty = true;
|
||||
}
|
||||
catch (EndOfStreamException) { }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Snapshot für neue Spieler
|
||||
|
||||
/// <summary>
|
||||
@@ -280,6 +307,16 @@ public sealed class WorldState
|
||||
}
|
||||
w.Write(Destroyed.Count);
|
||||
foreach (int id in Destroyed) w.Write(id);
|
||||
|
||||
// Eigene Bedürfnisse des Beitretenden: bool vorhanden [int n, je string Name, float Wert]
|
||||
bool hasNeeds = steamId != null && PlayerNeeds.TryGetValue(steamId, out var own) && own.Count > 0;
|
||||
w.Write(hasNeeds);
|
||||
if (hasNeeds)
|
||||
{
|
||||
var needs = PlayerNeeds[steamId];
|
||||
w.Write(needs.Count);
|
||||
foreach (var kv in needs) { w.Write(kv.Key); w.Write(kv.Value); }
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user