Browse Source

showing opened roles and extended stats

Tigran 4 years ago
parent
commit
3c61f8239f

+ 41 - 0
MafiaTelegramBot/Models/Inlines/ShowMyExtendedStatsQuery.cs

@@ -0,0 +1,41 @@
+using System;
+using System.Linq;
+using System.Threading.Tasks;
+using MafiaTelegramBot.DataBase.EntityDao;
+using MafiaTelegramBot.Resources;
+using Telegram.Bot.Types;
+
+namespace MafiaTelegramBot.Models.Inlines
+{
+    public class ShowMyExtendedStatsQuery : Query
+    {
+        protected override Callback Name => Callback.ShowMyExtendedStats;
+
+        protected override async Task<Message> Execute(Update update)
+        {
+            await DeletePreviousMessage(ChatId, update.CallbackQuery.Message.MessageId);
+            var user = await UserDao.GetPlayerById(UserId);
+            var rolesList = Enum.GetValues(typeof(Roles)).Cast<Roles>().ToList();
+            rolesList.Remove(Roles.None);
+            rolesList.Remove(Roles.All);
+            if (!user.Statistics.Contains(Roles.All))
+                await UserDao.ActiveUsers[UserId].LoadStatistics();
+            var allStatsRow = user.Statistics[Roles.All];
+            var message = "";
+            if (allStatsRow.Games > 0)
+                foreach (var role in rolesList)
+                {
+                    if (user.Statistics.Contains(role) && user.Statistics[role].Games > 0)
+                    {
+                        var statsRow = user.Statistics[role];
+                        message += String.Format(strings.role_string, roles.ResourceManager.GetString(role.ToString()), statsRow.Wins, statsRow.Games, (int) (statsRow.GetWinrate()*100)) + '\n';
+                    }
+                }
+            else
+            {
+                message += strings.no_stats_by_roles;
+            }
+            return await Bot.SendWithMarkdown2(ChatId, message);
+        }
+    }
+}

+ 4 - 23
MafiaTelegramBot/Models/Inlines/ShowMyRolesQuery.cs

@@ -1,4 +1,3 @@
-using System;
 using System.Linq;
 using System.Threading.Tasks;
 using MafiaTelegramBot.DataBase.EntityDao;
@@ -15,28 +14,10 @@ namespace MafiaTelegramBot.Models.Inlines
         {
             await DeletePreviousMessage(ChatId, update.CallbackQuery.Message.MessageId);
             var user = await UserDao.GetPlayerById(UserId);
-            var rolesList = Enum.GetValues(typeof(Roles)).Cast<Roles>().ToList();
-            rolesList.Remove(Roles.None);
-            rolesList.Remove(Roles.All);
-            if (!user.Statistics.Contains(Roles.All))
-                await UserDao.ActiveUsers[UserId].LoadStatistics();
-            var allStatsRow = user.Statistics[Roles.All];
-            var message = "";
-            user = await UserDao.GetPlayerById(UserId);
-            if (allStatsRow.Games > 0)
-                foreach (var role in rolesList)
-                {
-                    if (user.Statistics.Contains(role) && user.Statistics[role].Games > 0)
-                    {
-                        var statsRow = user.Statistics[role];
-                        message += String.Format(strings.role_string, roles.ResourceManager.GetString(role.ToString()), statsRow.Wins, statsRow.Games, (int) (statsRow.GetWinrate()*100)) + '\n';
-                    }
-                }
-            else
-            {
-                message += strings.no_stats_by_roles;
-            }
-            return await Bot.SendWithMarkdown2(ChatId, message);
+            var opened = user.OpenedRoles.ToList();
+            if (opened.Count > 3) return await Bot.SendWithMarkdown2(ChatId, opened.Where(role => role is not (Roles.Cop or Roles.Don or Roles.Doctor))
+                .Aggregate(strings.your_opened_roles_list, (current, role) => current + $"\n{roles.ResourceManager.GetString(role.ToString())}"));
+            return await Bot.SendWithMarkdown2(ChatId, strings.you_dont_have_any_extended_role);
         }
     }
 }

+ 2 - 1
MafiaTelegramBot/Resources/Callback.cs

@@ -25,6 +25,7 @@ namespace MafiaTelegramBot.Resources
         MafiaTarget,
         NightTarget,
         DetectiveTarget,
-        StartGame
+        StartGame,
+        ShowMyExtendedStats
     }
 }

+ 5 - 3
MafiaTelegramBot/Resources/Keyboard.cs

@@ -83,14 +83,16 @@ namespace MafiaTelegramBot.Resources
 
         public static InlineKeyboardMarkup ProfileKeyboard(long userId)
         {
-            return new (new[]
+            return new InlineKeyboardMarkup(new[]
             {
                 new[] {
                     InlineKeyboardButton.WithCallbackData(strings.shop, $"{Callback.ShopMenu}|{userId}"),
                     InlineKeyboardButton.WithCallbackData(strings.settings, $"{Callback.SettingsProfile}|{userId}")
                 },
-                new[] {InlineKeyboardButton.WithCallbackData(strings.my_roles, $"{Callback.ShowMyRoles}|{userId}")}
-                
+                new[] {
+                    InlineKeyboardButton.WithCallbackData(strings.opened_roles, $"{Callback.ShowMyRoles}|{userId}"),
+                    InlineKeyboardButton.WithCallbackData(strings.extended_stats, $"{Callback.ShowMyExtendedStats}|{userId}")
+                },
             });
         }
 

+ 20 - 2
MafiaTelegramBot/Resources/strings.Designer.cs

@@ -81,9 +81,9 @@ namespace MafiaTelegramBot {
             }
         }
         
-        internal static string my_roles {
+        internal static string opened_roles {
             get {
-                return ResourceManager.GetString("my_roles", resourceCulture);
+                return ResourceManager.GetString("opened_roles", resourceCulture);
             }
         }
         
@@ -1148,5 +1148,23 @@ namespace MafiaTelegramBot {
                 return ResourceManager.GetString("previous", resourceCulture);
             }
         }
+        
+        internal static string you_dont_have_any_extended_role {
+            get {
+                return ResourceManager.GetString("you_dont_have_any_extended_role", resourceCulture);
+            }
+        }
+        
+        internal static string your_opened_roles_list {
+            get {
+                return ResourceManager.GetString("your_opened_roles_list", resourceCulture);
+            }
+        }
+        
+        internal static string extended_stats {
+            get {
+                return ResourceManager.GetString("extended_stats", resourceCulture);
+            }
+        }
     }
 }

+ 11 - 2
MafiaTelegramBot/Resources/strings.resx

@@ -36,8 +36,8 @@
     <data name="shop" xml:space="preserve">
         <value>Магазин</value>
     </data>
-    <data name="my_roles" xml:space="preserve">
-        <value>Статистика по ролям</value>
+    <data name="opened_roles" xml:space="preserve">
+        <value>Открытые роли</value>
     </data>
     <data name="settings" xml:space="preserve">
         <value>Настройки</value>
@@ -570,4 +570,13 @@
     <data name="previous" xml:space="preserve">
         <value>Назад</value>
     </data>
+    <data name="you_dont_have_any_extended_role" xml:space="preserve">
+        <value>У вас нет открытых ролей расширенной игры</value>
+    </data>
+    <data name="your_opened_roles_list" xml:space="preserve">
+        <value>У вас открыты следующие роли</value>
+    </data>
+    <data name="extended_stats" xml:space="preserve">
+        <value>Расширенная статистика</value>
+    </data>
 </root>