Parcourir la source

Migrate to SQL Database

Tigran il y a 4 ans
Parent
commit
5bed7f6399
47 fichiers modifiés avec 417 ajouts et 325 suppressions
  1. 5 7
      MafiaTelegramBot/Controllers/RoomController.cs
  2. 1 1
      MafiaTelegramBot/CustomCollections/Extensions/ListExtension.cs
  3. 34 0
      MafiaTelegramBot/CustomCollections/StatisticsList.cs
  4. 46 0
      MafiaTelegramBot/DataBase/Entity/StatisticsEntity.cs
  5. 41 0
      MafiaTelegramBot/DataBase/Entity/UserEntity.cs
  6. 15 0
      MafiaTelegramBot/DataBase/EntityDao/StatisticsDao.cs
  7. 43 0
      MafiaTelegramBot/DataBase/EntityDao/UserDao.cs
  8. 12 6
      MafiaTelegramBot/DataBase/MafiaDataBase.cs
  9. 0 30
      MafiaTelegramBot/DataBase/StatisticsEntity.cs
  10. 0 53
      MafiaTelegramBot/DataBase/UserDao.cs
  11. 0 115
      MafiaTelegramBot/DataBase/UserEntity.cs
  12. 0 11
      MafiaTelegramBot/Extensions/DictionaryExtension.cs
  13. 4 5
      MafiaTelegramBot/Game/GameRoles/CopRole.cs
  14. 6 6
      MafiaTelegramBot/Game/GameRoles/DoctorRole.cs
  15. 5 5
      MafiaTelegramBot/Game/GameRoles/DonRole.cs
  16. 5 5
      MafiaTelegramBot/Game/GameRoles/HookerRole.cs
  17. 5 5
      MafiaTelegramBot/Game/GameRoles/MafiaRole.cs
  18. 16 0
      MafiaTelegramBot/Game/GameRoles/NoneRole.cs
  19. 22 6
      MafiaTelegramBot/Game/GameRoles/Role.cs
  20. 5 5
      MafiaTelegramBot/Game/GameRoles/VillagerRole.cs
  21. 20 21
      MafiaTelegramBot/Game/GameRoom.cs
  22. 75 0
      MafiaTelegramBot/Game/Player.cs
  23. 0 5
      MafiaTelegramBot/Models/Bot.cs
  24. 2 1
      MafiaTelegramBot/Models/Commands/ConnectGameCommand.cs
  25. 2 1
      MafiaTelegramBot/Models/Commands/CreateGameCommand.cs
  26. 3 3
      MafiaTelegramBot/Models/Commands/CustomMessageHandlers/ChangeNicknameHandler.cs
  27. 2 2
      MafiaTelegramBot/Models/Commands/CustomMessageHandlers/CreateRoomHandler.cs
  28. 2 1
      MafiaTelegramBot/Models/Commands/CustomMessageHandlers/EnterPrivateCodeHandler.cs
  29. 2 1
      MafiaTelegramBot/Models/Commands/DissolveRoomCommand.cs
  30. 2 2
      MafiaTelegramBot/Models/Commands/KickPlayerCommand.cs
  31. 2 1
      MafiaTelegramBot/Models/Commands/LeaveCommand.cs
  32. 2 1
      MafiaTelegramBot/Models/Commands/LookPlayersListCommand.cs
  33. 2 1
      MafiaTelegramBot/Models/Commands/RoomSettingsCommand.cs
  34. 9 10
      MafiaTelegramBot/Models/Commands/ShowProfileCommand.cs
  35. 4 3
      MafiaTelegramBot/Models/Commands/StartCommand.cs
  36. 2 1
      MafiaTelegramBot/Models/Commands/StartGameCommand.cs
  37. 2 1
      MafiaTelegramBot/Models/Inlines/ConnectToSelectedRoomQuery.cs
  38. 2 2
      MafiaTelegramBot/Models/Inlines/KickSelectedPlayerQuery.cs
  39. 2 1
      MafiaTelegramBot/Models/Inlines/MakeExtendedGameQuery.cs
  40. 2 1
      MafiaTelegramBot/Models/Inlines/MakeNormalGameQuery.cs
  41. 2 1
      MafiaTelegramBot/Models/Inlines/MakePrivateRoomQuery.cs
  42. 2 1
      MafiaTelegramBot/Models/Inlines/MakePublicRoomQuery.cs
  43. 2 1
      MafiaTelegramBot/Models/Inlines/SetPlayersMaximumQuery.cs
  44. 2 1
      MafiaTelegramBot/Models/Inlines/SettingsProfileQuery.cs
  45. 2 1
      MafiaTelegramBot/Models/Inlines/TimerSwitchQuery.cs
  46. 2 1
      MafiaTelegramBot/Resources/Keyboards.cs
  47. 1 0
      MafiaTelegramBot/Resources/Roles.cs

+ 5 - 7
MafiaTelegramBot/Controllers/RoomController.cs

@@ -1,8 +1,6 @@
-using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
-using MafiaTelegramBot.DataBase;
 using MafiaTelegramBot.Game;
 using MafiaTelegramBot.Models;
 using MafiaTelegramBot.Resources;
@@ -13,7 +11,7 @@ namespace MafiaTelegramBot.Controllers
     {
         private static readonly Dictionary<string, GameRoom> OpenedGames = new();
 
-        public static async Task<ResultCode> CreateNewGame(UserEntity owner, string roomName, bool extended, string secretPhrase = null)
+        public static async Task<ResultCode> CreateNewGame(Player owner, string roomName, bool extended, string secretPhrase = null)
         {
             return await Task.Run(async () =>
             {
@@ -30,7 +28,7 @@ namespace MafiaTelegramBot.Controllers
             });
         }
 
-        public static async Task<ResultCode> ConnectToGame(UserEntity player, string roomKey)
+        public static async Task<ResultCode> ConnectToGame(Player player, string roomKey)
         {
             return await Task.Run(async () =>
             {
@@ -43,7 +41,7 @@ namespace MafiaTelegramBot.Controllers
             });
         }
 
-        public static async Task<List<UserEntity>> GetPlayers(string roomKey)
+        public static async Task<List<Player>> GetPlayers(string roomKey)
         {
             return await Task.Run( ()=>
             {
@@ -53,14 +51,14 @@ namespace MafiaTelegramBot.Controllers
             });
         }
         
-        public static async Task<ResultCode> LeaveFromGame(UserEntity player)
+        public static async Task<ResultCode> LeaveFromGame(Player player)
         {
             return await Task.Run(async () =>
             {
                 var roomKey = player.GetRoomKey();
                 if (!await player.RemoveGame()) return ResultCode.UserNotInGame;
                 OpenedGames[roomKey].Players.Remove(player.Id);
-                await OpenedGames[roomKey].NotifyPlayersAbout(player.Id, $"{player.NickName} {strings.connected_to_game}");
+                await OpenedGames[roomKey].NotifyPlayersAbout(player.Id, $"{player.NickName} {strings.leave_from_game}");
                 if (OpenedGames[roomKey].Players.Count >= 0) return ResultCode.CodeOk;
                 RoomEncrypter.RemoveShortName(OpenedGames[roomKey].RoomName);
                 if(OpenedGames[roomKey].IsPrivate) RoomEncrypter.Remove(OpenedGames[roomKey].RoomName);

+ 1 - 1
MafiaTelegramBot/Extensions/ListExtension.cs → MafiaTelegramBot/CustomCollections/Extensions/ListExtension.cs

@@ -1,6 +1,6 @@
 using System.Collections.Generic;
 
-namespace MafiaTelegramBot.Extensions
+namespace MafiaTelegramBot.CustomCollections.Extensions
 {
     public static class ListExtension
     {

+ 34 - 0
MafiaTelegramBot/CustomCollections/StatisticsList.cs

@@ -0,0 +1,34 @@
+using System.Collections.Generic;
+using MafiaTelegramBot.DataBase.Entity;
+using MafiaTelegramBot.Resources;
+
+namespace MafiaTelegramBot.CustomCollections
+{
+    public class StatisticsList
+    {
+        private readonly Dictionary<Roles, StatisticsEntity> _statistics = new();
+
+        public StatisticsEntity this[Roles role]
+        {
+            get => _statistics[role] ?? new StatisticsEntity();
+            set => _statistics[role] = value;
+        }
+
+        public bool Contains(Roles role)
+        {
+            return _statistics.ContainsKey(role);
+        }
+
+        public void Add(Roles role, StatisticsEntity entity)
+        {
+            if (_statistics.ContainsKey(role)) _statistics[role] = entity;
+            else _statistics.Add(role, entity);
+        }
+
+        public void AddNew(Roles role, long userId)
+        {
+            var statistics = new StatisticsEntity {Role = role, UserId = userId};
+            _statistics.Add(role, statistics);
+        }
+    }
+}

+ 46 - 0
MafiaTelegramBot/DataBase/Entity/StatisticsEntity.cs

@@ -0,0 +1,46 @@
+using System;
+using System.Threading.Tasks;
+using MafiaTelegramBot.DataBase.EntityDao;
+using MafiaTelegramBot.Resources;
+
+namespace MafiaTelegramBot.DataBase.Entity
+{
+    public class StatisticsEntity
+    {
+        public long UserId { get; init; }
+        public Roles Role { get; init; }
+
+        private int _games = 0;
+        public int Games
+        {
+            get=> _games;
+            set
+            {
+                if (_games == value) return;
+                _games = value;
+                Task.Run(async() => await StatisticsDao.Update(this));
+            }
+        }
+
+        private int _wins = 0;
+        public int Wins
+        {
+            get=> _wins;
+            set
+            {
+                if (_wins == value) return;
+                _wins = value;
+                Task.Run(async() => await StatisticsDao.Update(this));
+            }
+        }
+
+        public double GetWinrate()
+        {
+            if (Games == 0) return 0.00;
+            var wins = Convert.ToDouble(Wins);
+            var games = Convert.ToDouble(Games);
+            var result = wins / games;
+            return Math.Truncate(result * 100) / 100;
+        }
+    }
+}

+ 41 - 0
MafiaTelegramBot/DataBase/Entity/UserEntity.cs

@@ -0,0 +1,41 @@
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Threading.Tasks;
+using MafiaTelegramBot.CustomCollections;
+using MafiaTelegramBot.DataBase.EntityDao;
+
+namespace MafiaTelegramBot.DataBase.Entity
+{
+    [Table("users")]
+    public class UserEntity
+    {
+        [Key]
+        [DatabaseGenerated(DatabaseGeneratedOption.None)]
+        [Column("id")] public long Id { get; init; }
+        [Column("chat_id")] public long ChatId { get; init; }
+        
+        [NotMapped] private string _username = "\\[NoUsername\\]";
+        [Column("username")] public string Username
+        {
+            get => _username;
+            set
+            {
+                var buff = _username;
+                _username = value;
+                if (buff != value && buff != "\\[NoUsername\\]") Task.Run(async () => await UserDao.Update(this));
+            }
+        }
+
+        [Column("nickname")] public string NickName { get; set; } = "\\[NoNickname\\]";
+
+        public async Task UpdateNickName(string newName)
+        {
+            var buff = NickName;
+            NickName = newName;
+            if (buff != newName && buff != "\\[NoNickname\\]")
+                await UserDao.Update(this);
+        }
+
+        [NotMapped] public StatisticsList Statistics = new();
+    }
+}

+ 15 - 0
MafiaTelegramBot/DataBase/EntityDao/StatisticsDao.cs

@@ -0,0 +1,15 @@
+using System.Threading.Tasks;
+using MafiaTelegramBot.DataBase.Entity;
+
+namespace MafiaTelegramBot.DataBase.EntityDao
+{
+    public static class StatisticsDao
+    {
+        private static readonly MafiaDataBase DataBase = MafiaDataBase.GetInstance();
+        
+        public static async Task Update(StatisticsEntity statistics)
+        {
+            
+        }
+    }
+}

+ 43 - 0
MafiaTelegramBot/DataBase/EntityDao/UserDao.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using MafiaTelegramBot.DataBase.Entity;
+using MafiaTelegramBot.Game;
+using Microsoft.EntityFrameworkCore;
+
+namespace MafiaTelegramBot.DataBase.EntityDao
+{
+    public static class UserDao
+    {
+        private static readonly MafiaDataBase DataBase = MafiaDataBase.GetInstance();
+        private static readonly Dictionary<long, Player> ActiveUsers = new();
+        public static async Task<Player> GetPlayerById(long id)
+        {
+            if (ActiveUsers.ContainsKey(id)) return ActiveUsers[id];
+            var user = await Task.Run(()=> DataBase.Users.First(user1 => user1.Id == id));
+            var player = Player.FromUserEntity(user);
+            ActiveUsers.Add(user.Id, player);
+            return player;
+        }
+        
+        public static async Task Update(UserEntity user)
+        {
+            var result = await DataBase.Users.SingleOrDefaultAsync(b => b.Id == user.Id);
+            if (result == null) DataBase.Users.Add(user);
+            else
+            {
+                result.NickName = user.NickName;
+                result.Username = user.Username;
+                DataBase.Users.Update(result);
+            }
+            await DataBase.SaveChangesAsync();
+        }
+
+        public static async Task<bool> UserExists(long id)
+        {
+            if (ActiveUsers.ContainsKey(id)) return true;
+            return await DataBase.Users.AnyAsync(user => user.Id == id);
+        }
+    }
+}

+ 12 - 6
MafiaTelegramBot/DataBase/Mafia.cs → MafiaTelegramBot/DataBase/MafiaDataBase.cs

@@ -1,20 +1,26 @@
-using System.ComponentModel.DataAnnotations.Schema;
+using MafiaTelegramBot.DataBase.Entity;
 using MafiaTelegramBot.Resources;
 using Microsoft.EntityFrameworkCore;
 
 namespace MafiaTelegramBot.DataBase
 {
-    public class Mafia : DbContext
+    public class MafiaDataBase : DbContext
     {
+        private MafiaDataBase() { }
+        private static MafiaDataBase _instance;
+
+        public static MafiaDataBase GetInstance()
+        {
+            if(_instance!=null) return _instance;
+            _instance = new MafiaDataBase();
+            return _instance;
+        }
+
         public DbSet<UserEntity> Users { get; set; }
         //public DbSet<StatisticsEntity> Statistics { get; set; }
 
         protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
         {
-            //#warning To protect potentially sensitive information in your connection string, 
-            //you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 
-            //for guidance on storing connection strings.
-
             optionsBuilder.UseMySQL(
                 $"server={AppSettings.IpAddress};" +
                 $"port={AppSettings.Port};" +

+ 0 - 30
MafiaTelegramBot/DataBase/StatisticsEntity.cs

@@ -1,30 +0,0 @@
-using MafiaTelegramBot.Resources;
-
-namespace MafiaTelegramBot.DataBase
-{
-    public class StatisticsEntity
-    {
-        public long UserId { get; init; }
-        public Roles Role { get; init; }
-
-        private int _games = 0;
-        public int Games
-        {
-            get=> _games;
-            set
-            {
-                _games = value;
-            }
-        }
-
-        private int _wins = 0;
-        public int Wins
-        {
-            get=> _wins;
-            set
-            {
-                _wins = value;
-            }
-        }
-    }
-}

+ 0 - 53
MafiaTelegramBot/DataBase/UserDao.cs

@@ -1,53 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using Microsoft.EntityFrameworkCore;
-
-namespace MafiaTelegramBot.DataBase
-{
-    public static class UserDao
-    {
-        //private static readonly List<UserEntity> DataBase = new();
-        private static Mafia DataBase = new Mafia();
-        
-        private static readonly Dictionary<long,UserEntity> ActiveUsers = new();
-        public static async Task<UserEntity> GetUserById(long id)
-        {
-            if (ActiveUsers.ContainsKey(id)) return ActiveUsers[id];
-            var user = await Task.Run(()=> DataBase.Users.First(user1 => user1.Id == id));
-            ActiveUsers.Add(user.Id, user);
-            return user;
-        }
-
-        private static UserEntity ConvertToUser()
-        {
-            return new();
-        }
-        
-        public static async Task Update(UserEntity userEntity)
-        {
-            if (await DataBase.Users.AnyAsync(user => user.Id == userEntity.Id))
-            {
-                DataBase.Update(userEntity);
-            }
-            else
-            {
-                DataBase.Add(userEntity);
-            }
-            await DataBase.SaveChangesAsync();
-        }
-
-        public static async Task<bool> UserExists(long id)
-        {
-            if (ActiveUsers.ContainsKey(id))
-                return true;
-            return await DataBase.Users.AnyAsync(user => user.Id == id);
-                /*
-                 return await Task.Run(() =>
-                {
-                    return ActiveUsers.ContainsKey(id) || DataBase.Users.AnyAsync(user => user.Id == id);
-                });
-                */
-        }
-    }
-}

+ 0 - 115
MafiaTelegramBot/DataBase/UserEntity.cs

@@ -1,115 +0,0 @@
-#nullable enable
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-using System.ComponentModel.DataAnnotations.Schema;
-using System.Threading.Tasks;
-using MafiaTelegramBot.Controllers;
-using MafiaTelegramBot.Resources;
-
-namespace MafiaTelegramBot.DataBase
-{
-    [Table("users")]
-    public class  UserEntity
-    {
-        [Key]
-        [DatabaseGenerated(DatabaseGeneratedOption.None)]
-        [Column("id")]
-        public long Id { get; init; }
-        [Column("chat_id")]
-        public long ChatId { get; init; }
-        [NotMapped]
-        private string _username = strings.no_name;
-        [Column("username")]
-        public string Username
-        {
-            get => _username;
-            set
-            {
-                if(_username != strings.no_name && _username != value) OnPropertyChangedListener("Username", value);
-                _username = value;
-            }
-        }
-        [NotMapped]
-        private string _nickName = "";
-        [Column("nickname")]
-        public string NickName
-        {
-            get => _nickName;
-            set
-            {
-                if(_nickName != "" && _nickName != value) OnPropertyChangedListener("NickName", value);
-                _nickName = value;
-            }
-        }
-        [NotMapped]
-        public Dictionary<Roles, StatisticsEntity> Statistics = new();
-        [NotMapped]
-        private Roles _currentRole = Roles.None;
-        [NotMapped]
-        public int TurnOrder = -1;
-        [NotMapped]
-        private string _roomKey = "";
-        
-        public async Task UpdateName(string name)
-        {
-            NickName = name;
-            await UserDao.Update(this);
-        }
-
-        public string GetRoomKey()
-        {
-            return _roomKey;
-        }
-
-        public async Task<bool> SetRoomKey(string roomKey)
-        {
-            if (_roomKey != "") return false;
-            _roomKey = roomKey;
-            await UserDao.Update(this);
-            return true;
-        }
-
-        public async Task<string> GetRoomName()
-        {
-            return await Task.Run( async() =>
-            {
-                if (_roomKey == "") return "";
-                var room = await RoomController.GetRoom(_roomKey);
-                return room.RoomName;
-            });
-        }
-        
-        public async Task<bool> RemoveGame()
-        {
-            if (_roomKey == "") return false;
-            _roomKey = "";
-            await UserDao.Update(this);
-            return true;
-        }
-
-        public override bool Equals(object? obj)
-        {
-            return obj is UserEntity user && user.Id == Id;
-        }
-
-        public override int GetHashCode()
-        {
-            return Id.GetHashCode();
-        }
-
-        public void SetRole(Roles role)
-        {
-            _currentRole = role;
-        }
-
-        public string GetRole()
-        {
-            return roles.ResourceManager.GetString(_currentRole.ToString())!;
-        }
-
-        private void OnPropertyChangedListener<T>(string property, T value)
-        {
-            
-        }
-    }
-}

+ 0 - 11
MafiaTelegramBot/Extensions/DictionaryExtension.cs

@@ -1,11 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using MafiaTelegramBot.Resources;
-
-namespace MafiaTelegramBot.Extensions
-{
-    public static class DictionaryExtension
-    {
-        
-    }
-}

+ 4 - 5
MafiaTelegramBot/Game/GameRoles/CopRole.cs

@@ -3,19 +3,18 @@ using MafiaTelegramBot.Controllers;
 using MafiaTelegramBot.Models;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
-using User = MafiaTelegramBot.DataBase.UserEntity;
 
 namespace MafiaTelegramBot.Game.GameRoles
 {
     public class CopRole : Role
     {
-        protected override Roles RoleKey => Roles.Cop;
+        public override Roles RoleKey => Roles.Cop;
         
-        protected override async Task<Message> NightAction(User user)
+        protected override async Task<Message> NightAction(Player player)
         {
-            var room = await RoomController.GetRoom(user.GetRoomKey());
+            var room = await RoomController.GetRoom(player.GetRoomKey());
             //TODO this is what user can do in night phase
-            return await Bot.SendWithMarkdown2(user.ChatId, strings.unexpected_error);
+            return await Bot.SendWithMarkdown2(player.ChatId, strings.unexpected_error);
         }
     }
 }

+ 6 - 6
MafiaTelegramBot/Game/GameRoles/DoctorRole.cs

@@ -3,19 +3,19 @@ using MafiaTelegramBot.Controllers;
 using MafiaTelegramBot.Models;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
-using User = MafiaTelegramBot.DataBase.UserEntity;
+using User = MafiaTelegramBot.DataBase.Entity.UserEntity;
 
 namespace MafiaTelegramBot.Game.GameRoles
 {
-    public class DotorRole : Role
+    public class DoctorRole : Role
     {
-        protected override Roles RoleKey => Roles.Doctor;
+        public override Roles RoleKey => Roles.Doctor;
         
-        protected override async Task<Message> NightAction(User user)
+        protected override async Task<Message> NightAction(Player player)
         {
-            var room = await RoomController.GetRoom(user.GetRoomKey());
+            var room = await RoomController.GetRoom(player.GetRoomKey());
             //TODO this is what user can do in night phase
-            return await Bot.SendWithMarkdown2(user.ChatId, strings.unexpected_error);
+            return await Bot.SendWithMarkdown2(player.ChatId, strings.unexpected_error);
         }
     }
 }

+ 5 - 5
MafiaTelegramBot/Game/GameRoles/DonRole.cs

@@ -3,19 +3,19 @@ using MafiaTelegramBot.Controllers;
 using MafiaTelegramBot.Models;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
-using User = MafiaTelegramBot.DataBase.UserEntity;
+using User = MafiaTelegramBot.DataBase.Entity.UserEntity;
 
 namespace MafiaTelegramBot.Game.GameRoles
 {
     public class DonRole : Role
     {
-        protected override Roles RoleKey => Roles.Don;
+        public override Roles RoleKey => Roles.Don;
         
-        protected override async Task<Message> NightAction(User user)
+        protected override async Task<Message> NightAction(Player player)
         {
-            var room = await RoomController.GetRoom(user.GetRoomKey());
+            var room = await RoomController.GetRoom(player.GetRoomKey());
             //TODO this is what user can do in night phase
-            return await Bot.SendWithMarkdown2(user.ChatId, strings.unexpected_error);
+            return await Bot.SendWithMarkdown2(player.ChatId, strings.unexpected_error);
         }
     }
 }

+ 5 - 5
MafiaTelegramBot/Game/GameRoles/HookerRole.cs

@@ -3,19 +3,19 @@ using MafiaTelegramBot.Controllers;
 using MafiaTelegramBot.Models;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
-using User = MafiaTelegramBot.DataBase.UserEntity;
+using User = MafiaTelegramBot.DataBase.Entity.UserEntity;
 
 namespace MafiaTelegramBot.Game.GameRoles
 {
     public class HookerRole : Role
     {
-        protected override Roles RoleKey => Roles.Hooker;
+        public override Roles RoleKey => Roles.Hooker;
         
-        protected override async Task<Message> NightAction(User user)
+        protected override async Task<Message> NightAction(Player player)
         {
-            var room = await RoomController.GetRoom(user.GetRoomKey());
+            var room = await RoomController.GetRoom(player.GetRoomKey());
             //TODO this is what user can do in night phase
-            return await Bot.SendWithMarkdown2(user.ChatId, strings.unexpected_error);
+            return await Bot.SendWithMarkdown2(player.ChatId, strings.unexpected_error);
         }
     }
 }

+ 5 - 5
MafiaTelegramBot/Game/GameRoles/MafiaRole.cs

@@ -3,19 +3,19 @@ using MafiaTelegramBot.Controllers;
 using MafiaTelegramBot.Models;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
-using User = MafiaTelegramBot.DataBase.UserEntity;
+using User = MafiaTelegramBot.DataBase.Entity.UserEntity;
 
 namespace MafiaTelegramBot.Game.GameRoles
 {
     public class MafiaRole : Role
     {
-        protected override Roles RoleKey => Roles.Mafia;
+        public override Roles RoleKey => Roles.Mafia;
         
-        protected override async Task<Message> NightAction(User user)
+        protected override async Task<Message> NightAction(Player player)
         {
-            var room = await RoomController.GetRoom(user.GetRoomKey());
+            var room = await RoomController.GetRoom(player.GetRoomKey());
             //TODO this is what user can do in night phase
-            return await Bot.SendWithMarkdown2(user.ChatId, strings.unexpected_error);
+            return await Bot.SendWithMarkdown2(player.ChatId, strings.unexpected_error);
         }
     }
 }

+ 16 - 0
MafiaTelegramBot/Game/GameRoles/NoneRole.cs

@@ -0,0 +1,16 @@
+using System.Threading.Tasks;
+using MafiaTelegramBot.Models;
+using MafiaTelegramBot.Resources;
+using Telegram.Bot.Types;
+
+namespace MafiaTelegramBot.Game.GameRoles
+{
+    public class NoneRole : Role
+    {
+        public override Roles RoleKey => Roles.None;
+        protected override async Task<Message> NightAction(Player player)
+        {
+            return await Bot.SendWithMarkdown2(player.ChatId, strings.unexpected_error);
+        }
+    }
+}

+ 22 - 6
MafiaTelegramBot/Game/GameRoles/Role.cs

@@ -1,23 +1,39 @@
+using System;
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
 using MafiaTelegramBot.Models;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
-using User = MafiaTelegramBot.DataBase.UserEntity;
 
 namespace MafiaTelegramBot.Game.GameRoles
 {
     public abstract class Role
     {
-        protected abstract Roles RoleKey { get; }
+        public abstract Roles RoleKey { get; }
 
-        protected async Task<Message> DayAction(User user)
+        protected async Task<Message> DayAction(Player player)
         {
-            var room = await RoomController.GetRoom(user.GetRoomKey());
+            var room = await RoomController.GetRoom(player.GetRoomKey());
             //TODO user telling anything in one minute and vote
-            return await Bot.SendWithMarkdown2(user.ChatId, strings.unexpected_error);
+            return await Bot.SendWithMarkdown2(player.ChatId, strings.unexpected_error);
         }
 
-        protected abstract Task<Message> NightAction(User user);
+        protected abstract Task<Message> NightAction(Player player);
+
+        public static Role GetNewRoleInstance(Roles roleKey)
+        {
+            return roleKey switch
+            {
+                Roles.All => new NoneRole(),
+                Roles.Doctor => new DoctorRole(),
+                Roles.Mafia => new MafiaRole(),
+                Roles.Don => new DonRole(),
+                Roles.Cop => new CopRole(),
+                Roles.Villager => new VillagerRole(),
+                Roles.Hooker => new HookerRole(),
+                Roles.None =>  new NoneRole(),
+                _ => throw new ArgumentOutOfRangeException(nameof(roleKey), roleKey, null)
+            };
+        }
     }
 }

+ 5 - 5
MafiaTelegramBot/Game/GameRoles/VillagerRole.cs

@@ -3,19 +3,19 @@ using MafiaTelegramBot.Controllers;
 using MafiaTelegramBot.Models;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
-using User = MafiaTelegramBot.DataBase.UserEntity;
+using User = MafiaTelegramBot.DataBase.Entity.UserEntity;
 
 namespace MafiaTelegramBot.Game.GameRoles
 {
     public class VillagerRole : Role
     {
-        protected override Roles RoleKey => Roles.Villager;
+        public override Roles RoleKey => Roles.Villager;
         
-        protected override async Task<Message> NightAction(User user)
+        protected override async Task<Message> NightAction(Player player)
         {
-            var room = await RoomController.GetRoom(user.GetRoomKey());
+            var room = await RoomController.GetRoom(player.GetRoomKey());
             //TODO this is what user can do in night phase
-            return await Bot.SendWithMarkdown2(user.ChatId, strings.unexpected_error);
+            return await Bot.SendWithMarkdown2(player.ChatId, strings.unexpected_error);
         }
     }
 }

+ 20 - 21
MafiaTelegramBot/Game/GameRoom.cs

@@ -4,10 +4,10 @@ using System.Linq;
 using System.Threading;
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
-using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.CustomCollections.Extensions;
+using MafiaTelegramBot.Game.GameRoles;
 using MafiaTelegramBot.Models;
 using MafiaTelegramBot.Resources;
-using MafiaTelegramBot.Extensions;
 using Telegram.Bot.Types.ReplyMarkups;
 
 namespace MafiaTelegramBot.Game
@@ -22,11 +22,11 @@ namespace MafiaTelegramBot.Game
         public bool IsExtended { get; init; }
         public bool TimerEnabled { get; set; } = true;
         public string RoomName { get; init; } = "NoNameRoom";
-        public UserEntity Owner { get; init; } = new();
+        public Player Owner { get; init; } = new();
 
-        private readonly Queue<UserEntity> _turnOrder = new();
+        private readonly Queue<Player> _turnOrder = new();
 
-        public readonly Dictionary<long, UserEntity> Players = new();
+        public readonly Dictionary<long, Player> Players = new();
 
         public readonly Dictionary<Roles, int> Settings = new()
         {
@@ -76,18 +76,16 @@ namespace MafiaTelegramBot.Game
             await Task.Run(async () =>
             {
                 foreach (var (_, player) in Players)
+                    player.CurrentRole = Role.GetNewRoleInstance(Roles.None);
+                _isRunning = false;
+                _turnOrder.Clear();
+                Thread.Sleep(10000);//TODO just for tests
+                if (!Players.ContainsKey(Owner.Id) || Players.Count == 0) new Task(async() => 
+                    await RoomController.DissolveRoom(IsPrivate ? RoomEncrypter.NameToCode(RoomName) : RoomName)).Start();
+                else
                 {
-                    player.SetRole(Roles.None);
-                    _isRunning = false;
-                    _turnOrder.Clear();
-                    Thread.Sleep(10000);//TODO just for tests
-                    if (!Players.ContainsKey(Owner.Id) || Players.Count == 0) new Task(async() => 
-                        await RoomController.DissolveRoom(IsPrivate ? RoomEncrypter.NameToCode(RoomName) : RoomName)).Start();
-                    else
-                    {
-                        await Bot.SendWithMarkdown2(Owner.ChatId, strings.thanks_for_game, Keyboards.OwnerGameMenu);
-                        await NotifyPlayersAbout(Owner.Id, strings.thanks_for_game, Keyboards.PlayerGameMenu);
-                    }
+                    await Bot.SendWithMarkdown2(Owner.ChatId, strings.thanks_for_game, Keyboards.OwnerGameMenu);
+                    await NotifyPlayersAbout(Owner.Id, strings.thanks_for_game, Keyboards.PlayerGameMenu);
                 }
             });
         }
@@ -132,7 +130,7 @@ namespace MafiaTelegramBot.Game
             });
         }
 
-        public async Task<List<UserEntity>> GetPlayers()
+        public async Task<List<Player>> GetPlayers()
         {
             return await Task.Run(() =>
             {
@@ -147,12 +145,13 @@ namespace MafiaTelegramBot.Game
             await Task.Run(() =>
             {
                 var random = new Random();
+                var roles = new List<Roles>();
+                foreach (var (key, value) in Settings) roles.AddTimes(key, value);
                 for (var i = 0; i < _turnOrder.Count; ++i)
                 {
                     var user = _turnOrder.Dequeue();
-                    var roles = new List<Roles>();
-                    foreach (var (key, value) in Settings) roles.AddTimes(key, value);
-                    user.SetRole(roles.GetAndRemove(random.Next(roles.Count)));
+                    var next = roles.GetAndRemove(random.Next(roles.Count));
+                    user.CurrentRole = (Role.GetNewRoleInstance(next));
                     _turnOrder.Enqueue(user);
                 }
             });
@@ -191,7 +190,7 @@ namespace MafiaTelegramBot.Game
             foreach (var player in Players.Values)
             {
                 var message =
-                    $"{strings.your_role}: _*{player.GetRole()}*_\n" +
+                    $"{strings.your_role}: _*{player.GetRoleName()}*_\n" +
                     $"{strings.your_turn_order}: _*{player.TurnOrder}*_\n"+
                     $"{strings.bot_starting_game}";
                 await Bot.SendWithMarkdown2(player.ChatId, message, Keyboards.InGamePlayerMenu);

+ 75 - 0
MafiaTelegramBot/Game/Player.cs

@@ -0,0 +1,75 @@
+#nullable enable
+using System.Threading.Tasks;
+using MafiaTelegramBot.Controllers;
+using MafiaTelegramBot.DataBase.Entity;
+using MafiaTelegramBot.DataBase.EntityDao;
+using MafiaTelegramBot.Game.GameRoles;
+using MafiaTelegramBot.Resources;
+using Newtonsoft.Json;
+
+namespace MafiaTelegramBot.Game
+{
+    public class Player : UserEntity
+    {
+        public Role CurrentRole = new NoneRole();
+        public int TurnOrder = -1;
+        private string _roomKey = "";
+        public static Player FromUserEntity(UserEntity b)
+        {
+            var serialized = JsonConvert.SerializeObject(b);
+            Player a = JsonConvert.DeserializeObject<Player>(serialized);
+            return a;
+        }
+
+        public string GetRoomKey()
+        {
+            return _roomKey;
+        }
+
+        public async Task<bool> SetRoomKey(string roomKey)
+        {
+            if (_roomKey != "") return false;
+            _roomKey = roomKey;
+            await UserDao.Update(this);
+            return true;
+        }
+
+        public async Task<string> GetRoomName()
+        {
+            return await Task.Run( async() =>
+            {
+                if (_roomKey == "") return "";
+                var room = await RoomController.GetRoom(_roomKey);
+                return room.RoomName;
+            });
+        }
+        
+        public async Task<bool> RemoveGame()
+        {
+            if (_roomKey == "") return false;
+            _roomKey = "";
+            await UserDao.Update(this);
+            return true;
+        }
+
+        public override bool Equals(object? obj)
+        {
+            return obj is UserEntity user && user.Id == Id;
+        }
+
+        public override int GetHashCode()
+        {
+            return Id.GetHashCode();
+        }
+
+        public Roles GetRole()
+        {
+            return CurrentRole.RoleKey;
+        }
+
+        public string GetRoleName()
+        {
+            return roles.ResourceManager.GetString(CurrentRole.RoleKey.ToString())!;
+        }
+    }
+}

+ 0 - 5
MafiaTelegramBot/Models/Bot.cs

@@ -29,15 +29,10 @@ namespace MafiaTelegramBot.Models
         public static TelegramBotClient Get()
         {
             if (_client != null) return _client;
-
             InitCommands();
             InitQueries();
             InitReplies();
-
             _client = new TelegramBotClient(AppSettings.Token);
-            //var hook = string.Format(AppSettings.Url, "api/message/update");
-            //await _client.SetWebhookAsync(hook);
-
             return _client;
         }
 

+ 2 - 1
MafiaTelegramBot/Models/Commands/ConnectGameCommand.cs

@@ -1,5 +1,6 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -11,7 +12,7 @@ namespace MafiaTelegramBot.Models.Commands
 
         protected override async Task<Message> Execute(Update update)
         {
-            var user = await UserDao.GetUserById(UserId);
+            var user = await UserDao.GetPlayerById(UserId);
             if (user.GetRoomKey() != "")
                 return await Bot.SendWithMarkdown2(ChatId, strings.user_already_in_game);
             return await Bot.SendWithMarkdown2(ChatId, strings.choose_type_room, 

+ 2 - 1
MafiaTelegramBot/Models/Commands/CreateGameCommand.cs

@@ -1,5 +1,6 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -11,7 +12,7 @@ namespace MafiaTelegramBot.Models.Commands
 
         protected override async Task<Message> Execute(Update update)
         {
-            var user = await UserDao.GetUserById(UserId);
+            var user = await UserDao.GetPlayerById(UserId);
             await Bot.SendStickerWithoutPackAsync(ChatId, "https://github.com/TelegramBots/book/raw/master/src/docs/sticker-fred.webp");
             if (user.GetRoomKey() != "")
                 return await Bot.SendWithMarkdown2(ChatId, strings.user_already_in_game);

+ 3 - 3
MafiaTelegramBot/Models/Commands/CustomMessageHandlers/ChangeNicknameHandler.cs

@@ -1,5 +1,5 @@
 using System.Threading.Tasks;
-using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using Telegram.Bot.Types;
 
 namespace MafiaTelegramBot.Models.Commands.CustomMessageHandlers
@@ -12,8 +12,8 @@ namespace MafiaTelegramBot.Models.Commands.CustomMessageHandlers
         {
             var newNickname = update.Message.Text;
             var escapedNickName = await Utilities.EscapeSpecific(newNickname);
-            var user = await UserDao.GetUserById(UserId);
-            await user.UpdateName(escapedNickName);
+            var user = await UserDao.GetPlayerById(UserId);
+            await user.UpdateNickName(escapedNickName);
             return await Bot.SendWithMarkdown2(ChatId, $"{strings.name_updated} _*{escapedNickName}*_");
         }
     }

+ 2 - 2
MafiaTelegramBot/Models/Commands/CustomMessageHandlers/CreateRoomHandler.cs

@@ -1,6 +1,6 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
-using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Game;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
@@ -16,7 +16,7 @@ namespace MafiaTelegramBot.Models.Commands.CustomMessageHandlers
             var param = Bot.UsersThatCreatesRoom[UserId];
             var isExtended = param[1] == Callback.MakeExtendedGame.ToString();
             Bot.UsersThatCreatesRoom.Remove(UserId);
-            var user = await UserDao.GetUserById(UserId);
+            var user = await UserDao.GetPlayerById(UserId);
             var roomName = update.Message.Text;
             var resultCode = param[0] == "public"
                 ? await RoomController.CreateNewGame(user, roomName, isExtended)

+ 2 - 1
MafiaTelegramBot/Models/Commands/CustomMessageHandlers/EnterPrivateCodeHandler.cs

@@ -1,6 +1,7 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
 using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -12,7 +13,7 @@ namespace MafiaTelegramBot.Models.Commands.CustomMessageHandlers
 
         protected override async Task<Message> Execute(Update update)
         {
-            var user = await UserDao.GetUserById(UserId);
+            var user = await UserDao.GetPlayerById(UserId);
             var roomKey = update.Message.Text;
             var resultCode = await RoomController.ConnectToGame(user, roomKey);
             var result = resultCode == ResultCode.CodeOk

+ 2 - 1
MafiaTelegramBot/Models/Commands/DissolveRoomCommand.cs

@@ -1,6 +1,7 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
 using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -11,7 +12,7 @@ namespace MafiaTelegramBot.Models.Commands
         protected override string Name => keyboard.dissolve_room;
         protected override async Task<Message> Execute(Update update)
         { 
-            var user = await UserDao.GetUserById(UserId);
+            var user = await UserDao.GetPlayerById(UserId);
             var roomKey = user.GetRoomKey();
             var resultCode = await RoomController.LeaveFromGame(user);
             var result = resultCode == ResultCode.CodeOk

+ 2 - 2
MafiaTelegramBot/Models/Commands/KickPlayerCommand.cs

@@ -1,6 +1,6 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
-using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -11,7 +11,7 @@ namespace MafiaTelegramBot.Models.Commands
         protected override string Name => keyboard.kick_player;
         protected override async Task<Message> Execute(Update update)
         {
-            var user = await UserDao.GetUserById(UserId);
+            var user = await UserDao.GetPlayerById(UserId);
             var room = await RoomController.GetRoom(user.GetRoomKey());
             var players = await room.GetPlayers();
             if (players.Count > 0)

+ 2 - 1
MafiaTelegramBot/Models/Commands/LeaveCommand.cs

@@ -1,6 +1,7 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
 using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -12,7 +13,7 @@ namespace MafiaTelegramBot.Models.Commands
 
         protected override async Task<Message> Execute(Update update)
         {
-            var user = await UserDao.GetUserById(UserId);
+            var user = await UserDao.GetPlayerById(UserId);
             var roomName = await user.GetRoomName();
             var resultCode = await RoomController.LeaveFromGame(user);
             return resultCode == ResultCode.CodeOk

+ 2 - 1
MafiaTelegramBot/Models/Commands/LookPlayersListCommand.cs

@@ -2,6 +2,7 @@ using System.Linq;
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
 using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -13,7 +14,7 @@ namespace MafiaTelegramBot.Models.Commands
 
         protected override async Task<Message> Execute(Update update)
         {
-            var user = await UserDao.GetUserById(UserId);
+            var user = await UserDao.GetPlayerById(UserId);
             var roomKey = user.GetRoomKey();
             var users = await RoomController.GetPlayers(roomKey);
             var list = users.Count > 1

+ 2 - 1
MafiaTelegramBot/Models/Commands/RoomSettingsCommand.cs

@@ -1,6 +1,7 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
 using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -12,7 +13,7 @@ namespace MafiaTelegramBot.Models.Commands
 
         protected override async Task<Message> Execute(Update update)
         {
-            var user = await UserDao.GetUserById(UserId);
+            var user = await UserDao.GetPlayerById(UserId);
             var roomKey = user.GetRoomKey();
             var room = await RoomController.GetRoom(roomKey);
             var roomMaxCapacity = room.MaxPlayers;

+ 9 - 10
MafiaTelegramBot/Models/Commands/ShowProfileCommand.cs

@@ -1,6 +1,5 @@
-using System;
 using System.Threading.Tasks;
-using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -11,16 +10,16 @@ namespace MafiaTelegramBot.Models.Commands
         protected override string Name => keyboard.show_profile;
 
         protected override async Task<Message> Execute(Update update)
-        { /*
-            var user = await UserDao.GetUserById(UserId);
-            var winRate = user < 1 ? 0.0 : Convert.ToDouble(user.Wins) / Convert.ToDouble(user.Games);
+        { 
+            var user = await UserDao.GetPlayerById(UserId);
+            if(!user.Statistics.Contains(Roles.All)) user.Statistics.AddNew(Roles.All, UserId);
+            var result = user.Statistics[Roles.All];
             var message =
                 $"__*{strings.statistics_for} _{user.NickName}_*__\n" +
-                $"{strings.games_count} {user.Games}\n" +
-                $"{strings.wins_count} {user.Wins}\n" +
-                $"{strings.winrate} {winRate}%\n";
-                */
-            return await Bot.SendWithMarkdown2(ChatId, "message", Keyboards.ProfileKeyboard(UserId));
+                $"{strings.games_count} {result.Games}\n" +
+                $"{strings.wins_count} {result.Wins}\n" +
+                $"{strings.winrate} {result.GetWinrate()}%\n";
+            return await Bot.SendWithMarkdown2(ChatId, message, Keyboards.ProfileKeyboard(UserId));
             
         }
     }

+ 4 - 3
MafiaTelegramBot/Models/Commands/StartCommand.cs

@@ -1,5 +1,6 @@
 using System.Threading.Tasks;
-using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
+using MafiaTelegramBot.Game;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -13,7 +14,7 @@ namespace MafiaTelegramBot.Models.Commands
         {
             if (await UserDao.UserExists(UserId))
             {
-                var player = await UserDao.GetUserById(UserId);
+                var player = await UserDao.GetPlayerById(UserId);
                 if (player.GetRoomKey() != "")
                     return await Bot.SendWithMarkdown2(ChatId, $"{strings.prefer_leave_from_room} {await player.GetRoomName()}");
                 return await Bot.SendWithMarkdown2(ChatId, strings.start_message, Keyboards.MainMenu);
@@ -21,7 +22,7 @@ namespace MafiaTelegramBot.Models.Commands
             var username = await Utilities.EscapeSpecific(update.Message.From.Username);
             var firstName = await Utilities.EscapeSpecific(update.Message.From.FirstName);
             var lastName = await Utilities.EscapeSpecific(update.Message.From.LastName);
-            var user = new DataBase.UserEntity
+            var user = new Player
             {
                 Id = UserId, ChatId = ChatId, Username = username, NickName =  $"{firstName} {lastName}"
             };

+ 2 - 1
MafiaTelegramBot/Models/Commands/StartGameCommand.cs

@@ -1,6 +1,7 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
 using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -11,7 +12,7 @@ namespace MafiaTelegramBot.Models.Commands
         protected override string Name => keyboard.begin_game;
         protected override async Task<Message> Execute(Update update)
         {
-            var owner = await UserDao.GetUserById(UserId);
+            var owner = await UserDao.GetPlayerById(UserId);
             var room = await RoomController.GetRoom(owner.GetRoomKey());
             var result = await Bot.SendWithMarkdown2(owner.ChatId, strings.game_process_started);
             var resultCode = await room.Prepare();

+ 2 - 1
MafiaTelegramBot/Models/Inlines/ConnectToSelectedRoomQuery.cs

@@ -1,6 +1,7 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
 using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Game;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
@@ -18,7 +19,7 @@ namespace MafiaTelegramBot.Models.Inlines
             var param = data.Split('|');
             var shortName = param[2];
             var roomName = RoomEncrypter.ShortToFull(shortName);
-            var user = await UserDao.GetUserById(UserId);
+            var user = await UserDao.GetPlayerById(UserId);
             var resultCode = await RoomController.ConnectToGame(user, roomName);
             if (resultCode != ResultCode.CodeOk) return await Utilities.GetResultCodeMessage(resultCode, ChatId);
             return await Bot.SendWithMarkdown2(ChatId, strings.successful_entry_into_room, Keyboards.PlayerGameMenu);

+ 2 - 2
MafiaTelegramBot/Models/Inlines/KickSelectedPlayerQuery.cs

@@ -1,6 +1,6 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
-using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -11,7 +11,7 @@ namespace MafiaTelegramBot.Models.Inlines
         protected override Callback Name => Callback.KickUser;
         protected override async Task<Message> Execute(Update update)
         {
-            var user = await UserDao.GetUserById(UserId);
+            var user = await UserDao.GetPlayerById(UserId);
             var resultCode = await RoomController.LeaveFromGame(user);
             if (resultCode != ResultCode.CodeOk) return await Utilities.GetResultCodeMessage(resultCode, ChatId);
             await Bot.SendWithMarkdown2(ChatId, $"{strings.kick_user_success}");

+ 2 - 1
MafiaTelegramBot/Models/Inlines/MakeExtendedGameQuery.cs

@@ -1,5 +1,6 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -14,7 +15,7 @@ namespace MafiaTelegramBot.Models.Inlines
             await DeletePreviousMessage(ChatId, update.CallbackQuery.Message.MessageId);
             var data = update.CallbackQuery.Data;
             var param = data.Split('|');
-            var user = await UserDao.GetUserById(UserId);
+            var user = await UserDao.GetPlayerById(UserId);
             if (user.GetRoomKey() != "")
                 return await Bot.SendWithMarkdown2(ChatId, strings.user_already_in_game);
             if (Bot.UsersThatCreatesRoom.TryAdd(UserId, new[] {param[2], Name.ToString()}))

+ 2 - 1
MafiaTelegramBot/Models/Inlines/MakeNormalGameQuery.cs

@@ -1,5 +1,6 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -14,7 +15,7 @@ namespace MafiaTelegramBot.Models.Inlines
             await DeletePreviousMessage(ChatId, update.CallbackQuery.Message.MessageId);
             var data = update.CallbackQuery.Data;
             var param = data.Split('|');
-            var user = await UserDao.GetUserById(UserId);
+            var user = await UserDao.GetPlayerById(UserId);
             if (user.GetRoomKey() != "")
                 return await Bot.SendWithMarkdown2(ChatId, strings.user_already_in_game);
             if (Bot.UsersThatCreatesRoom.TryAdd(UserId, new[] {param[2], Name.ToString()}))

+ 2 - 1
MafiaTelegramBot/Models/Inlines/MakePrivateRoomQuery.cs

@@ -1,5 +1,6 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -12,7 +13,7 @@ namespace MafiaTelegramBot.Models.Inlines
         protected override async Task<Message> Execute(Update update)
         {
             await DeletePreviousMessage(ChatId, update.CallbackQuery.Message.MessageId);
-            var user = await UserDao.GetUserById(UserId);
+            var user = await UserDao.GetPlayerById(UserId);
             if (user.GetRoomKey() != "")
                 return await Bot.SendWithMarkdown2(ChatId, strings.user_already_in_game);
             return await Bot.SendWithMarkdown2(ChatId, strings.choose_game_type, Keyboards.NormalExtendedKeyboard(UserId, "private"));

+ 2 - 1
MafiaTelegramBot/Models/Inlines/MakePublicRoomQuery.cs

@@ -1,5 +1,6 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -12,7 +13,7 @@ namespace MafiaTelegramBot.Models.Inlines
         protected override async Task<Message> Execute(Update update)
         { 
             await DeletePreviousMessage(ChatId, update.CallbackQuery.Message.MessageId);
-            var user = await UserDao.GetUserById(UserId);
+            var user = await UserDao.GetPlayerById(UserId);
             if (user.GetRoomKey() != "")
                 return await Bot.SendWithMarkdown2(ChatId, strings.user_already_in_game);
             return await Bot.SendWithMarkdown2(ChatId, strings.choose_game_type, Keyboards.NormalExtendedKeyboard(UserId, "public"));

+ 2 - 1
MafiaTelegramBot/Models/Inlines/SetPlayersMaximumQuery.cs

@@ -1,6 +1,7 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
 using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -15,7 +16,7 @@ namespace MafiaTelegramBot.Models.Inlines
             await DeletePreviousMessage(ChatId, update.CallbackQuery.Message.MessageId);
             var data = update.CallbackQuery.Data;
             var count = int.Parse(data.Split('|')[2]);
-            var user = await UserDao.GetUserById(UserId);
+            var user = await UserDao.GetPlayerById(UserId);
             var roomKey = user.GetRoomKey();
             var room = await RoomController.GetRoom(roomKey);
             room.MaxPlayers = count;

+ 2 - 1
MafiaTelegramBot/Models/Inlines/SettingsProfileQuery.cs

@@ -1,5 +1,6 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -12,7 +13,7 @@ namespace MafiaTelegramBot.Models.Inlines
         protected override async Task<Message> Execute(Update update)
         {
             await DeletePreviousMessage(ChatId, update.CallbackQuery.Message.MessageId);
-            var user = await UserDao.GetUserById(UserId);
+            var user = await UserDao.GetPlayerById(UserId);
             return await Bot.SendWithMarkdown2(ChatId, $"{strings.your_name} {user.NickName}", Keyboards.ChangeNameKeyboard(UserId));
         }
     }

+ 2 - 1
MafiaTelegramBot/Models/Inlines/TimerSwitchQuery.cs

@@ -1,6 +1,7 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
 using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -12,7 +13,7 @@ namespace MafiaTelegramBot.Models.Inlines
         protected override async Task<Message> Execute(Update update)
         {
             await DeletePreviousMessage(ChatId, update.CallbackQuery.Message.MessageId);
-            var user = await UserDao.GetUserById(UserId);
+            var user = await UserDao.GetPlayerById(UserId);
             var roomKey = user.GetRoomKey();
             var room = await RoomController.GetRoom(roomKey);
             room.TimerEnabled = !room.TimerEnabled;

+ 2 - 1
MafiaTelegramBot/Resources/Keyboards.cs

@@ -1,5 +1,6 @@
 using System.Collections.Generic;
 using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.DataBase.Entity;
 using MafiaTelegramBot.Game;
 using Telegram.Bot.Types.ReplyMarkups;
 
@@ -115,7 +116,7 @@ namespace MafiaTelegramBot.Resources
             return new InlineKeyboardMarkup(inlineButtons);
         }
 
-        public static InlineKeyboardMarkup KickKeyboard(List<UserEntity> users)
+        public static InlineKeyboardMarkup KickKeyboard(List<Player> users)
         {
             var inlineButtons = new InlineKeyboardButton[users.Count][];
             for (var i = 0; i < users.Count; ++i)

+ 1 - 0
MafiaTelegramBot/Resources/Roles.cs

@@ -2,6 +2,7 @@ namespace MafiaTelegramBot.Resources
 {
     public enum Roles
     {
+        All,
         Doctor, //Доктор
         Mafia, //Мафия
         Don, //Дон