quantum-space-buddies/QSB/ItemSync/Messages/DropItemMessage.cs

50 lines
1.1 KiB
C#
Raw Normal View History

using Mirror;
using QSB.ItemSync.WorldObjects.Items;
2021-12-26 06:35:32 +00:00
using QSB.Messaging;
using QSB.Player;
2021-02-24 10:45:25 +00:00
using QSB.SectorSync.WorldObjects;
using QSB.WorldSync;
using UnityEngine;
namespace QSB.ItemSync.Messages
2021-02-24 10:45:25 +00:00
{
2021-12-26 06:35:32 +00:00
internal class DropItemMessage : QSBWorldObjectMessage<IQSBOWItem>
2021-02-24 10:45:25 +00:00
{
2021-12-26 06:35:32 +00:00
private Vector3 Position;
private Vector3 Normal;
private int SectorId;
2021-02-24 10:45:25 +00:00
2021-12-26 06:35:32 +00:00
public DropItemMessage(Vector3 position, Vector3 normal, Sector sector)
2021-02-24 10:45:25 +00:00
{
2021-12-26 06:35:32 +00:00
Position = position;
Normal = normal;
SectorId = sector.GetWorldObject<QSBSector>().ObjectId;
2021-02-24 10:45:25 +00:00
}
public override void Serialize(NetworkWriter writer)
2021-02-24 10:45:25 +00:00
{
base.Serialize(writer);
writer.Write(Position);
writer.Write(Normal);
2021-12-26 06:35:32 +00:00
writer.Write(SectorId);
}
public override void Deserialize(NetworkReader reader)
2021-12-26 06:35:32 +00:00
{
base.Deserialize(reader);
Position = reader.ReadVector3();
Normal = reader.ReadVector3();
SectorId = reader.Read<int>();
2021-12-26 06:35:32 +00:00
}
public override void OnReceiveRemote()
{
var sector = SectorId.GetWorldObject<QSBSector>().AttachedObject;
2021-12-26 06:35:32 +00:00
WorldObject.DropItem(Position, Normal, sector);
var player = QSBPlayerManager.GetPlayer(From);
player.HeldItem = WorldObject;
2021-02-24 10:45:25 +00:00
}
}
}