mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-03-11 10:14:17 +00:00
add moon stuff
This commit is contained in:
parent
9117e223fb
commit
eec388a3d3
@ -41,6 +41,7 @@
|
||||
public static string QSBSocketStateChange = "QSBSocketStateChange";
|
||||
public static string QSBMultiStateChange = "QSBMultiStateChange";
|
||||
public static string QSBQuantumShuffle = "QSBQuantumShuffle";
|
||||
public static string QSBMoonStateChange = "QSBMoonStateChange";
|
||||
public static string QSBIdentifyFrequency = "QSBIdentifyFrequency";
|
||||
public static string QSBIdentifySignal = "QSBIdentifySignal";
|
||||
public static string QSBTextTranslated = "QSBTextTranslated";
|
||||
|
@ -29,6 +29,7 @@
|
||||
SocketStateChange,
|
||||
MultiStateChange,
|
||||
QuantumShuffle,
|
||||
MoonStateChange,
|
||||
IdentifyFrequency,
|
||||
IdentifySignal,
|
||||
TextTranslated
|
||||
|
@ -52,6 +52,7 @@ namespace QSB.Events
|
||||
new MultiStateChangeEvent(),
|
||||
new SetAsTranslatedEvent(),
|
||||
new QuantumShuffleEvent(),
|
||||
new MoonStateChangeEvent(),
|
||||
// Conversation/dialogue/exploration
|
||||
new ConversationEvent(),
|
||||
new ConversationStartEndEvent(),
|
||||
|
@ -78,7 +78,7 @@ namespace QSB.Player
|
||||
public static List<OWCamera> GetPlayerCameras()
|
||||
{
|
||||
var cameraList = PlayerList.Where(x => x.Camera != null).Select(x => x.Camera).ToList();
|
||||
cameraList.Add(Locator.GetPlayerCamera());
|
||||
cameraList.Add(Locator.GetActiveCamera());
|
||||
return cameraList;
|
||||
}
|
||||
}
|
||||
|
@ -190,6 +190,8 @@
|
||||
<Compile Include="Patches\QSBPatch.cs" />
|
||||
<Compile Include="Patches\QSBPatchTypes.cs" />
|
||||
<Compile Include="QSBSceneManager.cs" />
|
||||
<Compile Include="QuantumSync\Events\MoonStateChangeEvent.cs" />
|
||||
<Compile Include="QuantumSync\Events\MoonStateChangeMessage.cs" />
|
||||
<Compile Include="QuantumSync\Events\QuantumShuffleEvent.cs" />
|
||||
<Compile Include="QuantumSync\Events\QuantumShuffleMessage.cs" />
|
||||
<Compile Include="QuantumSync\Patches\ClientQuantumStateChangePatches.cs" />
|
||||
|
51
QSB/QuantumSync/Events/MoonStateChangeEvent.cs
Normal file
51
QSB/QuantumSync/Events/MoonStateChangeEvent.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using OWML.Utils;
|
||||
using QSB.Events;
|
||||
using QSB.Utility;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.QuantumSync.Events
|
||||
{
|
||||
public class MoonStateChangeEvent : QSBEvent<MoonStateChangeMessage>
|
||||
{
|
||||
public override QSB.Events.EventType Type => QSB.Events.EventType.MoonStateChange;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger<int, Vector3, int>.AddListener(EventNames.QSBMoonStateChange, Handler);
|
||||
public override void CloseListener() => GlobalMessenger<int, Vector3, int>.RemoveListener(EventNames.QSBMoonStateChange, Handler);
|
||||
|
||||
private void Handler(int stateIndex, Vector3 onUnitSphere, int orbitAngle) => SendEvent(CreateMessage(stateIndex, onUnitSphere, orbitAngle));
|
||||
|
||||
private MoonStateChangeMessage CreateMessage(int stateIndex, Vector3 onUnitSphere, int orbitAngle) => new MoonStateChangeMessage
|
||||
{
|
||||
AboutId = LocalPlayerId,
|
||||
StateIndex = stateIndex,
|
||||
OnUnitSphere = onUnitSphere,
|
||||
OrbitAngle = orbitAngle
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(bool server, MoonStateChangeMessage message)
|
||||
{
|
||||
if (!QSBCore.HasWokenUp)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DebugLog.DebugWrite($"MOON TO INDEX {message.StateIndex}, ANGLE {message.OrbitAngle}, POINT {message.OnUnitSphere}");
|
||||
var moon = Locator.GetQuantumMoon();
|
||||
var moonBody = moon.GetValue<OWRigidbody>("_moonBody");
|
||||
var constantFoceDetector = (ConstantForceDetector)moonBody.GetAttachedForceDetector();
|
||||
var orbits = moon.GetValue<QuantumOrbit[]>("_orbits");
|
||||
var orbit = orbits.First(x => x.GetStateIndex() == message.StateIndex);
|
||||
var orbitRadius = orbit.GetOrbitRadius();
|
||||
var owRigidbody = orbit.GetAttachedOWRigidbody();
|
||||
var position = (message.OnUnitSphere * orbitRadius) + owRigidbody.GetWorldCenterOfMass();
|
||||
moonBody.transform.position = position;
|
||||
if (!Physics.autoSyncTransforms)
|
||||
{
|
||||
Physics.SyncTransforms();
|
||||
}
|
||||
constantFoceDetector.AddConstantVolume(owRigidbody.GetAttachedGravityVolume(), true, true);
|
||||
moonBody.SetVelocity(OWPhysics.CalculateOrbitVelocity(owRigidbody, moonBody, message.OrbitAngle) + owRigidbody.GetVelocity());
|
||||
moon.SetValue("_stateIndex", message.StateIndex);
|
||||
}
|
||||
}
|
||||
}
|
29
QSB/QuantumSync/Events/MoonStateChangeMessage.cs
Normal file
29
QSB/QuantumSync/Events/MoonStateChangeMessage.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using QSB.Messaging;
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.QuantumSync.Events
|
||||
{
|
||||
public class MoonStateChangeMessage : PlayerMessage
|
||||
{
|
||||
public int StateIndex { get; set; }
|
||||
public Vector3 OnUnitSphere { get; set; }
|
||||
public int OrbitAngle { get; set; }
|
||||
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
StateIndex = reader.ReadInt32();
|
||||
OnUnitSphere = reader.ReadVector3();
|
||||
OrbitAngle = reader.ReadInt32();
|
||||
}
|
||||
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(StateIndex);
|
||||
writer.Write(OnUnitSphere);
|
||||
writer.Write(OrbitAngle);
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ namespace QSB.QuantumSync.Events
|
||||
{
|
||||
public class MultiStateChangeEvent : QSBEvent<MultiStateChangeMessage>
|
||||
{
|
||||
public override QSB.Events.EventType Type => QSB.Events.EventType.MultiStateChange;
|
||||
public override EventType Type => EventType.MultiStateChange;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger<int, int>.AddListener(EventNames.QSBMultiStateChange, Handler);
|
||||
public override void CloseListener() => GlobalMessenger<int, int>.RemoveListener(EventNames.QSBMultiStateChange, Handler);
|
||||
|
@ -11,6 +11,7 @@ namespace QSB.QuantumSync.Patches
|
||||
QSBCore.Helper.HarmonyHelper.AddPrefix<SocketedQuantumObject>("ChangeQuantumState", typeof(ClientQuantumStateChangePatches), nameof(ReturnFalsePatch));
|
||||
QSBCore.Helper.HarmonyHelper.AddPrefix<MultiStateQuantumObject>("ChangeQuantumState", typeof(ClientQuantumStateChangePatches), nameof(ReturnFalsePatch));
|
||||
QSBCore.Helper.HarmonyHelper.AddPrefix<QuantumShuffleObject>("ChangeQuantumState", typeof(ClientQuantumStateChangePatches), nameof(ReturnFalsePatch));
|
||||
QSBCore.Helper.HarmonyHelper.AddPrefix<QuantumMoon>("ChangeQuantumState", typeof(ClientQuantumStateChangePatches), nameof(ReturnFalsePatch));
|
||||
}
|
||||
|
||||
public static bool ReturnFalsePatch() => false;
|
||||
|
@ -1,8 +1,6 @@
|
||||
using OWML.Utils;
|
||||
using QSB.Events;
|
||||
using QSB.Events;
|
||||
using QSB.Patches;
|
||||
using QSB.QuantumSync.WorldObjects;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -166,7 +164,8 @@ namespace QSB.QuantumSync.Patches
|
||||
velocity = (initialMotion == null) ? Vector3.zero : initialMotion.GetInitVelocity();
|
||||
____useInitialMotion = false;
|
||||
}
|
||||
____moonBody.SetVelocity(OWPhysics.CalculateOrbitVelocity(owRigidbody, ____moonBody, UnityEngine.Random.Range(0, 360)) + velocity);
|
||||
var orbitAngle = UnityEngine.Random.Range(0, 360);
|
||||
____moonBody.SetVelocity(OWPhysics.CalculateOrbitVelocity(owRigidbody, ____moonBody, orbitAngle) + velocity);
|
||||
____lastStateIndex = ____stateIndex;
|
||||
____stateIndex = stateIndex;
|
||||
____collapseToIndex = -1;
|
||||
@ -175,6 +174,7 @@ namespace QSB.QuantumSync.Patches
|
||||
{
|
||||
____stateSkipCounts[k] = (k != ____stateIndex) ? (____stateSkipCounts[k] + 1) : 0;
|
||||
}
|
||||
GlobalMessenger<int, Vector3, int>.FireEvent(EventNames.QSBMoonStateChange, stateIndex, onUnitSphere, orbitAngle);
|
||||
break;
|
||||
}
|
||||
____visibilityTracker.transform.localPosition = Vector3.zero;
|
||||
@ -192,7 +192,7 @@ namespace QSB.QuantumSync.Patches
|
||||
}
|
||||
else
|
||||
{
|
||||
__instance.GetType().GetMethod("SetSurfaceState", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { ____stateIndex });
|
||||
__instance.GetType().GetMethod("SetSurfaceState", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { -1 });
|
||||
____quantumSignal.SetSignalActivation(____stateIndex != 5, 2f);
|
||||
}
|
||||
____referenceFrameVolume.gameObject.SetActive(____stateIndex != 5);
|
||||
|
Loading…
x
Reference in New Issue
Block a user