mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-01 03:32:38 +00:00
ConversationStartEndMessage: make it a QSBWorldObjectMessage
This commit is contained in:
parent
2394ee90b9
commit
a217df9168
@ -45,11 +45,9 @@ public class ConversationManager : WorldObjectManager
|
||||
QSBWorldSync.Init<QSBCharacterDialogueTree, CharacterDialogueTree>();
|
||||
}
|
||||
|
||||
public uint GetPlayerTalkingToTree(CharacterDialogueTree tree)
|
||||
{
|
||||
var player = QSBPlayerManager.PlayerList.FirstOrDefault(x => x.CurrentCharacterDialogueTree?.AttachedObject == tree);
|
||||
return player != null ? player.PlayerId : uint.MaxValue;
|
||||
}
|
||||
public uint GetPlayerTalkingToTree(CharacterDialogueTree tree) =>
|
||||
QSBPlayerManager.PlayerList.FirstOrDefault(x => x.CurrentCharacterDialogueTree?.AttachedObject == tree)
|
||||
?.PlayerId ?? uint.MaxValue;
|
||||
|
||||
public void SendPlayerOption(string text)
|
||||
=> new ConversationMessage(ConversationType.Player, (int)QSBPlayerManager.LocalPlayerId, text).Send();
|
||||
@ -63,8 +61,8 @@ public class ConversationManager : WorldObjectManager
|
||||
public void CloseBoxCharacter(int id) =>
|
||||
new ConversationMessage(ConversationType.CloseCharacter, id).Send();
|
||||
|
||||
public void SendConvState(int charId, bool state)
|
||||
=> new ConversationStartEndMessage(charId, state).Send();
|
||||
public void SendConvState(QSBCharacterDialogueTree tree, bool state)
|
||||
=> tree.SendMessage(new ConversationStartEndMessage(state));
|
||||
|
||||
public void DisplayPlayerConversationBox(uint playerId, string text)
|
||||
{
|
||||
|
@ -1,47 +1,27 @@
|
||||
using OWML.Common;
|
||||
using QSB.ConversationSync.WorldObjects;
|
||||
using QSB.ConversationSync.WorldObjects;
|
||||
using QSB.Messaging;
|
||||
using QSB.Player;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
|
||||
namespace QSB.ConversationSync.Messages;
|
||||
|
||||
public class ConversationStartEndMessage : QSBMessage<(int TreeId, bool Start)>
|
||||
public class ConversationStartEndMessage : QSBWorldObjectMessage<QSBCharacterDialogueTree, bool>
|
||||
{
|
||||
public ConversationStartEndMessage(int treeId, bool start) : base((treeId, start)) { }
|
||||
|
||||
public override bool ShouldReceive => QSBWorldSync.AllObjectsReady;
|
||||
public ConversationStartEndMessage(bool start) : base(start) { }
|
||||
|
||||
public override void OnReceiveRemote()
|
||||
{
|
||||
var dialogueTree = Data.TreeId.GetWorldObject<QSBCharacterDialogueTree>();
|
||||
|
||||
if (Data.Start)
|
||||
if (Data)
|
||||
{
|
||||
StartConversation(From, dialogueTree);
|
||||
QSBPlayerManager.GetPlayer(From).CurrentCharacterDialogueTree = WorldObject;
|
||||
WorldObject.AttachedObject.GetInteractVolume().DisableInteraction();
|
||||
WorldObject.AttachedObject.RaiseEvent(nameof(CharacterDialogueTree.OnStartConversation));
|
||||
}
|
||||
else
|
||||
{
|
||||
EndConversation(From, dialogueTree);
|
||||
QSBPlayerManager.GetPlayer(From).CurrentCharacterDialogueTree = null;
|
||||
WorldObject.AttachedObject.GetInteractVolume().EnableInteraction();
|
||||
WorldObject.AttachedObject.RaiseEvent(nameof(CharacterDialogueTree.OnEndConversation));
|
||||
}
|
||||
}
|
||||
|
||||
private static void StartConversation(
|
||||
uint playerId,
|
||||
QSBCharacterDialogueTree tree)
|
||||
{
|
||||
QSBPlayerManager.GetPlayer(playerId).CurrentCharacterDialogueTree = tree;
|
||||
tree.AttachedObject.GetInteractVolume().DisableInteraction();
|
||||
tree.AttachedObject.RaiseEvent(nameof(CharacterDialogueTree.OnStartConversation));
|
||||
}
|
||||
|
||||
private static void EndConversation(
|
||||
uint playerId,
|
||||
QSBCharacterDialogueTree tree)
|
||||
{
|
||||
QSBPlayerManager.GetPlayer(playerId).CurrentCharacterDialogueTree = null;
|
||||
tree.AttachedObject.GetInteractVolume().EnableInteraction();
|
||||
tree.AttachedObject.RaiseEvent(nameof(CharacterDialogueTree.OnEndConversation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class ConversationPatches : QSBPatch
|
||||
var worldObject = __instance.GetWorldObject<QSBCharacterDialogueTree>();
|
||||
|
||||
QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTree = worldObject;
|
||||
ConversationManager.Instance.SendConvState(worldObject.ObjectId, true);
|
||||
ConversationManager.Instance.SendConvState(worldObject, true);
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
@ -45,7 +45,7 @@ public class ConversationPatches : QSBPatch
|
||||
return true;
|
||||
}
|
||||
|
||||
ConversationManager.Instance.SendConvState(QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTree.ObjectId, false);
|
||||
ConversationManager.Instance.SendConvState(QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTree, false);
|
||||
ConversationManager.Instance.CloseBoxCharacter(QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTree.ObjectId);
|
||||
QSBPlayerManager.LocalPlayer.CurrentCharacterDialogueTree = null;
|
||||
ConversationManager.Instance.CloseBoxPlayer();
|
||||
|
Loading…
Reference in New Issue
Block a user