private void OnPong(Error error)
        {
            //Currently MatchEngine will be launched immediately and it does not care about different RTT for diffierent clients.
            //Some clients will look -50 ms to the past and some clients will look -500 ms or more to the past.
            //Is this a big deal? Don't know... Further investigation and playtest needed

            m_room = m_gState.GetValue <Room>("LocalGameServer.m_room");

            Player[] players;
            VoxelAbilitiesArray[]          abilities;
            SerializedTaskArray[]          serializedTasks;
            SerializedTaskTemplatesArray[] serializedTaskTemplates;
            AssignmentGroupArray[]         assignmentGroups;
            if (m_room != null)
            {
                error.Code = StatusCode.OK;
                players    = new Player[m_room.Players.Count];

                List <IBotController> bots = new List <IBotController>();

                //Will override or
                abilities               = new VoxelAbilitiesArray[m_room.Players.Count];
                serializedTasks         = new SerializedTaskArray[m_room.Players.Count];
                serializedTaskTemplates = new SerializedTaskTemplatesArray[m_room.Players.Count];
                assignmentGroups        = new AssignmentGroupArray[m_room.Players.Count];
                for (int i = 0; i < m_room.Players.Count; ++i)
                {
                    Player player = m_players[m_room.Players[i]];

                    players[i]                 = player;
                    abilities[i]               = m_abilities[m_room.Players[i]];
                    serializedTasks[i]         = m_tasks[m_room.Players[i]];
                    serializedTaskTemplates[i] = m_serializedTaskTemplates[m_room.Players[i]];
                    assignmentGroups[i]        = new AssignmentGroupArray
                    {
                        Groups = new AssignmentGroup[0]
                    };
                    if (player.IsActiveBot)
                    {
                        bots.Add(MatchFactory.CreateBotController(player, m_engine.GetTaskEngine(i), new DefaultStrategy()));
                    }
                }

                m_bots = bots.ToArray();
            }
            else
            {
                error.Code              = StatusCode.NotFound;
                error.Message           = "Room not found";
                players                 = new Player[0];
                abilities               = new VoxelAbilitiesArray[0];
                serializedTasks         = new SerializedTaskArray[0];
                serializedTaskTemplates = new SerializedTaskTemplatesArray[0];
                assignmentGroups        = new AssignmentGroupArray[0];
            }

            RaiseReadyToPlayAll(error, players, abilities, serializedTasks, serializedTaskTemplates, assignmentGroups);
            for (int i = 0; i < players.Length; ++i)
            {
                if (players[i].IsActiveBot)
                {
                    m_engine.GrantBotCtrl(i);
                    break;
                }
            }
        }
Exemplo n.º 2
0
        GetReadyToPlayAllArgs(Error error)
        {
            Player[] players;
            VoxelAbilitiesArray[]          abilities;
            SerializedTaskArray[]          taskInfo;
            SerializedTaskTemplatesArray[] taskTemplateInfo;
            AssignmentGroupArray[]         assignmentGroupArray;
            if (m_room != null)
            {
                enabled        = true;
                m_prevTickTime = m_time.Time;
                m_initialized  = true;

                error.Code = StatusCode.OK;
                players    = new Player[m_players.Count];

                List <IBotController> bots = new List <IBotController>();

                //Will override or
                abilities            = new VoxelAbilitiesArray[m_players.Count];
                taskInfo             = new SerializedTaskArray[m_players.Count];
                taskTemplateInfo     = new SerializedTaskTemplatesArray[m_players.Count];
                assignmentGroupArray = new AssignmentGroupArray[players.Length];
                for (int i = 0; i < m_players.Count; ++i)
                {
                    Player player = m_players[m_room.Players[i]];

                    players[i]              = player;
                    abilities[i]            = m_abilities[m_room.Players[i]];
                    taskInfo[i]             = m_taskTemplates[m_room.Players[i]];
                    taskTemplateInfo[i]     = m_taskTemplatesInfo[m_room.Players[i]];
                    assignmentGroupArray[i] = new AssignmentGroupArray
                    {
                        Groups = m_engine.GetPlayerView(i).AssignmentsController.GetGroups()
                    };
                    if (player.IsBot && player.BotType != BotType.Replay)
                    {
                        bots.Add(MatchFactory.CreateBotController(player, m_engine.GetTaskEngine(i)));
                    }
                }

                m_bots = bots.ToArray();
            }
            else
            {
                error.Code           = StatusCode.NotFound;
                error.Message        = "Room not found";
                players              = new Player[0];
                abilities            = new VoxelAbilitiesArray[0];
                taskInfo             = new SerializedTaskArray[0];
                taskTemplateInfo     = new SerializedTaskTemplatesArray[0];
                assignmentGroupArray = new AssignmentGroupArray[0];
            }


            var readyToPlayAllArgs = new ServerEventArgs <Player[], Dictionary <Guid, Dictionary <Guid, Player> >, VoxelAbilitiesArray[], SerializedTaskArray[], SerializedTaskTemplatesArray[], AssignmentGroupArray[], Room>();

            readyToPlayAllArgs.Arg    = players;
            readyToPlayAllArgs.Arg2   = m_clientIdToPlayers;
            readyToPlayAllArgs.Arg3   = abilities;
            readyToPlayAllArgs.Arg4   = taskInfo;
            readyToPlayAllArgs.Arg5   = taskTemplateInfo;
            readyToPlayAllArgs.Arg6   = assignmentGroupArray;
            readyToPlayAllArgs.Arg7   = m_room;
            readyToPlayAllArgs.Except = Guid.Empty;
            return(readyToPlayAllArgs);
        }