diff --git a/Assets/Scripts/Items/InventoryActionHandler.cs b/Assets/Scripts/Items/InventoryActionHandler.cs index e41169a..0648c73 100644 --- a/Assets/Scripts/Items/InventoryActionHandler.cs +++ b/Assets/Scripts/Items/InventoryActionHandler.cs @@ -56,17 +56,17 @@ namespace Cyber.Items { /// The to run /// The item related to the action. /// Weather the action failed or not. - public bool HandleAction(InventoryAction action, int relatedInt) { + public bool HandleAction(InventoryAction action, int[] intList) { switch (action) { case InventoryAction.Equip: - Inventory.Drive.EquipItem(relatedInt); + Inventory.Drive.EquipItem(intList[0]); return true; case InventoryAction.Unequip: - EquipSlot Slot = (EquipSlot) relatedInt; + EquipSlot Slot = (EquipSlot) intList[0]; Inventory.Drive.UnequipSlot(Slot); return true; case InventoryAction.Use: - EquipSlot UseSlot = (EquipSlot) relatedInt; + EquipSlot UseSlot = (EquipSlot) intList[0]; Item UseItem = Inventory.Drive.GetSlot(UseSlot); if (UseItem != null && UseItem.Action != null && Character != null && (!Client.IsRunning() || Client.GetConnectedPlayer().Character != Character)) { diff --git a/Assets/Scripts/Networking/Clientside/Client.cs b/Assets/Scripts/Networking/Clientside/Client.cs index ad82e5e..0759858 100644 --- a/Assets/Scripts/Networking/Clientside/Client.cs +++ b/Assets/Scripts/Networking/Clientside/Client.cs @@ -209,7 +209,7 @@ namespace Cyber.Networking.Clientside { case (PktType.MassIdentity): IntListPkt Identities = new IntListPkt(); Identities.Deserialize(msg.reader); - foreach (int currId in Identities.IdList) { + foreach (int currId in Identities.IntList) { Players.Add(currId, new CConnectedPlayer(currId)); } break; @@ -268,7 +268,7 @@ namespace Cyber.Networking.Clientside { case (PktType.StaticObjectIds): IntListPkt StaticIds = new IntListPkt(); StaticIds.Deserialize(msg.reader); - Spawner.SyncDB.SetStaticObjectsIDs(StaticIds.IdList); + Spawner.SyncDB.SetStaticObjectsIDs(StaticIds.IntList); break; case (PktType.Disconnect): DisconnectPkt Disconnect = new DisconnectPkt(); @@ -290,7 +290,7 @@ namespace Cyber.Networking.Clientside { break; } - Inventory.ActionHandler.HandleAction(InventoryActionPkt.Action, InventoryActionPkt.RelatedInt); + Inventory.ActionHandler.HandleAction(InventoryActionPkt.Action, InventoryActionPkt.IntList); break; default: diff --git a/Assets/Scripts/Networking/Messages/IntListPkt.cs b/Assets/Scripts/Networking/Messages/IntListPkt.cs index b8b3133..acd54c9 100644 --- a/Assets/Scripts/Networking/Messages/IntListPkt.cs +++ b/Assets/Scripts/Networking/Messages/IntListPkt.cs @@ -11,14 +11,14 @@ namespace Cyber.Networking.Messages { /// /// List of Integers. /// - public int[] IdList; + public int[] IntList; /// /// Create a packet containing integers. /// /// public IntListPkt(int[] idList) { - IdList = idList; + IntList = idList; } /// @@ -38,7 +38,7 @@ namespace Cyber.Networking.Messages { ByteArray[1] = reader.ReadBytesAndSize(); ByteArray[2] = reader.ReadBytesAndSize(); ByteArray[3] = reader.ReadBytesAndSize(); - IdList = NetworkHelper.DeserializeIntArray(ByteArray); + IntList = NetworkHelper.DeserializeIntArray(ByteArray); } /// @@ -46,7 +46,7 @@ namespace Cyber.Networking.Messages { /// /// public override void Serialize(NetworkWriter writer) { - byte[][] ByteArray = NetworkHelper.SerializeIntArray(IdList); + byte[][] ByteArray = NetworkHelper.SerializeIntArray(IntList); writer.WriteBytesFull(ByteArray[0]); writer.WriteBytesFull(ByteArray[1]); writer.WriteBytesFull(ByteArray[2]); diff --git a/Assets/Scripts/Networking/Messages/InventoryActionPkt.cs b/Assets/Scripts/Networking/Messages/InventoryActionPkt.cs index 3c7b32f..6e36c4f 100644 --- a/Assets/Scripts/Networking/Messages/InventoryActionPkt.cs +++ b/Assets/Scripts/Networking/Messages/InventoryActionPkt.cs @@ -15,9 +15,9 @@ namespace Cyber.Networking.Messages { public InventoryAction Action; /// - /// The related int to the + /// The related int list to the /// - public int RelatedInt; + public int[] IntList; /// /// The inventory SyncBaseID this happened in. Only set by server. @@ -29,9 +29,19 @@ namespace Cyber.Networking.Messages { /// /// The action done. /// + public InventoryActionPkt(InventoryAction action, int[] intList) { + Action = action; + IntList = intList; + } + + /// + /// Creates an inventory packet containing only one int. + /// + /// + /// public InventoryActionPkt(InventoryAction action, int relatedInt) { Action = action; - RelatedInt = relatedInt; + IntList = new int[1] { relatedInt }; } /// @@ -45,7 +55,7 @@ namespace Cyber.Networking.Messages { /// public override void Deserialize(NetworkReader reader) { Action = (InventoryAction) reader.ReadByte(); - RelatedInt = reader.ReadInt32(); + IntList = reader.ReadMessage().IntList; SyncBaseID = reader.ReadInt32(); } @@ -55,7 +65,7 @@ namespace Cyber.Networking.Messages { /// public override void Serialize(NetworkWriter writer) { writer.Write((byte) Action); - writer.Write(RelatedInt); + writer.Write(new IntListPkt(IntList)); writer.Write(SyncBaseID); } } diff --git a/Assets/Scripts/Networking/Serverside/Server.cs b/Assets/Scripts/Networking/Serverside/Server.cs index 81d0b55..e9300ce 100644 --- a/Assets/Scripts/Networking/Serverside/Server.cs +++ b/Assets/Scripts/Networking/Serverside/Server.cs @@ -237,7 +237,7 @@ namespace Cyber.Networking.Serverside { case PktType.FailedChecksums: IntListPkt FailedSyncs = new IntListPkt(); FailedSyncs.Deserialize(msg.reader); - foreach (int SyncBaseId in FailedSyncs.IdList) { + foreach (int SyncBaseId in FailedSyncs.IntList) { Syncer.DirtSyncBase(SyncBaseId); } break; @@ -249,7 +249,7 @@ namespace Cyber.Networking.Serverside { Inventory CurrInventory = Character.GetComponent(); InventoryActionPkt.SyncBaseID = CurrInventory.ID; - if (CurrInventory.ActionHandler.HandleAction(InventoryActionPkt.Action, InventoryActionPkt.RelatedInt)) { + if (CurrInventory.ActionHandler.HandleAction(InventoryActionPkt.Action, InventoryActionPkt.IntList)) { SendToAll(PktType.InventoryAction, InventoryActionPkt); }