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

30 lines
779 B
C#
Raw Normal View History

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