Per-player needs, jumping figure, round belt/shoulders/boots, reset-point UI
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using HutongGames.PlayMaker;
|
||||
|
||||
namespace MSCO
|
||||
{
|
||||
/// <summary>
|
||||
/// Bedürfnisse pro Spieler (Hunger, Durst, Stress, Harndrang, Müdigkeit, Schmutz): Im gemeinsamen Spielstand gibt es
|
||||
/// sie nur einmal - ohne das hätte jeder beim Beitreten die Werte desjenigen, der den Spielstand zuletzt hochgeladen
|
||||
/// hat. Deshalb schickt jeder seine eigenen Werte regelmäßig an den Server, der sie pro Spieler speichert und beim
|
||||
/// nächsten Beitreten zurückgibt.
|
||||
/// </summary>
|
||||
public static class PlayerNeeds
|
||||
{
|
||||
public static readonly string[] Names =
|
||||
{
|
||||
"PlayerHunger", "PlayerThirst", "PlayerStress", "PlayerUrine", "PlayerFatigue", "PlayerDirtiness"
|
||||
};
|
||||
|
||||
/// <summary>Eigene Werte: int n, je [string Name, float Wert]. null, wenn das Spiel sie (noch) nicht hat.</summary>
|
||||
public static byte[] Build()
|
||||
{
|
||||
var values = new List<KeyValuePair<string, float>>();
|
||||
foreach (string name in Names)
|
||||
{
|
||||
FsmFloat f = FsmVariables.GlobalVariables.FindFsmFloat(name);
|
||||
if (f != null && !float.IsNaN(f.Value) && !float.IsInfinity(f.Value)) values.Add(new KeyValuePair<string, float>(name, f.Value));
|
||||
}
|
||||
if (values.Count == 0) return null;
|
||||
return NetSession.Build(w =>
|
||||
{
|
||||
w.Write(values.Count);
|
||||
foreach (KeyValuePair<string, float> v in values) { w.Write(v.Key); w.Write(v.Value); }
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>Gespeicherte Werte vom Server übernehmen (Format wie Build).</summary>
|
||||
public static int Apply(BinaryReader r)
|
||||
{
|
||||
int count = r.ReadInt32();
|
||||
int applied = 0;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
string name = r.ReadString();
|
||||
float value = r.ReadSingle();
|
||||
if (System.Array.IndexOf(Names, name) < 0 || float.IsNaN(value) || float.IsInfinity(value)) continue;
|
||||
FsmFloat f = FsmVariables.GlobalVariables.FindFsmFloat(name);
|
||||
if (f == null) continue;
|
||||
f.Value = value;
|
||||
applied++;
|
||||
}
|
||||
return applied;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user