2020-10-24 15:31:20 +01:00
|
|
|
|
using OWML.Common;
|
2020-12-14 16:24:52 +00:00
|
|
|
|
using QSB.Events;
|
2020-11-03 21:33:48 +00:00
|
|
|
|
using QSB.Player;
|
2020-10-24 15:31:20 +01:00
|
|
|
|
using QSB.Utility;
|
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
|
2020-11-03 17:56:48 +00:00
|
|
|
|
namespace QSB.ConversationSync.Events
|
2020-10-24 15:31:20 +01:00
|
|
|
|
{
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public class ConversationStartEndEvent : QSBEvent<ConversationStartEndMessage>
|
|
|
|
|
{
|
|
|
|
|
public override void SetupListener() => GlobalMessenger<int, uint, bool>.AddListener(EventNames.QSBConversationStartEnd, Handler);
|
|
|
|
|
public override void CloseListener() => GlobalMessenger<int, uint, bool>.RemoveListener(EventNames.QSBConversationStartEnd, Handler);
|
2020-10-24 15:31:20 +01:00
|
|
|
|
|
2021-04-29 18:30:45 +01:00
|
|
|
|
private void Handler(int objId, uint playerId, bool state) => SendEvent(CreateMessage(objId, playerId, state));
|
2020-10-24 15:31:20 +01:00
|
|
|
|
|
2021-11-20 19:49:50 +00:00
|
|
|
|
private ConversationStartEndMessage CreateMessage(int objId, uint playerId, bool state) => new()
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
AboutId = LocalPlayerId,
|
2021-04-29 18:30:45 +01:00
|
|
|
|
TreeId = objId,
|
2020-12-02 21:23:01 +00:00
|
|
|
|
PlayerId = playerId,
|
|
|
|
|
State = state
|
|
|
|
|
};
|
2020-10-24 15:31:20 +01:00
|
|
|
|
|
2020-12-11 22:42:21 +00:00
|
|
|
|
public override void OnReceiveRemote(bool server, ConversationStartEndMessage message)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2021-04-29 18:30:45 +01:00
|
|
|
|
if (message.TreeId == -1)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole("Warning - Received conv. start/end event with char id -1.", MessageType.Warning);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-12-19 10:56:25 +00:00
|
|
|
|
|
2021-12-04 09:51:27 +00:00
|
|
|
|
if (!WorldObjectManager.AllObjectsReady)
|
2020-12-19 10:56:25 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-29 18:30:45 +01:00
|
|
|
|
var dialogueTree = QSBWorldSync.OldDialogueTrees[message.TreeId];
|
2020-12-19 14:44:03 +00:00
|
|
|
|
|
2020-12-11 22:42:21 +00:00
|
|
|
|
if (message.State)
|
|
|
|
|
{
|
2021-04-29 18:30:45 +01:00
|
|
|
|
StartConversation(message.PlayerId, message.TreeId, dialogueTree);
|
2020-12-11 22:42:21 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-04-29 18:30:45 +01:00
|
|
|
|
EndConversation(message.PlayerId, dialogueTree);
|
2020-12-19 14:44:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void StartConversation(
|
|
|
|
|
uint playerId,
|
2021-04-29 18:30:45 +01:00
|
|
|
|
int dialogueTreeId,
|
2020-12-19 14:44:03 +00:00
|
|
|
|
CharacterDialogueTree tree)
|
|
|
|
|
{
|
2021-04-29 18:30:45 +01:00
|
|
|
|
QSBPlayerManager.GetPlayer(playerId).CurrentCharacterDialogueTreeId = dialogueTreeId;
|
2021-03-07 22:22:02 +00:00
|
|
|
|
tree.GetInteractVolume().DisableInteraction();
|
2020-12-19 14:44:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EndConversation(
|
|
|
|
|
uint playerId,
|
|
|
|
|
CharacterDialogueTree tree)
|
|
|
|
|
{
|
2021-04-29 18:30:45 +01:00
|
|
|
|
QSBPlayerManager.GetPlayer(playerId).CurrentCharacterDialogueTreeId = -1;
|
2021-03-07 22:22:02 +00:00
|
|
|
|
tree.GetInteractVolume().EnableInteraction();
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|