diff --git a/QSB/ConversationSync/Events/ConversationStartEndEvent.cs b/QSB/ConversationSync/Events/ConversationStartEndEvent.cs index fb8b8ec2..88f22d8e 100644 --- a/QSB/ConversationSync/Events/ConversationStartEndEvent.cs +++ b/QSB/ConversationSync/Events/ConversationStartEndEvent.cs @@ -42,35 +42,50 @@ namespace QSB.ConversationSync.Events var dialogueTree = QSBWorldSync.OldDialogueTrees[message.CharacterId]; var animController = Resources.FindObjectsOfTypeAll().FirstOrDefault(x => x.GetValue("_dialogueTree") == dialogueTree); - // Make character face player and talk if (animController == default(CharacterAnimController)) { return; } + if (message.State) { - // Start talking - QSBPlayerManager.GetPlayer(message.PlayerId).CurrentDialogueID = message.CharacterId; - animController.SetValue("_inConversation", true); - animController.SetValue("_playerInHeadZone", true); - if (animController.GetValue("_hasTalkAnimation")) - { - animController.GetValue("_animator").SetTrigger("Talking"); - } - dialogueTree.GetComponent().DisableInteraction(); + StartConversation(message.PlayerId, message.CharacterId, animController, dialogueTree); } else { - // Stop talking - QSBPlayerManager.GetPlayer(message.PlayerId).CurrentDialogueID = -1; - animController.SetValue("_inConversation", false); - animController.SetValue("_playerInHeadZone", false); - if (animController.GetValue("_hasTalkAnimation")) - { - animController.GetValue("_animator").SetTrigger("Idle"); - } - dialogueTree.GetComponent().EnableInteraction(); + 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("_hasTalkAnimation")) + { + controller.GetValue("_animator").SetTrigger("Talking"); + } + tree.GetComponent().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("_hasTalkAnimation")) + { + controller.GetValue("_animator").SetTrigger("Idle"); + } + tree.GetComponent().EnableInteraction(); + } } } \ No newline at end of file