public static void Serialize(this NetworkWriter writer, RequestInteractMessage.NetMessage message) { // indicate unknown component if client requested it if (message.ComponentType == null) { writer.WriteUInt16(RequestInteractMessage.UNKNOWN_COMPONENT_TYPE_ID); } else { writer.WriteUInt16(RequestInteractMessage.componentTypeToComponentID[message.ComponentType]); } writer.WriteByte(RequestInteractMessage.interactionTypeToInteractionID[message.InteractionType]); //server determines processor object if client specified unknown component if (message.ComponentType != null) { writer.WriteUInt32(message.ProcessorObject); } writer.WriteByte((byte)message.Intent); if (message.InteractionType == typeof(PositionalHandApply)) { writer.WriteUInt32(message.TargetObject); writer.WriteVector2(message.TargetVector); writer.WriteInt32((int)message.TargetBodyPart); } else if (message.InteractionType == typeof(HandApply)) { writer.WriteUInt32(message.TargetObject); writer.WriteInt32((int)message.TargetBodyPart); writer.WriteBoolean(message.IsAltUsed); } else if (message.InteractionType == typeof(AimApply)) { writer.WriteVector2(message.TargetVector); writer.WriteBoolean(message.MouseButtonState == MouseButtonState.PRESS); } else if (message.InteractionType == typeof(MouseDrop)) { writer.WriteUInt32(message.TargetObject); writer.WriteUInt32(message.UsedObject); } else if (message.InteractionType == typeof(InventoryApply)) { writer.WriteUInt32(message.StorageIndexOnGameObject); writer.WriteUInt32(message.UsedObject); writer.WriteUInt32(message.Storage); writer.WriteInt32(message.SlotIndex); writer.WriteInt32((int)message.NamedSlot); writer.WriteBoolean(message.IsAltUsed); } else if (message.InteractionType == typeof(TileApply)) { writer.WriteVector2(message.TargetVector); } else if (message.InteractionType == typeof(TileMouseDrop)) { writer.WriteUInt32(message.UsedObject); writer.WriteVector2(message.TargetVector); } else if (message.InteractionType == typeof(ConnectionApply)) { writer.WriteUInt32(message.TargetObject); writer.WriteVector2(message.TargetVector); writer.WriteByte((byte)message.connectionPointA); writer.WriteByte((byte)message.connectionPointB); } else if (message.InteractionType == typeof(ContextMenuApply)) { writer.WriteUInt32(message.TargetObject); writer.WriteString(message.RequestedOption); } else if (message.InteractionType == typeof(AiActivate)) { writer.WriteUInt32(message.TargetObject); writer.WriteByte((byte)message.ClickTypes); } }
public static RequestInteractMessage.NetMessage Deserialize(this NetworkReader reader) { var message = new RequestInteractMessage.NetMessage(); var componentID = reader.ReadUInt16(); if (componentID == RequestInteractMessage.UNKNOWN_COMPONENT_TYPE_ID) { //client didn't know which to trigger, leave ComponentType null message.ComponentType = null; } else { //client requested a specific component. message.ComponentType = RequestInteractMessage.componentIDToComponentType[componentID]; } message.InteractionType = RequestInteractMessage.interactionIDToInteractionType[reader.ReadByte()]; if (componentID != RequestInteractMessage.UNKNOWN_COMPONENT_TYPE_ID) { // client specified exact component message.ProcessorObject = reader.ReadUInt32(); } else { // client requested server to check the interaction message.ProcessorObject = NetId.Invalid; } message.Intent = (Intent)reader.ReadByte(); if (message.InteractionType == typeof(PositionalHandApply)) { message.TargetObject = reader.ReadUInt32(); message.TargetVector = reader.ReadVector2(); message.TargetBodyPart = (BodyPartType)reader.ReadUInt32(); } else if (message.InteractionType == typeof(HandApply)) { message.TargetObject = reader.ReadUInt32(); message.TargetBodyPart = (BodyPartType)reader.ReadUInt32(); message.IsAltUsed = reader.ReadBoolean(); } else if (message.InteractionType == typeof(AimApply)) { message.TargetVector = reader.ReadVector2(); message.MouseButtonState = reader.ReadBoolean() ? MouseButtonState.PRESS : MouseButtonState.HOLD; } else if (message.InteractionType == typeof(MouseDrop)) { message.TargetObject = reader.ReadUInt32(); message.UsedObject = reader.ReadUInt32(); } else if (message.InteractionType == typeof(InventoryApply)) { message.StorageIndexOnGameObject = reader.ReadUInt32(); message.UsedObject = reader.ReadUInt32(); message.Storage = reader.ReadUInt32(); message.SlotIndex = reader.ReadInt32(); message.NamedSlot = (NamedSlot)reader.ReadInt32(); message.IsAltUsed = reader.ReadBoolean(); } else if (message.InteractionType == typeof(TileApply)) { message.TargetVector = reader.ReadVector2(); } else if (message.InteractionType == typeof(TileMouseDrop)) { message.UsedObject = reader.ReadUInt32(); message.TargetVector = reader.ReadVector2(); } else if (message.InteractionType == typeof(ConnectionApply)) { message.TargetObject = reader.ReadUInt32(); message.TargetVector = reader.ReadVector2(); message.connectionPointA = (Connection)reader.ReadByte(); message.connectionPointB = (Connection)reader.ReadByte(); } else if (message.InteractionType == typeof(ContextMenuApply)) { message.TargetObject = reader.ReadUInt32(); message.RequestedOption = reader.ReadString(); } else if (message.InteractionType == typeof(AiActivate)) { message.TargetObject = reader.ReadUInt32(); message.ClickTypes = (AiActivate.ClickTypes)reader.ReadByte(); } return(message); }