Пример #1
0
        public async Task <StormState> GetStateAsync(Replay replay, StormState currentState)
        {
            TimeSpan?elapsed = await heroesOfTheStorm.TryGetTimerAsync();

            if (elapsed != null && elapsed != TimeSpan.Zero)
            {
                TimeSpan next = replayHelper.RemoveNegativeOffset(elapsed.Value);

                if (replayHelper.IsNearEnd(replay, next))
                {
                    return(new StormState(next, GameState.EndOfGame));
                }
                if (next <= TimeSpan.Zero)
                {
                    return(new StormState(next, GameState.StartOfGame));
                }
                if (next > currentState.Timer)
                {
                    return(new StormState(next, GameState.Running));
                }
                if (next < currentState.Timer)
                {
                    return(new StormState(next, GameState.Paused));
                }
                return(new StormState(next, currentState.State));
            }

            if (replayHelper.IsNearEnd(replay, currentState.Timer))
            {
                return(new StormState(currentState.Timer, GameState.EndOfGame));
            }


            return(currentState);
        }