quantum-space-buddies/QSB/TriggerSync/Messages/TriggerInitialStateMessage.cs

31 lines
802 B
C#
Raw Normal View History

using QSB.Messaging;
2022-01-13 02:43:18 +00:00
using QSB.Player;
2022-01-13 03:18:59 +00:00
using QSB.TriggerSync.WorldObjects;
2022-01-13 02:43:18 +00:00
using System.Collections.Generic;
using System.Linq;
namespace QSB.TriggerSync.Messages
2022-01-13 02:43:18 +00:00
{
/// <summary>
/// always sent by host
/// </summary>
public class TriggerInitialStateMessage : QSBWorldObjectMessage<IQSBTrigger, uint[]>
{
public TriggerInitialStateMessage(IEnumerable<PlayerInfo> occupants) =>
Value = occupants.Select(x => x.PlayerId).ToArray();
2022-01-13 02:43:18 +00:00
public override void OnReceiveRemote()
{
var serverOccupants = Value.Select(QSBPlayerManager.GetPlayer).ToList();
foreach (var added in serverOccupants.Except(WorldObject.Occupants))
{
WorldObject.Enter(added);
}
foreach (var removed in WorldObject.Occupants.Except(serverOccupants))
{
WorldObject.Exit(removed);
}
2022-01-13 02:43:18 +00:00
}
}
}