mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-09 12:54:51 +00:00
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using QSB.Events;
|
|
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)
|
|
{
|
|
if (!QSBCore.WorldObjectsReady)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var obj = QSBWorldSync.GetWorldFromId<QSBQuantumShuffleObject>(message.ObjectId);
|
|
obj.ShuffleObjects(message.IndexArray);
|
|
}
|
|
}
|
|
}
|