Browse Source

Random roles edit

Tigran 4 years ago
parent
commit
beea9460e7

+ 1 - 1
MafiaTelegramBot.sln.DotSettings.user

@@ -2,7 +2,7 @@
 	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=MafiaTelegramBot_002Fappsettings/@EntryIndexedValue">True</s:Boolean>
 	
 	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=MafiaTelegramBot_002FResources_002Fkeyboard/@EntryIndexedValue">False</s:Boolean>
-	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=MafiaTelegramBot_002FResources_002Froles/@EntryIndexedValue">False</s:Boolean>
+	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=MafiaTelegramBot_002FResources_002Froles/@EntryIndexedValue">True</s:Boolean>
 	
 	
 	

+ 1 - 7
MafiaTelegramBot/Extensions/DictionaryExtension.cs

@@ -6,12 +6,6 @@ namespace MafiaTelegramBot.Extensions
 {
     public static class DictionaryExtension
     {
-        public static Roles GetRole(this Dictionary<Roles, int> dictionary, int index)
-        {
-            var (key, _) = dictionary.ElementAt(index);
-            dictionary[key]--;
-            if (dictionary[key] == 0) dictionary.Remove(key);
-            return key;
-        }
+        
     }
 }

+ 5 - 0
MafiaTelegramBot/Extensions/ListExtension.cs

@@ -10,5 +10,10 @@ namespace MafiaTelegramBot.Extensions
             list.RemoveAt(index);
             return value;
         }
+
+        public static void AddTimes<T>(this List<T> list, T item, int times)
+        {
+            for (var i = 0; i < times; ++i) list.Add(item);
+        }
     }
 }

+ 4 - 6
MafiaTelegramBot/Game/GameRoom.cs

@@ -5,7 +5,6 @@ using System.Threading.Tasks;
 using MafiaTelegramBot.DataBase;
 using MafiaTelegramBot.Models;
 using MafiaTelegramBot.Resources;
-using Telegram.Bot.Types.ReplyMarkups;
 using MafiaTelegramBot.Extensions;
 
 namespace MafiaTelegramBot.Game
@@ -138,13 +137,12 @@ namespace MafiaTelegramBot.Game
             await Task.Run(() =>
             {
                 var random = new Random();
-                var settingsCopy = Settings.ToDictionary(
-                    entry => entry.Key,
-                    entry => entry.Value);
-                for (int i = 0; i < _turnOrder.Count; ++i)
+                for (var i = 0; i < _turnOrder.Count; ++i)
                 {
                     var user = _turnOrder.Dequeue();
-                    user.SetRole(settingsCopy.GetRole(random.Next(settingsCopy.Count)));
+                    var roles = new List<Roles>();
+                    foreach (var (key, value) in Settings) roles.AddTimes(key, value);
+                    user.SetRole(roles.GetAndRemove(random.Next(roles.Count)));
                     _turnOrder.Enqueue(user);
                 }
             });