Change RelatedInt to IntList in InventoryActionPkt

This commit is contained in:
Sofia 2017-05-17 00:41:03 +03:00
parent 6a48f0aa20
commit c33f3b7d58
5 changed files with 28 additions and 18 deletions

View File

@ -56,17 +56,17 @@ namespace Cyber.Items {
/// <param name="action">The <see cref="InventoryAction"/> to run</param> /// <param name="action">The <see cref="InventoryAction"/> to run</param>
/// <param name="relatedInt">The item related to the action.</param> /// <param name="relatedInt">The item related to the action.</param>
/// <returns>Weather the action failed or not.</returns> /// <returns>Weather the action failed or not.</returns>
public bool HandleAction(InventoryAction action, int relatedInt) { public bool HandleAction(InventoryAction action, int[] intList) {
switch (action) { switch (action) {
case InventoryAction.Equip: case InventoryAction.Equip:
Inventory.Drive.EquipItem(relatedInt); Inventory.Drive.EquipItem(intList[0]);
return true; return true;
case InventoryAction.Unequip: case InventoryAction.Unequip:
EquipSlot Slot = (EquipSlot) relatedInt; EquipSlot Slot = (EquipSlot) intList[0];
Inventory.Drive.UnequipSlot(Slot); Inventory.Drive.UnequipSlot(Slot);
return true; return true;
case InventoryAction.Use: case InventoryAction.Use:
EquipSlot UseSlot = (EquipSlot) relatedInt; EquipSlot UseSlot = (EquipSlot) intList[0];
Item UseItem = Inventory.Drive.GetSlot(UseSlot); Item UseItem = Inventory.Drive.GetSlot(UseSlot);
if (UseItem != null && UseItem.Action != null && Character != null && if (UseItem != null && UseItem.Action != null && Character != null &&
(!Client.IsRunning() || Client.GetConnectedPlayer().Character != Character)) { (!Client.IsRunning() || Client.GetConnectedPlayer().Character != Character)) {

View File

@ -209,7 +209,7 @@ namespace Cyber.Networking.Clientside {
case (PktType.MassIdentity): case (PktType.MassIdentity):
IntListPkt Identities = new IntListPkt(); IntListPkt Identities = new IntListPkt();
Identities.Deserialize(msg.reader); Identities.Deserialize(msg.reader);
foreach (int currId in Identities.IdList) { foreach (int currId in Identities.IntList) {
Players.Add(currId, new CConnectedPlayer(currId)); Players.Add(currId, new CConnectedPlayer(currId));
} }
break; break;
@ -268,7 +268,7 @@ namespace Cyber.Networking.Clientside {
case (PktType.StaticObjectIds): case (PktType.StaticObjectIds):
IntListPkt StaticIds = new IntListPkt(); IntListPkt StaticIds = new IntListPkt();
StaticIds.Deserialize(msg.reader); StaticIds.Deserialize(msg.reader);
Spawner.SyncDB.SetStaticObjectsIDs(StaticIds.IdList); Spawner.SyncDB.SetStaticObjectsIDs(StaticIds.IntList);
break; break;
case (PktType.Disconnect): case (PktType.Disconnect):
DisconnectPkt Disconnect = new DisconnectPkt(); DisconnectPkt Disconnect = new DisconnectPkt();
@ -290,7 +290,7 @@ namespace Cyber.Networking.Clientside {
break; break;
} }
Inventory.ActionHandler.HandleAction(InventoryActionPkt.Action, InventoryActionPkt.RelatedInt); Inventory.ActionHandler.HandleAction(InventoryActionPkt.Action, InventoryActionPkt.IntList);
break; break;
default: default:

View File

@ -11,14 +11,14 @@ namespace Cyber.Networking.Messages {
/// <summary> /// <summary>
/// List of Integers. /// List of Integers.
/// </summary> /// </summary>
public int[] IdList; public int[] IntList;
/// <summary> /// <summary>
/// Create a packet containing integers. /// Create a packet containing integers.
/// </summary> /// </summary>
/// <param name="idList"></param> /// <param name="idList"></param>
public IntListPkt(int[] idList) { public IntListPkt(int[] idList) {
IdList = idList; IntList = idList;
} }
/// <summary> /// <summary>
@ -38,7 +38,7 @@ namespace Cyber.Networking.Messages {
ByteArray[1] = reader.ReadBytesAndSize(); ByteArray[1] = reader.ReadBytesAndSize();
ByteArray[2] = reader.ReadBytesAndSize(); ByteArray[2] = reader.ReadBytesAndSize();
ByteArray[3] = reader.ReadBytesAndSize(); ByteArray[3] = reader.ReadBytesAndSize();
IdList = NetworkHelper.DeserializeIntArray(ByteArray); IntList = NetworkHelper.DeserializeIntArray(ByteArray);
} }
/// <summary> /// <summary>
@ -46,7 +46,7 @@ namespace Cyber.Networking.Messages {
/// </summary> /// </summary>
/// <param name="writer"></param> /// <param name="writer"></param>
public override void Serialize(NetworkWriter writer) { public override void Serialize(NetworkWriter writer) {
byte[][] ByteArray = NetworkHelper.SerializeIntArray(IdList); byte[][] ByteArray = NetworkHelper.SerializeIntArray(IntList);
writer.WriteBytesFull(ByteArray[0]); writer.WriteBytesFull(ByteArray[0]);
writer.WriteBytesFull(ByteArray[1]); writer.WriteBytesFull(ByteArray[1]);
writer.WriteBytesFull(ByteArray[2]); writer.WriteBytesFull(ByteArray[2]);

View File

@ -15,9 +15,9 @@ namespace Cyber.Networking.Messages {
public InventoryAction Action; public InventoryAction Action;
/// <summary> /// <summary>
/// The related int to the <see cref="InventoryAction"/> /// The related int list to the <see cref="InventoryAction"/>
/// </summary> /// </summary>
public int RelatedInt; public int[] IntList;
/// <summary> /// <summary>
/// The inventory SyncBaseID this happened in. Only set by server. /// The inventory SyncBaseID this happened in. Only set by server.
@ -29,9 +29,19 @@ namespace Cyber.Networking.Messages {
/// </summary> /// </summary>
/// <param name="action">The action done.</param> /// <param name="action">The action done.</param>
/// <param name="relatedInt"></param> /// <param name="relatedInt"></param>
public InventoryActionPkt(InventoryAction action, int[] intList) {
Action = action;
IntList = intList;
}
/// <summary>
/// Creates an inventory packet containing only one int.
/// </summary>
/// <param name="action"></param>
/// <param name="relatedInt"></param>
public InventoryActionPkt(InventoryAction action, int relatedInt) { public InventoryActionPkt(InventoryAction action, int relatedInt) {
Action = action; Action = action;
RelatedInt = relatedInt; IntList = new int[1] { relatedInt };
} }
/// <summary> /// <summary>
@ -45,7 +55,7 @@ namespace Cyber.Networking.Messages {
/// <param name="reader"></param> /// <param name="reader"></param>
public override void Deserialize(NetworkReader reader) { public override void Deserialize(NetworkReader reader) {
Action = (InventoryAction) reader.ReadByte(); Action = (InventoryAction) reader.ReadByte();
RelatedInt = reader.ReadInt32(); IntList = reader.ReadMessage<IntListPkt>().IntList;
SyncBaseID = reader.ReadInt32(); SyncBaseID = reader.ReadInt32();
} }
@ -55,7 +65,7 @@ namespace Cyber.Networking.Messages {
/// <param name="writer"></param> /// <param name="writer"></param>
public override void Serialize(NetworkWriter writer) { public override void Serialize(NetworkWriter writer) {
writer.Write((byte) Action); writer.Write((byte) Action);
writer.Write(RelatedInt); writer.Write(new IntListPkt(IntList));
writer.Write(SyncBaseID); writer.Write(SyncBaseID);
} }
} }

View File

@ -237,7 +237,7 @@ namespace Cyber.Networking.Serverside {
case PktType.FailedChecksums: case PktType.FailedChecksums:
IntListPkt FailedSyncs = new IntListPkt(); IntListPkt FailedSyncs = new IntListPkt();
FailedSyncs.Deserialize(msg.reader); FailedSyncs.Deserialize(msg.reader);
foreach (int SyncBaseId in FailedSyncs.IdList) { foreach (int SyncBaseId in FailedSyncs.IntList) {
Syncer.DirtSyncBase(SyncBaseId); Syncer.DirtSyncBase(SyncBaseId);
} }
break; break;
@ -249,7 +249,7 @@ namespace Cyber.Networking.Serverside {
Inventory CurrInventory = Character.GetComponent<Inventory>(); Inventory CurrInventory = Character.GetComponent<Inventory>();
InventoryActionPkt.SyncBaseID = CurrInventory.ID; InventoryActionPkt.SyncBaseID = CurrInventory.ID;
if (CurrInventory.ActionHandler.HandleAction(InventoryActionPkt.Action, InventoryActionPkt.RelatedInt)) { if (CurrInventory.ActionHandler.HandleAction(InventoryActionPkt.Action, InventoryActionPkt.IntList)) {
SendToAll(PktType.InventoryAction, InventoryActionPkt); SendToAll(PktType.InventoryAction, InventoryActionPkt);
} }