Example #1
0
        public StatsExport GetCurrentInfo(Inventory inventory)
        {
            var         stats  = inventory.GetPlayerStats().Result;
            StatsExport output = null;
            var         stat   = stats.FirstOrDefault();

            if (stat != null)
            {
                var ep      = stat.NextLevelXp - stat.PrevLevelXp - (stat.Experience - stat.PrevLevelXp);
                var time    = Math.Round(ep / (TotalExperience / GetRuntime()), 2);
                var hours   = 0.00;
                var minutes = 0.00;
                if (double.IsInfinity(time) == false && time > 0)
                {
                    hours   = Math.Truncate(TimeSpan.FromHours(time).TotalHours);
                    minutes = TimeSpan.FromHours(time).Minutes;
                }

                if (LevelForRewards == -1 || stat.Level >= LevelForRewards)
                {
                    var Result = Execute(inventory).Result;

                    if (Result.ToString().ToLower().Contains("awarded_already"))
                    {
                        LevelForRewards = stat.Level + 1;
                    }

                    if (Result.ToString().ToLower().Contains("success"))
                    {
                        Logger.Write("Leveled up: " + stat.Level, LogLevel.Info);

                        var items = Result.ItemsAwarded;

                        if (items.Any())
                        {
                            Logger.Write("- Received Items -", LogLevel.Info);
                            foreach (var item in items)
                            {
                                Logger.Write($"[ITEM] {item.ItemId} x {item.ItemCount} ", LogLevel.Info);
                            }
                        }
                    }
                }
                var Result2 = Execute(inventory).Result;
                LevelForRewards = stat.Level;
                if (Result2.ToString().ToLower().Contains("success"))
                {
                    var tokens = Result2.Result.ToString().Split(new[] { "itemId" }, StringSplitOptions.None);
                    Logger.Write("Items Awarded:" + Result2.ItemsAwarded);
                }
                output = new StatsExport
                {
                    Level             = stat.Level,
                    HoursUntilLvl     = hours,
                    MinutesUntilLevel = minutes,
                    CurrentXp         = stat.Experience - stat.PrevLevelXp - GetXpDiff(stat.Level),
                    LevelupXp         = stat.NextLevelXp - stat.PrevLevelXp - GetXpDiff(stat.Level)
                };
            }
            return(output);
        }
Example #2
0
 public void Dirty(Inventory inventory)
 {
     _exportStats = GetCurrentInfo(inventory);
     DirtyEvent?.Invoke();
 }