123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #nullable enable
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using MafiaTelegramBot.Controllers;
- using MafiaTelegramBot.Resources;
- namespace MafiaTelegramBot.DataBase
- {
- public class User
- {
- public long Id { get; init; }
- public long ChatId { get; init; }
- public string Username { get; init; } = strings.no_name;
- public int Games { get; set; } = 0;
- public string NickName { get; set; } = "";
- public int Wins { get; set; } = 0;
- public Dictionary<Roles, int> RoleGames = new();
- public Dictionary<Roles, int> RoleWins = new();
- public Roles CurrentRole = Roles.None;
- 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 User user && user.Id == Id;
- }
- public override int GetHashCode()
- {
- return Id.GetHashCode();
- }
- }
- }
|