using System.Collections.Generic;
using HutongGames.PlayMaker;
using UnityEngine;
namespace MSCO
{
///
/// Admin-Cheats für den eigenen Spieler (Geld, Bedürfnisse). Nur aus dem Admin-Menü erreichbar, also nur für
/// Server-Admins bzw. den P2P-Host. Geld wird über MoneySync automatisch an alle weitergegeben.
///
public static class Cheats
{
// Globale PlayMaker-Variablen des Spielers: Wert, auf den "auffüllen" sie setzt
static readonly KeyValuePair[] Needs =
{
new KeyValuePair("PlayerHunger", 0f),
new KeyValuePair("PlayerThirst", 0f),
new KeyValuePair("PlayerStress", 0f),
new KeyValuePair("PlayerUrine", 0f),
new KeyValuePair("PlayerFatigue", 0f),
new KeyValuePair("PlayerDirtiness", 0f),
};
public static string AddMoney(float amount)
{
FsmFloat money = FsmVariables.GlobalVariables.FindFsmFloat("PlayerMoney");
if (money == null) return "Money not found (only works in the game)";
money.Value += amount;
return "+" + amount.ToString("0") + " MK (now " + money.Value.ToString("0") + " MK)";
}
public static string FillNeeds()
{
int done = 0;
foreach (KeyValuePair need in Needs)
{
FsmFloat v = FsmVariables.GlobalVariables.FindFsmFloat(need.Key);
if (v == null) continue;
v.Value = need.Value;
done++;
}
return done > 0 ? "Hunger, thirst, stress, fatigue, bladder and dirt reset" : "Player needs not found (only works in the game)";
}
/// Teleport-Ziele im Admin-Menü: Anzeigename und Objekt im Spiel.
public static readonly string[][] Places =
{
new[] { "Home", "YARD" }, new[] { "Shop (Teimo)", "STORE" }, new[] { "Repair shop", "REPAIRSHOP" },
new[] { "Inspection", "INSPECTION" }, new[] { "Peräjärvi", "PERAJARVI" }, new[] { "Landfill", "LANDFILL" },
new[] { "Dance hall", "DANCEHALL" }, new[] { "Cottage", "COTTAGE" }, new[] { "Cabin", "CABIN" },
new[] { "Rally", "RALLY" }, new[] { "Drag race", "DRAGRACE" }, new[] { "Soccer field", "SOCCER" },
new[] { "Kilju buyer", "KILJUGUY" }, new[] { "Theatre", "THEATRE" }, new[] { "Satsuma", "SATSUMA" },
};
///
/// Wohin bei einem Teleport-Ziel? Neben das Objekt (Mitte seiner sichtbaren Teile, ein Stück außerhalb, damit man
/// nicht im Dach oder in einer Wand landet) und dort auf den Boden.
///
public static bool FindPlace(string objectName, out Vector3 position)
{
position = Vector3.zero;
GameObject root = FindRoot(objectName);
if (root == null) return false;
Bounds bounds = new Bounds(root.transform.position, Vector3.zero);
bool any = false;
foreach (Renderer r in root.GetComponentsInChildren(true))
{
if (r == null || r.bounds.size == Vector3.zero) continue;
if (!any) { bounds = r.bounds; any = true; }
else bounds.Encapsulate(r.bounds);
}
Vector3 center = bounds.center;
float ox = Mathf.Min(bounds.extents.x, 25f) + 3f, oz = Mathf.Min(bounds.extents.z, 25f) + 3f;
Vector3[] candidates =
{
center + new Vector3(ox, 0f, 0f), center + new Vector3(-ox, 0f, 0f),
center + new Vector3(0f, 0f, oz), center + new Vector3(0f, 0f, -oz), center,
};
foreach (Vector3 c in candidates)
{
Vector3 ground;
if (Ground(c, bounds.max.y + 30f, out ground)) { position = ground; return true; }
}
position = center;
return true;
}
static GameObject FindRoot(string name)
{
GameObject go = GameObject.Find(name);
if (go != null) return go;
// auch ausgeblendete Objekte (das Spiel schaltet entfernte Orte ab)
foreach (GameObject candidate in Resources.FindObjectsOfTypeAll())
if (candidate.name == name && candidate.transform.parent == null && candidate.hideFlags == HideFlags.None) return candidate;
return null;
}
/// Höchster fester Boden unter einem Punkt (ohne Trigger).
static bool Ground(Vector3 at, float top, out Vector3 ground)
{
ground = at;
bool found = false;
foreach (RaycastHit hit in Physics.RaycastAll(new Vector3(at.x, top, at.z), Vector3.down, 1000f))
{
if (hit.collider == null || hit.collider.isTrigger || hit.normal.y < 0.6f) continue;
if (!found || hit.point.y > ground.y) { ground = hit.point; found = true; }
}
return found;
}
/// Eigenen Spieler an eine Position setzen (etwas darüber, damit er nicht im Boden steckt).
public static bool Teleport(Transform player, Vector3 position)
{
if (player == null) return false;
player.position = position + Vector3.up * 0.3f;
Rigidbody rb = player.GetComponent();
if (rb != null && !rb.isKinematic) rb.velocity = Vector3.zero;
return true;
}
}
}