Exemplo n.º 1
0
    public void btnBet_Click(object sender, EventArgs e)
    {
        ErrorMessagePanel.Visible = false;
        ErrorMessage.Text         = "";

        try
        {
            AppSettings.Reload();
            var TheButton = (Button)sender;

            Money   maxProfit = Money.MultiplyPercent(siteInvestment, AppSettings.DiceGame.MaxBitCoinProfitPercent);
            Money   minBet    = AppSettings.DiceGame.MinBitCoinBet;
            decimal maxChance = AppSettings.DiceGame.MaxChance;

            decimal formChance    = Convert.ToDecimal(chanceTextBox.Text);
            Money   formBetAmount = Money.Parse(betAmountTextBox.Text);
            int     houseEdge     = AppSettings.DiceGame.HouseEdgePercent;
            Money   formProfit    = Money.Parse(profitTextBox.Text);
            bool    low           = Convert.ToBoolean(TheButton.CommandArgument);

            DiceGameManager.TryToBet(maxProfit, minBet, formChance, formBetAmount, houseEdge, formProfit, low);

            MyBetsGridView.DataBind();
            siteInvestment          = SiteInvestmentManager.GetCurrentBankroll();
            sitesBankrollLabel.Text = siteInvestment.ToClearString();
            maxProfitLabel.Text     = Money.MultiplyPercent(siteInvestment, AppSettings.DiceGame.MaxBitCoinProfitPercent).ToClearString();
            adBalanceLabel.Text     = Member.Current.PurchaseBalance.ToClearString();
        }
        catch (MsgException ex)
        {
            ErrorMessagePanel.Visible = true;
            ErrorMessage.Text         = ex.Message;
        }
        catch (Exception ex)
        {
            ErrorLogger.Log(ex);
            throw ex;
        }
    }
Exemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        AccessManager.RedirectIfDisabled(AppSettings.TitanFeatures.MoneyDiceGameEnabled);
        user = Member.Current;

        if (!IsPostBack)
        {
            GetStatsData();
            btnBetLow.Text    = U4200.LO;
            btnBetHigh.Text   = U4200.HI;
            btnInvest.Text    = U4200.INVEST;
            btnInvestAll.Text = U4200.INVESTALL;
            btnDivest.Text    = U4200.DIVEST;
            btnDivestAll.Text = U4200.DIVESTALL;

            LangAdder.Add(MyBetsButton, U4200.MYBETS);
            LangAdder.Add(AllBetsButton, U4200.ALLBETS);
            LangAdder.Add(RandomizeButton, U4200.RANDOMIZE);
            LangAdder.Add(InvestButton, U4200.INVEST);
            LangAdder.Add(StatsButton, L1.STATISTICS);
            MyBetsGridView.EmptyDataText      = L1.NODATA;
            AllBetsGridView.EmptyDataText     = L1.NODATA;
            InvestmentsGridView.EmptyDataText = L1.NODATA;
            investTextBox.Attributes.Add("title", U4200.MAXDIGITSINFO);
            divestTextBox.Attributes.Add("title", U4200.MAXDIGITSINFO);
            kellyInvestTextBox.Attributes.Add("title", U4200.KELLYINFO + "<br />" + U4200.MAXKELLYINFO + ": " + AppSettings.DiceGame.MaxKellyLevelInt);
            kellyDivestTextBox.Attributes.Add("title", U4200.DIVESTKELLYINFO);
        }
        siteInvestment          = SiteInvestmentManager.GetCurrentBankroll();
        sitesBankrollLabel.Text = siteInvestment.ToClearString();
        maxProfitLabel.Text     = Money.MultiplyPercent(siteInvestment, AppSettings.DiceGame.MaxBitCoinProfitPercent).ToClearString();
        maxChanceLabel.Text     = AppSettings.DiceGame.MaxChance.ToString() + "%";
        adBalanceLabel.Text     = Member.Current.PurchaseBalance.ToClearString();

        ScriptManager.RegisterStartupScript(GamePanel, GetType(), "isBettingEnabled", "isBettingEnabled();", true);
        ScriptManager.RegisterStartupScript(MultiViewUpdatePanel, GetType(), "isBettingEnabled", "isBettingEnabled();", true);
        ScriptManager.RegisterStartupScript(MultiViewUpdatePanel, GetType(), "setConfirmations", "setConfirmations();", true);
    }
Exemplo n.º 3
0
    public static void TryToBet(Money maxProfit, Money minBet, decimal formChance, Money formBetAmount, int houseEdge, Money formProfit, bool low)
    {
        if (formBetAmount < minBet)
        {
            throw new MsgException(U4200.BETTOOLOW + " " + minBet);
        }
        else if (formChance <= 0)
        {
            throw new MsgException(U4200.CHANCEBELOWZERO);
        }
        else if (formChance > AppSettings.DiceGame.MaxChance)
        {
            throw new MsgException(U4200.CHANCETOOHIGH);
        }

        Money houseProfit = formBetAmount * houseEdge / formChance;

        if (formProfit > maxProfit)
        {
            throw new MsgException(U4200.PROFITTOOHIGH + " " + maxProfit);
        }
        else if (formProfit <= Money.Zero)
        {
            throw new MsgException(U4200.PROFITBELOWZERO);
        }
        else if (houseProfit < new Money(0.00000001))
        {
            throw new MsgException(U4200.HOUSEPROFITTOOLOW);
        }

        Member User = Member.Current;

        DiceGameHash CurrentDiceGameHash = DiceGameHash.Get(User);
        UserBet      Bet = new UserBet();

        Bet.UserId = User.Id;

        if (User.PurchaseBalance < formBetAmount)
        {
            throw new MsgException(L1.NOTENOUGHFUNDS);
        }

        string  serverSeed    = CurrentDiceGameHash.ServerSeedCurrent;
        string  clientSeed    = CurrentDiceGameHash.ClientSeedCurrent;
        string  salt          = DiceGameHashLogic.GenerateSalt(clientSeed, Bet.UserId);
        string  hashToCompute = DiceGameHashLogic.ComputeHash(salt, serverSeed);
        decimal diceRoll      = RollTheDice(hashToCompute);
        bool    hasWon        = HasWon(formChance, low, diceRoll);
        string  query;

        Bet.BetSize = formBetAmount;
        Bet.BetDate = DateTime.Now;
        Bet.Chance  = formChance;
        Bet.Low     = low;
        if (hasWon)
        {
            Bet.Profit = formProfit;
            User.AddToMainBalance(Bet.Profit, "Dice bet win", BalanceLogType.Other);
            query = SiteInvestmentManager.GetUpdateAmountQuery(formProfit.Negatify());

            //To do: should investors lose money based on betsize or profit?
            //AppSettings.DiceGame.HouseProfit += (houseProfit);
        }
        else
        {
            Bet.Profit = Bet.BetSize.Negatify();
            User.SubtractFromPurchaseBalance(Bet.BetSize, "Dice bet lose", BalanceLogType.Other);

            query = SiteInvestmentManager.GetUpdateAmountQuery(formBetAmount);
            //AppSettings.DiceGame.HouseProfit += ((0.01m * formBetAmount));
        }
        Bet.Roll = diceRoll;
        Bet.Save();

        string clearTableQuery = " DELETE FROM SiteInvestments WHERE Amount = 0;";

        TableHelper.ExecuteRawCommandNonQuery(query + clearTableQuery);

        AppSettings.DiceGame.Save();
        User.SaveBalances();
    }
Exemplo n.º 4
0
    public void btnInvest_Click(object sender, EventArgs e)
    {
        ErrorMessagePanel.Visible = false;
        try
        {
            var   TheButton      = (Button)sender;
            int   buttonArgument = Int32.Parse(TheButton.CommandArgument);
            Money adBalance      = Member.Current.PurchaseBalance;
            int   kelly;

            if (buttonArgument == 0)
            {
                Money amountToInvest = Money.Parse(investTextBox.Text);
                if (string.IsNullOrWhiteSpace(kellyInvestTextBox.Text))
                {
                    throw new MsgException(U4200.KELLYERROR + ": " + AppSettings.DiceGame.MaxKellyLevelInt);
                }
                kelly = Convert.ToInt32(kellyInvestTextBox.Text);
                SiteInvestmentManager.TryInvest(amountToInvest, kelly, user);
            }
            else if (buttonArgument == 1)
            {
                Money amountToInvest = adBalance;
                if (string.IsNullOrWhiteSpace(kellyInvestTextBox.Text))
                {
                    throw new MsgException(U4200.KELLYERROR + ": " + AppSettings.DiceGame.MaxKellyLevelInt);
                }
                kelly = Convert.ToInt32(kellyInvestTextBox.Text);
                SiteInvestmentManager.TryInvest(amountToInvest, kelly, user);
            }
            else if (buttonArgument == 2)

            {
                if (string.IsNullOrWhiteSpace(kellyDivestTextBox.Text))
                {
                    throw new MsgException(U4200.KELLYERROR + ": " + AppSettings.DiceGame.MaxKellyLevelInt);
                }
                Money amountToDivest = Money.Parse(divestTextBox.Text);
                kelly = Convert.ToInt32(kellyDivestTextBox.Text);

                SiteInvestmentManager.TryDivest(amountToDivest, kelly, user);
            }
            else if (buttonArgument == 3)
            {
                SiteInvestmentManager.TryDivestAll(user);
            }

            InvestmentsGridView.DataBind();
            siteInvestment          = SiteInvestmentManager.GetCurrentBankroll();
            sitesBankrollLabel.Text = siteInvestment.ToClearString();
            maxProfitLabel.Text     = Money.MultiplyPercent(siteInvestment, AppSettings.DiceGame.MaxBitCoinProfitPercent).ToClearString();
            adBalanceLabel.Text     = Member.Current.PurchaseBalance.ToClearString();
        }
        catch (MsgException ex)
        {
            ErrorMessagePanel.Visible = true;
            ErrorMessage.Text         = ex.Message;
        }
        catch (Exception ex)
        {
            ErrorLogger.Log(ex);
            throw ex;
        }
    }