Example #1
0
 public WheelOfFortuneViewModel()
 {
     _wheelOfFortune               = new WheelOfFortune();
     _wheelOfFortune.VoteEnded    += _wheelOfFortune_VoteEnded;
     _wheelOfFortune.WheelUpdated += _wheelOfFortune_WheelUpdated;
     WinnerImg = "pack://siteoforigin:,,,/Resources/and-the-winner-is1170px.jpg";
 }
            public async Task WheelOfFortune(long amount)
            {
                if (!await CheckBetMandatory(amount))
                {
                    return;
                }

                if (!await _cs.RemoveAsync(Context.User.Id, "Wheel Of Fortune - bet", amount, gamble: true))
                {
                    await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false);

                    return;
                }

                var wof = new WheelOfFortune();

                amount = (long)(amount * wof.Multiplier);

                if (amount > 0)
                {
                    await _cs.AddAsync(Context.User.Id, "Wheel Of Fortune - won", amount, gamble : true).ConfigureAwait(false);
                }

                await Context.Channel.SendConfirmAsync(
                    Format.Bold($@"{Context.User.ToString()} won: {amount + _bc.BotConfig.CurrencySign}

   『{Wof.Multipliers[1]}』   『{Wof.Multipliers[0]}』   『{Wof.Multipliers[7]}』

『{Wof.Multipliers[2]}』      {wof.Emoji}      『{Wof.Multipliers[6]}』

     『{Wof.Multipliers[3]}』   『{Wof.Multipliers[4]}』   『{Wof.Multipliers[5]}』")).ConfigureAwait(false);
            }
Example #3
0
        public async Task WheelOfFortuneAsync(CommandContext ctx,
                                              [Description("Bid.")] long bid = 5)
        {
            if (bid <= 0 || bid > _maxBet)
            {
                throw new InvalidCommandUsageException($"Invalid bid amount! Needs to be in range [1, {_maxBet:n0}]");
            }

            using (DatabaseContext db = this.Database.CreateContext()) {
                if (!await db.TryDecreaseBankAccountAsync(ctx.User.Id, ctx.Guild.Id, bid))
                {
                    throw new CommandFailedException($"You do not have enough {this.Shared.GetGuildConfig(ctx.Guild.Id).Currency ?? "credits"}! Use command {Formatter.InlineCode("bank")} to check your account status.");
                }
                await db.SaveChangesAsync();
            }

            var wof = new WheelOfFortune(ctx.Client.GetInteractivity(), ctx.Channel, ctx.User, bid, this.Shared.GetGuildConfig(ctx.Guild.Id).Currency ?? "credits");
            await wof.RunAsync();

            if (wof.WonAmount > 0)
            {
                using (DatabaseContext db = this.Database.CreateContext()) {
                    await db.ModifyBankAccountAsync(ctx.User.Id, ctx.Guild.Id, v => v + wof.WonAmount);

                    await db.SaveChangesAsync();
                }
            }
        }
Example #4
0
        public WinResult Get()
        {
            WheelOfFortune _won       = new WheelOfFortune();
            ExtraPoints    _wonPoints = new ExtraPoints()
            {
                point = 0
            };

            Random random       = new Random(DateTime.Now.Millisecond);
            int    randomNumber = random.Next(1, 101);

            foreach (WheelOfFortune _fortune in _wheel)
            {
                randomNumber -= _fortune.winPercentage;

                if (randomNumber <= 0)
                {
                    _won = _fortune;
                    break;
                }
            }

            randomNumber = random.Next(1, 101);
            if (_won.canWinpoints)
            {
                List <ExtraPoints> _points = new List <ExtraPoints>();

                using (StreamReader r = new StreamReader("ExtraPoints.json"))
                {
                    string json = r.ReadToEnd();
                    _points = JsonConvert.DeserializeObject <List <ExtraPoints> >(json);
                }

                foreach (ExtraPoints _point in _points)
                {
                    randomNumber -= _point.winPercentage;

                    if (randomNumber <= 0)
                    {
                        _wonPoints = _point;
                        break;
                    }
                }
            }
            return(new WinResult()
            {
                gift = _won.gift,
                points = _wonPoints.point
            });
        }
        public Task <bool> Handle(RegisterNewRoundCommand request, CancellationToken cancellationToken)
        {
            Random rnd    = new Random();
            Array  values = Enum.GetValues(typeof(WheelOfFortuneColors));
            WheelOfFortuneColors randomColor = (WheelOfFortuneColors)values.GetValue(rnd.Next(values.Length));

            var wheelOfFortune = new WheelOfFortune(request.Id, request.Number, request.Color, request.Date);

            wheelOfFortune.Number = rnd.Next(1, 37);
            wheelOfFortune.Color  = GetColorByNumber(wheelOfFortune.Number);
            wheelOfFortune.Date   = DateTime.Now;
            _repository.Add(wheelOfFortune);

            Commit();
            return(Task.FromResult(true));
        }
        //WheelOfFortuneApplicationService _service;
        //private readonly IMapper _mapper;
        //private readonly IBusHandler _bus;
        //private readonly IWheelOfFortuneRepository _repository;

        //construtor
        public WheelOfFortuneTest()
        {
            var fakeMediator        = new Mock <IMediator>();
            var fakedResult         = new TestResult(new TestCase());
            var mediator            = new InMemoryBus(fakeMediator.Object);
            var wheelOFFortuneModel = new WheelOfFortune(Guid.NewGuid(), 3, WheelOfFortuneColors.Black, DateTime.Now);
            var wheelOFFortuneVM    = new WheelOfFortuneViewModel();
            var mockRepo            = new Mock <IWheelOfFortuneRepository>();
            var mapperMock          = new Mock <IMapper>();

            mockRepo.Setup(repo => repo.Get()).Returns(Task.FromResult(GetTestWheelOfFortune()).Result);
            mapperMock.Setup(m => m.Map <WheelOfFortune, WheelOfFortuneViewModel>(wheelOFFortuneModel)).Returns(wheelOFFortuneVM);

            var service = new WheelOfFortuneApplicationService(mockRepo.Object, mediator, mapperMock.Object);

            _controller = new WheelOfFortuneController(service);
        }
            public async Task WheelOfFortune(long bet)
            {
                const int minBet = 10;

                if (bet < minBet)
                {
                    await ReplyErrorLocalized("min_bet_limit", minBet + _bc.BotConfig.CurrencySign).ConfigureAwait(false);

                    return;
                }

                if (!_cs.Remove(Context.User.Id, "Wheel Of Fortune - bet", bet, gamble: true))
                {
                    await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false);

                    return;
                }

                var wof = new WheelOfFortune();

                var amount = (int)(bet * wof.Multiplier);

                if (amount > 0)
                {
                    await _cs.AddAsync(Context.User.Id, "Wheel Of Fortune - won", amount, gamble : true).ConfigureAwait(false);
                }

                await Context.Channel.SendConfirmAsync(
                    Format.Bold($@"{Context.User.ToString()} won: {amount + _bc.BotConfig.CurrencySign}

   『{Wof.Multipliers[1]}』   『{Wof.Multipliers[0]}』   『{Wof.Multipliers[7]}』

『{Wof.Multipliers[2]}』      {wof.Emoji}      『{Wof.Multipliers[6]}』

     『{Wof.Multipliers[3]}』   『{Wof.Multipliers[4]}』   『{Wof.Multipliers[5]}』")).ConfigureAwait(false);
            }