public override ICommandResponse Handle(EndPeriodCommand command)
        {
            var state = _boutRunner.GetBoutState(command.BoutId);

            if (state.Phase != Entities.BoutPhase.Lineup)
            {
                throw new InvalidBoutPhaseException(state.Phase);
            }
            var bout = _boutData.Load(command.BoutId);

            if (state.GameClock.Elapsed.TotalSeconds < bout.RuleSet.PeriodDurationSeconds)
            {
                return(new CommandResponse());
            }

            if (state.Period < bout.RuleSet.NumberOfPeriods)
            {
                state.Phase = BoutPhase.Halftime;
                state.Period++;
                state.JamNumber = 1;
                state.Jams.Add(new Jam(state.Period, state.JamNumber));
            }
            else
            {
                state.Phase = Entities.BoutPhase.UnofficialFinal;
            }

            var response = new UpdateBoutStateResponse(state);

            return(response);
        }
        public override ICommandResponse Handle(StartPeriodCommand command)
        {
            //Bout must be running
            var bout = _boutDataService.Load(command.BoutId);

            if (!_boutRunnerService.IsRunning(bout.BoutId))
            {
                throw new BoutNotRunningException(bout.BoutId);
            }

            //Game Must Be in pregame or halftime
            var state = _boutRunnerService.GetBoutState(command.BoutId);

            if (state.Phase != BoutPhase.Pregame && state.Phase != BoutPhase.Halftime)
            {
                return(new CommandResponse());
            }

            state.Phase = BoutPhase.Lineup;
            state.GameClock.Clear();

            var response = new UpdateBoutStateResponse(state);

            return(response);
        }
        public override ICommandResponse Handle(AddSkaterToJamCommand command)
        {
            var bout  = _boutData.Load(command.BoutId);
            var state = _boutRunner.GetBoutState(command.BoutId);
            var jam   = state.Jams.SingleOrDefault(x => x.JamNumber == command.Jam && x.Period == command.Period);

            if (jam == null)
            {
                throw new JamNotFoundException(command.Period, command.Jam);
            }

            var team   = jam.Team(command.Team);
            var roster = command.Team == "left" ? bout.Left.Roster : bout.Right.Roster;
            var lineup = team.Roster;

            if (roster.All(x => x.Number != command.Number))
            {
                throw new InvalidSkaterNumberException(command.Team, command.Number);
            }

            if (lineup.Any(x => x.Number == command.Number || lineup.Count == 6))
            {
                return(new CommandResponse());
            }

            lineup.Add(new JamParticipant {
                Number = command.Number, Position = Position.Blocker
            });

            var response = new UpdateBoutStateResponse(state);

            return(response);
        }
Пример #4
0
        public override ICommandResponse Handle(StopJamCommand command)
        {
            var bout  = _boutDataService.Load(command.BoutId);
            var state = _boutRunnerService.GetBoutState(command.BoutId);

            //State must be in jam
            if (state.Phase != BoutPhase.Jam)
            {
                throw new InvalidBoutPhaseException(state.Phase);
            }

            //Check to see if bout is over
            if (state.GameClock.Elapsed.Seconds < bout.RuleSet.PeriodDurationSeconds)
            {
                //Still good
                state.LineupStart = DateTime.Now;
                state.Phase       = BoutPhase.Lineup;
                state.CreateNextJam();

                //keep the jam clock going in case of undo
            }
            else
            {
                //Intermission
                if (state.Period < bout.RuleSet.NumberOfPeriods)
                {
                    state.JamNumber = 1;
                    state.Period++;
                    state.GameClock.Clear();
                    state.Phase = BoutPhase.Halftime;
                }
                else
                //Game Over
                {
                    state.Phase = BoutPhase.UnofficialFinal;
                }
            }


            state.JamStart = DateTime.Now;
            state.GameClock.Start();

            var response = new UpdateBoutStateResponse(state);

            state.PenaltyBox.ForEach(x =>
            {
                x.StopWatch.Stop();
                response.AddEvent(new ChairUpdatedEvent(state.BoutId, x), Audiences.Bout(state.BoutId));
            });

            return(response);
        }
        public override ICommandResponse Handle(StartTimeoutCommand command)
        {
            var state = _boutRunner.GetBoutState(command.BoutId);

            if (state.Phase != BoutPhase.Lineup)
            {
                throw new InvalidBoutPhaseException(state.Phase);
            }
            state.TimeOutStart       = command.ServerTime;
            state.LoseOfficialReview = false;
            state.TimeoutType        = TimeoutType.Official;
            state.Phase = BoutPhase.Timeout;
            state.GameClock.Stop();
            var response = new UpdateBoutStateResponse(state);

            return(response);
        }
Пример #6
0
        public override ICommandResponse Handle(StopTimeoutCommand command)
        {
            var state = _boutRunner.GetBoutState(command.BoutId);

            state.Phase       = BoutPhase.Lineup;
            state.LineupStart = DateTime.Now;

            switch (state.TimeoutType)
            {
            case TimeoutType.Official:
                break;

            case TimeoutType.LeftTeam:
                state.LeftTeamState.TimeOutsRemaining--;
                break;

            case TimeoutType.RightTeam:
                state.RightTeamState.TimeOutsRemaining--;
                break;

            case TimeoutType.LeftReview:
                if (state.LoseOfficialReview)
                {
                    state.LeftTeamState.OfficialReviews--;
                }
                break;

            case TimeoutType.RightReview:
                if (state.LoseOfficialReview)
                {
                    state.RightTeamState.OfficialReviews--;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            state.TimeoutType = TimeoutType.Official;

            var response = new UpdateBoutStateResponse(state);

            return(response);
        }
        public override ICommandResponse Handle(SetLoseOfficialReviewCommand command)
        {
            var state = _boutRunner.GetBoutState(command.BoutId);

            if (state.Phase != BoutPhase.Timeout)
            {
                throw new InvalidBoutPhaseException(state.Phase);
            }

            if (command.LoseOfficialReview == state.LoseOfficialReview)
            {
                return(new CommandResponse());
            }

            state.LoseOfficialReview = command.LoseOfficialReview;

            var response = new UpdateBoutStateResponse(state);

            return(response);
        }