Esempio n. 1
0
        public async Task Enqueue(InputSet inputSet, User user)
        {
            QueuedInput queuedInput = new(_inputIdSeq++, inputSet);
            await _overlayConnection.Send(new NewAnarchyInput(queuedInput.InputId, queuedInput.InputSet, user),
                                          CancellationToken.None);

            _inputBufferQueue.Enqueue(queuedInput);
        }
Esempio n. 2
0
        private async Task Loop(CancellationToken cancellationToken)
        {
            var teams = new Teams
            {
                Blue = ImmutableList.Create(MatchTesting.TestVenonatForOverlay),
                Red  = ImmutableList.Create(MatchTesting.TestVenonatForOverlay),
            };
            await Task.Delay(TimeSpan.FromSeconds(3), cancellationToken);

            IMatchCycle match     = new CoinflipMatchCycle(_loggerFactory.CreateLogger <CoinflipMatchCycle>());
            Task        setupTask = match.SetUp(new MatchInfo(teams.Blue, teams.Red), cancellationToken);
            await _overlayConnection.Send(new MatchCreatedEvent(), cancellationToken);

            await _overlayConnection.Send(new MatchBettingEvent(), cancellationToken);

            await _overlayConnection.Send(new MatchModesChosenEvent(), cancellationToken); // TODO

            await _overlayConnection.Send(new MatchSettingUpEvent
            {
                MatchId         = 1234,
                Teams           = teams,
                BettingDuration = _matchmodeConfig.DefaultBettingDuration.TotalSeconds,
                RevealDuration  = 0,
                Gimmick         = "speed",
                Switching       = SwitchingPolicy.Never,
                BattleStyle     = BattleStyle.Singles,
                InputOptions    = new InputOptions
                {
                    Moves = new MovesInputOptions
                    {
                        Policy    = MoveSelectingPolicy.Always,
                        Permitted = ImmutableList.Create("a", "b", "c", "d")
                    },
                    Switches = new SwitchesInputOptions
                    {
                        Policy       = SwitchingPolicy.Never,
                        Permitted    = ImmutableList <string> .Empty,
                        RandomChance = 0
                    },
                    Targets = new TargetsInputOptions
                    {
                        Policy        = TargetingPolicy.Disabled,
                        Permitted     = ImmutableList <string> .Empty,
                        AllyHitChance = 0
                    },
                },
                BetBonus     = 35,
                BetBonusType = "bet",
            }, cancellationToken);

            Duration bettingBeforeWarning = _matchmodeConfig.DefaultBettingDuration - _matchmodeConfig.WarningDuration;
            await Task.Delay(bettingBeforeWarning.ToTimeSpan(), cancellationToken);

            await _overlayConnection.Send(new MatchWarningEvent(), cancellationToken);

            await Task.Delay(_matchmodeConfig.WarningDuration.ToTimeSpan(), cancellationToken);

            await setupTask;
            Task <MatchResult> performTask = match.Perform(cancellationToken);
            await _overlayConnection.Send(new MatchPerformingEvent { Teams = teams }, cancellationToken);

            MatchResult result = await performTask;
            await _overlayConnection.Send(new MatchOverEvent { MatchResult = result }, cancellationToken);

            await Task.Delay(_matchmodeConfig.ResultDuration.ToTimeSpan(), cancellationToken);

            await _overlayConnection.Send(new ResultsFinishedEvent(), cancellationToken);
        }
Esempio n. 3
0
        private async Task Loop(CancellationToken cancellationToken)
        {
            var teams = new Teams
            {
                Blue = ImmutableList.Create(MatchTesting.TestVenonatForOverlay),
                Red = ImmutableList.Create(MatchTesting.TestVenonatForOverlay),
            };
            await Task.Delay(TimeSpan.FromSeconds(3), cancellationToken);

            await ResetBalances(); //ensure everyone has money to bet before the betting period
            const int matchId = -1; // TODO
            IBettingShop<User> bettingShop = new DefaultBettingShop<User>(
                async user => await _pokeyenBank.GetAvailableMoney(user));
            bettingShop.BetPlaced += (_, args) => TaskToVoidSafely(_logger, () =>
                _overlayConnection.Send(new MatchPokeyenBetUpdateEvent
                {
                    MatchId = matchId,
                    DefaultAction = "",
                    NewBet = new Bet { Amount = args.Amount, Team = args.Side, BetBonus = 0 },
                    NewBetUser = args.User,
                    Odds = bettingShop.GetOdds()
                }, cancellationToken));
            _bettingPeriod = new BettingPeriod<User>(_pokeyenBank, bettingShop);
            _bettingPeriod.Start();

            IMatchCycle match = new CoinflipMatchCycle(_loggerFactory.CreateLogger<CoinflipMatchCycle>());
            Task setupTask = match.SetUp(new MatchInfo(teams.Blue, teams.Red), cancellationToken);
            await _overlayConnection.Send(new MatchCreatedEvent(), cancellationToken);
            await _overlayConnection.Send(new MatchBettingEvent(), cancellationToken);
            await _overlayConnection.Send(new MatchModesChosenEvent(), cancellationToken); // TODO
            await _overlayConnection.Send(new MatchSettingUpEvent
            {
                MatchId = 1234,
                Teams = teams,
                BettingDuration = _matchmodeConfig.DefaultBettingDuration.TotalSeconds,
                RevealDuration = 0,
                Gimmick = "speed",
                Switching = SwitchingPolicy.Never,
                BattleStyle = BattleStyle.Singles,
                InputOptions = new InputOptions
                {
                    Moves = new MovesInputOptions
                    {
                        Policy = MoveSelectingPolicy.Always,
                        Permitted = ImmutableList.Create("a", "b", "c", "d")
                    },
                    Switches = new SwitchesInputOptions
                    {
                        Policy = SwitchingPolicy.Never,
                        Permitted = ImmutableList<string>.Empty,
                        RandomChance = 0
                    },
                    Targets = new TargetsInputOptions
                    {
                        Policy = TargetingPolicy.Disabled,
                        Permitted = ImmutableList<string>.Empty,
                        AllyHitChance = 0
                    },
                },
                BetBonus = 35,
                BetBonusType = "bet",
            }, cancellationToken);

            Duration bettingBeforeWarning = _matchmodeConfig.DefaultBettingDuration - _matchmodeConfig.WarningDuration;
            await Task.Delay(bettingBeforeWarning.ToTimeSpan(), cancellationToken);
            await _overlayConnection.Send(new MatchWarningEvent(), cancellationToken);

            await Task.Delay(_matchmodeConfig.WarningDuration.ToTimeSpan(), cancellationToken);
            await setupTask;
            _bettingPeriod.Close();
            Task<MatchResult> performTask = match.Perform(cancellationToken);
            await _overlayConnection.Send(new MatchPerformingEvent { Teams = teams }, cancellationToken);

            MatchResult result = await performTask;
            await _overlayConnection.Send(new MatchOverEvent { MatchResult = result }, cancellationToken);

            // TODO log matches
            Dictionary<User, long> changes = await _bettingPeriod.Resolve(matchId, result, cancellationToken);
            await _overlayConnection.Send(
                new MatchResultsEvent
                {
                    PokeyenResults = new PokeyenResults
                    {
                        Transactions = changes.ToImmutableDictionary(kvp => kvp.Key.Id,
                            kvp => new Transaction { Change = kvp.Value, NewBalance = kvp.Key.Pokeyen })
                    }
                }, cancellationToken);

            await Task.Delay(_matchmodeConfig.ResultDuration.ToTimeSpan(), cancellationToken);
            await _overlayConnection.Send(new ResultsFinishedEvent(), cancellationToken);
        }