mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-10 21:40:19 +00:00
make auto-triggers work
This commit is contained in:
parent
b918b62663
commit
1b0934be9f
@ -1,4 +1,5 @@
|
|||||||
using OWML.Common;
|
using OWML.Common;
|
||||||
|
using QSB.ConversationSync.WorldObjects;
|
||||||
using QSB.Events;
|
using QSB.Events;
|
||||||
using QSB.Player;
|
using QSB.Player;
|
||||||
using QSB.Utility;
|
using QSB.Utility;
|
||||||
@ -10,7 +11,7 @@ using UnityEngine.UI;
|
|||||||
|
|
||||||
namespace QSB.ConversationSync
|
namespace QSB.ConversationSync
|
||||||
{
|
{
|
||||||
public class ConversationManager : MonoBehaviour
|
public class ConversationManager : WorldObjectManager
|
||||||
{
|
{
|
||||||
public static ConversationManager Instance { get; private set; }
|
public static ConversationManager Instance { get; private set; }
|
||||||
public Dictionary<CharacterDialogueTree, GameObject> BoxMappings { get; } = new Dictionary<CharacterDialogueTree, GameObject>();
|
public Dictionary<CharacterDialogueTree, GameObject> BoxMappings { get; } = new Dictionary<CharacterDialogueTree, GameObject>();
|
||||||
@ -33,6 +34,9 @@ namespace QSB.ConversationSync
|
|||||||
_boxPrefab.GetComponent<Text>().color = Color.white;
|
_boxPrefab.GetComponent<Text>().color = Color.white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void RebuildWorldObjects(OWScene scene)
|
||||||
|
=> QSBWorldSync.Init<QSBRemoteDialogueTrigger, RemoteDialogueTrigger>();
|
||||||
|
|
||||||
public uint GetPlayerTalkingToTree(CharacterDialogueTree tree)
|
public uint GetPlayerTalkingToTree(CharacterDialogueTree tree)
|
||||||
{
|
{
|
||||||
var treeIndex = QSBWorldSync.OldDialogueTrees.IndexOf(tree);
|
var treeIndex = QSBWorldSync.OldDialogueTrees.IndexOf(tree);
|
||||||
|
35
QSB/ConversationSync/Events/EnterRemoteDialogueEvent.cs
Normal file
35
QSB/ConversationSync/Events/EnterRemoteDialogueEvent.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using QSB.ConversationSync.WorldObjects;
|
||||||
|
using QSB.Events;
|
||||||
|
using QSB.WorldSync;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace QSB.ConversationSync.Events
|
||||||
|
{
|
||||||
|
internal class EnterRemoteDialogueEvent : QSBEvent<EnterRemoteDialogueMessage>
|
||||||
|
{
|
||||||
|
public override bool RequireWorldObjectsReady => true;
|
||||||
|
|
||||||
|
public override void SetupListener() => GlobalMessenger<QSBRemoteDialogueTrigger, int, int>.AddListener(EventNames.QSBEnterRemoteDialogue, Handler);
|
||||||
|
public override void CloseListener() => GlobalMessenger<QSBRemoteDialogueTrigger, int, int>.RemoveListener(EventNames.QSBEnterRemoteDialogue, Handler);
|
||||||
|
|
||||||
|
private void Handler(QSBRemoteDialogueTrigger remoteTrigger, int activatedIndex, int listIndex) => SendEvent(CreateMessage(remoteTrigger, activatedIndex, listIndex));
|
||||||
|
|
||||||
|
private EnterRemoteDialogueMessage CreateMessage(QSBRemoteDialogueTrigger remoteTrigger, int activatedIndex, int listIndex) => new()
|
||||||
|
{
|
||||||
|
AboutId = LocalPlayerId,
|
||||||
|
ObjectId = remoteTrigger.ObjectId,
|
||||||
|
ActivatedDialogueIndex = activatedIndex,
|
||||||
|
ListDialoguesIndex = listIndex
|
||||||
|
};
|
||||||
|
|
||||||
|
public override void OnReceiveRemote(bool isHost, EnterRemoteDialogueMessage message)
|
||||||
|
{
|
||||||
|
var qsbObj = QSBWorldSync.GetWorldFromId<QSBRemoteDialogueTrigger>(message.ObjectId);
|
||||||
|
qsbObj.RemoteEnterDialogue(message.ActivatedDialogueIndex, message.ListDialoguesIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
QSB/ConversationSync/Events/EnterRemoteDialogueMessage.cs
Normal file
25
QSB/ConversationSync/Events/EnterRemoteDialogueMessage.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using QSB.WorldSync.Events;
|
||||||
|
using QuantumUNET.Transport;
|
||||||
|
|
||||||
|
namespace QSB.ConversationSync.Events
|
||||||
|
{
|
||||||
|
public class EnterRemoteDialogueMessage : WorldObjectMessage
|
||||||
|
{
|
||||||
|
public int ActivatedDialogueIndex { get; set; }
|
||||||
|
public int ListDialoguesIndex { get; set; }
|
||||||
|
|
||||||
|
public override void Deserialize(QNetworkReader reader)
|
||||||
|
{
|
||||||
|
base.Deserialize(reader);
|
||||||
|
ActivatedDialogueIndex = reader.ReadInt32();
|
||||||
|
ListDialoguesIndex = reader.ReadInt32();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Serialize(QNetworkWriter writer)
|
||||||
|
{
|
||||||
|
base.Serialize(writer);
|
||||||
|
writer.Write(ActivatedDialogueIndex);
|
||||||
|
writer.Write(ListDialoguesIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,13 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using OWML.Common;
|
using OWML.Common;
|
||||||
|
using QSB.ConversationSync.WorldObjects;
|
||||||
|
using QSB.Events;
|
||||||
using QSB.Patches;
|
using QSB.Patches;
|
||||||
using QSB.Player;
|
using QSB.Player;
|
||||||
using QSB.Utility;
|
using QSB.Utility;
|
||||||
using QSB.WorldSync;
|
using QSB.WorldSync;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace QSB.ConversationSync.Patches
|
namespace QSB.ConversationSync.Patches
|
||||||
{
|
{
|
||||||
@ -74,5 +77,75 @@ namespace QSB.ConversationSync.Patches
|
|||||||
QSBCore.UnityEvents.RunWhen(() => QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTreeId != -1,
|
QSBCore.UnityEvents.RunWhen(() => QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTreeId != -1,
|
||||||
() => ConversationManager.Instance.SendCharacterDialogue(QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTreeId, key));
|
() => ConversationManager.Instance.SendCharacterDialogue(QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTreeId, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(RemoteDialogueTrigger), nameof(RemoteDialogueTrigger.ConversationTriggered))]
|
||||||
|
public static bool ConversationTriggeredReplacement(RemoteDialogueTrigger __instance, ref bool __result, out RemoteDialogueTrigger.RemoteDialogueCondition dialogue)
|
||||||
|
{
|
||||||
|
dialogue = default;
|
||||||
|
var maxValue = int.MaxValue;
|
||||||
|
var num = -1;
|
||||||
|
var sharedInstance = DialogueConditionManager.SharedInstance;
|
||||||
|
for (var i = 0; i < __instance._listDialogues.Length; i++)
|
||||||
|
{
|
||||||
|
if (!__instance._activatedDialogues[i])
|
||||||
|
{
|
||||||
|
var flag = true;
|
||||||
|
var flag2 = false;
|
||||||
|
if (__instance._listDialogues[i].prereqConditions.Length == 0)
|
||||||
|
{
|
||||||
|
flag2 = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < __instance._listDialogues[i].prereqConditions.Length; j++)
|
||||||
|
{
|
||||||
|
if (sharedInstance.GetConditionState(__instance._listDialogues[i].prereqConditions[j]))
|
||||||
|
{
|
||||||
|
flag2 = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool flag3 = false;
|
||||||
|
RemoteDialogueTrigger.MultiConditionType prereqConditionType = __instance._listDialogues[i].prereqConditionType;
|
||||||
|
if (prereqConditionType != RemoteDialogueTrigger.MultiConditionType.OR)
|
||||||
|
{
|
||||||
|
if (prereqConditionType == RemoteDialogueTrigger.MultiConditionType.AND && flag)
|
||||||
|
{
|
||||||
|
flag3 = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (flag2)
|
||||||
|
{
|
||||||
|
flag3 = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag3 && __instance._listDialogues[i].priority < maxValue)
|
||||||
|
{
|
||||||
|
dialogue = __instance._listDialogues[i];
|
||||||
|
num = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (num == -1)
|
||||||
|
{
|
||||||
|
__result = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
__instance._activatedDialogues[num] = true;
|
||||||
|
|
||||||
|
QSBEventManager.FireEvent(EventNames.QSBEnterRemoteDialogue,
|
||||||
|
QSBWorldSync.GetWorldFromUnity<QSBRemoteDialogueTrigger>(__instance),
|
||||||
|
num,
|
||||||
|
__instance._listDialogues.IndexOf(dialogue));
|
||||||
|
|
||||||
|
__result = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
using QSB.Utility;
|
||||||
|
using QSB.WorldSync;
|
||||||
|
|
||||||
|
namespace QSB.ConversationSync.WorldObjects
|
||||||
|
{
|
||||||
|
internal class QSBRemoteDialogueTrigger : WorldObject<RemoteDialogueTrigger>
|
||||||
|
{
|
||||||
|
public void RemoteEnterDialogue(int activatedIndex, int listIndex)
|
||||||
|
{
|
||||||
|
var dialogueCondition = AttachedObject._listDialogues[listIndex];
|
||||||
|
AttachedObject._activeRemoteDialogue = dialogueCondition.dialogue;
|
||||||
|
AttachedObject._inRemoteDialogue = true;
|
||||||
|
AttachedObject._activatedDialogues[activatedIndex] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -105,5 +105,6 @@
|
|||||||
public const string QSBTornadoFormState = nameof(QSBTornadoFormState);
|
public const string QSBTornadoFormState = nameof(QSBTornadoFormState);
|
||||||
public const string QSBRequestGameDetails = nameof(QSBRequestGameDetails);
|
public const string QSBRequestGameDetails = nameof(QSBRequestGameDetails);
|
||||||
public const string QSBGameDetails = nameof(QSBGameDetails);
|
public const string QSBGameDetails = nameof(QSBGameDetails);
|
||||||
|
public const string QSBEnterRemoteDialogue = nameof(QSBEnterRemoteDialogue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,6 +120,7 @@ namespace QSB.Events
|
|||||||
new IdentifySignalEvent(),
|
new IdentifySignalEvent(),
|
||||||
new NpcAnimationEvent(),
|
new NpcAnimationEvent(),
|
||||||
new AuthQueueEvent(),
|
new AuthQueueEvent(),
|
||||||
|
new EnterRemoteDialogueEvent(),
|
||||||
// Ship
|
// Ship
|
||||||
new FlyShipEvent(),
|
new FlyShipEvent(),
|
||||||
new HatchEvent(),
|
new HatchEvent(),
|
||||||
|
@ -114,7 +114,6 @@ namespace QSB
|
|||||||
|
|
||||||
gameObject.AddComponent<QSBNetworkManager>();
|
gameObject.AddComponent<QSBNetworkManager>();
|
||||||
gameObject.AddComponent<DebugActions>();
|
gameObject.AddComponent<DebugActions>();
|
||||||
gameObject.AddComponent<ConversationManager>();
|
|
||||||
gameObject.AddComponent<QSBInputManager>();
|
gameObject.AddComponent<QSBInputManager>();
|
||||||
gameObject.AddComponent<TimeSyncUI>();
|
gameObject.AddComponent<TimeSyncUI>();
|
||||||
gameObject.AddComponent<PlayerEntanglementWatcher>();
|
gameObject.AddComponent<PlayerEntanglementWatcher>();
|
||||||
@ -144,6 +143,7 @@ namespace QSB
|
|||||||
gameObject.AddComponent<JellyfishManager>();
|
gameObject.AddComponent<JellyfishManager>();
|
||||||
gameObject.AddComponent<ZeroGCaveManager>();
|
gameObject.AddComponent<ZeroGCaveManager>();
|
||||||
gameObject.AddComponent<TornadoManager>();
|
gameObject.AddComponent<TornadoManager>();
|
||||||
|
gameObject.AddComponent<ConversationManager>();
|
||||||
|
|
||||||
DebugBoxManager.Init();
|
DebugBoxManager.Init();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user