2.8: sync bought/consumed items, wheel spin, crash damage, jobs/shop, traffic

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-27 14:58:38 +02:00
co-authored by Claude Opus 5.5
parent 96e8790f0b
commit 2eb15f2166
12 changed files with 799 additions and 17 deletions
+22 -5
View File
@@ -47,12 +47,13 @@ namespace MSCO
return objectNames.TryGetValue(item, out name) ? name : item + "(itemx)";
}
static GameObject FindTemplate(string item)
static GameObject FindTemplate(string item) { return FindTemplateByObjectName(ObjectName(item)); }
static GameObject FindTemplateByObjectName(string name)
{
GameObject cached;
if (templates.TryGetValue(item, out cached) && cached != null) return cached;
if (templates.TryGetValue(name, out cached) && cached != null) return cached;
string name = ObjectName(item);
GameObject best = null;
foreach (Object o in Resources.FindObjectsOfTypeAll(typeof(GameObject)))
{
@@ -62,20 +63,36 @@ namespace MSCO
if (go.transform.parent != null && go.transform.parent.GetComponentInParent<Rigidbody>() != null) continue;
if (best == null || (go.activeInHierarchy && !best.activeInHierarchy)) best = go; // am liebsten eins aus der Welt
}
templates[item] = best;
templates[name] = best;
return best;
}
/// <summary>Zuletzt erzeugtes Objekt (damit der Objekt-Sync es nicht als "neu gekauft" meldet).</summary>
public static GameObject LastSpawned { get; private set; }
/// <summary>Item nach seinem Objektnamen erzeugen (z.B. "beer case(itemx)") - für Einkäufe anderer Spieler.</summary>
public static bool SpawnObjectNamed(string objectName, Vector3 position, Quaternion rotation)
{
if (string.IsNullOrEmpty(objectName) || !objectName.EndsWith("(itemx)") || objectName.Length > 100) return false;
return SpawnTemplate(FindTemplateByObjectName(objectName), objectName, position, rotation);
}
/// <summary>Item erzeugen. Gibt false zurück, wenn es im Spiel kein solches Item gibt.</summary>
public static bool Spawn(string item, Vector3 position, Quaternion rotation)
{
GameObject template = FindTemplate(item);
return SpawnTemplate(FindTemplate(item), item, position, rotation);
}
static bool SpawnTemplate(GameObject template, string item, Vector3 position, Quaternion rotation)
{
LastSpawned = null;
if (template == null)
{
MscoLog.Warning("Cannot spawn '" + item + "' - no such item in this game");
return false;
}
var clone = (GameObject)Object.Instantiate(template, position, rotation);
LastSpawned = clone;
clone.name = template.name;
clone.transform.SetParent(null, true);
clone.SetActive(true);