Example #1
0
        public void LoadRoom(Player player, Room room)
        {
            NetCommandBuilder.RoomCommands[player].Clear();
            var currentRoom = room;

            foreach (var t in currentRoom.Enemies)
            {
                NetCommandBuilder.AppendToRoomCommand(player, "enemy_add/" + t.X + "/" + t.Y + "/" +
                                                      t.Width + "/" + t.Height + "/" + t.Texture);
            }
            foreach (var shot in currentRoom.Shots)
            {
                NetCommandBuilder.AppendToRoomCommand(player, "shot_add/" + shot.X + "/" + shot.Y + "/"
                                                      + shot.Form.Width + "/" + shot.Form.Height + "/" + shot.Texture);
            }
            foreach (var t in currentRoom.Players)
            {
                NetCommandBuilder.AppendToRoomCommand(player, "player_add/" + t.X + "/" + t.Y + "/" +
                                                      t.Width + "/" + t.Height + "/" + t.Texture);
            }
        }
        public void Run()
        {
            //var player = _room.Players[0];
            foreach (var player in _room.Players)
            {
                foreach (var t in _room.Players)
                {
                    NetCommandBuilder.AppendToRoomCommand(player, "player_move/" + _room.Players.IndexOf(t) + "/"
                                                          + t.X + "/" + t.Y + "/" + t.Texture);
                }
            }

            foreach (var t in _room.Enemies)
            {
                if (!t.IsWaiting)
                {
                    _room.EnemyControllers[t].Control();
                    foreach (var player in _room.Players)
                    {
                        NetCommandBuilder.AppendToRoomCommand(player, "enemy_move/" + _room.Enemies.IndexOf(t) + "/"
                                                              + t.X + "/" + t.Y + "/" + t.Texture);
                    }
                    //NetCommandBuilder.AppendToRoomCommand("enemy_move/" + _room.Enemies.IndexOf(t) + "/"
                    //    +  t.X + "/" + t.Y + "/" + t.Texture);

                    //if (t is Boss)
                    //{
                    //    var bEnemy = t as Boss;
                    //    var bRoom = _room as BossRoom;
                    //    if (bEnemy.CanUseSkill && bEnemy.Hp < bEnemy.MaxHp / 2)
                    //    {
                    //        bEnemy.UseSkill(bEnemy, bRoom);
                    //    }
                    //}
                }
            }

            if (_room.SummonedEnemies.Count != 0)
            {
                foreach (var t in _room.SummonedEnemies)
                {
                    t.IsWaiting = false;
                    _room.Enemies.Add(t);
                    foreach (var player in _room.Players)
                    {
                        NetCommandBuilder.AppendToRoomCommand(player, "enemy_add/" + t.X + "/" + t.Y + "/" +
                                                              t.Form.Width + "/" + t.Form.Height + "/" + t.Texture);
                    }
                }
                _room.SummonedEnemies.Clear();
            }


            foreach (var t in _room.Shots)
            {
                t.Move();
                foreach (var player in _room.Players)
                {
                    NetCommandBuilder.AppendToRoomCommand(player, "shot_move/" + _room.Shots.IndexOf(t) + "/"
                                                          + t.X + "/" + t.Y + "/" + t.Texture);
                }
            }
            foreach (var t in _room.Shots)
            {
                if (ShotIsRemoved(t))
                {
                    foreach (var player in _room.Players)
                    {
                        NetCommandBuilder.AppendToRoomCommand(player, "shot_remove/" + _room.Shots.IndexOf(t));
                    }
                }
            }
            _room.Shots.RemoveAll(ShotIsRemoved);

            var collisionChecker = new CollisionChecker();

            foreach (var t in _room.Shots)
            {
                foreach (var player in _room.Players)
                {
                    if (collisionChecker.IsCollided(t, _room))
                    {
                        OnShotBorderCollision?.Invoke(t, _room);
                    }
                    if (collisionChecker.IsCollided(t, player))
                    {
                        if (t.Owner.GetType() != player.GetType())
                        {
                            OnShotPlayerCollision?.Invoke(t, player);
                        }
                    }
                }
                foreach (var item in _room.Enemies)
                {
                    if (collisionChecker.IsCollided(t, item))
                    {
                        if (t.Owner != item)
                        {
                            OnShotEnemyCollision?.Invoke(t, item);
                        }
                    }
                }
            }

            foreach (var t in _room.Items)
            {
                foreach (var player in _room.Players)
                {
                    if (collisionChecker.IsCollided(player, t) && t.IsAvailable)
                    {
                        OnPlayerItemCollision?.Invoke(player, t);
                    }
                }
            }
            foreach (var t in _room.Shots)
            {
                if (ShotIsRemoved(t))
                {
                    foreach (var player in _room.Players)
                    {
                        NetCommandBuilder.AppendToRoomCommand(player, "shot_remove/" + _room.Shots.IndexOf(t));
                    }
                }
            }
            _room.Shots.RemoveAll(ShotIsRemoved);
            foreach (var t in _room.Enemies)
            {
                if (EnemyIsDead(t))
                {
                    foreach (var player in _room.Players)
                    {
                        NetCommandBuilder.AppendToRoomCommand(player, "enemy_remove/" + _room.Enemies.IndexOf(t));
                    }
                }
            }
            _room.Enemies.RemoveAll(EnemyIsDead);
            _room.Items.RemoveAll(ItemIsPicked);
            //Network.NetWorker.Send(Encoding.UTF8.GetBytes(NetCommandBuilder.Command));
        }
Example #3
0
        public void Run()
        {
            foreach (var player in Players.GamePlayers)
            {
                if (!_currentRooms.ContainsKey(player))
                {
                    _currentRooms[player] = _level.Rooms[_level.StartRoomIndex];
                    LoadRoom(player, _level.Rooms[_level.StartRoomIndex]);

                    foreach (var t in _level.Rooms[_level.StartRoomIndex].Players)
                    {
                        NetCommandBuilder.AppendToRoomCommand(t, "player_add/" + player.X + "/" + player.Y + "/" +
                                                              player.Width + "/" + player.Height + "/" + player.Texture);
                    }

                    _level.Rooms[_level.StartRoomIndex].Players.Add(player);



                    NetCommandBuilder.AppendToRoomCommand(player, "player_add/" + player.X + "/" + player.Y + "/" +
                                                          player.Width + "/" + player.Height + "/" + player.Texture);
                }


                var currentRoom = _currentRooms[player];
                if (_commands.ContainsKey(player))
                {
                    _controller.Control(player, currentRoom, _commands[player]);
                }
                _level.RoomSupervisors[currentRoom].Run();

                //new PlayerUpdater(_playerRemotes).Update(player);
                var collisionChecker = new CollisionChecker();
                if (currentRoom.Enemies.Count == 0 && !(currentRoom is ChallengeRoom))
                {
                    var doors = currentRoom.GetAllDoors();
                    foreach (var t in doors)
                    {
                        t.IsLocked = false;
                    }
                }


                if ((currentRoom.TopDoor != null) && (collisionChecker.IsCollided(player, currentRoom.TopDoor)))
                {
                    if (!currentRoom.TopDoor.IsLocked)
                    {
                        //currentRoom.Shots.Clear();
                        var index = currentRoom.Players.IndexOf(player);
                        currentRoom.Players.Remove(player);



                        foreach (var t in currentRoom.Players)
                        {
                            NetCommandBuilder.AppendToRoomCommand(t, "player_remove/" + index);
                        }

                        currentRoom = currentRoom.TopDoor.NextRoom;
                        foreach (var t in currentRoom.Players)
                        {
                            NetCommandBuilder.AppendToRoomCommand(t, "player_add/" + player.X + "/" + player.Y + "/" +
                                                                  player.Width + "/" + player.Height + "/" + player.Texture);
                        }
                        LoadRoom(player, currentRoom);
                        currentRoom.Players.Add(player);
                        player.MoveTo(currentRoom.BotDoor.Form.Left, currentRoom.BotDoor.Form.Top + 0.25f);
                        _currentRooms[player] = currentRoom;
                        foreach (var t in currentRoom.Enemies)
                        {
                            t.Timer.Start();
                        }
                    }
                    NetCommandBuilder.AppendToLevelCommand(player, "change_room/" + _level.Rooms.IndexOf(currentRoom));
                }
                if ((currentRoom.BotDoor != null) && (collisionChecker.IsCollided(player, currentRoom.BotDoor)))
                {
                    if (!currentRoom.BotDoor.IsLocked)
                    {
                        //currentRoom.Shots.Clear();
                        var index = currentRoom.Players.IndexOf(player);
                        currentRoom.Players.Remove(player);
                        foreach (var t in currentRoom.Players)
                        {
                            NetCommandBuilder.AppendToRoomCommand(t, "player_remove/" + index);
                        }
                        currentRoom = currentRoom.BotDoor.NextRoom;
                        foreach (var t in currentRoom.Players)
                        {
                            NetCommandBuilder.AppendToRoomCommand(t, "player_add/" + player.X + "/" + player.Y + "/" +
                                                                  player.Width + "/" + player.Height + "/" + player.Texture);
                        }
                        LoadRoom(player, currentRoom);
                        currentRoom.Players.Add(player);
                        player.MoveTo(currentRoom.TopDoor.Form.Left, currentRoom.TopDoor.Form.Bottom);
                        _currentRooms[player] = currentRoom;
                        foreach (var t in currentRoom.Enemies)
                        {
                            t.Timer.Start();
                        }
                        NetCommandBuilder.AppendToLevelCommand(player, "change_room/" + _level.Rooms.IndexOf(currentRoom));
                    }
                }
                if ((currentRoom.LeftDoor != null) && (collisionChecker.IsCollided(player, currentRoom.LeftDoor)))
                {
                    if (!currentRoom.LeftDoor.IsLocked)
                    {
                        //currentRoom.Shots.Clear();
                        var index = currentRoom.Players.IndexOf(player);
                        currentRoom.Players.Remove(player);
                        foreach (var t in currentRoom.Players)
                        {
                            NetCommandBuilder.AppendToRoomCommand(t, "player_remove/" + index);
                        }
                        currentRoom = currentRoom.LeftDoor.NextRoom;
                        foreach (var t in currentRoom.Players)
                        {
                            NetCommandBuilder.AppendToRoomCommand(t, "player_add/" + player.X + "/" + player.Y + "/" +
                                                                  player.Width + "/" + player.Height + "/" + player.Texture);
                        }
                        LoadRoom(player, currentRoom);
                        currentRoom.Players.Add(player);
                        player.MoveTo(currentRoom.RightDoor.Form.Left - player.Form.Width - 0.005f,
                                      currentRoom.RightDoor.Form.Top);
                        _currentRooms[player] = currentRoom;
                        foreach (var t in currentRoom.Enemies)
                        {
                            t.Timer.Start();
                        }
                        NetCommandBuilder.AppendToLevelCommand(player, "change_room/" + _level.Rooms.IndexOf(currentRoom));
                    }
                }
                if ((currentRoom.RightDoor != null) && (collisionChecker.IsCollided(player, currentRoom.RightDoor)))
                {
                    if (!currentRoom.RightDoor.IsLocked)
                    {
                        // currentRoom.Shots.Clear();
                        var index = currentRoom.Players.IndexOf(player);
                        currentRoom.Players.Remove(player);
                        foreach (var t in currentRoom.Players)
                        {
                            NetCommandBuilder.AppendToRoomCommand(t, "player_remove/" + index);
                        }
                        currentRoom = currentRoom.RightDoor.NextRoom;
                        foreach (var t in currentRoom.Players)
                        {
                            NetCommandBuilder.AppendToRoomCommand(t, "player_add/" + player.X + "/" + player.Y + "/" +
                                                                  player.Width + "/" + player.Height + "/" + player.Texture);
                        }
                        LoadRoom(player, currentRoom);
                        currentRoom.Players.Add(player);
                        player.MoveTo(currentRoom.LeftDoor.Form.Right, currentRoom.LeftDoor.Form.Top);
                        _currentRooms[player] = currentRoom;
                        foreach (var t in currentRoom.Enemies)
                        {
                            t.Timer.Start();
                        }
                        NetCommandBuilder.AppendToLevelCommand(player, "change_room/" + _level.Rooms.IndexOf(currentRoom));
                    }
                }
                //NetCommandBuilder.AppendToLevelCommand(player, "change_room/" + _level.Rooms.IndexOf(currentRoom));
            }
        }