Exemplo n.º 1
0
        public override void NotifyStopMoving(bool canceled, bool refused)
        {
            base.NotifyStopMoving(canceled, refused);

            if (m_useAfterMove != null)
            {
                if (!canceled)
                {
                    var skill = m_useAfterMove;
                    Bot.AddMessage(() => UseInteractiveObject(skill)); // call next tick
                }

                m_useAfterMove = null;
            }
            if (_actionAfterMove != null)
            {
                Bot.AddMessage(_actionAfterMove);
                _actionAfterMove = null;
            }

            if (m_nextMap != null)
            {
                if (!canceled && !refused)
                {
                    var id = m_nextMap.Value;
                    m_previousMap = Map.Id;
                    Bot.AddMessage(() => Bot.SendToServer(new ChangeMapMessage(id)));
                }

                m_nextMap = null;
            }
        }
        private void UpdateClient(Client client, ref Message message)
        {
            {
                Bot.UpdateClient(client);

                Bot.AddCommand(client);
                Bot.AddMessage(client, message);
                message.Text    = null;
                message.Contact = null;
            }
        }
Exemplo n.º 3
0
        private void OnSelect(object parameter)
        {
            if (parameter == null || !CanSelect(parameter))
            {
                return;
            }

            var server = (ServersListEntry)parameter;

            Bot.AddMessage(() => Bot.SendToServer(new ServerSelectionMessage((short)server.Id)));
        }
Exemplo n.º 4
0
        public MapNeighbour ChangeMap(MapNeighbour neighbour = MapNeighbour.Any)
        {
            m_nextMap = null;
            PathFinder pathFinder = new PathFinder(Map, false);

            // Select a random cell in the set of all reachable cells that allow map change in the right direction.
            Cell destCell = pathFinder.FindConnectedCells(Cell, false, true, cell => (cell.Cell.MapChangeData & Map.MapChangeDatas[neighbour]) != 0).GetRandom();

            if (destCell == null)
            {
                return(MapNeighbour.None);
            }
            neighbour = Map.GetDirectionOfTransitionCell(destCell);
            if (neighbour == MapNeighbour.None)
            {
                SendMessage(String.Format("Can't find any linked map from {0}", this), Color.Red);
                return(MapNeighbour.None);
            }

            if (destCell.Id != Cell.Id)
            {
                if (Move(destCell, pathFinder, 0, true))
                {
                    m_nextMap = GetNeighbourId(neighbour);
                    SendMessage(String.Format("Moving at the {2} of map {0} to map {1}", this, m_nextMap, neighbour), Color.Pink);
                    return(neighbour);
                }
                else
                {
                    return(MapNeighbour.None);
                }
            }
            else
            {
                Bot.AddMessage(() => Bot.SendToServer(new ChangeMapMessage(GetNeighbourId(neighbour))));
                m_previousMap = Map.Id;
                SendMessage(String.Format("Moving at the {2} of map {0} to map {1} (direct)", this, m_nextMap, neighbour), Color.Pink);
            }
            return(neighbour);
        }
        // public async Task<OkResult> Post([FromBody]Update update)
        //    public async Task<OkResult> Post([FromBody]Update update)
        public async Task <OkResult> Post([FromBody] Update update)

        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            try
            {
                var botClient = await Bot.GetBotClientAsync();

                if (update.CallbackQuery != null)
                {
                    try
                    {
                        var callbackQuery = update.CallbackQuery;

                        await ExecuteCallbackMessage(callbackQuery, botClient);

                        return(Ok());
                    }
                    catch (Exception ex)
                    {
                        Bot.MyLogger(ex.Message);
                        Bot.MyLogger(ex.StackTrace);
                        return(Ok());
                    }
                }
                else if (update == null)
                {
                    Bot.MyLogger("Какая то херня =(");

                    return(Ok());
                }

                var    message     = update.Message;
                string copymessage = null;
                if (update.Message.Text != null)
                {
                    copymessage = (string)update.Message.Text.Clone();
                }

                client        = new Client();
                client.ChatId = (long)message.Chat.Id;

                if (!Bot.Contains(client))
                {
                    if (message.Text.Contains("/start") && message.Text.Length > 8)
                    {
                        client.Metrica = message.Text.Substring(8);
                    }
                    Bot.AddClient(client);
                    Kitchen kitchen = new Kitchen();
                    kitchen.ChatId = client.ChatId;
                    Bot.AddKitchen(kitchen);
                    Bot.AddMessage(client, message);
                }
                else
                {
                    client = Bot.GetClient(client);
                    if (!DBHelper.ChekKitchen(client))
                    {
                        Kitchen kitchen = new Kitchen();
                        kitchen.ChatId = client.ChatId;
                        Bot.AddKitchen(kitchen);
                    }
                }



                Bot.AddCommand(client);


                //Bot.AddMessage(client, message);



                //return Ok();
                await ExecuteCommand(message, botClient, copymessage);

                return(Ok());
            }
            catch (Exception ex)
            {
                Bot.MyLogger(ex.Message);
                Bot.MyLogger(ex.StackTrace);
                return(Ok());
            }
        }
        private async Task ExecuteCommand(Message message, Telegram.Bot.TelegramBotClient botClient, string copymessage)
        {
            var commands = Bot.Commands;

            foreach (var command in commands)
            {
                if (command is TextMessageCommand || command is ImageMessageCommand || command is InlineImageGalleryCommand)
                {
                    await command.Execute(message, botClient, client);

                    client.Stage = command.NextStage(message, client);
                    UpdateClient(client, ref message);

                    await ExecuteCommand(message, botClient, copymessage);
                }
                else if (command is QuestionCommand || command is QuestionKitchenCommand)
                {
                    if (!command.Contains(message))
                    {
                        await command.Execute(message, botClient, client);
                    }
                    if (command.Contains(message))
                    {
                        client.Stage = command.NextStage(message, client);
                        UpdateClient(client, ref message);

                        if (command is QuestionKitchenCommand)
                        {
                            Kitchen kitchen = DBHelper.GetKitchen(client);
                            if (kitchen.Lenght == -1)
                            {
                                kitchen.Lenght = int.Parse(copymessage);
                            }
                            else if (kitchen.TypeFace == "null")
                            {
                                kitchen.TypeFace = copymessage;
                            }
                            else if (kitchen.TypeTable == "null")
                            {
                                kitchen.TypeTable = copymessage;
                            }
                            DBHelper.UpdateKitchen(kitchen);
                            if (kitchen.Lenght != -1 && kitchen.TypeFace != "null" && kitchen.TypeTable != "null")
                            {
                                var    culture     = new System.Globalization.CultureInfo("ru-RU");
                                string messageTEXT = "Базовая стоимость: " + kitchen.GetFullPrice("./DataBase/price.xlsx").ToString("#,#", culture) + "р. минус ваша скидка 10% = " + kitchen.GetSalePrice("./DataBase/price.xlsx", 1.2).ToString("#,#", culture) +
                                                     "р. (Кухня длиной " + kitchen.Lenght + " метра, фасады: "
                                                     + kitchen.TypeFace + ", фурнитура Blum, " +
                                                     "столешница: " + kitchen.TypeTable.ToLower() + ". В цену включены: замеры, создание прототипа, доставка, разгрузка, сборка и клининг.)";
                                string text = "Хорошие новости, при заказе кухни у Стаса, персональный бонус – скидка 10% 🎁";
                                await botClient.SendTextMessageAsync(message.Chat.Id, text, parseMode : Telegram.Bot.Types.Enums.ParseMode.Html);

                                await botClient.SendTextMessageAsync(message.Chat.Id, messageTEXT, parseMode : Telegram.Bot.Types.Enums.ParseMode.Html);

                                DBHelper.AddMessageTEXT(client, messageTEXT);
                                DBHelper.AddMessageTEXT(client, text);
                                DBHelper.EraseKitchen(kitchen);
                            }
                        }

                        await ExecuteCommand(message, botClient, copymessage);
                    }
                }

                else if (command is NameMessageCommand)
                {
                    await command.Execute(message, botClient, client);
                }
                else if (command is PhoneMessageCommand)
                {
                    if (message.Contact != null)
                    {
                        if (client.Name == "-1")
                        {
                            client.Name = message.Contact.FirstName + " " + message.Contact.LastName;
                        }
                        client.PhoneNumber = message.Contact.PhoneNumber;
                        client.Stage       = command.NextStage(message, client);
                        UpdateClient(client, ref message);
                        await BItrix24CRM.Start(client);
                        await ExecuteCommand(message, botClient, copymessage);
                    }

                    else if (message.Text == "Не буду")
                    {
                        client.Stage = command.NextStage(message, client);
                        UpdateClient(client, ref message);

                        await ExecuteCommand(message, botClient, copymessage);
                    }
                    else
                    {
                        // if (client.Name == null)
                        //   client.Name = message.Text;
                        Bot.AddMessage(client, message);
                        await command.Execute(message, botClient, client);
                    }
                }
            }
        }
Exemplo n.º 7
0
        private void InternalChangeMap()
        {
            _changingMap = true;
            if (IsFighting())
            {
                SendWarning("InternalChangeMap : I'm fighting => stop it !");
                _changingMap = false;
                return;
            }
            if (_srcLeaderMap != Map.Id)
            {
                SendWarning("I'm not on the proper map to follow leader on the next map");
                _changingMap = false;
                return;
            }
            if (_pivotLeaderCell != Cell.Id)
            {
                PathFinder pathFinder = new PathFinder(Map, false);
                if (!Move(_pivotLeaderCell, pathFinder, 0, true))
                {
                    if (_nbTryLeft > 0)
                    {
                        SendWarning("InternalChangeMap : Can't join the leader yet, try later");
                        _nbTryLeft--;
                        Bot.CallDelayed(6000, InternalChangeMap);
                    }
                    else
                    if (_nbTryLeft > -6)
                    {
                        MapNeighbour neighbour = Map.GetDirectionOfTransitionCell(Map.Cells[_pivotLeaderCell]);
                        Cell         destCell  = pathFinder.FindConnectedCells(Cell, false, true, cell => (cell.Cell.MapChangeData & Map.MapChangeDatas[neighbour]) != 0).GetRandom();
                        if (destCell == null)
                        {
                            SendWarning("InternalChangeMap  : Can't join the leader, no try left. Can't even find any alternate path to go {0}", neighbour);
                        }
                        else
                        {
                            SendWarning("InternalChangeMap : Can't join the leader, no try left. Trying alternative path to go {0} : cell {1}", neighbour, destCell);
                            _pivotLeaderCell = destCell.Id;
                        }
                        _nbTryLeft--;
                        Bot.CallDelayed(2000, InternalChangeMap);
                    }
                    else
                    {
                        SendError("InternalChangeMap : Can't find any path to join the leader. Trying again later. ");
                        _changingMap = false;
                    }
                    return;
                }

                SendWarning("InternalChangeMap : Move from {0} to {1} succeeded. When move is complete, should go from map {2} to map {3}. ", Cell, Map.Cells[_pivotLeaderCell], Map.ToString(), new Map(_dstLeaderMap));
                _changingMap = false;
                m_nextMap    = _dstLeaderMap;
                return;
            }
            SendError("I'm already on the good Cell, just try to jump to the other map.");

            Bot.CallDelayed(400, () => Bot.AddMessage(() => Bot.SendToServer(new ChangeMapMessage(_dstLeaderMap))));
            m_previousMap = Map.Id;
            _changingMap  = false;
            return;
        }