2020-10-24 15:31:20 +01:00
|
|
|
|
using OWML.Common;
|
2020-12-20 10:56:15 +00:00
|
|
|
|
using OWML.Utils;
|
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;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
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>
|
|
|
|
|
{
|
2020-12-14 16:24:52 +00:00
|
|
|
|
public override QSB.Events.EventType Type => QSB.Events.EventType.ConversationStartEnd;
|
2020-10-24 15:31:20 +01:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
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
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private void Handler(int charId, uint playerId, bool state) => SendEvent(CreateMessage(charId, playerId, state));
|
2020-10-24 15:31:20 +01:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private ConversationStartEndMessage CreateMessage(int charId, uint playerId, bool state) => new ConversationStartEndMessage
|
|
|
|
|
{
|
|
|
|
|
AboutId = LocalPlayerId,
|
|
|
|
|
CharacterId = charId,
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
if (message.CharacterId == -1)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole("Warning - Received conv. start/end event with char id -1.", MessageType.Warning);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-12-19 10:56:25 +00:00
|
|
|
|
|
|
|
|
|
if (!QSBCore.HasWokenUp)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 13:14:58 +00:00
|
|
|
|
var dialogueTree = QSBWorldSync.OldDialogueTrees[message.CharacterId];
|
2020-12-02 21:23:01 +00:00
|
|
|
|
var animController = Resources.FindObjectsOfTypeAll<CharacterAnimController>().FirstOrDefault(x => x.GetValue<CharacterDialogueTree>("_dialogueTree") == dialogueTree);
|
2020-10-25 15:19:23 +00:00
|
|
|
|
|
2020-12-11 22:42:21 +00:00
|
|
|
|
if (animController == default(CharacterAnimController))
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2020-12-11 22:42:21 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2020-12-19 14:44:03 +00:00
|
|
|
|
|
2020-12-11 22:42:21 +00:00
|
|
|
|
if (message.State)
|
|
|
|
|
{
|
2020-12-19 14:44:03 +00:00
|
|
|
|
StartConversation(message.PlayerId, message.CharacterId, animController, dialogueTree);
|
2020-12-11 22:42:21 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-12-19 14:44:03 +00:00
|
|
|
|
EndConversation(message.PlayerId, animController, dialogueTree);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void StartConversation(
|
|
|
|
|
uint playerId,
|
|
|
|
|
int characterId,
|
|
|
|
|
CharacterAnimController controller,
|
|
|
|
|
CharacterDialogueTree tree)
|
|
|
|
|
{
|
|
|
|
|
QSBPlayerManager.GetPlayer(playerId).CurrentDialogueID = characterId;
|
|
|
|
|
controller.SetValue("_inConversation", true);
|
|
|
|
|
controller.SetValue("_playerInHeadZone", true);
|
|
|
|
|
if (controller.GetValue<bool>("_hasTalkAnimation"))
|
|
|
|
|
{
|
|
|
|
|
controller.GetValue<Animator>("_animator").SetTrigger("Talking");
|
|
|
|
|
}
|
|
|
|
|
tree.GetComponent<InteractVolume>().DisableInteraction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EndConversation(
|
|
|
|
|
uint playerId,
|
|
|
|
|
CharacterAnimController controller,
|
|
|
|
|
CharacterDialogueTree tree)
|
|
|
|
|
{
|
|
|
|
|
QSBPlayerManager.GetPlayer(playerId).CurrentDialogueID = -1;
|
|
|
|
|
controller.SetValue("_inConversation", false);
|
|
|
|
|
controller.SetValue("_playerInHeadZone", false);
|
|
|
|
|
if (controller.GetValue<bool>("_hasTalkAnimation"))
|
|
|
|
|
{
|
|
|
|
|
controller.GetValue<Animator>("_animator").SetTrigger("Idle");
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
2020-12-19 14:44:03 +00:00
|
|
|
|
tree.GetComponent<InteractVolume>().EnableInteraction();
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|