Пример #1
0
        private void LevelUp(DiabloChecker checker)
        {
            string message = "You LEVEL UP to " + checker.botStatus.Level;

            bot.SendTextMessageAsync(checker.data.UserChatId, message);
            Console.WriteLine("LevelUp()");
        }
Пример #2
0
        private void Death(DiabloChecker checker)
        {
            string message = "You are DEATH and lost experience";

            bot.SendTextMessageAsync(checker.data.UserChatId, message);
            Console.WriteLine("Death()");
        }
Пример #3
0
        private void CheckLevelUp(DiabloChecker check, string level)
        {
            //TODO CHECK IF ERROR OCCUR MODIFING THE FILE
            //If level not updated
            if (check.botStatus.Level.ToString() == level)
            {
                //Increment local level
                check.botStatus.Level++;
                //Increment level on file
                try
                {
                    foreach (var item in data.PathStatus)
                    {
                        File.WriteAllText(item, JsonConvert.SerializeObject(check.botStatus));
                    }
                }
                catch (Exception e)
                {
                    bot.SendTextMessageAsync(check.data.UserChatId, e.StackTrace);
                    bot.SendTextMessageAsync(check.data.UserChatId, "Contact @Triko about this error");
                }

                //Send message LEVEL UP
                LevelUp(check);
            }
        }
Пример #4
0
        public async Task ExecuterAsync()
        {
            //Init all objects
            data          = new Data();
            diabloChecker = new DiabloChecker(data);
            keyboards     = new Keyboards();
            profile       = new Profile();

            //Init bot
            bot = data.Initialize();
            if (bot != null)
            {
                bot.OnMessage       += BotOnMessageReceived;
                bot.OnCallbackQuery += BotOnCallbackQueryReceived;
                bot.StartReceiving(Array.Empty <UpdateType>());
            }

            if (data.UserChatId <= 0)
            {
                // Wait until user text me
                while (!isFirstMessageArrived)
                {
                    Console.WriteLine("Waiting for message...");
                    await Task.Delay(5000);
                }
                //Save the new data in the config.json
                SaveOnFile();
            }

            //Init Profile
            //Create List of Schedule and get all schedule existing
            List <Profile> profiles = new List <Profile>();

            int    counter = 0;
            string line;

            // Read the file and store it line by line.
            System.IO.StreamReader file = new System.IO.StreamReader(data.PathToJsonProfile);
            while ((line = file.ReadLine()) != null)
            {
                profiles.Add(JsonConvert.DeserializeObject <Profile>(line));
                counter++;
            }

            file.Close();
            //profile = JsonConvert.DeserializeObject<Profile>(File.ReadAllText(data.PathToJsonProfile));

            //diabloChecker = new DiabloChecker(data);
            //diabloChecker.ReadStatus();
            //Start updating every X minutes
            Update();
        }
Пример #5
0
        //--------------------SEND_MESSAGES_METHODS--------------------------
        private async void Experience(DiabloChecker checker, Dictionary <string, long> levels)
        {
            //Prendo livello corrente
            string currentLevel = checker.botStatus.Level.ToString();
            //Prendo livello successivo
            string nextLevel = (System.Convert.ToInt32(currentLevel) + 1).ToString();

            //Prendo exp inizio livello corrente
            long expInitialCurrentLevel;

            levels.TryGetValue(currentLevel, out expInitialCurrentLevel);

            //Prendo exp fine livello corrente
            long expEndCurrentLevel;

            levels.TryGetValue(nextLevel, out expEndCurrentLevel);

            //Prendo exp corrente
            long currentExp = checker.botStatus.Experience;

            //Mappo il tutto e trasformo in stringa percentuale
            decimal expRemained = Remap(currentExp, expInitialCurrentLevel, expEndCurrentLevel, 0, 100);

            expRemained = System.Math.Round(expRemained, 2);
            if (expRemained >= 100)
            {
                //Check if level is actually changed
                CheckLevelUp(checker, currentLevel);
                expRemained -= 100;
            }

            string percent = expRemained.ToString() + "%";
            string message;

            if (checker.IsLevelEnabled)
            {
                message = "Current Level: " + currentLevel + "\nPercent complete " + percent;
            }
            else
            {
                message = percent + " completed";
            }
            //Invio il messaggio usando il bot
            await bot.SendTextMessageAsync(checker.data.UserChatId, message);

            Console.WriteLine("Experience()");
        }
Пример #6
0
        private void Update()
        {
            diabloChecker = new DiabloChecker(data);
            Dictionary <string, long> levels = GetAllLevels();

            //Get number of picked up objects lines
            int currentLine = File.ReadLines(data.PathToItemLog).Count();

            //Get number of picked up objects images
            int fileInFolder = Directory.GetFiles(data.PathImages).Length;

            //Start Task and every minutes read and update the status
            Task task = new Task(async() =>
            {
                //Leggo stato prima volta per inizializzare
                diabloChecker.ReadStatus();
                //Loop for item, exp, death
                while (true)
                {
                    //Controllo se ci sono aggiornamenti
                    Tuple <string, bool> WasUpdated = diabloChecker.IsUpdated();
                    if (WasUpdated.Item2)
                    {
                        switch (WasUpdated.Item1)
                        {
                        case "EXP":
                            Experience(diabloChecker, levels);
                            break;

                        case "DEATH":
                            Death(diabloChecker);
                            break;

                        case "LVLUP":
                            LevelUp(diabloChecker);
                            break;
                        }
                    }
                    int readLine = File.ReadLines(data.PathToItemLog).Count();
                    //Se si son aggiunte righe
                    if (currentLine < readLine)
                    {
                        currentLine     = readLine;
                        string lastLine = File.ReadLines(data.PathToItemLog).Last();
                        string message  = "I picked an object:\n" + lastLine;
                        //Invio il messaggio assieme alla foto usando il bot
                        await bot.SendTextMessageAsync(data.UserChatId, message);

                        var directory = new DirectoryInfo(data.PathImages);
                        //var myFile = (from f in directory.GetFiles() orderby f.LastWriteTime descending select f).First();
                        var myFile       = directory.GetFiles().OrderByDescending(f => f.LastWriteTime).First();
                        string imagePath = myFile.Directory.ToString() + "\\" + myFile.ToString();

                        //Send image of object found
                        using (Stream stream = System.IO.File.OpenRead(imagePath))
                        {
                            if (stream != null && stream.Length > 0)
                            {
                                await bot.SendPhotoAsync(
                                    chatId: data.UserChatId,
                                    photo: stream
                                    );
                            }
                            else
                            {
                                await bot.SendTextMessageAsync(data.UserChatId, "Corrupted image");
                            }
                        }
                        Console.WriteLine("Item Drop/Pick");
                    }
                    else if (currentLine > readLine)
                    {
                        currentLine = readLine;
                    }
                    Thread.Sleep(seconds);
                    Console.WriteLine("Current timer: " + seconds);
                }
            });

            task.Start();
            Console.Clear();
            Console.WriteLine("Running...");
            Console.ReadLine();
        }