Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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;
                    }
                }
            }
        }
Esempio n. 5
0
 private static void ProcessUpdatePlayerClassMessage(Player player)
 {
     player.Class = (Class)Storage.PacketReader.ReadByte();
 }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        private static string ProcessPlaySoundMessage(Player player)
        {
            var soundName = Storage.PacketReader.ReadString();

            Sound.OneShot(soundName, false, player);

            return soundName;
        }
Esempio n. 8
0
        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);
            }
        }
Esempio n. 9
0
        public static void SendPlaySoundMessage(Player player, string soundName, byte id, bool immediate)
        {
            SendMessageHeader(MessageType.PlaySound, id);

            Storage.PacketWriter.Write(soundName);

            if(immediate)
            {
                SendOneOffMessage(player);
            }
        }
Esempio n. 10
0
        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);
            }
        }
Esempio n. 11
0
 private static void ProcessUpdatePlayerTeamMessage(Player player)
 {
     player.Team = (Team)Storage.PacketReader.ReadByte();
 }
Esempio n. 12
0
        public static void SendUpdatePlayerTeamMessage(Player player, byte id, bool immediate)
        {
            SendMessageHeader(MessageType.UpdatePlayerTeam, id);

            Storage.PacketWriter.Write((Byte)player.Team);

            if(immediate)
            {
                SendOneOffMessage(player);
            }
        }
Esempio n. 13
0
        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);
            }
        }
Esempio n. 14
0
        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);
            }
        }
Esempio n. 15
0
        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);
            }
        }
Esempio n. 16
0
        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);
            }
        }
Esempio n. 17
0
        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());
            }
        }
Esempio n. 18
0
 private static void ProcessUpdateScoreMessage(Player player)
 {
     if(player.Gamer.IsHost)
     {
         Storage.Scores[Team.Red] = Storage.PacketReader.ReadInt32();
         Storage.Scores[Team.Blue] = Storage.PacketReader.ReadInt32();
     }
 }
Esempio n. 19
0
        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);
        }
Esempio n. 20
0
        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);
                }
            }
        }
Esempio n. 21
0
        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;
        }
Esempio n. 22
0
        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;
                }
            }
        }
Esempio n. 23
0
        public static void SendChangeTutorialLevelMessage(Player player, byte id, bool immediate)
        {
            SendMessageHeader(MessageType.ChangeTutorialLevel, id);

            Storage.PacketWriter.Write(Storage.TutorialLevel);

            if (immediate)
            {
                SendOneOffMessage(player);
            }
        }
Esempio n. 24
0
        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();
            }
        }
Esempio n. 25
0
        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;
        }
Esempio n. 26
0
        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);
            }
        }