2021-01-26 14:07:17 +00:00
|
|
|
|
using QSB.Events;
|
2021-01-01 10:17:35 +00:00
|
|
|
|
using QSB.QuantumSync.WorldObjects;
|
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
|
|
|
|
|
namespace QSB.QuantumSync.Events
|
|
|
|
|
{
|
|
|
|
|
public class QuantumShuffleEvent : QSBEvent<QuantumShuffleMessage>
|
|
|
|
|
{
|
|
|
|
|
public override QSB.Events.EventType Type => QSB.Events.EventType.QuantumShuffle;
|
|
|
|
|
|
|
|
|
|
public override void SetupListener() => GlobalMessenger<int, int[]>.AddListener(EventNames.QSBQuantumShuffle, Handler);
|
|
|
|
|
public override void CloseListener() => GlobalMessenger<int, int[]>.RemoveListener(EventNames.QSBQuantumShuffle, Handler);
|
|
|
|
|
|
|
|
|
|
private void Handler(int objid, int[] indexArray) => SendEvent(CreateMessage(objid, indexArray));
|
|
|
|
|
|
|
|
|
|
private QuantumShuffleMessage CreateMessage(int objid, int[] indexArray) => new QuantumShuffleMessage
|
|
|
|
|
{
|
|
|
|
|
AboutId = LocalPlayerId,
|
|
|
|
|
ObjectId = objid,
|
|
|
|
|
IndexArray = indexArray
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public override void OnReceiveRemote(bool server, QuantumShuffleMessage message)
|
|
|
|
|
{
|
2021-05-08 15:57:01 +00:00
|
|
|
|
if (!QSBCore.WorldObjectsReady)
|
2021-01-01 10:17:35 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-06-18 21:38:32 +00:00
|
|
|
|
|
2021-02-24 10:45:25 +00:00
|
|
|
|
var obj = QSBWorldSync.GetWorldFromId<QSBQuantumShuffleObject>(message.ObjectId);
|
2021-01-26 14:07:17 +00:00
|
|
|
|
obj.ShuffleObjects(message.IndexArray);
|
2021-01-01 10:17:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|