Ejemplo n.º 1
0
        public static void CheckOnTheEnd(int id)
        {
            Parser.ParseEndGameResults(id);

            lock (Program.gamesLocker)
            {
                Game game = Program.games[id];

                //if game wasn't finished
                if (!game.isFinished)
                {
                    TasksMgr.AddTask(new Task
                    {
                        TimeUNIX = Utilites.NowUNIX() + 30,
                        Func     = CheckOnTheEnd,
                        GameID   = id
                    });
                    return;
                }
                //смайлы в Telegram
                string yes = Encoding.UTF8.GetString(new byte[] { 0xE2, 0x9C, 0x85 });
                string not = Encoding.UTF8.GetString(new byte[] { 0xE2, 0x9D, 0x8E });

                string   text;
                double   goals;
                Algoritm algoritm;
                //First algoritm
                algoritm = game.algoritms[0];
                if (algoritm.sendedTotal > 0)
                {
                    text  = algoritm.messageText + " ";
                    goals = game.teams[0].allGoals + game.teams[1].allGoals;

                    if ((algoritm.tMore && goals > algoritm.sendedTotal) ||
                        (!algoritm.tMore && goals < algoritm.sendedTotal))
                    {
                        text += yes;
                    }
                    else
                    {
                        text += not;
                    }

                    text += " " + goals;

                    Debug.Log("Редактирую сообщения");

                    foreach (Message message in algoritm.messages)
                    {
                        Telegram.EditMessage(text, message.chatID, message.msgID);
                    }
                }

                //Second algoritm
                algoritm = game.algoritms[1];
                if (algoritm.sendedTotal > 0)
                {
                    text  = algoritm.messageText + " ";
                    goals = game.teams[0].goals1T + game.teams[1].goals1T;

                    if ((algoritm.tMore && goals > algoritm.sendedTotal) ||
                        (!algoritm.tMore && goals < algoritm.sendedTotal))
                    {
                        text += yes;
                    }
                    else
                    {
                        text += not;
                    }

                    text += " " + goals;

                    foreach (Message message in algoritm.messages)
                    {
                        Telegram.EditMessage(text, message.chatID, message.msgID);
                    }
                }

                //Third algoritm
                algoritm = game.algoritms[2];
                if (algoritm.sendedTotal > 0)
                {
                    text  = algoritm.messageText + " ";
                    goals = game.teams[game.favTeam - 1].goals1T;

                    if (goals > algoritm.sendedTotal)
                    {
                        text += yes;
                    }
                    else
                    {
                        text += not;
                    }

                    text += " " + goals;

                    foreach (Message message in algoritm.messages)
                    {
                        Telegram.EditMessage(text, message.chatID, message.msgID);
                    }
                }


                Program.games.Remove(id);
            }
        }