45 lines
1.2 KiB
C#
Raw Normal View History

2023-05-08 14:48:36 +01:00
using Cysharp.Threading.Tasks;
using QSB.ConversationSync.Messages;
using QSB.Messaging;
2023-05-08 14:48:36 +01:00
using QSB.Player;
using QSB.Utility;
using QSB.WorldSync;
2023-05-08 14:48:36 +01:00
using System.Threading;
using UnityEngine;
2022-05-13 22:38:06 +01:00
namespace QSB.ConversationSync.WorldObjects;
public class QSBCharacterDialogueTree : WorldObject<CharacterDialogueTree>
{
2023-05-08 14:48:36 +01:00
public override async UniTask Init(CancellationToken ct)
{
QSBPlayerManager.OnRemovePlayer += OnRemovePlayer;
}
public override void OnRemoval()
{
QSBPlayerManager.OnRemovePlayer -= OnRemovePlayer;
}
2022-05-13 22:38:06 +01:00
public override void SendInitialState(uint to)
{
var playerId = ConversationManager.Instance.GetPlayerTalkingToTree(AttachedObject);
if (playerId != uint.MaxValue)
{
this.SendMessage(new ConversationStartEndMessage(playerId, true) { To = to });
}
// TODO: maybe also sync the dialogue box and player box?
2022-05-13 22:38:06 +01:00
}
2023-05-08 14:48:36 +01:00
private void OnRemovePlayer(PlayerInfo player)
{
if (player.CurrentCharacterDialogueTree == this)
{
AttachedObject.GetInteractVolume().EnableInteraction();
AttachedObject.RaiseEvent(nameof(CharacterDialogueTree.OnEndConversation));
Object.Destroy(ConversationManager.Instance.BoxMappings[AttachedObject]);
Object.Destroy(player.CurrentDialogueBox);
}
}
2022-05-13 22:38:06 +01:00
}