123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #nullable enable
- using System.Threading.Tasks;
- 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 _roomName = "";
- public static Player FromUserEntity(UserEntity b)
- {
- var serialized = JsonConvert.SerializeObject(b);
- Player a = JsonConvert.DeserializeObject<Player>(serialized);
- return a;
- }
- public string GetRoomName()
- {
- return _roomName;
- }
- public bool SetRoomName(string roomName)
- {
- if (_roomName != "") return false;
- _roomName = roomName;
- return true;
- }
-
- public async Task<bool> RemoveGame()
- {
- if (_roomName == "") return false;
- _roomName = "";
- 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())!;
- }
- }
- }
|