private void OnTriggerEnter2D(Collider2D collision) { availability = SpawnPointStatus.UNAVAILABLE; if (spawnerManager.GetComponent <Spawner_Manager>().availableSpawnPoints.Contains(this.spawnerID)) { spawnerManager.GetComponent <Spawner_Manager>().availableSpawnPoints.Remove(this.spawnerID); } }
static bool Prefix(out Vector3 point, out bool usedLogoutPoint, float dt, Game __instance, ref bool __result) { Plugin.Log("FindSpawnPoint_Patch"); point = SpawnPoint; usedLogoutPoint = false; try { // let the original code run if (!Settings.MMRandomSpawnPointEnabled.Value) { return(true); } // we previously found a spawn point... if (FindSpawnPointStatus == SpawnPointStatus.Found) { ZNet.instance.SetReferencePosition(SpawnPoint); __result = ZNetScene.instance.IsAreaReady(SpawnPoint); return(false); } // if the status NotFound, then it's already searched and not found a spawn point, so run the default. if (FindSpawnPointStatus == SpawnPointStatus.NotFound) { return(true); } Plugin.LogVerbose("Does Player HaveLogoutPoint?"); if (__instance.m_playerProfile.HaveLogoutPoint()) { return(true); } Plugin.LogVerbose("Is Player dead?"); // If RandomSpawnOnDeath is TRUE and player is dead, then clear spawn point and also clear homepoint // if this is not the players first respawn in the game, then the player died.... // but the Player object isn't accessible at this level bool playerDied = false; if (!__instance.m_firstSpawn) { Plugin.LogVerbose($"Player died? yes"); playerDied = true; if (Settings.RandomSpawnOnDeath.Value) { Plugin.LogVerbose("Clear CustomSpawnPoint and Clearing SetHomePoint"); __instance.m_playerProfile.ClearCustomSpawnPoint(); __instance.m_playerProfile.SetHomePoint(Vector3.zero); } } else { Plugin.LogVerbose($"Player died? no"); } // we got here so... do the things.... __instance.m_respawnWait += dt; usedLogoutPoint = false; // copied this code because this needs to run to see if the player has a bed nearby and what to do // Above, we clear the CustomSpawnPoint if the settings are configured and the player has died... if (__instance.m_playerProfile.HaveCustomSpawnPoint()) { Plugin.LogVerbose("Player has CustomSpawnPoint"); Vector3 customSpawnPoint = __instance.m_playerProfile.GetCustomSpawnPoint(); ZNet.instance.SetReferencePosition(customSpawnPoint); if (__instance.m_respawnWait > 8f && ZNetScene.instance.IsAreaReady(customSpawnPoint)) { Bed bed = __instance.FindBedNearby(customSpawnPoint, 5f); if (bed != null) { Plugin.Log($"Found bed at custom spawn point"); point = bed.GetSpawnPoint(); __result = true; return(false); } Plugin.Log($"Failed to find bed at custom spawn point"); __instance.m_playerProfile.ClearCustomSpawnPoint(); // finally, If the player had a custom spawn point because of bed, but now does not... clear the home point. if (Settings.RandomSpawnOnDeathIfNoBed.Value) { __instance.m_playerProfile.SetHomePoint(Vector3.zero); } } else { // respawn wait time not long enough and/or scene isn't ready so return until it is // this tells the callee it's not found yet.. __result = false; // this tells the patch not to run the original code return(false); } } // the homepoint is set by UpdateRespawn however, we've patched it so it's never called (because it makes no sense for the original method to need to set this Vector3 homePoint = __instance.m_playerProfile.GetHomePoint(); // if the homepoint isn't vector3.zero AND the player had died... then use the homePoint // note: The homepoint was reset to Vector3.zero if the player needed to be forced to a new position. if (homePoint != Vector3.zero && playerDied) { point = homePoint; FindSpawnPointStatus = SpawnPointStatus.Found; SpawnPoint = point; ZNet.instance.SetReferencePosition(SpawnPoint); __result = ZNetScene.instance.IsAreaReady(SpawnPoint); __instance.m_playerProfile.SetHomePoint(SpawnPoint); return(false); } bool FoundSpawnPoint = FindNewSpawnPoint(Settings.Biome.Value, Settings.BiomeAreaType.Value, Settings.MinXDistance.Value, Settings.MaxXDistance.Value, Settings.MinZDistance.Value, Settings.MaxZDistance.Value, Settings.IgnoreWaterDepthCheck.Value, Settings.IgnoreWorldGeneratorConstraints.Value, Settings.MaxSpawnPointChecks.Value, out point); if (FoundSpawnPoint) { // this identifies that a new spawnpoint has been found (it's reset to Ready after user spawns) FindSpawnPointStatus = SpawnPointStatus.Found; SpawnPoint = point; ZNet.instance.SetReferencePosition(SpawnPoint); __result = ZNetScene.instance.IsAreaReady(SpawnPoint); __instance.m_playerProfile.SetHomePoint(SpawnPoint); return(false); } else { // not found so give up and go with the default search behavior FindSpawnPointStatus = SpawnPointStatus.NotFound; // just ensure the SpawnPoint is reset SpawnPoint = Vector3.zero; return(true); } } catch (Exception ex) { // do nothing, just log and swallow it up Plugin.LogError(ex.ToString()); } // just run the default... somehow we got here. return(true); }
public static void Reset() { SpawnPoint = Vector3.zero; FindSpawnPointStatus = SpawnPointStatus.Ready; }