using NewHorizons.External; using OWML.Utils; using System; using UnityEngine; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Builder.General { static class SpawnPointBuilder { private static bool suitUpQueued = false; public static SpawnPoint Make(GameObject body, SpawnModule module, OWRigidbody rb) { SpawnPoint playerSpawn = null; if(!Main.IsWarping && module.PlayerSpawnPoint != null) { GameObject spawnGO = new GameObject("PlayerSpawnPoint"); spawnGO.transform.parent = body.transform; spawnGO.layer = 8; spawnGO.transform.localPosition = module.PlayerSpawnPoint; playerSpawn = spawnGO.AddComponent(); spawnGO.transform.rotation = Quaternion.FromToRotation(Vector3.up, (playerSpawn.transform.position - body.transform.position).normalized); spawnGO.transform.position = spawnGO.transform.position + spawnGO.transform.TransformDirection(Vector3.up) * 2f; GameObject.FindObjectOfType().SetInitialSpawnPoint(playerSpawn); } if(module.ShipSpawnPoint != null) { GameObject spawnGO = new GameObject("ShipSpawnPoint"); spawnGO.transform.parent = body.transform; spawnGO.layer = 8; spawnGO.transform.localPosition = module.ShipSpawnPoint; var spawnPoint = spawnGO.AddComponent(); spawnPoint.SetValue("_isShipSpawn", true); var ship = GameObject.Find("Ship_Body"); ship.transform.position = spawnPoint.transform.position; ship.transform.rotation = Quaternion.FromToRotation(Vector3.up, (spawnPoint.transform.position - body.transform.position).normalized); // Move it up a bit more ship.transform.position = ship.transform.position + ship.transform.TransformDirection(Vector3.up) * 5f; ship.GetRequiredComponent().SetBodyToMatch(rb); if(Main.IsWarping) { GameObject playerSpawnGO = new GameObject("PlayerSpawnPoint"); playerSpawnGO.transform.parent = ship.transform; playerSpawnGO.layer = 8; playerSpawnGO.transform.localPosition = Vector3.zero; playerSpawn = playerSpawnGO.AddComponent(); playerSpawnGO.transform.localRotation = Quaternion.Euler(0,0,0); GameObject.FindObjectOfType().SetInitialSpawnPoint(playerSpawn); } } if(!Main.IsWarping && module.StartWithSuit && !suitUpQueued) { suitUpQueued = true; Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => SuitUp(), 4); } Logger.Log("Made spawnpoint on [" + body.name + "]"); return playerSpawn; } public static void SuitUp() { suitUpQueued = false; if (Locator.GetPlayerController()._isWearingSuit) return; try { var spv = GameObject.Find("Ship_Body/Module_Supplies/Systems_Supplies/ExpeditionGear").GetComponent(); spv.SetValue("_containsSuit", false); if (spv.GetValue("_allowSuitReturn")) spv.GetValue("_interactVolume").ChangePrompt(UITextType.ReturnSuitPrompt, spv.GetValue("_pickupSuitCommandIndex")); else spv.GetValue("_interactVolume").EnableSingleInteraction(false, spv.GetValue("_pickupSuitCommandIndex")); Locator.GetPlayerTransform().GetComponent().SuitUp(false, true, true); spv.SetValue("_timer", 0f); spv.SetValue("_index", 0); GameObject suitGeometry = spv.GetValue("_suitGeometry"); if (suitGeometry != null) suitGeometry.SetActive(false); OWCollider suitOWCollider = spv.GetValue("_suitOWCollider"); if (suitOWCollider != null) suitOWCollider.SetActivation(false); spv.enabled = true; } catch(Exception e) { Logger.LogWarning($"Was unable to suit up player. {e.Message}, {e.StackTrace}"); } } } }