Skip to content

Commit

Permalink
Merge pull request #6 from TRSasasusu/work-on-every-nh
Browse files Browse the repository at this point in the history
Fix player spawning to work on even in every PC
  • Loading branch information
2walker2 committed Jul 30, 2023
2 parents 715a555 + eba2047 commit 9400e08
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 6 deletions.
100 changes: 97 additions & 3 deletions FixPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,32 @@ namespace Evacuation {
public static class FixPatch {
static bool _canBeDamaged = false;
static bool _isRaftPushed = false;
static bool _wakeUp = false;
static float _wakeLength = 1f;
static bool _initialWakeUp = true;

Check warning on line 16 in FixPatch.cs

View workflow job for this annotation

GitHub Actions / Create Release

The field 'FixPatch._initialWakeUp' is assigned but its value is never used

Check warning on line 16 in FixPatch.cs

View workflow job for this annotation

GitHub Actions / Create Release

The field 'FixPatch._initialWakeUp' is assigned but its value is never used
static Coroutine _fixRaftCoroutine;
static Coroutine _fixPlayerSpawnPosition;

const string RAFT_PLATFORM_PATH = "LayeredLagoon_Body/Sector/Prefab_NOM_SimpleChair_NoSkeleton (1)";
const string RAFT_PATH = "LayeredLagoonRaft_Body";
const string SLEEPING_BAG_PATH = "TheCampground_Body/Sector/Props_HEA_CampsiteSleepingBag";
const string CAMPGROUND_PATH = "TheCampground_Body";

public static void Initialize() {
LoadManager.OnCompleteSceneLoad += (scene, loadScene) => {
if (loadScene == OWScene.SolarSystem) {
Evacuation.Log("SolarSystem is loaded");
if(_fixRaftCoroutine != null) {
Evacuation.Instance.StopCoroutine(_fixRaftCoroutine);
_fixRaftCoroutine = null;
}
_fixRaftCoroutine = Evacuation.Instance.StartCoroutine(FixRaft());
_fixPlayerSpawnPosition = Evacuation.Instance.StartCoroutine(FixPlayerSpawnPosition());
}
else if(loadScene == OWScene.TitleScreen) {
_initialWakeUp = true;
}
};
}
Expand Down Expand Up @@ -63,13 +79,73 @@ public static class FixPatch {
}
}

static IEnumerator FixPlayerSpawnPosition() {
Transform playerTransform = null;
Rigidbody playerRigidbody = null;
OWRigidbody playerOWRigidbody = null;
SpawnPoint spawnPoint = null;

float timeFromWakingUp = 0;

Vector3 velocity = Vector3.zero;
Vector3 prevPosOfPlayer = Vector3.zero;

while(true) {
//yield return new WaitForEndOfFrame();
yield return null;
if(!playerTransform) {
var player = GameObject.FindObjectOfType<PlayerCharacterController>();
if(player) {
playerTransform = player.transform;
playerRigidbody = player.GetComponent<Rigidbody>();
playerOWRigidbody = player.GetComponent<OWRigidbody>();
prevPosOfPlayer = player.transform.position;
Evacuation.Log("player is found");
}
}
if(!spawnPoint) {
var campground_body = GameObject.Find(CAMPGROUND_PATH);
if(campground_body) {
var spawnPointTransform = campground_body.transform.Find("PlayerSpawnPoint");
if(spawnPointTransform) {
spawnPoint = spawnPointTransform.GetComponent<SpawnPoint>();
Evacuation.Log("spawn point is found");
}
}
}
if(!playerTransform || !spawnPoint) {
continue;
}

var pos = spawnPoint.transform.position;
playerOWRigidbody.WarpToPositionRotation(pos, spawnPoint.transform.rotation);
velocity = spawnPoint._attachedBody.GetVelocity() + spawnPoint._attachedBody.GetPointTangentialVelocity(pos);
playerOWRigidbody.SetVelocity(velocity);

if(timeFromWakingUp > _wakeLength * 0.8f) {
yield break;
}
if(_wakeUp) {
timeFromWakingUp += Time.deltaTime;
}
}
}

[HarmonyPrefix]
[HarmonyPatch(typeof(RaftController), nameof(RaftController.OnPressInteract))]
public static void RaftController_OnPressInteract_Prefix() {
Evacuation.Log("Raft is pushed");
//Evacuation.Log("Raft is pushed");
_isRaftPushed = true;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerCameraEffectController), nameof(PlayerCameraEffectController.WakeUp))]
public static void PlayerCameraEffectController_WakeUp_Prefix(PlayerCameraEffectController __instance) {
_wakeUp = true;
_wakeLength = __instance._wakeLength;
Evacuation.Log($"Player is wake up. wakeLength: {_wakeLength}");
}

// Player does not get damaged before using their jetpack.
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerResources), nameof(PlayerResources.ApplyInstantDamage))]
Expand Down Expand Up @@ -115,8 +191,26 @@ public static class FixPatch {
//Evacuation.Log("Player is dead now");
_canBeDamaged = false;
_isRaftPushed = false;
Evacuation.Instance.StopCoroutine(_fixRaftCoroutine);
_fixRaftCoroutine = null;
_wakeUp = false;
_initialWakeUp = false;

//Evacuation.Instance.StopCoroutine(_fixRaftCoroutine); // this would move the raft when death (you can see it with closing your eyes)
//_fixRaftCoroutine = null;

Evacuation.Instance.StopCoroutine(_fixPlayerSpawnPosition);
_fixPlayerSpawnPosition = null;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(DeathManager), nameof(DeathManager.KillPlayer))]
public static bool DeathManager_KillPlayer_Prefix(DeathType deathType) {
if(deathType == DeathType.Meditation) {
return true;
}
if(_canBeDamaged) {
return true;
}
return false;
}
}
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "2walker2, Texture_Turtle, and Samster68",
"name": "Evacuation",
"uniqueName": "2walker2.Evacuation",
"version": "2.1.0",
"version": "2.1.2",
"owmlVersion": "2.9.0",
"dependencies": [ "xen.NewHorizons" ]
}
3 changes: 2 additions & 1 deletion planets/LayeredLagoonRaft.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"singularities": [
{
"position": {
"y": 50.0
"x": -5.0,
"y": 55.0
},
"horizonRadius": 10.0,
"distortRadius": 11.0,
Expand Down
2 changes: 1 addition & 1 deletion translations/japanese.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"Here we are in a completely different solar system, and still the Nomai have left their mark.": "ここで私たちはまったく別の星系にいるが、それでもNomaiはその痕跡を残している。",
"Do you still have that translator tool? Perhaps you could <![CDATA[<color=orange>go give Riebeck a hand</color>]]>?": "まだあの翻訳機は持っているよな?もしかしたら<![CDATA[<color=orange>Riebeckに手を貸せる</color>]]>かもしれない。",
"You know how to find them.": "あいつを見つける方法は知っているだろうし。",
"It seems to be coming from the <![CDATA[<color=orange>large blue planet</color>]]>. We can't seem to pinpoint it closer than that.": "<![CDATA[<color=orange>大きなあの白い惑星</color>]]>からだ。それ以上はここからだと特定できないな。",
"It seems to be coming from the <![CDATA[<color=orange>large blue planet</color>]]>. We can't seem to pinpoint it closer than that.": "<![CDATA[<color=orange>大きなあの灰色の惑星</color>]]>からだ。それ以上はここからだと特定できないな。",

// Porphy
"The children wouldn't stop pestering me about dinner, so I told them to play the quiet game.": "子どもたちが夜ごはんのことでうるさいから、静かにするゲームをするように言ってるんだ。",
Expand Down

0 comments on commit 9400e08

Please sign in to comment.