public static FenceHitMessage Deserialize(ref BinaryReader reader) { FenceHitMessage output = new FenceHitMessage(); output.fence_id = reader.ReadInt32(); return(output); }
public void OnHit() { AudioManager.PlaySoundEvent(AUDIO_EVENT.FENCE_HIT); ParticleSpawner.SpawnParticleEvent(PARTICLE_EVENT.FENCE_HIT, this); FenceHitMessage msg = new FenceHitMessage(fence_id); InputQueue.AddToQueue(msg); }
public void SendMessageToClient(DataMessage msg) { if (server.ConnectionsCount > 0) { NetworkMessage sm = new NetworkMessage(); // Temporary switch (msg.type) { case DataMessage_Type.GAME_STATE: GameStateMessage gameStateMsg = msg as GameStateMessage; sm.Set_Data(gameStateMsg); break; case DataMessage_Type.PLAYER_UPDATE: PlayerUpdateMessage playerMsg = msg as PlayerUpdateMessage; sm.Set_Data(playerMsg); break; case DataMessage_Type.FENCE_HIT: FenceHitMessage fMsg = msg as FenceHitMessage; sm.Set_Data(fMsg); break; case DataMessage_Type.MISSLE_MINE: MissileMineMessage MMMsg = msg as MissileMineMessage; sm.Set_Data(msg); break; case DataMessage_Type.ROTATION: RotationMessage rMsg = msg as RotationMessage; sm.Set_Data(msg); break; case DataMessage_Type.MISSILEUPDATE: MissileUpdateMessage tmsg = msg as MissileUpdateMessage; sm.Set_Data(msg); break; case DataMessage_Type.GAME_OVER: GAMEOVERMESSAGE gomsg = msg as GAMEOVERMESSAGE; sm.Set_Data(msg); break; default: break; } NetOutgoingMessage om = server.CreateMessage(); om.Write(sm.Serialize()); server.SendMessage(om, server.Connections, NetDeliveryMethod.ReliableOrdered, 4); server.FlushSendQueue(); } }
public static void RecieveMessage(DataMessage msg) { if (instance.state == GAME_STATE.LOBBY) { switch (msg.type) { case DataMessage_Type.GAME_STATE: instance.ProcessGameStateMessage(msg as GameStateMessage); break; } } else if (instance.state == GAME_STATE.PLAY) { switch (msg.type) { case DataMessage_Type.PLAYER_INPUT: PlayerInputMessage pMsg = msg as PlayerInputMessage; instance.ProcessPlayerInputMessage(pMsg); break; case DataMessage_Type.PLAYER_UPDATE: PlayerUpdateMessage updateMsg = msg as PlayerUpdateMessage; instance.ProcessPlayerUpdateMessage(updateMsg); break; case DataMessage_Type.FENCE_HIT: FenceHitMessage fenceMsg = msg as FenceHitMessage; instance.ProcessFenceHitMessage(fenceMsg); break; case DataMessage_Type.MISSLE_MINE: MissileMineMessage MMMsg = msg as MissileMineMessage; instance.ProcessMissileMineMessage(MMMsg); break; case DataMessage_Type.ROTATION: RotationMessage rMsg = msg as RotationMessage; instance.ProcessRotationMessage(rMsg); break; case DataMessage_Type.MISSILEUPDATE: MissileUpdateMessage MMsg = msg as MissileUpdateMessage; instance.ProcessMissileUpdateMessage(MMsg); break; case DataMessage_Type.GAME_OVER: GAMEOVERMESSAGE gomsg = msg as GAMEOVERMESSAGE; instance.ProcessGameOverMessage(gomsg); break; default: break; } } }
void ProcessFenceHitMessage(FenceHitMessage msg) { for (int i = gameObjList.Count - 1; i >= 0; i--) { if (gameObjList[i] is Fence) { Fence temp = gameObjList[i] as Fence; if (temp.GetFenceID() == msg.fence_id) { temp.OnHit(); break; } } } }
public static NetworkMessage Deserialize(byte[] bytes) { BinaryReader reader = new BinaryReader(new MemoryStream(bytes)); NetworkMessage output = new NetworkMessage(); output.data_type = (DataMessage_Type)reader.ReadInt32(); switch (output.data_type) { case DataMessage_Type.GAME_STATE: output.data = GameStateMessage.Deserialize(ref reader); break; case DataMessage_Type.PLAYER_UPDATE: output.data = PlayerUpdateMessage.Deserialize(ref reader); break; case DataMessage_Type.MISSLE_MINE: output.data = MissileMineMessage.Deserialize(ref reader); break; case DataMessage_Type.ROTATION: output.data = RotationMessage.Deserialize(ref reader); break; case DataMessage_Type.FENCE_HIT: output.data = FenceHitMessage.Deserialize(ref reader); break; case DataMessage_Type.MISSILEUPDATE: output.data = MissileUpdateMessage.Deserialize(ref reader); break; case DataMessage_Type.GAME_OVER: output.data = GAMEOVERMESSAGE.Deserialize(ref reader); break; default: Debug.Assert(false, "INVALID DATA TYPE"); break; } return(output); }