using System.Collections.Generic; using System.Threading; using Cysharp.Threading.Tasks; using Game.Player; using UnityEngine; namespace Game.Room; public interface IRoom { string roomName { get; } RoomData roomData { get; } RoomInfo roomInfo { get; } List players { get; } RoomType roomType { get; } UniTask JoinAsync(IPlayer player, CancellationToken token); UniTask Quit(IPlayer player); float ClearAll(); void Dispose(); bool InvestmentJinbei(IPlayer player, float jinbei); } class Room : IRoom { private GameObject self; private RoomInfo _roomInfo; private RoomData _roomData; private string _roomName; public RoomType roomType => this._roomData.roomType; public string roomName => this._roomName; public RoomData roomData => this._roomData; public RoomInfo roomInfo => this._roomInfo; public List players => this._roomData.players; public Room(RoomType roomType, GameObject roomGo) { this._roomData = new RoomData(roomType); _roomName = roomType.ToString(); // view this._roomInfo = roomGo.GetComponent(); this._roomInfo.SetRoom(this); this.self = roomGo; } public async UniTask JoinAsync(IPlayer player, CancellationToken token) { if (this.players.Contains(player)) return false; Debug.Log($"{player.playerName} join {roomType} !!"); bool res = await player.WaitMoveRoomAsync(this, token); this.players.Add(player); return true; } public async UniTask Quit(IPlayer player) { if (!this.players.Contains(player)) return false; Debug.Log($"{player.playerName} quit {roomType} !!"); // player.SetRoom(null); this.players.Remove(player); await UniTask.Yield(); return true; } public float ClearAll() { // TODO: // EventManager.Instance.FireNow(this, new InputNameFinishEventArgs()); this.players.Clear(); return this._roomData.jinbei; } public void Dispose() { foreach (var player in this.players) { player.Dispose(); } } public bool InvestmentJinbei(IPlayer player, float jinbei) { if (!this.players.Contains(player)) return false; this._roomData.jinbei += jinbei; return true; } }