95 lines
3.7 KiB
C#
95 lines
3.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Xml.Linq;
|
|
|
|
namespace Harmony.SpawnPointManagerPatches
|
|
{
|
|
[HarmonyPatch(typeof(SpawnPointManager))]
|
|
[HarmonyPatch("Load")]
|
|
public class LoadPatch
|
|
{
|
|
public static bool Prefix(SpawnPointManager __instance, bool __result, string _path)
|
|
{
|
|
//Log.Out("===================================================================");
|
|
//Log.Out("SpawnPointManagerPatches-Load START");
|
|
//Log.Out("===================================================================");
|
|
|
|
int numFound = 0;
|
|
|
|
string biome = RebirthVariables.customBiomeSpawn;
|
|
|
|
if (biome == "random")
|
|
{
|
|
return true;
|
|
}
|
|
|
|
List<PrefabInstance> prefabInstances = GameManager.Instance.World.ChunkClusters[0].ChunkProvider.GetDynamicPrefabDecorator().GetDynamicPrefabs().FindAll(instance => instance.name.Contains("trader_"));
|
|
|
|
if (prefabInstances.Count > 0)
|
|
{
|
|
//Log.Out("SpawnPointManagerPatches-Load 1, prefabInstances.Count: " + prefabInstances.Count);
|
|
|
|
Vector3 vector = Vector3.zero;
|
|
|
|
for (int i = 0; i < prefabInstances.Count; i++)
|
|
{
|
|
//Log.Out("SpawnPointManagerPatches-Load 2, i: " + i);
|
|
|
|
//Log.Out("SpawnPointManagerPatches-Load 2, prefabInstances[i].name: " + prefabInstances[i].name);
|
|
|
|
Vector2 position = new Vector2((float)prefabInstances[i].boundingBoxPosition.x, (float)prefabInstances[i].boundingBoxPosition.z);
|
|
|
|
if (position.x == -0.1f && position.y == -0.1f)
|
|
{
|
|
//Log.Out("SpawnPointManagerPatches-Load 3");
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("SpawnPointManagerPatches-Load 4");
|
|
int num = (int)position.x;
|
|
int num2 = (int)position.y;
|
|
int num3 = (int)GameManager.Instance.World.GetHeightAt(position.x, position.y);
|
|
|
|
//Log.Out("SpawnPointManagerPatches-Load num3: " + num3);
|
|
|
|
Vector3 positionTrader = new Vector3((float)num, (float)num3, (float)num2);
|
|
numFound++;
|
|
__instance.spawnPointList.Add(new SpawnPoint(positionTrader, vector.y));
|
|
}
|
|
}
|
|
}
|
|
|
|
if (numFound == 0)
|
|
{
|
|
//Log.Out("SpawnPointManagerPatches-Load 7");
|
|
if (!SdFile.Exists(_path + "/spawnpoints.xml"))
|
|
{
|
|
__result = false;
|
|
return false;
|
|
}
|
|
try
|
|
{
|
|
foreach (XElement element in new XmlFile(_path, "spawnpoints", false, false).XmlDoc.Root.Elements("spawnpoint"))
|
|
{
|
|
Vector3 position = StringParsers.ParseVector3(element.GetAttribute("position"), 0, -1);
|
|
Vector3 vector = Vector3.zero;
|
|
if (element.HasAttribute("rotation"))
|
|
{
|
|
vector = StringParsers.ParseVector3(element.GetAttribute("rotation"), 0, -1);
|
|
}
|
|
__instance.spawnPointList.Add(new SpawnPoint(position, vector.y));
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error("Loading spawnpoints xml file for level '" + Path.GetFileName(_path) + "': " + ex.Message);
|
|
}
|
|
}
|
|
|
|
__result = true;
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
}
|