/// <summary> /// Increments the level of the base. /// </summary> public void Upgrade() { var cash = GameObject.FindWithTag("Player"); PlayerCash.Extract(UpgradeCost); Level++; }
private void ToggleDoubleDownButton() { if (!_playerAction.IsPlaying) { return; } PlayerCash pc = _playerAction.GetComponent <PlayerCash>(); _doubleDownButton.interactable = pc.CurrentCash >= pc.CurrentBet; }
private void PlayerCashChange(object sender, System.EventArgs e) { PlayerCash pc = _playerAction.PlayerCash; _currentCashText.text = "$" + pc.CurrentCash; _initialBetSlider.maxValue = pc.CurrentCash; _initialBetText.text = "$" + _initialBetSlider.value.ToString(); _initialBetSlider.value = Mathf.Min(_initialBetSlider.value, pc.CurrentCash); _currentBetText.text = "$" + pc.CurrentBet; }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl ??= Url.Content("~/"); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (ModelState.IsValid) { var user = new IdentityUser { UserName = Input.Email, Email = Input.Email }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { await _signInManager.SignInAsync(user, isPersistent : false); //Creates player after they are authenticated and not in database PlayerProfile player = new PlayerProfile(); player.ProfileName = Input.Email; 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); } } return(Page()); }
/// <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")); }
private void Awake() { _playerCash = GetComponent <PlayerCash>(); }
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")); }
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()); }