コード例 #1
0
        /// <summary>
        /// 向玩家请求一个动作的回应
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public Task <Response> WaitAnswer(Request request)
        {
            var tcs   = new TaskCompletionSource <Response>(cts.Token);
            int index = Players.FindIndex(x => x.Id == request.PlayerId);

            Requests[index] = tcs;
            OnRequest?.Invoke(this, request);
            if (TimeManager != null)
            {
                TimeManager.Register(request);
                tcs.Task.ContinueWith(x => { TimeManager.Cancel(request); }, cts.Token);
            }
            return(tcs.Task);
        }