Parcourir la source

Make sum of opened roles

Tigran il y a 4 ans
Parent
commit
da6e4b633f

+ 6 - 0
MafiaTelegramBot/CustomCollections/Extensions/ListExtension.cs

@@ -1,4 +1,5 @@
 using System.Collections.Generic;
+using System.Linq;
 
 namespace MafiaTelegramBot.CustomCollections.Extensions
 {
@@ -27,5 +28,10 @@ namespace MafiaTelegramBot.CustomCollections.Extensions
             list.Add(item);
             return true;
         }
+
+        public static void ConcatenateUnique<T>(this List<T> list, List<T> list2)
+        {
+            foreach (var item in list2.Where(item => !list.Contains(item))) list.Add(item);
+        }
     }
 }

+ 4 - 1
MafiaTelegramBot/Resources/Keyboard.cs

@@ -1,4 +1,5 @@
 using System.Collections.Generic;
+using MafiaTelegramBot.CustomCollections.Extensions;
 using MafiaTelegramBot.Game;
 using MafiaTelegramBot.Game.GameRoles;
 using MafiaTelegramBot.Game.GameRooms;
@@ -226,7 +227,9 @@ namespace MafiaTelegramBot.Resources
 
         public static InlineKeyboardMarkup ChangeRolesKeyboard(long userId, string roomKey, ExtendedGameRoom room)
         {
-            var openedRoles = room.Owner.OpenedRoles.ToList();
+            List<Roles> openedRoles = new();
+            foreach (var player in room.Players.Values)
+                openedRoles.ConcatenateUnique(player.OpenedRoles.ToList());
             var keyboard = new InlineKeyboardButton[3+openedRoles.Count][];
             keyboard[0] = new[]
             {