public object HandlePacket(PacketBlockSet packet, IPropertyBag propertyBag = null, IStateMachine gameInstance = null) { if (propertyBag == null) { return(null); } var blockEngine = propertyBag.GetEngine <IBlockEngine>("blockEngine"); // x, y, z, type, all bytes var x = packet.X; var y = packet.Y; var z = packet.Z; var blockType = (BlockType)packet.BlockType; if (blockType == BlockType.None) { if (blockEngine.BlockAtPoint(new Vector3(x, y, z)) != BlockType.None) { blockEngine.RemoveBlock(x, y, z); } } else { if (blockEngine.BlockAtPoint(new Vector3(x, y, z)) != BlockType.None) { blockEngine.RemoveBlock(x, y, z); } blockEngine.AddBlock(x, y, z, blockType); gameInstance?.CheckForStandingInLava(); } return(null); }
public object HandlePacket(PacketPlayerDead packet, IPropertyBag propertyBag = null, IStateMachine gameInstance = null) { if (propertyBag == null || !propertyBag.PlayerList.ContainsKey(packet.PlayerId)) { return(null); } var player = propertyBag.PlayerList[packet.PlayerId]; player.Alive = false; propertyBag.GetEngine <IParticleEngine>("particleEngine").CreateBloodSplatter(player.Position, player.Team == PlayerTeam.Red ? Color.Red : Color.Blue); if (packet.PlayerId != propertyBag.PlayerContainer.PlayerMyId) { propertyBag.PlaySound(InfiniminerSound.Death, player.Position); } return(null); }
public object HandlePacket(PacketTriggerExplosion packet, IPropertyBag propertyBag = null, IStateMachine gameInstance = null) { if (propertyBag == null) { return(null); } // Play the explosion sound. propertyBag.PlaySound(InfiniminerSound.Explosion, packet.BlockPos); // Create some particles. propertyBag.GetEngine <IParticleEngine>("particleEngine").CreateExplosionDebris(packet.BlockPos); // Figure out what the effect is. var distFromExplosive = (packet.BlockPos + 0.5f * Vector3.One - propertyBag.PlayerContainer.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.PlayerContainer.ScreenEffect != ScreenEffect.Explosion) { propertyBag.PlayerContainer.ScreenEffect = ScreenEffect.Explosion; propertyBag.PlayerContainer.ScreenEffectCounter = 2; } // If this bomb would result in a bigger shake, use its value. propertyBag.PlayerContainer.ScreenEffectCounter = Math.Min(propertyBag.PlayerContainer.ScreenEffectCounter, (distFromExplosive - 2) / 5); } return(null); }
public object HandlePacket(PacketBlockBulkTransfer packet, IPropertyBag propertyBag = null, IStateMachine gameInstance = null) { if (propertyBag == null) { return(null); } var blockEngine = propertyBag.GetEngine <IBlockEngine>("blockEngine"); try { // TODO: Make compression code work if (packet.IsCompressed) { /*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) * blockEngine.downloadList[x, y + dy, z] = blockType; * }*/ } else { propertyBag.MapLoadProgress[packet.X, packet.Y] = true; for (byte dy = 0; dy < 16; dy++) { for (byte z = 0; z < 64; z++) { var blockType = (BlockType)packet.BlockList[dy, z]; if (blockType != BlockType.None) { blockEngine.DownloadList[packet.X, packet.Y + dy, z] = blockType; } } } } var downloadComplete = true; for (var x = 0; x < 64; x++) { for (var y = 0; y < 64; y += 16) { if (propertyBag.MapLoadProgress[x, y]) { continue; } downloadComplete = false; break; } } if (downloadComplete) { gameInstance?.ChangeState("Infiniminer.States.TeamSelectionState"); if (!propertyBag.SettingsContainer.NoSound) { MediaPlayer.Stop(); } blockEngine.DownloadComplete(); } } catch (Exception e) { Console.OpenStandardError(); Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.StackTrace); Console.Error.Close(); } return(null); }