public void PlaySound(InfiniminerSound sound) { if (soundList.Count == 0) { return; } soundList[sound].Play(volumeLevel); }
public void PlaySound(InfiniminerSound sound) { if (soundList.Count == 0) { return; } soundList[sound].Play(SettingsContainer.VolumeLevel, 0.0f, 0.0f); }
public void PlaySound(InfiniminerSound sound, Vector3 position) { if (soundList.Count == 0) { return; } float distance = (position - playerPosition).Length(); float volume = Math.Max(0, 10 - distance) / 10.0f * volumeLevel; soundList[sound].Play(volume); }
public void PlaySound(InfiniminerSound sound, Vector3 position) { if (soundList.Count == 0) { return; } float distance = (position - PlayerContainer.PlayerPosition).Length(); float volume = Math.Max(0, 10 - distance) / 10.0f * SettingsContainer.VolumeLevel; volume = volume > 1.0f ? 1.0f : volume < 0.0f ? 0.0f : volume; soundList[sound].Play(volume, 0.0f, 0.0f); }
public void PlaySoundForEveryone(InfiniminerSound sound, Vector3 position) { if (netClient.Status != NetConnectionStatus.Connected) { return; } // The PlaySound message can be used to instruct the server to have all clients play a directional sound. NetBuffer msgBuffer = netClient.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.PlaySound); msgBuffer.Write((byte)sound); msgBuffer.Write(position); netClient.SendMessage(msgBuffer, NetChannel.ReliableUnordered); }
public void PlaySoundForEveryone(InfiniminerSound sound, Vector3 position) { if (netClient.Status != NetPeerStatus.Running) { return; } // The PlaySound message can be used to instruct the server to have all clients play a directional sound. NetOutgoingMessage msgBuffer = netClient.CreateMessage(); msgBuffer.Write((byte)InfiniminerMessage.PlaySound); msgBuffer.Write((byte)sound); msgBuffer.Write(position); netClient.SendMessage(msgBuffer, NetDeliveryMethod.ReliableUnordered); }
public void UpdateNetwork(GameTime gameTime) { // Update the server with our status. timeSinceLastUpdate += gameTime.ElapsedGameTime.TotalSeconds; if (timeSinceLastUpdate > 0.05) { timeSinceLastUpdate = 0; if (CurrentStateType == "Infiniminer.States.MainGameState") { propertyBag.SendPlayerUpdate(); } } // Recieve messages from the server. while ((msgBuffer = propertyBag.netClient.ReadMessage()) != null) { switch (msgBuffer.MessageType) { case NetIncomingMessageType.StatusChanged: { if (propertyBag.netClient.ConnectionStatus == NetConnectionStatus.RespondedConnect) { anyPacketsReceived = true; } if (propertyBag.netClient.ConnectionStatus == NetConnectionStatus.Disconnected) { anyPacketsReceived = false; try { string[] reason = msgBuffer.ReadString().Split(";".ToCharArray()); if (reason.Length < 2 || reason[0] == "VER") { InfiniminerMessageBox.Show("Error: client/server version incompability!\r\nServer: " + msgBuffer.ReadString() + "\r\nClient: " + Defines.INFINIMINER_VERSION); } else { InfiniminerMessageBox.Show("Error: you are banned from this server!"); } } catch { } ChangeState("Infiniminer.States.ServerBrowserState"); } } break; case NetIncomingMessageType.Data: { try { InfiniminerMessage dataType = (InfiniminerMessage)msgBuffer.ReadByte(); switch (dataType) { case InfiniminerMessage.BlockBulkTransfer: { anyPacketsReceived = true; try { //This is either the compression flag or the x coordiante byte isCompressed = msgBuffer.ReadByte(); byte x; byte y; //255 was used because it exceeds the map size - of course, bytes won't work anyway if map sizes are allowed to be this big, so this method is a non-issue if (isCompressed == 255) { var compressed = msgBuffer.ReadBytes(msgBuffer.LengthBytes - (int)(msgBuffer.Position / 8)); var compressedstream = new System.IO.MemoryStream(compressed); var decompresser = new System.IO.Compression.GZipStream(compressedstream, System.IO.Compression.CompressionMode.Decompress); x = (byte)decompresser.ReadByte(); y = (byte)decompresser.ReadByte(); propertyBag.mapLoadProgress[x, y] = true; for (byte dy = 0; dy < 16; dy++) { for (byte z = 0; z < 64; z++) { BlockType blockType = (BlockType)decompresser.ReadByte(); if (blockType != BlockType.None) { propertyBag.blockEngine.downloadList[x, y + dy, z] = blockType; } } } } else { x = isCompressed; y = msgBuffer.ReadByte(); propertyBag.mapLoadProgress[x, y] = true; for (byte dy = 0; dy < 16; dy++) { for (byte z = 0; z < 64; z++) { BlockType blockType = (BlockType)msgBuffer.ReadByte(); if (blockType != BlockType.None) { propertyBag.blockEngine.downloadList[x, y + dy, z] = blockType; } } } } bool downloadComplete = true; for (x = 0; x < 64; x++) { for (y = 0; y < 64; y += 16) { if (propertyBag.mapLoadProgress[x, y] == false) { downloadComplete = false; break; } } } if (downloadComplete) { ChangeState("Infiniminer.States.TeamSelectionState"); if (!NoSound) { MediaPlayer.Stop(); } propertyBag.blockEngine.DownloadComplete(); } } catch (Exception e) { Console.OpenStandardError(); Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.StackTrace); Console.Error.Close(); } } break; case InfiniminerMessage.SetBeacon: { Vector3 position = msgBuffer.ReadVector3(); string text = msgBuffer.ReadString(); PlayerTeam team = (PlayerTeam)msgBuffer.ReadByte(); if (text == "") { if (propertyBag.beaconList.ContainsKey(position)) { propertyBag.beaconList.Remove(position); } } else { Beacon newBeacon = new Beacon(); newBeacon.ID = text; newBeacon.Team = team; propertyBag.beaconList.Add(position, newBeacon); } } break; case InfiniminerMessage.TriggerConstructionGunAnimation: { propertyBag.constructionGunAnimation = msgBuffer.ReadFloat(); if (propertyBag.constructionGunAnimation <= -0.1) { propertyBag.PlaySound(InfiniminerSound.RadarSwitch); } } break; case InfiniminerMessage.ResourceUpdate: { // ore, cash, weight, max ore, max weight, team ore, red cash, blue cash, all uint propertyBag.playerOre = msgBuffer.ReadUInt32(); propertyBag.playerCash = msgBuffer.ReadUInt32(); propertyBag.playerWeight = msgBuffer.ReadUInt32(); propertyBag.playerOreMax = msgBuffer.ReadUInt32(); propertyBag.playerWeightMax = msgBuffer.ReadUInt32(); propertyBag.teamOre = msgBuffer.ReadUInt32(); propertyBag.teamRedCash = msgBuffer.ReadUInt32(); propertyBag.teamBlueCash = msgBuffer.ReadUInt32(); } break; case InfiniminerMessage.BlockSet: { // x, y, z, type, all bytes byte x = msgBuffer.ReadByte(); byte y = msgBuffer.ReadByte(); byte z = msgBuffer.ReadByte(); BlockType blockType = (BlockType)msgBuffer.ReadByte(); if (blockType == BlockType.None) { if (propertyBag.blockEngine.BlockAtPoint(new Vector3(x, y, z)) != BlockType.None) { propertyBag.blockEngine.RemoveBlock(x, y, z); } } else { if (propertyBag.blockEngine.BlockAtPoint(new Vector3(x, y, z)) != BlockType.None) { propertyBag.blockEngine.RemoveBlock(x, y, z); } propertyBag.blockEngine.AddBlock(x, y, z, blockType); CheckForStandingInLava(); } } break; case InfiniminerMessage.TriggerExplosion: { Vector3 blockPos = msgBuffer.ReadVector3(); // Play the explosion sound. propertyBag.PlaySound(InfiniminerSound.Explosion, blockPos); // Create some particles. propertyBag.particleEngine.CreateExplosionDebris(blockPos); // Figure out what the effect is. float distFromExplosive = (blockPos + 0.5f * Vector3.One - propertyBag.playerPosition).Length(); if (distFromExplosive < 3) { propertyBag.KillPlayer(Defines.deathByExpl); //"WAS KILLED IN AN EXPLOSION!"); } else if (distFromExplosive < 8) { // If we're not in explosion mode, turn it on with the minimum ammount of shakiness. if (propertyBag.screenEffect != ScreenEffect.Explosion) { propertyBag.screenEffect = ScreenEffect.Explosion; propertyBag.screenEffectCounter = 2; } // If this bomb would result in a bigger shake, use its value. propertyBag.screenEffectCounter = Math.Min(propertyBag.screenEffectCounter, (distFromExplosive - 2) / 5); } } break; case InfiniminerMessage.PlayerSetTeam: { uint playerId = msgBuffer.ReadUInt32(); if (propertyBag.playerList.ContainsKey(playerId)) { Player player = propertyBag.playerList[playerId]; player.Team = (PlayerTeam)msgBuffer.ReadByte(); } } break; case InfiniminerMessage.PlayerJoined: { uint playerId = msgBuffer.ReadUInt32(); string playerName = msgBuffer.ReadString(); bool thisIsMe = msgBuffer.ReadBoolean(); bool playerAlive = msgBuffer.ReadBoolean(); propertyBag.playerList[playerId] = new Player(null, (Game)this); propertyBag.playerList[playerId].Handle = playerName; propertyBag.playerList[playerId].ID = playerId; propertyBag.playerList[playerId].Alive = playerAlive; propertyBag.playerList[playerId].AltColours = customColours; propertyBag.playerList[playerId].redTeam = red; propertyBag.playerList[playerId].blueTeam = blue; if (thisIsMe) { propertyBag.playerMyId = playerId; } } break; case InfiniminerMessage.PlayerLeft: { uint playerId = msgBuffer.ReadUInt32(); if (propertyBag.playerList.ContainsKey(playerId)) { propertyBag.playerList.Remove(playerId); } } break; case InfiniminerMessage.PlayerDead: { uint playerId = msgBuffer.ReadUInt32(); if (propertyBag.playerList.ContainsKey(playerId)) { Player player = propertyBag.playerList[playerId]; player.Alive = false; propertyBag.particleEngine.CreateBloodSplatter(player.Position, player.Team == PlayerTeam.Red ? Color.Red : Color.Blue); if (playerId != propertyBag.playerMyId) { propertyBag.PlaySound(InfiniminerSound.Death, player.Position); } } } break; case InfiniminerMessage.PlayerAlive: { uint playerId = msgBuffer.ReadUInt32(); if (propertyBag.playerList.ContainsKey(playerId)) { Player player = propertyBag.playerList[playerId]; player.Alive = true; } } break; case InfiniminerMessage.PlayerUpdate: { uint playerId = msgBuffer.ReadUInt32(); if (propertyBag.playerList.ContainsKey(playerId)) { Player player = propertyBag.playerList[playerId]; player.UpdatePosition(msgBuffer.ReadVector3(), gameTime.TotalGameTime.TotalSeconds); player.Heading = msgBuffer.ReadVector3(); player.Tool = (PlayerTools)msgBuffer.ReadByte(); player.UsingTool = msgBuffer.ReadBoolean(); player.Score = (uint)(msgBuffer.ReadUInt16() * 100); } } break; case InfiniminerMessage.GameOver: { propertyBag.teamWinners = (PlayerTeam)msgBuffer.ReadByte(); } break; case InfiniminerMessage.ChatMessage: { ChatMessageType chatType = (ChatMessageType)msgBuffer.ReadByte(); string chatString = Defines.Sanitize(msgBuffer.ReadString()); //Time to break it up into multiple lines propertyBag.addChatMessage(chatString, chatType, 10); } break; case InfiniminerMessage.PlayerPing: { uint playerId = (uint)msgBuffer.ReadInt32(); if (propertyBag.playerList.ContainsKey(playerId)) { if (propertyBag.playerList[playerId].Team == propertyBag.playerTeam) { propertyBag.playerList[playerId].Ping = 1; propertyBag.PlaySound(InfiniminerSound.Ping); } } } break; case InfiniminerMessage.PlaySound: { InfiniminerSound sound = (InfiniminerSound)msgBuffer.ReadByte(); bool hasPosition = msgBuffer.ReadBoolean(); if (hasPosition) { Vector3 soundPosition = msgBuffer.ReadVector3(); propertyBag.PlaySound(sound, soundPosition); } else { propertyBag.PlaySound(sound); } } break; } } catch { } //Error in a received message } break; } } // Make sure our network thread actually gets to run. Thread.Sleep(1); }
public void PlaySound(InfiniminerSound sound, Vector3 position) { NetBuffer msgBuffer = netServer.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.PlaySound); msgBuffer.Write((byte)sound); msgBuffer.Write(true); msgBuffer.Write(position); foreach (NetConnection netConn in playerList.Keys) if (netConn.Status == NetConnectionStatus.Connected) netServer.SendMessage(msgBuffer, netConn, NetChannel.ReliableUnordered); }
public void PlaySound(InfiniminerSound sound, Vector3 position) { NetBuffer msgBuffer = netServer.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.PlaySound); msgBuffer.Write((byte)sound); msgBuffer.Write(true); msgBuffer.Write(position); foreach (IClient player in playerList.Values) //if (netConn.Status == NetConnectionStatus.Connected) player.AddQueMsg(msgBuffer, NetChannel.ReliableUnordered); }
public void UpdateNetwork(GameTime gameTime) { // Update the server with our status. timeSinceLastUpdate += gameTime.ElapsedGameTime.TotalSeconds; if (timeSinceLastUpdate > 0.05) { timeSinceLastUpdate = 0; if (CurrentStateType == "Infiniminer.States.MainGameState") { propertyBag.SendPlayerUpdate(); } } // Recieve messages from the server. NetMessageType msgType; while (propertyBag.netClient.ReadMessage(msgBuffer, out msgType)) { switch (msgType) { case NetMessageType.StatusChanged: { if (propertyBag.netClient.Status == NetConnectionStatus.Disconnected) { ChangeState("Infiniminer.States.ServerBrowserState"); } } break; case NetMessageType.ConnectionRejected: { string[] reason = msgBuffer.ReadString().Split(";".ToCharArray()); if (reason.Length < 2 || reason[0] == "VER") { MessageBox.Show("Error: client/server version incompability!\r\nServer: " + msgBuffer.ReadString() + "\r\nClient: " + INFINIMINER_VERSION); } else { MessageBox.Show("Error: you are banned from this server!"); } ChangeState("Infiniminer.States.ServerBrowserState"); } break; case NetMessageType.Data: { InfiniminerMessage dataType = (InfiniminerMessage)msgBuffer.ReadByte(); switch (dataType) { case InfiniminerMessage.BlockBulkTransfer: { byte x = msgBuffer.ReadByte(); byte y = msgBuffer.ReadByte(); propertyBag.mapLoadProgress[x, y] = true; for (byte dy = 0; dy < 16; dy++) { for (byte z = 0; z < 64; z++) { BlockType blockType = (BlockType)msgBuffer.ReadByte(); if (blockType != BlockType.None) { propertyBag.blockEngine.downloadList[x, y + dy, z] = blockType; } } } bool downloadComplete = true; for (x = 0; x < 64; x++) { for (y = 0; y < 64; y += 16) { if (propertyBag.mapLoadProgress[x, y] == false) { downloadComplete = false; break; } } } if (downloadComplete) { ChangeState("Infiniminer.States.TeamSelectionState"); if (!NoSound) { MediaPlayer.Stop(); } propertyBag.blockEngine.DownloadComplete(); } } break; case InfiniminerMessage.SetBeacon: { Vector3 position = msgBuffer.ReadVector3(); string text = msgBuffer.ReadString(); PlayerTeam team = (PlayerTeam)msgBuffer.ReadByte(); if (text == "") { if (propertyBag.beaconList.ContainsKey(position)) { propertyBag.beaconList.Remove(position); } } else { Beacon newBeacon = new Beacon(); newBeacon.ID = text; newBeacon.Team = team; propertyBag.beaconList.Add(position, newBeacon); } } break; case InfiniminerMessage.TriggerConstructionGunAnimation: { propertyBag.constructionGunAnimation = msgBuffer.ReadFloat(); if (propertyBag.constructionGunAnimation <= -0.1) { propertyBag.PlaySound(InfiniminerSound.RadarSwitch); } } break; case InfiniminerMessage.ResourceUpdate: { // ore, cash, weight, max ore, max weight, team ore, red cash, blue cash, all uint propertyBag.playerOre = msgBuffer.ReadUInt32(); propertyBag.playerCash = msgBuffer.ReadUInt32(); propertyBag.playerWeight = msgBuffer.ReadUInt32(); propertyBag.playerOreMax = msgBuffer.ReadUInt32(); propertyBag.playerWeightMax = msgBuffer.ReadUInt32(); propertyBag.teamOre = msgBuffer.ReadUInt32(); propertyBag.teamRedCash = msgBuffer.ReadUInt32(); propertyBag.teamBlueCash = msgBuffer.ReadUInt32(); } break; case InfiniminerMessage.BlockSet: { // x, y, z, type, all bytes byte x = msgBuffer.ReadByte(); byte y = msgBuffer.ReadByte(); byte z = msgBuffer.ReadByte(); BlockType blockType = (BlockType)msgBuffer.ReadByte(); if (blockType == BlockType.None) { if (propertyBag.blockEngine.BlockAtPoint(new Vector3(x, y, z)) != BlockType.None) { propertyBag.blockEngine.RemoveBlock(x, y, z); } } else { if (propertyBag.blockEngine.BlockAtPoint(new Vector3(x, y, z)) != BlockType.None) { propertyBag.blockEngine.RemoveBlock(x, y, z); } propertyBag.blockEngine.AddBlock(x, y, z, blockType); CheckForStandingInLava(); } } break; case InfiniminerMessage.TriggerExplosion: { Vector3 blockPos = msgBuffer.ReadVector3(); // Play the explosion sound. propertyBag.PlaySound(InfiniminerSound.Explosion, blockPos); // Create some particles. propertyBag.particleEngine.CreateExplosionDebris(blockPos); // Figure out what the effect is. float distFromExplosive = (blockPos + 0.5f * Vector3.One - propertyBag.playerPosition).Length(); if (distFromExplosive < 3) { propertyBag.KillPlayer("WAS KILLED IN AN EXPLOSION!"); } else if (distFromExplosive < 8) { // If we're not in explosion mode, turn it on with the minimum ammount of shakiness. if (propertyBag.screenEffect != ScreenEffect.Explosion) { propertyBag.screenEffect = ScreenEffect.Explosion; propertyBag.screenEffectCounter = 2; } // If this bomb would result in a bigger shake, use its value. propertyBag.screenEffectCounter = Math.Min(propertyBag.screenEffectCounter, (distFromExplosive - 2) / 5); } } break; case InfiniminerMessage.PlayerSetTeam: { uint playerId = msgBuffer.ReadUInt32(); if (propertyBag.playerList.ContainsKey(playerId)) { Player player = propertyBag.playerList[playerId]; player.Team = (PlayerTeam)msgBuffer.ReadByte(); } } break; case InfiniminerMessage.PlayerJoined: { uint playerId = msgBuffer.ReadUInt32(); string playerName = msgBuffer.ReadString(); bool thisIsMe = msgBuffer.ReadBoolean(); bool playerAlive = msgBuffer.ReadBoolean(); propertyBag.playerList[playerId] = new Player(null, (Game)this); propertyBag.playerList[playerId].Handle = playerName; propertyBag.playerList[playerId].ID = playerId; propertyBag.playerList[playerId].Alive = playerAlive; if (thisIsMe) { propertyBag.playerMyId = playerId; } } break; case InfiniminerMessage.PlayerLeft: { uint playerId = msgBuffer.ReadUInt32(); if (propertyBag.playerList.ContainsKey(playerId)) { propertyBag.playerList.Remove(playerId); } } break; case InfiniminerMessage.PlayerDead: { uint playerId = msgBuffer.ReadUInt32(); if (propertyBag.playerList.ContainsKey(playerId)) { Player player = propertyBag.playerList[playerId]; player.Alive = false; propertyBag.particleEngine.CreateBloodSplatter(player.Position, player.Team == PlayerTeam.Red ? Color.Red : Color.Blue); if (playerId != propertyBag.playerMyId) { propertyBag.PlaySound(InfiniminerSound.Death, player.Position); } } } break; case InfiniminerMessage.PlayerAlive: { uint playerId = msgBuffer.ReadUInt32(); if (propertyBag.playerList.ContainsKey(playerId)) { Player player = propertyBag.playerList[playerId]; player.Alive = true; } } break; case InfiniminerMessage.PlayerUpdate: { uint playerId = msgBuffer.ReadUInt32(); if (propertyBag.playerList.ContainsKey(playerId)) { Player player = propertyBag.playerList[playerId]; player.UpdatePosition(msgBuffer.ReadVector3(), gameTime.TotalGameTime.TotalSeconds); player.Heading = msgBuffer.ReadVector3(); player.Tool = (PlayerTools)msgBuffer.ReadByte(); player.UsingTool = msgBuffer.ReadBoolean(); player.Score = (uint)(msgBuffer.ReadUInt16() * 100); } } break; case InfiniminerMessage.GameOver: { propertyBag.teamWinners = (PlayerTeam)msgBuffer.ReadByte(); } break; case InfiniminerMessage.ChatMessage: { ChatMessageType chatType = (ChatMessageType)msgBuffer.ReadByte(); string chatString = msgBuffer.ReadString(); ChatMessage chatMsg = new ChatMessage(chatString, chatType, 10); propertyBag.chatBuffer.Insert(0, chatMsg); propertyBag.PlaySound(InfiniminerSound.ClickLow); } break; case InfiniminerMessage.PlayerPing: { uint playerId = (uint)msgBuffer.ReadInt32(); if (propertyBag.playerList.ContainsKey(playerId)) { if (propertyBag.playerList[playerId].Team == propertyBag.playerTeam) { propertyBag.playerList[playerId].Ping = 1; propertyBag.PlaySound(InfiniminerSound.Ping); } } } break; case InfiniminerMessage.PlaySound: { InfiniminerSound sound = (InfiniminerSound)msgBuffer.ReadByte(); bool hasPosition = msgBuffer.ReadBoolean(); if (hasPosition) { Vector3 soundPosition = msgBuffer.ReadVector3(); propertyBag.PlaySound(sound, soundPosition); } else { propertyBag.PlaySound(sound); } } break; } } break; } } // Make sure our network thread actually gets to run. Thread.Sleep(1); }
public void PlaySoundForEveryone(InfiniminerSound sound, Vector3 position) { if (netClient.Status != NetConnectionStatus.Connected) return; // The PlaySound message can be used to instruct the server to have all clients play a directional sound. NetBuffer msgBuffer = netClient.CreateBuffer(); msgBuffer.Write((byte)InfiniminerMessage.PlaySound); msgBuffer.Write((byte)sound); msgBuffer.Write(position); netClient.SendMessage(msgBuffer, NetChannel.ReliableUnordered); PlaySound(sound);//plays the sound locally }
public void PlaySound(InfiniminerSound sound, Vector3 position) { if (soundList.Count == 0) return; float distance = (position - playerPosition).Length(); float volume = 1.0f;// Math.Max(0, 20 - (0)) / 10.0f * volumeLevel; if (distance > 24)//we cant hear this far return; AudioEmitter emitter = new AudioEmitter(); emitter.Position = position; int ns = soundListInstance.Count; float pitch = 0.0f; if (sound == InfiniminerSound.RockFall) { pitch = (float)(randGen.NextDouble() * 0.5); } soundListInstance[ns] = soundList[sound].Play3D(listenPos,emitter,volume,pitch,false); soundListEmitter[ns] = emitter; }
public void PlaySound(InfiniminerSound sound) { if (soundList.Count == 0) return; soundList[sound].Play(volumeLevel); }
public void PlaySound(InfiniminerSound sound, Vector3 position) { if (soundList.Count == 0) return; float distance = (position - playerPosition).Length(); float volume = Math.Max(0, 10 - distance) / 10.0f * volumeLevel; volume = volume > 1.0f ? 1.0f : volume < 0.0f ? 0.0f : volume; soundList[sound].Play(volume); }