Example #1
0
        void PurchasePacks()
        {
            for (int playr = 0; playr < 50; playr++)
            {
                PlayerTransaction transaction;
                BingoPlayer       player;
                player      = new BingoPlayer();
                transaction = new PlayerTransaction(player, playr);
                player.transactions.Add(transaction);

                foreach (DataRow row in pack_play_table.Rows)
                {
                    int numplay     = Convert.ToInt32(row["Avg"]);
                    int percent_avg = Convert.ToInt32(row["percent average"]);
                    if (OverPercent(percent_avg))
                    {
                        // not average
                        if (OverPercent(Convert.ToInt32(row["percent above average"])))
                        {
                            numplay = numplay - (entropy.Next(numplay - Convert.ToInt32(row["min"])) + 1);
                        }
                        else
                        {
                            // above average (less than or equal to 75% for instance)
                            numplay = numplay + (entropy.Next(Convert.ToInt32(row["max"]) - numplay) + 1);
                        }
                    }
                    if (numplay > 0)
                    {
                        BingoPack pack = session.GameList.pack_list[pack_play_table.Rows.IndexOf(row)];
                        for (int n = 0; n < numplay; n++)
                        {
                            player.PlayPack(transaction, pack);
                        }
                    }
                }
                session_event.PlayerList.Add(player);
            }
            session_event.StorePlayers();
        }
Example #2
0
        //GameInfo prior_game = null;
        public state Step()
        {
            state result = new state();

            //Log.log( "Begin Step" );
            lock (this.step_lock)
            {
                // check to see if we're trying to end this.
                if (end)
                {
                    // valid will already be false.
                    return(result);
                }

                // check to see if the total duration is complete...
                if (_years == Years)
                {
                    return(result);
                }

                {
                    {
                        _total_games++;
                        _games++;

                        if (_games >= Games)
                        {
                            // need to do a step of session.
                            // setup some hotballs ....
                            _total_sessions++;
                            _sessions++;
                            if (_sessions >= Sessions)
                            {
                                _halls++;
                                if (_halls >= Halls)
                                {
                                    _days++;
                                    if (_days >= Days)
                                    {
                                        _years++;
                                        if (_years >= Years)
                                        {
                                            return(result);                                                         // here, result is not stepped.
                                        }
                                        _days = 0;
                                    }
                                    _halls = 0;
                                }
                                _sessions = 0;
                            }
                            _games = 0;

                            /// have counted the session, and now session is correct.
                            ///
                            // new session, create a new session event.
                            session_event = new BingoSessionEvent(bingo_session, false);
                            if (trigger_stats.enabled)
                            {
                                ball_data_interface.DropBalls();
                                session_event.trigger_balls = ball_data_interface.CallBalls(1);
                                ball_data_interface.DropBalls();
                                session_event.triggered_balls    = new int[trigger_stats.max_triggered];
                                session_event.triggered_ball_won = new bool[trigger_stats.max_triggered];
                            }
                            session_event.SaveToDatabase = flags.database_run;
                            session_event.Open(base_date.AddDays(_days), _sessions + 1);

                            // We need to add _days to the session_event.bingoday
                            // here so StateWriter (in BingoGameCore, which knows
                            // nothing about the OddsRunInfo.state) will assign
                            // the correct date to the records written to table
                            // called_game_player_rank2.

                            session_event.bingoday = session_event.bingoday.AddDays(_days);

                            {
                                BingoPlayers players = new BingoPlayers();                                 // create some players.
                                for (int p = 0; p < Players; p++)
                                {
                                    BingoPlayer player;
                                    players.Add(player = new BingoPlayer(Guid.NewGuid()));
                                    PlayerTransaction transaction;
                                    player.transactions.Add(transaction = new PlayerTransaction(player, p));
                                    foreach (BingoGameGroup bgg in session_event.session.GameGroups)
                                    {
                                        foreach (BingoPack pack in bgg.packs)
                                        {
                                            // something like this... so we can sell so many packs for players
                                            // but now players are not just sets of cards.
                                            for (int n = 0; n < Cards / PackSize; n++)
                                            {
                                                PlayerPack played;
                                                player.played_packs.Add(played = new PlayerPack());
                                                played.transaction             = transaction;
                                                played.pack_info           = pack;
                                                played.start_card          = pack.AutoDeal();
                                                played.pack_set            = 1;
                                                played.player              = player;
                                                played.pack_info.game_list = bingo_session.GameList;
                                                transaction.Add(played);
                                            }
                                        }
                                    }
                                }
                                session_event.PlayerList = players;
                            }
                        }

                        /// have counted the games and the game is correct.
                        session_event.StepToUsing(_games, (BingoGameState)result, ball_data_interface);                           // this is passed game index...

                        session_event.LoadPlayerCards(result);
                        result.Year = _years;
                        result.Day  = _days;

                        result.Hall = _halls;
                        result.Game = _games;

                        // here we can keep going, it's counting... maybe
                        // something like skipping a game for some reason causes invalidity...
                        // which is not terminal.
                        result.stepped = true;
                    }
                }
                //Log.log( "Created session evnet and players in session" );

                // return this state so we can unlock it.
                // with these balls and cards referenced
                // we should not have a problem with multi-threading this.
                return(result);
            }
        }
        /// <summary>
        /// Once Order has been confirmed this endpoint will handle the transaction of
        /// updating players balance and add to player's stocks.  Prestige score
        /// is calculted with the weighted value coming from the P/E Ratio.
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="playerId"></param>
        /// <param name="price"></param>
        /// <param name="shares"></param>
        /// <param name="peRatio"></param>
        /// <returns></returns>
        public IActionResult Buy(string symbol, string price, string shares, string peRatio)
        {
            decimal _price   = decimal.Parse(price);
            int     _shares  = int.Parse(shares);
            decimal _peRatio = decimal.Parse(peRatio ?? "0");
            decimal total    = _price * _shares;

            var           userId = _userManager.GetUserId(User);
            PlayerProfile player = _ProfileRepository.FindByCondition(p => p.UserId == userId).First();

            PlayerCash playerCash = new PlayerCash();

            playerCash.ProfileId = player.Id;
            playerCash.Balance   = _cashRepository
                                   .FindByCondition(p => p.ProfileId == player.Id)
                                   .OrderByDescending(c => c.CreatedDate)
                                   .Select(p => p.Balance)
                                   .FirstOrDefault();

            //verfiy player has enough currency to purchase order
            if (total > playerCash.Balance)
            {
                return(View("InsufficentFundsView", total));
            }
            else
            {
                PlayerStock PlayerStock = new PlayerStock();
                PlayerStock.StockSymbol   = symbol;
                PlayerStock.ProfileId     = player.Id;
                PlayerStock.PurchasePrice = _price;
                PlayerStock.Shares        = _shares;
                _stockRepository.Create(PlayerStock);

                playerCash.Balance -= total;
                _cashRepository.Create(playerCash);

                PlayerTransaction playerTransaction = new PlayerTransaction();
                playerTransaction.ProfileId              = player.Id;
                playerTransaction.TransactionType        = "Buy";
                playerTransaction.TransactionDescription = $"{symbol} Purchased";
                playerTransaction.Quantity = _shares;
                playerTransaction.Price    = total;
                _transactionRepository.Create(playerTransaction);

                //prestige score is based on P/E Ratio.
                PlayerPrestigeScore playerPrestige = new PlayerPrestigeScore();
                playerPrestige.ProfileId = player.Id;
                playerPrestige.Source    = "Risk Reward";
                playerPrestige.Score     = _prestigescoreRepository
                                           .FindByCondition(p => p.ProfileId == player.Id)
                                           .OrderByDescending(c => c.CreatedDate)
                                           .Select(p => p.Score)
                                           .FirstOrDefault();
                decimal purchaseToPlayerBalanceRatio = total / playerCash.Balance; //how vested the player is in this stock
                decimal stockValue = 1000 - _peRatio;                              //lower P/E Ratio means stock is more valuable
                playerPrestige.Score       += (int)(stockValue * purchaseToPlayerBalanceRatio);
                playerPrestige.PointsEarned = (int)(stockValue * purchaseToPlayerBalanceRatio);
                _prestigescoreRepository.Create(playerPrestige);
            }



            return(RedirectToAction("Portfolio", "stock"));
        }
        public IActionResult Sell(string stockId, string value)
        {
            var           userId = _userManager.GetUserId(User);
            PlayerProfile player = _ProfileRepository.FindByCondition(p => p.UserId == userId).FirstOrDefault();


            PlayerStock playerStock = _stockRepository.FindByCondition(s => s.Id == int.Parse(stockId)).FirstOrDefault();

            _stockRepository.Delete(playerStock);


            PlayerCash playerCash = new PlayerCash();

            playerCash.ProfileId = player.Id;
            decimal marketValue = decimal.Parse(value);

            playerCash.Balance = _cashRepository
                                 .FindByCondition(p => p.ProfileId == player.Id)
                                 .OrderByDescending(c => c.CreatedDate)
                                 .Select(p => p.Balance)
                                 .FirstOrDefault();
            playerCash.Balance += marketValue;
            _cashRepository.Create(playerCash);


            string  symbol    = playerStock.StockSymbol;
            int     shares    = playerStock.Shares;
            decimal totalCost = (shares * playerStock.PurchasePrice);

            PlayerTransaction playerTransaction = new PlayerTransaction();

            playerTransaction.ProfileId              = player.Id;
            playerTransaction.TransactionType        = "Sell";
            playerTransaction.TransactionDescription = $"{symbol} Purchased";
            playerTransaction.Quantity = shares;
            playerTransaction.Price    = marketValue;
            _transactionRepository.Create(playerTransaction);


            PlayerPrestigeScore playerPrestige = new PlayerPrestigeScore();

            playerPrestige.ProfileId = player.Id;
            playerPrestige.Source    = "Profit Reward";
            decimal stockReturn = marketValue - totalCost;

            playerPrestige.Score = _prestigescoreRepository
                                   .FindByCondition(p => p.ProfileId == player.Id)
                                   .OrderByDescending(c => c.CreatedDate)
                                   .Select(p => p.Score)
                                   .FirstOrDefault();
            if (stockReturn > 0)
            {
                playerPrestige.Score       += (int)stockReturn;
                playerPrestige.PointsEarned = (int)stockReturn;
            }
            _prestigescoreRepository.Create(playerPrestige);



            _stockRepository.Delete(playerStock);

            return(RedirectToAction("Portfolio"));
        }
        public IActionResult Results(TriviaQuestionsViewModel triviaQuestionsViewModel)
        {
            TriviaQuestionsViewModel t = triviaQuestionsViewModel;
            string difficultySelect    = t.Questions.Results.First().Difficulty;
            string categorySelect      = t.Questions.Results.First().Category;
            string typeSelect          = t.Questions.Results.First().Type == "multiple" ? "Multiple Choice" : "True/False";


            var           userId     = _userManager.GetUserId(User);
            PlayerProfile player     = _profileRepository.FindByCondition(p => p.UserId == userId).First();
            Difficulty    difficulty = _difficultyRepository.FindByCondition(q => q.Name == difficultySelect).First();
            Category      category   = _categoryRepository.FindByCondition(q => q.Name == categorySelect).First();
            QuestionType  type       = _questionTypeRepository.FindByCondition(q => q.Name == typeSelect).First();


            //Adds Entry to Player's quizes
            PlayerQuiz quiz = new PlayerQuiz();

            quiz.Player       = player;
            quiz.Difficulty   = difficulty;
            quiz.QuestionType = type;
            quiz.Category     = category;
            quiz.Attempted    = t.Questions.Results.Select(q => q.Selected).Count();
            quiz.Correct      = t.Questions.Results.Where(q => q.Selected == "true").Count();
            _quizRepository.Create(quiz);



            //Adds Entry into Players Cash account
            PlayerCash playerCash = new PlayerCash();

            playerCash.ProfileId = player.Id;
            int multiplier = 0;

            switch (difficultySelect)
            {
            case "easy":
                multiplier += quiz.Correct * (typeSelect == "Multiple Choice" ? 2 : 1);
                break;

            case "medium":
                multiplier += quiz.Correct * (typeSelect == "Multiple Choice" ? 2 : 1) * 2;
                break;

            case "hard":
                multiplier += quiz.Correct * (typeSelect == "Multiple Choice" ? 2 : 1) * 3;
                break;
            }

            playerCash.Balance = _cashRepository
                                 .FindByCondition(p => p.ProfileId == player.Id)
                                 .OrderByDescending(c => c.CreatedDate)
                                 .Select(p => p.Balance)
                                 .FirstOrDefault();
            playerCash.Balance += (multiplier * 10);
            _cashRepository.Create(playerCash);


            //Adds Entry to Players Transactions
            PlayerTransaction playerTransaction = new PlayerTransaction();

            playerTransaction.ProfileId              = player.Id;
            playerTransaction.TransactionType        = "Trivia";
            playerTransaction.TransactionDescription = $"{quiz.Correct} ,{difficultySelect}, {typeSelect} questions";
            playerTransaction.Price = multiplier * 10;
            _transactionRepository.Create(playerTransaction);


            //Adds Entry to Players Prestige Score
            PlayerPrestigeScore playerPrestige = new PlayerPrestigeScore();

            playerPrestige.ProfileId = player.Id;
            playerPrestige.Source    = "Knowledge Reward";
            playerPrestige.Score     = _prestigeScoreRepository
                                       .FindByCondition(p => p.ProfileId == player.Id)
                                       .OrderByDescending(c => c.CreatedDate)
                                       .Select(p => p.Score)
                                       .FirstOrDefault();
            playerPrestige.Score       += multiplier * 10;
            playerPrestige.PointsEarned = multiplier * 10;
            _prestigeScoreRepository.Create(playerPrestige);



            return(RedirectToAction("Performance"));
        }
Example #6
0
        public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            // Get the information about the user from the external login provider
            var info = await _signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                ErrorMessage = "Error loading external login information during confirmation.";
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }

            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = Input.Email, Email = Input.Email
                };

                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);

                    if (result.Succeeded)
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false, info.LoginProvider);


                        PlayerProfile player = new PlayerProfile();
                        player.ProfileName = User.Identity.Name;
                        player.UserId      = user.Id;
                        _profileRepository.Create(player);
                        player = _profileRepository.FindByCondition(p => p.UserId == user.Id).FirstOrDefault();


                        PlayerCash playerCash = new PlayerCash();
                        playerCash.ProfileId = player.Id;
                        playerCash.Balance   = 1000000;
                        _cashRepository.Create(playerCash);

                        PlayerTransaction playerTransaction = new PlayerTransaction();
                        playerTransaction.Price                  = 1000000;
                        playerTransaction.ProfileId              = player.Id;
                        playerTransaction.TransactionType        = "Credit";
                        playerTransaction.TransactionDescription = "Player Created";
                        _transactionRepository.Create(playerTransaction);

                        PlayerPrestigeScore playerPrestigeScore = new PlayerPrestigeScore();
                        playerPrestigeScore.ProfileId = player.Id;
                        playerPrestigeScore.Score     = 0;
                        playerPrestigeScore.Source    = "Player Created";
                        _prestigescoreRepository.Create(playerPrestigeScore);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            ProviderDisplayName = info.ProviderDisplayName;
            ReturnUrl           = returnUrl;
            return(Page());
        }