public ParticleSystem(Game game, Player player, bool isSand = false) : base(game) { DrawOrder = 50; Player = player; Particles = new Dictionary<string, Particle>(1000); IsSand = isSand; _particleQueue = new HashSet<Particle>(); _createParticleQueue = new HashSet<Particle>(); if(IsSand) { _fireParticles = new ParticleSystem(Game, Player); Children.Add(_fireParticles); _burningSound = Storage.Sound("SandBurning").CreateInstance(); _burningSound.Volume = 0.0f; _burningSound.IsLooped = true; _burningSound.Play(); _updateRemoteSandTimer = new Animation { CompletedDelegate = UpdateRemoteSand }; _updateRemoteSandTimerGroup = new AnimationGroup(_updateRemoteSandTimer, 60) { Loops = true }; Storage.AnimationController.AddGroup(_updateRemoteSandTimerGroup); } }
public static void SendActivateToolMessage(Player player, ToolSlot slot, ToolType type, bool newState, string propertyName, float propertyValue, byte id, bool immediate) { SendMessageHeader(MessageType.ActivateTool, id); Storage.PacketWriter.Write((byte)slot); Storage.PacketWriter.Write((byte)type); Storage.PacketWriter.Write(newState); Storage.PacketWriter.Write(propertyName ?? ""); Storage.PacketWriter.Write(propertyValue); if(immediate) { SendOneOffMessage(player); } }
public static void OneShot(string soundName, bool broadcast = true, Player remotePlayer = null) { var player = Storage.NetworkSession.LocalGamers[0].Tag as Player; float distance = 0.0f; if (remotePlayer != null) { distance = (float)Math.Sqrt(Math.Pow(remotePlayer.X - player.X, 2) + Math.Pow(remotePlayer.Y - player.Y, 2)); } var sound = Storage.Sound(soundName).CreateInstance(); sound.Volume = Math.Max(0.0f, (1700.0f - distance) / 1700.0f); Add(sound).Play(); if (player == null || !broadcast) return; Messages.SendPlaySoundMessage(player, soundName, player.Gamer.Id, true); }
private static void ProcessUpdatePlayerMenuStateMessage(Player player) { player.Class = (Class)Storage.PacketReader.ReadByte(); player.Team = (Team)Storage.PacketReader.ReadByte(); var primaryAType = (ToolType)Storage.PacketReader.ReadByte(); var primaryBType = (ToolType)Storage.PacketReader.ReadByte(); var weaponType = (ToolType)Storage.PacketReader.ReadByte(); var mobilityType = (ToolType)Storage.PacketReader.ReadByte(); var utilityType = (ToolType)Storage.PacketReader.ReadByte(); // TODO: copypasta if(primaryAType != ToolType.None && (player.PrimaryA == null || primaryAType != player.PrimaryA.Type)) { player.PrimaryA = Tool.OfType(primaryAType, player); } if(primaryBType != ToolType.None && (player.PrimaryB == null || primaryBType != player.PrimaryB.Type)) { player.PrimaryB = Tool.OfType(primaryBType, player); } if(weaponType != ToolType.None && (player.Weapon == null || weaponType != player.Weapon.Type)) { player.Weapon = Tool.OfType(weaponType, player); } if(mobilityType != ToolType.None && (player.Mobility == null || mobilityType != player.Mobility.Type)) { player.Mobility = Tool.OfType(mobilityType, player); } if(utilityType != ToolType.None && (player.Utility == null || utilityType != player.Utility.Type)) { player.Utility = Tool.OfType(utilityType, player); } var mapName = Storage.PacketReader.ReadString(); if(player.Gamer.IsHost) { foreach(var pair in Storage.Game.MapManager.Maps) { if(pair.Value.Name == mapName) { Storage.Game.GameMap = pair.Value; } } } }
private static void ProcessUpdatePlayerClassMessage(Player player) { player.Class = (Class)Storage.PacketReader.ReadByte(); }
private static Tuple<byte, int> ProcessStunMessage(Player player) { var stunId = Storage.PacketReader.ReadByte(); var stunEnergy = Storage.PacketReader.ReadInt32(); var localGamer = Storage.NetworkSession.LocalGamers[0]; if(stunId == localGamer.Id) { var localPlayer = localGamer.Tag as Player; if(localPlayer != null) { localPlayer.Stun(stunEnergy); } return null; } return Tuple.Create(stunId, stunEnergy); }
private static string ProcessPlaySoundMessage(Player player) { var soundName = Storage.PacketReader.ReadString(); Sound.OneShot(soundName, false, player); return soundName; }
public static void SendCreateSandMessage(Player player, Particle p, byte id, bool immediate) { SendMessageHeader(MessageType.CreateSand, id); Storage.PacketWriter.Write(p.Id); Storage.PacketWriter.Write(p.Owner); Storage.PacketWriter.Write(p.Position); Storage.PacketWriter.Write(p.Velocity); Storage.PacketWriter.Write((byte)p.Team); Storage.PacketWriter.Write(p.Alive); if(immediate) { SendOneOffMessage(player); } }
public static void SendPlaySoundMessage(Player player, string soundName, byte id, bool immediate) { SendMessageHeader(MessageType.PlaySound, id); Storage.PacketWriter.Write(soundName); if(immediate) { SendOneOffMessage(player); } }
public static void SendUpdateScoreMessage(Player player, byte id, bool immediate) { SendMessageHeader(MessageType.UpdateScore, id); Storage.PacketWriter.Write(Storage.Scores[Team.Red]); Storage.PacketWriter.Write(Storage.Scores[Team.Blue]); if(immediate) { SendOneOffMessage(player); } }
private static void ProcessUpdatePlayerTeamMessage(Player player) { player.Team = (Team)Storage.PacketReader.ReadByte(); }
public static void SendUpdatePlayerTeamMessage(Player player, byte id, bool immediate) { SendMessageHeader(MessageType.UpdatePlayerTeam, id); Storage.PacketWriter.Write((Byte)player.Team); if(immediate) { SendOneOffMessage(player); } }
public static void SendUpdateSandMessage(Player player, Particle p, byte id, bool immediate) { SendMessageHeader(MessageType.UpdateSand, id); Storage.PacketWriter.Write(p.Id); Storage.PacketWriter.Write(p.Position); Storage.PacketWriter.Write(p.Velocity); Storage.PacketWriter.Write(p.Alive); Storage.PacketWriter.Write(p.OnFire); if(immediate) { SendOneOffMessage(player, false); } }
public static void SendUpdatePlayerStateMessage(Player player, byte id) { SendMessageHeader(MessageType.UpdatePlayerState, id); Storage.PacketWriter.Write(player.X); Storage.PacketWriter.Write(player.Y); Storage.PacketWriter.Write(player.Angle); Storage.PacketWriter.Write(player.Stunned); Storage.PacketWriter.Write(player.Invisible); Storage.PacketWriter.Write(player.PureAcceleration); Storage.PacketWriter.Write((byte)player.Phase); Storage.PacketWriter.Write(Storage.RemainingTime.Ticks); Storage.PacketWriter.Write(player.ProtectTicks); if(player.Stunned) { Storage.PacketWriter.Write((UInt64)player.StunTimeRemaining.Ticks); } }
public static void SendUpdatePlayerMenuStateMessage(Player player, byte id) { SendMessageHeader(MessageType.UpdatePlayerMenuState, id); Storage.PacketWriter.Write((Byte)player.Class); Storage.PacketWriter.Write((Byte)player.Team); Storage.PacketWriter.Write((byte)(player.PrimaryA != null ? player.PrimaryA.Type : ToolType.None)); Storage.PacketWriter.Write((byte)(player.PrimaryB != null ? player.PrimaryB.Type : ToolType.None)); Storage.PacketWriter.Write((byte)(player.Weapon != null ? player.Weapon.Type : ToolType.None)); Storage.PacketWriter.Write((byte)(player.Mobility != null ? player.Mobility.Type : ToolType.None)); Storage.PacketWriter.Write((byte)(player.Utility != null ? player.Utility.Type : ToolType.None)); if(Storage.Game.GameMap == null) { Storage.PacketWriter.Write(""); } else { Storage.PacketWriter.Write(Storage.Game.GameMap.Name); } }
public static void SendStunMessage(Player player, Player stunnedPlayer, Int32 stunEnergy, byte id, bool immediate) { SendMessageHeader(MessageType.Stun, id); Storage.PacketWriter.Write(stunnedPlayer.Gamer.Id); Storage.PacketWriter.Write(stunEnergy); if(immediate) { SendOneOffMessage(player); } }
private static void ProcessUpdatePlayerStateMessage(Player player) { player.X = Storage.PacketReader.ReadSingle(); player.Y = Storage.PacketReader.ReadSingle(); player.Angle = Storage.PacketReader.ReadSingle(); player.Stunned = Storage.PacketReader.ReadBoolean(); player.Invisible = Storage.PacketReader.ReadSingle(); player.PureAcceleration = Storage.PacketReader.ReadVector2(); player.Phase = (GamePhases)Storage.PacketReader.ReadByte(); var remainingTime = Storage.PacketReader.ReadInt64(); player.ProtectTicks = Storage.PacketReader.ReadInt64(); if(player.Gamer.IsHost) { Storage.RemainingTime = new TimeSpan(remainingTime); } if(player.Stunned) { player.StunTimeRemaining = new TimeSpan((long)Storage.PacketReader.ReadUInt64()); } }
private static void ProcessUpdateScoreMessage(Player player) { if(player.Gamer.IsHost) { Storage.Scores[Team.Red] = Storage.PacketReader.ReadInt32(); Storage.Scores[Team.Blue] = Storage.PacketReader.ReadInt32(); } }
private static ActivationInfo ProcessActivateToolMessage(Player player) { var slot = (ToolSlot)Storage.PacketReader.ReadByte(); var type = (ToolType)Storage.PacketReader.ReadByte(); var state = Storage.PacketReader.ReadBoolean(); // This is scary. var propertyName = Storage.PacketReader.ReadString(); var propertyValue = Storage.PacketReader.ReadSingle(); if(player is RemotePlayer) { var tool = player.ToolInSlot(slot, type); tool.Active = state; if(propertyName != "") { var toolType = tool.GetType(); var property = toolType.GetProperty(propertyName); if(property != null) { var propertyType = property.PropertyType; property.SetValue(tool, Convert.ChangeType(propertyValue, propertyType), null); } } } return new ActivationInfo(slot, type, state, propertyName, propertyValue); }
public static void SendOneOffMessage(Player player, bool reliable = true) { var reliability = reliable ? SendDataOptions.Reliable : SendDataOptions.None; if(!Storage.NetworkSession.IsHost) { var gamer = player.Gamer as LocalNetworkGamer; if(gamer != null) { gamer.SendData(Storage.PacketWriter, reliability, Storage.NetworkSession.Host); } } else { var server = Storage.NetworkSession.Host as LocalNetworkGamer; if(server != null) { server.SendData(Storage.PacketWriter, reliability); } } }
private static Particle ProcessUpdateSandMessage(Player player) { var id = Storage.PacketReader.ReadString(); var exists = Storage.SandParticles.Particles.ContainsKey(id); var p = exists ? Storage.SandParticles.Particles[id] : new Particle(id); p.Position = Storage.PacketReader.ReadVector2(); p.Velocity = Storage.PacketReader.ReadVector2(); p.Alive = Storage.PacketReader.ReadBoolean(); p.OnFire = Storage.PacketReader.ReadBoolean(); return p; }
private static void ProcessChangeTutorialLevelMessage(Player uselessPlayer) { Storage.TutorialLevel = Storage.PacketReader.ReadInt32(); Storage.InTutorial = true; Storage.Game.GameMap = Storage.Game.MapManager.TutorialMap; if(Storage.TutorialLevel == 0 && !_inited) { _inited = true; var player = Storage.NetworkSession.LocalGamers[0].Tag as LocalPlayer; if (player != null) { player.Weapon = new Cannon(player); player.Utility = new Shield(player); player.Mobility = new BoostDrive(player); switch (player.Class) { case Class.None: break; case Class.Defense: player.PrimaryA = new Jet(player); player.PrimaryB = new SandCharge(player); Storage.Game.GameMap.RedSpawn.X = (player.Team == Team.Red) ? 100 : 1100; Storage.Game.GameMap.RedSpawn.Y = 400; break; case Class.Offense: player.PrimaryA = new Laser(player); player.PrimaryB = new FlameCharge(player); Storage.Game.GameMap.RedSpawn.X = (player.Team == Team.Red) ? 100 : 1100; Storage.Game.GameMap.RedSpawn.Y = 600; break; case Class.Support: player.PrimaryA = new Plow(player); player.PrimaryB = new PressureCharge(player); Storage.Game.GameMap.RedSpawn.X = (player.Team == Team.Red) ? 100 : 1100; Storage.Game.GameMap.RedSpawn.Y = 800; break; default: throw new ArgumentOutOfRangeException(); } Storage.Game.GameMap.BlueSpawn.X = Storage.Game.GameMap.RedSpawn.X; Storage.Game.GameMap.BlueSpawn.Y = Storage.Game.GameMap.RedSpawn.Y; } } }
public static void SendChangeTutorialLevelMessage(Player player, byte id, bool immediate) { SendMessageHeader(MessageType.ChangeTutorialLevel, id); Storage.PacketWriter.Write(Storage.TutorialLevel); if (immediate) { SendOneOffMessage(player); } }
private static void ProcessChangeWinStateMessage(Player player) { var state = (GamePhases)Storage.PacketReader.ReadByte(); var team = (Team)Storage.PacketReader.ReadByte(); var playState = Storage.Game.CurrentState() as PlayState; if(playState == null) { return; } switch(state) { case GamePhases.WonPhase1: playState.WinPhase1(team); break; case GamePhases.WonPhase2: playState.WinPhase2(team); break; default: throw new ArgumentOutOfRangeException(); } }
private static Particle ProcessCreateSandMessage(Player player) { var id = Storage.PacketReader.ReadString(); var exists = Storage.SandParticles.Particles.ContainsKey(id); var p = exists ? Storage.SandParticles.Particles[id] : new Particle(id); p.Owner = Storage.PacketReader.ReadByte(); p.Position = Storage.PacketReader.ReadVector2(); p.Velocity = Storage.PacketReader.ReadVector2(); p.Team = (Team)Storage.PacketReader.ReadByte(); p.Alive = Storage.PacketReader.ReadBoolean(); if(!exists) { Storage.SandParticles.Emit(p, false); } return p; }
public static void SendChangeWinStateMessage(Player player, GamePhases state, Team team, byte id, bool immediate) { SendMessageHeader(MessageType.ChangeWinState, id); Storage.PacketWriter.Write((byte)state); Storage.PacketWriter.Write((byte)team); if(immediate) { SendOneOffMessage(player); } }