#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(serialized); return a; } public string GetRoomName() { return _roomName; } public bool SetRoomName(string roomName) { if (_roomName != "") return false; _roomName = roomName; return true; } public async Task 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())!; } } }