Selaa lähdekoodia

Move role to GameRoom class

Tigran 4 vuotta sitten
vanhempi
commit
8b13c97596

+ 6 - 3
MafiaTelegramBot/Game/GameRoles/CopRole.cs

@@ -1,21 +1,24 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
+using MafiaTelegramBot.Game.GameRooms;
 using MafiaTelegramBot.Models;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
 namespace MafiaTelegramBot.Game.GameRoles
 {
-    public class CopRole : Role
+    public class CopRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Cop;
         
         protected override async Task<Message> NightAction(Player player)
         {
-            var roomKey = RoomEncrypter.GetCode(player.GetRoomName());
-            var room = RoomController.GetRoom(roomKey);
             //TODO this is what user can do in night phase
             return await Bot.SendWithMarkdown2(player.ChatId, strings.unexpected_error);
         }
+
+        public CopRole(GameRoom room) : base(room)
+        {
+        }
     }
 }

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

@@ -1,22 +1,24 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
+using MafiaTelegramBot.Game.GameRooms;
 using MafiaTelegramBot.Models;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
-using User = MafiaTelegramBot.DataBase.Entity.UserEntity;
 
 namespace MafiaTelegramBot.Game.GameRoles
 {
-    public class DoctorRole : Role
+    public class DoctorRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Doctor;
         
         protected override async Task<Message> NightAction(Player player)
         {
-            var roomKey = RoomEncrypter.GetCode(player.GetRoomName());
-            var room = RoomController.GetRoom(roomKey);
             //TODO this is what user can do in night phase
             return await Bot.SendWithMarkdown2(player.ChatId, strings.unexpected_error);
         }
+
+        public DoctorRole(GameRoom room) : base(room)
+        {
+        }
     }
 }

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

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

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

@@ -1,5 +1,6 @@
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
+using MafiaTelegramBot.Game.GameRooms;
 using MafiaTelegramBot.Models;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
@@ -7,7 +8,7 @@ using User = MafiaTelegramBot.DataBase.Entity.UserEntity;
 
 namespace MafiaTelegramBot.Game.GameRoles
 {
-    public class HookerRole : Role
+    public class HookerRole : GameRoom.Role
     {
         public override Roles RoleKey => Roles.Hooker;
         
@@ -18,5 +19,9 @@ namespace MafiaTelegramBot.Game.GameRoles
             //TODO this is what user can do in night phase
             return await Bot.SendWithMarkdown2(player.ChatId, strings.unexpected_error);
         }
+
+        public HookerRole(GameRoom room) : base(room)
+        {
+        }
     }
 }

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

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

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

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

+ 0 - 40
MafiaTelegramBot/Game/GameRoles/Role.cs

@@ -1,40 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using MafiaTelegramBot.Controllers;
-using MafiaTelegramBot.Models;
-using MafiaTelegramBot.Resources;
-using Telegram.Bot.Types;
-
-namespace MafiaTelegramBot.Game.GameRoles
-{
-    public abstract class Role
-    {
-        public abstract Roles RoleKey { get; }
-
-        protected async Task<Message> DayAction(Player player)
-        {
-            var roomKey = RoomEncrypter.GetCode(player.GetRoomName());
-            var room = RoomController.GetRoom(roomKey);
-            //TODO user telling anything in one minute and vote
-            return await Bot.SendWithMarkdown2(player.ChatId, strings.unexpected_error);
-        }
-
-        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)
-            };
-        }
-    }
-}

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

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

+ 48 - 0
MafiaTelegramBot/Game/GameRooms/GameRoom.Role.cs

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