Browse Source

Ranking game

Tigran 4 years ago
parent
commit
b59381ba86
40 changed files with 288 additions and 87 deletions
  1. 3 3
      MafiaTelegramBot/Controllers/RoomController.cs
  2. 2 0
      MafiaTelegramBot/DataBase/Entity/UserEntity.cs
  3. 11 0
      MafiaTelegramBot/DataBase/EntityDao/StatisticsDao.cs
  4. 1 0
      MafiaTelegramBot/DataBase/EntityDao/UserDao.cs
  5. 1 0
      MafiaTelegramBot/Game/GameRoles/BodyguardRole.cs
  6. 1 0
      MafiaTelegramBot/Game/GameRoles/CopRole.cs
  7. 1 0
      MafiaTelegramBot/Game/GameRoles/DameRole.cs
  8. 1 0
      MafiaTelegramBot/Game/GameRoles/DetectiveRole.cs
  9. 1 0
      MafiaTelegramBot/Game/GameRoles/DoctorRole.cs
  10. 1 0
      MafiaTelegramBot/Game/GameRoles/DonRole.cs
  11. 1 0
      MafiaTelegramBot/Game/GameRoles/ElderRole.cs
  12. 1 0
      MafiaTelegramBot/Game/GameRoles/FoolRole.cs
  13. 1 0
      MafiaTelegramBot/Game/GameRoles/HookerRole.cs
  14. 1 0
      MafiaTelegramBot/Game/GameRoles/JournalistRole.cs
  15. 1 0
      MafiaTelegramBot/Game/GameRoles/LawyerRole.cs
  16. 1 0
      MafiaTelegramBot/Game/GameRoles/MafiaRole.cs
  17. 1 0
      MafiaTelegramBot/Game/GameRoles/NecromancerRole.cs
  18. 1 0
      MafiaTelegramBot/Game/GameRoles/NoneRole.cs
  19. 1 0
      MafiaTelegramBot/Game/GameRoles/ParasiteRole.cs
  20. 1 0
      MafiaTelegramBot/Game/GameRoles/VillagerRole.cs
  21. 1 0
      MafiaTelegramBot/Game/GameRoles/WerewolfRole.cs
  22. 1 1
      MafiaTelegramBot/Game/GameRooms/ExtendedGameRoom.cs
  23. 18 13
      MafiaTelegramBot/Game/GameRooms/GameRoom.GameProcess.cs
  24. 1 1
      MafiaTelegramBot/Game/GameRooms/GameRoom.Role.cs
  25. 27 1
      MafiaTelegramBot/Game/GameRooms/GameRoom.Structure.cs
  26. 1 1
      MafiaTelegramBot/Game/GameRooms/NormalGameRoom.cs
  27. 80 30
      MafiaTelegramBot/Game/Player.cs
  28. 2 2
      MafiaTelegramBot/Models/Bot.cs
  29. 1 2
      MafiaTelegramBot/Models/Commands/CreateGameCommand.cs
  30. 5 3
      MafiaTelegramBot/Models/Commands/CustomMessageHandlers/CreateRoomHandler.cs
  31. 0 2
      MafiaTelegramBot/Models/Commands/ShowProfileCommand.cs
  32. 5 7
      MafiaTelegramBot/Models/Inlines/ChooseGameModeQuery.cs
  33. 4 4
      MafiaTelegramBot/Models/Inlines/ChooseGameTypeQuery.cs
  34. 23 0
      MafiaTelegramBot/Models/Inlines/ChooseRoomViewQuery.cs
  35. 4 9
      MafiaTelegramBot/Models/Inlines/ShowMyExtendedStatsQuery.cs
  36. 4 1
      MafiaTelegramBot/Resources/Callback.cs
  37. 8 0
      MafiaTelegramBot/Resources/Constants.cs
  38. 29 2
      MafiaTelegramBot/Resources/Keyboard.cs
  39. 26 2
      MafiaTelegramBot/Resources/strings.Designer.cs
  40. 15 3
      MafiaTelegramBot/Resources/strings.resx

+ 3 - 3
MafiaTelegramBot/Controllers/RoomController.cs

@@ -11,7 +11,7 @@ namespace MafiaTelegramBot.Controllers
     {
         private static readonly Dictionary<string, GameRoom> OpenedGames = new();
 
-        public static async Task<ResultCode> CreateNewGame(Player creator, string roomName, bool isExtended, bool isPrivate)
+        public static async Task<ResultCode> CreateNewGame(Player creator, string roomName, bool isExtended, bool isPrivate, bool isRanking)
         {
             return await Task.Run(() =>
             {
@@ -19,8 +19,8 @@ namespace MafiaTelegramBot.Controllers
                 if (OpenedGames.ContainsKey(roomKey)) return ResultCode.GameAlreadyExists;
                 if (!creator.SetRoomName(roomName)) return ResultCode.UserAlreadyInGame;
                 GameRoom room = isExtended
-                    ? new ExtendedGameRoom {Owner = creator, RoomName = roomName, IsPrivate = isPrivate}
-                    : new NormalGameRoom {Owner = creator, RoomName = roomName, IsPrivate = isPrivate};
+                    ? new ExtendedGameRoom {Owner = creator, RoomName = roomName, IsPrivate = isPrivate, IsRanking = isRanking}
+                    : new NormalGameRoom {Owner = creator, RoomName = roomName, IsPrivate = isPrivate, IsRanking = isRanking};
                 OpenedGames.Add(roomKey, room);
                 room.Players.Add(creator.Id, creator);
                 

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

@@ -26,6 +26,8 @@ namespace MafiaTelegramBot.DataBase.Entity
         }
 
         [Column("nickname") , MaxLength(127)] public string NickName { get; set; } = "\\[NoNickname\\]";
+        
+        [Column("rank_number") , MaxLength(127)] public int RankNumber { get; set; } = 0;
 
         public async Task UpdateNickName(string newName)
         {

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

@@ -1,4 +1,5 @@
 using System;
+using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using MafiaTelegramBot.CustomCollections;
@@ -16,6 +17,16 @@ namespace MafiaTelegramBot.DataBase.EntityDao
         {
             return Task.CompletedTask;
         }
+        public static async Task<StatisticsList> GetStatisticsListById(long userId)
+        {
+            var result = new StatisticsList();
+            var userStats = await UserDao.DataBase.Statistics.Where(s => s.UserId == userId).AsNoTracking().ToListAsync();
+            foreach (var role in userStats)
+            {
+                result.Add(Enum.Parse<Roles>(role.Role), role);
+            }
+            return result;
+        }
 
         public static async Task CreatePlayerStats(long id)
         {

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

@@ -33,6 +33,7 @@ namespace MafiaTelegramBot.DataBase.EntityDao
             var player = Player.FromUserEntity(user);
             player.OpenedRoles = await OpenedRolesDao.GetOpenedRolesById(id);
             player.Achievements = await AchievementsDao.GetAchievementsProgressById(id);
+            player.Statistics = await StatisticsDao.GetStatisticsListById(id);
             ActiveUsers.Add(user.Id, player);
             return player;
         }

+ 1 - 0
MafiaTelegramBot/Game/GameRoles/BodyguardRole.cs

@@ -9,6 +9,7 @@ namespace MafiaTelegramBot.Game.GameRoles
     public class BodyguardRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Bodyguard;
+        public override int RankingCost { get; } = 20;
 
         private int _color = 1;
 

+ 1 - 0
MafiaTelegramBot/Game/GameRoles/CopRole.cs

@@ -9,6 +9,7 @@ namespace MafiaTelegramBot.Game.GameRoles
     public class CopRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Cop;
+        public override int RankingCost { get; } = 30;
 
         private int _color = 1;
 

+ 1 - 0
MafiaTelegramBot/Game/GameRoles/DameRole.cs

@@ -9,6 +9,7 @@ namespace MafiaTelegramBot.Game.GameRoles
     public class DameRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Dame;
+        public override int RankingCost { get; } = 30;
         
         private int _color = 2;
 

+ 1 - 0
MafiaTelegramBot/Game/GameRoles/DetectiveRole.cs

@@ -8,6 +8,7 @@ namespace MafiaTelegramBot.Game.GameRoles
     public class DetectiveRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Detective;
+        public override int RankingCost { get; } = 35;
 
         private int _color = 1;
         private string _action = "";

+ 1 - 0
MafiaTelegramBot/Game/GameRoles/DoctorRole.cs

@@ -8,6 +8,7 @@ namespace MafiaTelegramBot.Game.GameRoles
     public class DoctorRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Doctor;
+        public override int RankingCost { get; } = 25;
         
         private int _color = 1;
 

+ 1 - 0
MafiaTelegramBot/Game/GameRoles/DonRole.cs

@@ -9,6 +9,7 @@ namespace MafiaTelegramBot.Game.GameRoles
     public class DonRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Don;
+        public override int RankingCost { get; } = 30;
         
         private int _color = 2;
         public override int ColorRole

+ 1 - 0
MafiaTelegramBot/Game/GameRoles/ElderRole.cs

@@ -7,6 +7,7 @@ namespace MafiaTelegramBot.Game.GameRoles
     public class ElderRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Elder;
+        public override int RankingCost { get; } = 15;
         
         private int _color = 1;
         public override int ColorRole

+ 1 - 0
MafiaTelegramBot/Game/GameRoles/FoolRole.cs

@@ -7,6 +7,7 @@ namespace MafiaTelegramBot.Game.GameRoles
     public class FoolRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Fool;
+        public override int RankingCost { get; } = 50;
 
         private int _color = 3;
 

+ 1 - 0
MafiaTelegramBot/Game/GameRoles/HookerRole.cs

@@ -11,6 +11,7 @@ namespace MafiaTelegramBot.Game.GameRoles
     public class HookerRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Hooker;
+        public override int RankingCost { get; } = 20;
 
         private int _color = 1;
         public override int ColorRole

+ 1 - 0
MafiaTelegramBot/Game/GameRoles/JournalistRole.cs

@@ -10,6 +10,7 @@ namespace MafiaTelegramBot.Game.GameRoles
     public class JournalistRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Journalist;
+        public override int RankingCost { get; } = 30;
         
         private int _color = 1;
 

+ 1 - 0
MafiaTelegramBot/Game/GameRoles/LawyerRole.cs

@@ -8,6 +8,7 @@ namespace MafiaTelegramBot.Game.GameRoles
     public class LawyerRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Lawyer;
+        public override int RankingCost { get; } = 25;
         
         private int _color = 1;
 

+ 1 - 0
MafiaTelegramBot/Game/GameRoles/MafiaRole.cs

@@ -8,6 +8,7 @@ namespace MafiaTelegramBot.Game.GameRoles
     public class MafiaRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Mafia;
+        public override int RankingCost { get; } = 20;
         private int _color = 2;
 
         public override int ColorRole

+ 1 - 0
MafiaTelegramBot/Game/GameRoles/NecromancerRole.cs

@@ -8,6 +8,7 @@ namespace MafiaTelegramBot.Game.GameRoles
     public class NecromancerRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Necromancer;
+        public override int RankingCost { get; } = 25;
 
         private int _color = 1;
 

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

@@ -6,6 +6,7 @@ namespace MafiaTelegramBot.Game.GameRoles
     public class NoneRole : GameRoom.Role
     {
         private int _color = 1;
+        public override int RankingCost { get; } = 0;
 
         public override int ColorRole
         {

+ 1 - 0
MafiaTelegramBot/Game/GameRoles/ParasiteRole.cs

@@ -8,6 +8,7 @@ namespace MafiaTelegramBot.Game.GameRoles
     public class ParasiteRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Parasite;
+        public override int RankingCost { get; } = 50;
 
         private int _color = 3;
 

+ 1 - 0
MafiaTelegramBot/Game/GameRoles/VillagerRole.cs

@@ -6,6 +6,7 @@ namespace MafiaTelegramBot.Game.GameRoles
     public class VillagerRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Villager;
+        public override int RankingCost { get; } = 10;
         
         private int _color = 1;
 

+ 1 - 0
MafiaTelegramBot/Game/GameRoles/WerewolfRole.cs

@@ -8,6 +8,7 @@ namespace MafiaTelegramBot.Game.GameRoles
     public class WerewolfRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Werewolf;
+        public override int RankingCost { get; } = 25;
         public bool IsMafia = false;
         
         private int _color = 1;

+ 1 - 1
MafiaTelegramBot/Game/GameRooms/ExtendedGameRoom.cs

@@ -7,7 +7,7 @@ namespace MafiaTelegramBot.Game.GameRooms
 {
     public class ExtendedGameRoom : GameRoom
     {
-        public override bool IsExtended { get; protected set; } = true;
+        public override bool IsExtended { get; init; } = true;
 
         public Dictionary<Roles, int> CustomRoomSettings = new();
 

+ 18 - 13
MafiaTelegramBot/Game/GameRooms/GameRoom.GameProcess.cs

@@ -5,7 +5,6 @@ using System.Threading;
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
 using MafiaTelegramBot.CustomCollections.Extensions;
-using MafiaTelegramBot.DataBase;
 using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Game.GameRoles;
 using MafiaTelegramBot.Models;
@@ -58,31 +57,31 @@ namespace MafiaTelegramBot.Game.GameRooms
             await Task.Run(async() =>
             {
                 //Start updating games stats
-                var statsQuery = "SELECT * FROM mafia.statistics WHERE";
-                foreach (var player in Players.Values)
-                {
-                    statsQuery += $" id = {player.Id} AND role = '{player.GetRole().ToString()}' OR role = 'All' OR";
-                }
+                // var statsQuery = "SELECT * FROM mafia.statistics WHERE";
+                // foreach (var player in Players.Values)
+                // {
+                //     statsQuery += $" id = {player.Id} AND role = '{player.GetRole().ToString()}' OR role = 'All' OR";
+                // }
 
-                statsQuery = statsQuery.Substring(0, statsQuery.Length - 2);
+                // statsQuery = statsQuery.Substring(0, statsQuery.Length - 2);
 
                 try
                 {
-                    var statsList = UserDao.DataBase.Statistics.FromSqlRaw(statsQuery).ToArrayAsync().Result;
+                    // var statsList = UserDao.DataBase.Statistics.FromSqlRaw(statsQuery).ToArrayAsync().Result;
 
                     foreach (var player in Players.Values)
                     {
                         var userProfile = UserDao.GetPlayerById(player.Id).Result;
-                        foreach (var row in statsList.Where(s => s.UserId == player.Id))
-                            row.Games++;
-
+                        // foreach (var row in statsList.Where(s => s.UserId == player.Id))
+                        //     row.Games++;
+                        
                         if (userProfile.Statistics.Contains(Roles.All))
                         {
                             userProfile.Statistics[player.CurrentRole.RoleKey].Games++;
                             userProfile.Statistics[Roles.All].Games++;
                         }
                     }
-                    UserDao.DataBase.Statistics.UpdateRange(statsList);
+                    // UserDao.DataBase.Statistics.UpdateRange(statsList);
                 }
                 catch (Exception e)
                 {
@@ -548,10 +547,14 @@ namespace MafiaTelegramBot.Game.GameRooms
                             if (player.CurrentRole.IsWon().Result != "")
                             {
                                 player.HookerRoleAchievementEvent();
+                                player.AddRankPoints();
                                 UpdateWins(player);
                             }
+                            else player.SubtractRankPoints();
                             player.ResetParasiteProgress();
                         }
+
+                        if (IsRanking) SumRankingPoints(player, aliveMafia != 0);
                         
                         if (player.CurrentRole.RoleKey == Roles.Cop)
                         {
@@ -560,6 +563,8 @@ namespace MafiaTelegramBot.Game.GameRooms
                             if (((CopRole) PlayersRole[Roles.Cop][0].CurrentRole).CountRed == 0 &&
                                 ((CopRole) PlayersRole[Roles.Cop][0].CurrentRole).CountBlack != 0) player.DetectiveAchievementEvent();
                         }
+                        
+                        
                         player.ResetState();
                     }
                     UserDao.DataBase.Statistics.UpdateRange(statsList);
@@ -580,7 +585,7 @@ namespace MafiaTelegramBot.Game.GameRooms
                     await RoomController.DissolveRoom(RoomEncrypter.GetCode(RoomName))).Start();
                 else
                 {
-                    await Bot.SendWithMarkdown2(Owner.ChatId, strings.thanks_for_game, Keyboard.OwnerGameMenu);
+                    await PlayersMessageChannel.SendTo(Owner.ChatId, strings.thanks_for_game, Keyboard.OwnerGameMenu);
                     await PlayersMessageChannel.SendExcept(Owner.Id, strings.thanks_for_game, Keyboard.PlayerGameMenu);
                 }
                 if (Players.Count <= Constants.MEMORY_CLEANER_INTERVAL) StartTimer();

+ 1 - 1
MafiaTelegramBot/Game/GameRooms/GameRoom.Role.cs

@@ -24,13 +24,13 @@ namespace MafiaTelegramBot.Game.GameRooms
                 set;
             }
             
-
             public readonly ManualResetEvent TalkingActionComplete = new(false);
             public readonly ManualResetEvent VoteActionComplete = new(false);
             protected int MessageId = -1;
             protected int MafiaMessageId = -1;
             protected List<Player> NightTargetList = null;
             public abstract Roles RoleKey { get; }
+            public abstract int RankingCost { get; }
             
             public virtual Task NightAction() { return Task.CompletedTask; }
             public virtual Task SetMafiaTarget(long userId) { return Task.CompletedTask; }

+ 27 - 1
MafiaTelegramBot/Game/GameRooms/GameRoom.Structure.cs

@@ -14,7 +14,8 @@ namespace MafiaTelegramBot.Game.GameRooms
         public int MaxPlayers = 10;
         private int _minPlayers = Constants.PLAYER_LIMITS_MIN;
         public bool IsPrivate { get; init; }
-        public abstract bool IsExtended { get; protected set; }
+        public abstract bool IsExtended { get; init; }
+        public bool IsRanking { get; init; }
         public bool TimerEnabled { get; set; } = true;
         public string RoomName { get; init; } = "NoNameRoom";
         public Player Owner { get; init; } = new();
@@ -87,6 +88,7 @@ namespace MafiaTelegramBot.Game.GameRooms
                     await PlayersRole[Roles.Parasite][0].CurrentRole.Kill();
                 if (player.CurrentRole.RoleKey==Roles.Werewolf) player.WerewolfRoleAchievementEvent(0,true);
             }
+            player.SubtractRankPoints();
             player.ResetState();
         }
 
@@ -99,5 +101,29 @@ namespace MafiaTelegramBot.Game.GameRooms
         {
             return await Task.FromResult(MaxPlayers);
         }
+
+        public async Task<char> GetRoomRank()
+        {
+            return await Task.FromResult(Owner.GetRank());
+        }
+
+        private void SumRankingPoints(Player player, bool mafiaWins)
+        {
+            if (player.CurrentRole.ColorRole == 3)
+            {
+                if (player.CurrentRole.IsWon().Result != "") player.AddRankPoints();
+                else player.SubtractRankPoints();
+            }
+            else if (player.CurrentRole.ColorRole == 1 && player.GetRole() != Roles.Lawyer)
+            {
+                if (!mafiaWins) player.AddRankPoints();
+                else player.SubtractRankPoints();
+            }
+            else if (player.CurrentRole.ColorRole == 2 || player.CurrentRole.RoleKey == Roles.Lawyer)
+            {
+                if (mafiaWins) player.AddRankPoints();
+                else player.SubtractRankPoints();
+            }
+        }
     }
 }

+ 1 - 1
MafiaTelegramBot/Game/GameRooms/NormalGameRoom.cs

@@ -6,7 +6,7 @@ namespace MafiaTelegramBot.Game.GameRooms
 {
     public class NormalGameRoom : GameRoom
     {
-        public override bool IsExtended { get; protected set; } = false;
+        public override bool IsExtended { get; init; } = false;
 
         public override Dictionary<Roles, List<Player>> PlayersRole { get; set;} = new()
         {

+ 80 - 30
MafiaTelegramBot/Game/Player.cs

@@ -32,16 +32,6 @@ namespace MafiaTelegramBot.Game
         public OpenedRolesEntity OpenedRoles = new();
         public AchievementsEntity Achievements = new();
 
-        public async Task<bool> LoadStatistics()
-        {
-            List<StatisticsEntity> userStats = await UserDao.DataBase.Statistics.Where(s => s.UserId == Id).AsNoTracking().ToListAsync();
-            foreach (var role in userStats)
-            {
-                Statistics.Add(Enum.Parse<Roles>(role.Role),role);
-            }
-            return true;
-        }
-
         public void SetActive()
         {
             _lastActivity = DateTime.Now;
@@ -51,7 +41,7 @@ namespace MafiaTelegramBot.Game
         {
             return DateTime.Now.Subtract(_lastActivity);
         }
-        
+
         public static Player FromUserEntity(UserEntity b)
         {
             var serialized = JsonConvert.SerializeObject(b);
@@ -70,7 +60,7 @@ namespace MafiaTelegramBot.Game
             _roomName = roomName;
             return true;
         }
-        
+
         public async Task<bool> RemoveGame()
         {
             if (_roomName == "") return false;
@@ -114,7 +104,7 @@ namespace MafiaTelegramBot.Game
         {
             if (!OpenedRoles.Bodyguard)
             {
-                Task.Run(async() =>
+                Task.Run(async () =>
                 {
                     Achievements.DoctorHeals++;
                     if (Achievements.DoctorHeals == 10)
@@ -178,7 +168,7 @@ namespace MafiaTelegramBot.Game
             }
         }
 
-        public void DetectiveAchievementEvent() 
+        public void DetectiveAchievementEvent()
         {
             if (!OpenedRoles.Detective)
             {
@@ -203,44 +193,43 @@ namespace MafiaTelegramBot.Game
                 if (!OpenedRoles.Dame)
                 {
                     Achievements.HaveSexWithDon++;
-                    if(Achievements.HaveSexWithDon == 5)
+                    if (Achievements.HaveSexWithDon == 5)
                     {
                         await Bot.SendWithMarkdown2(ChatId,
                             $"{strings.congrats} {roles.Dame}! {strings.you_can_use}");
                         await Bot.SendStickerAsync(ChatId, Stickers.Sticker[Roles.Dame.ToString()]);
                         OpenedRoles.OpenDame();
                     }
-                } 
-
+                }
             });
-
         }
 
         public void ElderRoleAchievementEvent()
         {
-            Task.Run(async() =>
+            Task.Run(async () =>
             {
                 if (!OpenedRoles.Elder)
                 {
                     Achievements.NotDispatchedOnSecondStage++;
-                    if(Achievements.NotDispatchedOnSecondStage == 2)
+                    if (Achievements.NotDispatchedOnSecondStage == 2)
                     {
                         await Bot.SendWithMarkdown2(ChatId,
                             $"{strings.congrats} {roles.Elder}! {strings.you_can_use}");
                         await Bot.SendStickerAsync(ChatId, Stickers.Sticker[Roles.Elder.ToString()]);
                         OpenedRoles.OpenElder();
                     }
-                } 
+                }
             });
         }
+
         public void LawyerRoleAchievementEvent()
         {
             if (!OpenedRoles.Lawyer)
             {
-                Task.Run(async() =>
+                Task.Run(async () =>
                 {
                     Achievements.MafiaSoloWins++;
-                    if(Achievements.MafiaSoloWins == 3)
+                    if (Achievements.MafiaSoloWins == 3)
                     {
                         await Bot.SendWithMarkdown2(ChatId,
                             $"{strings.congrats} {roles.Lawyer}! {strings.you_can_use}");
@@ -248,7 +237,7 @@ namespace MafiaTelegramBot.Game
                         OpenedRoles.OpenLawyer();
                     }
                 });
-            } 
+            }
         }
 
         public void WerewolfRoleAchievementEvent(int color, bool reset = false)
@@ -257,7 +246,6 @@ namespace MafiaTelegramBot.Game
             {
                 Task.Run(async () =>
                 {
-
                     if (reset)
                     {
                         Achievements.PreviousGameWinColor = 0;
@@ -274,7 +262,6 @@ namespace MafiaTelegramBot.Game
                     {
                         Achievements.PreviousGameWinColor = color;
                     }
-
                 });
             }
         }
@@ -285,7 +272,6 @@ namespace MafiaTelegramBot.Game
             {
                 Task.Run(async () =>
                 {
-                    
                     await Bot.SendWithMarkdown2(ChatId,
                         $"{strings.congrats} {roles.Hooker}! {strings.you_can_use}");
                     await Bot.SendStickerAsync(ChatId, Stickers.Sticker[Roles.Hooker.ToString()]);
@@ -293,13 +279,12 @@ namespace MafiaTelegramBot.Game
                 });
             }
         }
-        
+
         public async Task ParasiteRoleAchievementEvent(List<long> team)
         {
-            
             if (!OpenedRoles.Parasite)
             {
-                await Task.Run(async() =>
+                await Task.Run(async () =>
                 {
                     team.Remove(Id);
                     if (Achievements.PlayerWinTeam == "")
@@ -355,5 +340,70 @@ namespace MafiaTelegramBot.Game
             Achievements.PlayerWinTeam = "";
             Achievements.PlayerWinTeamTwo = "";
         }
+
+        public char GetRank()
+        {
+            return RankNumber switch
+            {
+                <100 => 'a',
+                >=100 and <300 => 'b',
+                >=300 and <500 => 'c',
+                >500 => 'd',
+                _ => '0'
+            };
+        }
+
+        public void AddRankPoints()
+        {
+            switch (GetRank())
+            {
+                case 'a':
+                {
+                    RankNumber += CurrentRole.RankingCost;
+                    break;
+                }
+                case 'b':
+                {
+                    RankNumber += CurrentRole.RankingCost;
+                    break;
+                }
+                case 'c':
+                {
+                    RankNumber += (int)(CurrentRole.RankingCost * Statistics[Roles.All].GetWinrate());
+                    break;
+                }
+                case 'd':
+                {
+                    RankNumber += (int)(CurrentRole.RankingCost * Statistics[Roles.All].GetWinrate());
+                    break;
+                }
+            }
+        }
+
+        public void SubtractRankPoints()
+        {
+            switch (GetRank())
+            {
+                case 'a':
+                {
+                    break;
+                }
+                case 'b':
+                {
+                    RankNumber -= CurrentRole.RankingCost;
+                    break;
+                }
+                case 'c':
+                {
+                    RankNumber -= (int)(CurrentRole.RankingCost * Statistics[Roles.All].GetWinrate());
+                    break;
+                }
+                case 'd':
+                {
+                    RankNumber -= CurrentRole.RankingCost;
+                    break;
+                }
+            }
+        }
     }
 }

+ 2 - 2
MafiaTelegramBot/Models/Bot.cs

@@ -67,8 +67,8 @@ namespace MafiaTelegramBot.Models
                 new ShopMenuQuery(),
                 new MakePrivateRoomQuery(),
                 new MakePublicRoomQuery(),
-                new MakeNormalGameQuery(),
-                new MakeExtendedGameQuery(),
+                new ChooseGameTypeQuery(),
+                new ChooseGameModeQuery(),
                 new MakePublicRoomQuery(),
                 new SettingsProfileQuery(),
                 new ChangeNickNameQuery(),

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

@@ -14,8 +14,7 @@ namespace MafiaTelegramBot.Models.Commands
             var user = await UserDao.GetPlayerById(UserId);
             if (user.GetRoomName() != "")
                 return await Bot.SendWithMarkdown2(ChatId, strings.user_already_in_game);
-            return await Bot.SendWithMarkdown2(ChatId, strings.choose_type_room, 
-                Keyboard.RoomTypeKeyboard(UserId, Callback.MakePrivateRoom, Callback.MakePublicRoom));
+            return await Bot.SendWithMarkdown2(ChatId, strings.choose_game_view, Keyboard.ChooseRoomView(UserId));
         }
     }
 }

+ 5 - 3
MafiaTelegramBot/Models/Commands/CustomMessageHandlers/CreateRoomHandler.cs

@@ -14,16 +14,18 @@ namespace MafiaTelegramBot.Models.Commands.CustomMessageHandlers
         protected override async Task<Message> Execute(Update update)
         {
             var param = Bot.UsersThatCreatesRoom[UserId];
-            var isExtended = param[1] == Callback.MakeExtendedGame.ToString();
             Bot.UsersThatCreatesRoom.Remove(UserId);
+            var isPrivate = param[1][0] == Constants.PRIVATE;
+            var isExtended = param[1][1] == Constants.EXTENDED;
+            var isRanking = param[1][2] == Constants.RANKING;
             var user = await UserDao.GetPlayerById(UserId);
             var roomName = update.Message.Text;
-            var resultCode = await RoomController.CreateNewGame(user, roomName, isExtended, param[0] == "private");
+            var resultCode = await RoomController.CreateNewGame(user, roomName, isExtended, isPrivate, isRanking);
             var result = resultCode == ResultCode.CodeOk
                 ? await Bot.SendWithMarkdown2(ChatId, 
                     $"{strings.room_with_name} _*{roomName}*_ {strings.was_created}\n", Keyboard.OwnerGameMenu)
                 : await Utilities.GetResultCodeMessage(resultCode, ChatId);
-            if (resultCode == ResultCode.CodeOk && param[0] == "private")
+            if (resultCode == ResultCode.CodeOk && isPrivate)
                 await Bot.SendWithMarkdown2(ChatId, $"{strings.secret_key_is} _*{roomName}*_: ```{RoomEncrypter.GetCode(roomName)}```");
             if (resultCode == ResultCode.CodeOk)
                 await Bot.SendHyperLink(ChatId, $"<a href='https://t.me/{AppSettings.Name}?start={RoomEncrypter.GetCode(roomName)}'>{strings.link}</a>");

+ 0 - 2
MafiaTelegramBot/Models/Commands/ShowProfileCommand.cs

@@ -17,8 +17,6 @@ namespace MafiaTelegramBot.Models.Commands
             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 =
                 $"__*{strings.statistics_for} _{user.NickName}_*__\n" +

+ 5 - 7
MafiaTelegramBot/Models/Inlines/MakeExtendedGameQuery.cs → MafiaTelegramBot/Models/Inlines/ChooseGameModeQuery.cs

@@ -5,21 +5,19 @@ using Telegram.Bot.Types;
 
 namespace MafiaTelegramBot.Models.Inlines
 {
-    public class MakeExtendedGameQuery : Query
+    public class ChooseGameModeQuery : Query
     {
-        protected override Callback Name => Callback.MakeExtendedGame;
+        protected override Callback Name => Callback.ChooseGameMode;
 
         protected override async Task<Message> Execute(Update update)
         {
             await DeletePreviousMessage(ChatId, update.CallbackQuery.Message.MessageId);
-            var data = update.CallbackQuery.Data;
-            var param = data.Split('|');
             var user = await UserDao.GetPlayerById(UserId);
             if (user.GetRoomName() != "")
                 return await Bot.SendWithMarkdown2(ChatId, strings.user_already_in_game);
-            if (Bot.UsersThatCreatesRoom.TryAdd(UserId, new[] {param[2], Name.ToString()}))
-                Bot.UsersThatCreatesRoom[UserId] = new[] {param[2], Name.ToString()};
-            return await Bot.SendWithMarkdown2(ChatId, strings.enter_room_name);
+            var data = update.CallbackQuery.Data;
+            var param = data.Split('|');
+            return await Bot.SendWithMarkdown2(ChatId, strings.choose_game_type, Keyboard.ChooseTypeKeyboard(UserId, param[2]));
         }
     }
 }

+ 4 - 4
MafiaTelegramBot/Models/Inlines/MakeNormalGameQuery.cs → MafiaTelegramBot/Models/Inlines/ChooseGameTypeQuery.cs

@@ -5,18 +5,18 @@ using Telegram.Bot.Types;
 
 namespace MafiaTelegramBot.Models.Inlines
 {
-    public class MakeNormalGameQuery : Query
+    public class ChooseGameTypeQuery : Query
     {
-        protected override Callback Name => Callback.MakeNormalGame;
+        protected override Callback Name => Callback.ChooseGameType;
 
         protected override async Task<Message> Execute(Update update)
         {
             await DeletePreviousMessage(ChatId, update.CallbackQuery.Message.MessageId);
-            var data = update.CallbackQuery.Data;
-            var param = data.Split('|');
             var user = await UserDao.GetPlayerById(UserId);
             if (user.GetRoomName() != "")
                 return await Bot.SendWithMarkdown2(ChatId, strings.user_already_in_game);
+            var data = update.CallbackQuery.Data;
+            var param = data.Split('|');
             if (Bot.UsersThatCreatesRoom.TryAdd(UserId, new[] {param[2], Name.ToString()}))
                 Bot.UsersThatCreatesRoom[UserId] = new[] {param[2], Name.ToString()};
             return await Bot.SendWithMarkdown2(ChatId, strings.enter_room_name);

+ 23 - 0
MafiaTelegramBot/Models/Inlines/ChooseRoomViewQuery.cs

@@ -0,0 +1,23 @@
+using System.Threading.Tasks;
+using MafiaTelegramBot.DataBase.EntityDao;
+using MafiaTelegramBot.Resources;
+using Telegram.Bot.Types;
+
+namespace MafiaTelegramBot.Models.Inlines
+{
+    public class ChooseRoomViewQuery : Query
+    {
+        protected override Callback Name => Callback.ChooseRoomView;
+
+        protected override async Task<Message> Execute(Update update)
+        {
+            await DeletePreviousMessage(ChatId, update.CallbackQuery.Message.MessageId);
+            var user = await UserDao.GetPlayerById(UserId);
+            if (user.GetRoomName() != "")
+                return await Bot.SendWithMarkdown2(ChatId, strings.user_already_in_game);
+            var data = update.CallbackQuery.Data;
+            var param = data.Split('|');
+            return await Bot.SendWithMarkdown2(ChatId, strings.choose_game_mode, Keyboard.ChooseModeKeyboard(UserId, param[2]));
+        }
+    }
+}

+ 4 - 9
MafiaTelegramBot/Models/Inlines/ShowMyExtendedStatsQuery.cs

@@ -18,18 +18,13 @@ namespace MafiaTelegramBot.Models.Inlines
             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)
+            if (user.Statistics[Roles.All].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';
-                    }
+                    if (!user.Statistics.Contains(role) || user.Statistics[role].Games <= 0) continue;
+                    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
             {

+ 4 - 1
MafiaTelegramBot/Resources/Callback.cs

@@ -26,6 +26,9 @@ namespace MafiaTelegramBot.Resources
         NightTarget,
         DetectiveTarget,
         StartGame,
-        ShowMyExtendedStats
+        ShowMyExtendedStats,
+        ChooseRoomView,
+        ChooseGameMode,
+        ChooseGameType
     }
 }

+ 8 - 0
MafiaTelegramBot/Resources/Constants.cs

@@ -32,5 +32,13 @@ namespace MafiaTelegramBot.Resources
         public const int DISCUSSION_INTERVAL = 60 * 100;
 
         public const int ROOM_CODE_LENGTH = 6;
+        
+        
+        public const int PUBLIC = 0;
+        public const int PRIVATE = 1;
+        public const int STANDARD = 0;
+        public const int EXTENDED = 1;
+        public const int NORMAL = 0;
+        public const int RANKING = 1;
     }
 }

+ 29 - 2
MafiaTelegramBot/Resources/Keyboard.cs

@@ -53,9 +53,36 @@ namespace MafiaTelegramBot.Resources
             });
         }
 
+        public static InlineKeyboardMarkup ChooseRoomView(long userId)
+        {
+            return new InlineKeyboardMarkup(new[]
+            {
+                InlineKeyboardButton.WithCallbackData(strings._public, $"{Callback.ChooseRoomView}|{userId}|{Constants.PUBLIC}"),
+                InlineKeyboardButton.WithCallbackData(strings._private, $"{Callback.ChooseRoomView}|{userId}|{Constants.PRIVATE}"),
+            });
+        }
+
+        public static InlineKeyboardMarkup ChooseModeKeyboard(long userId, string info)
+        {
+            return new InlineKeyboardMarkup(new[]
+            {
+                InlineKeyboardButton.WithCallbackData(strings.standard, $"{Callback.ChooseGameMode}|{userId}|{info}{Constants.STANDARD}"),
+                InlineKeyboardButton.WithCallbackData(strings.extended, $"{Callback.ChooseGameMode}|{userId}|{info}{Constants.EXTENDED}"),
+            });
+        }
+
+        public static InlineKeyboardMarkup ChooseTypeKeyboard(long userId, string info)
+        {
+            return new InlineKeyboardMarkup(new[]
+            {
+                InlineKeyboardButton.WithCallbackData(strings.normal_game, $"{Callback.ChooseGameType}|{userId}|{info}{Constants.NORMAL}"),
+                InlineKeyboardButton.WithCallbackData(strings.ranking_game, $"{Callback.ChooseGameType}|{userId}|{info}{Constants.RANKING}"),
+            });
+        }
+
         public static InlineKeyboardMarkup SetMaximumKeyboard(long userId)
         {
-            return new (new[]
+            return new InlineKeyboardMarkup(new[]
             {
                 new[] {
                     InlineKeyboardButton.WithCallbackData(strings.minimum_players_count, $"{Callback.SetPlayersMaximum}|{userId}|6"),
@@ -99,7 +126,7 @@ namespace MafiaTelegramBot.Resources
             return new (new[]
             {
                 new[] {
-                    InlineKeyboardButton.WithCallbackData(strings.standart, $"{Callback.MakeNormalGame}|{userId}|{type}"),
+                    InlineKeyboardButton.WithCallbackData(strings.standard, $"{Callback.MakeNormalGame}|{userId}|{type}"),
                     InlineKeyboardButton.WithCallbackData(strings.extended, $"{Callback.MakeExtendedGame}|{userId}|{type}")
                 }
             });

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

@@ -177,9 +177,9 @@ namespace MafiaTelegramBot {
             }
         }
         
-        internal static string standart {
+        internal static string standard {
             get {
-                return ResourceManager.GetString("standart", resourceCulture);
+                return ResourceManager.GetString("standard", resourceCulture);
             }
         }
         
@@ -1166,5 +1166,29 @@ namespace MafiaTelegramBot {
                 return ResourceManager.GetString("extended_stats", resourceCulture);
             }
         }
+        
+        internal static string choose_game_mode {
+            get {
+                return ResourceManager.GetString("choose_game_mode", resourceCulture);
+            }
+        }
+        
+        internal static string choose_game_view {
+            get {
+                return ResourceManager.GetString("choose_game_view", resourceCulture);
+            }
+        }
+        
+        internal static string normal_game {
+            get {
+                return ResourceManager.GetString("normal_game", resourceCulture);
+            }
+        }
+        
+        internal static string ranking_game {
+            get {
+                return ResourceManager.GetString("ranking_game", resourceCulture);
+            }
+        }
     }
 }

+ 15 - 3
MafiaTelegramBot/Resources/strings.resx

@@ -61,7 +61,7 @@
         <value>Задайте настройки комнаты</value>
     </data>
     <data name="choose_game_type" xml:space="preserve">
-        <value>Выберите режим игры</value>
+        <value>Выберите тип игры</value>
     </data>
     <data name="enter_room_name" xml:space="preserve">
         <value>Введите название комнаты</value>
@@ -84,7 +84,7 @@
     <data name="user_not_in_game" xml:space="preserve">
         <value>Вы не находитесь сейчас в игре</value>
     </data>
-    <data name="standart" xml:space="preserve">
+    <data name="standard" xml:space="preserve">
         <value>Стандартный</value>
     </data>
     <data name="extended" xml:space="preserve">
@@ -574,9 +574,21 @@
         <value>У вас нет открытых ролей расширенной игры</value>
     </data>
     <data name="your_opened_roles_list" xml:space="preserve">
-        <value>У вас открыты следующие роли</value>
+        <value>У вас открыты следующие роли:</value>
     </data>
     <data name="extended_stats" xml:space="preserve">
         <value>Расширенная статистика</value>
     </data>
+    <data name="choose_game_mode" xml:space="preserve">
+        <value>Выберите режим игры</value>
+    </data>
+    <data name="choose_game_view" xml:space="preserve">
+        <value>Выберите вид игры</value>
+    </data>
+    <data name="normal_game" xml:space="preserve">
+        <value>Обычная игра</value>
+    </data>
+    <data name="ranking_game" xml:space="preserve">
+        <value>Рейтинговая игра</value>
+    </data>
 </root>