void TryFinishGamble(string name, BasePlayer player = null)
        {
            int index = GetGambleIndex(name);

            if (index == -1)//gamble not found
            {
                ReplyOrPutLang(player, "GambleNotFound");
                return;
            }

            Gamble gamble       = storedData.gambles[index];
            int    winnerNumber = UnityEngine.Random.Range(1, gamble.numbers + 1);

            List <ulong> winners = new List <ulong>();

            for (int i = 0; i < gamble.bets.Count; i++)//add all matching numbers to winners list
            {
                if (gamble.bets[i].number == winnerNumber)
                {
                    winners.Add(gamble.bets[i].player);
                }
            }


            if (winners.Count != 0)
            {
                PrintToChat(PlayerEqualNull(player, "GamblingFinished", name, winnerNumber, winners.Count));

                int eachAmount = (gamble.itemAmount * gamble.bets.Count + gamble.preservedPot) / winners.Count;
                foreach (ulong win in winners)
                {
                    storedData.rewards.Add(new Reward(win, gamble.item, gamble.itemAmount));
                }



                if (configData.showWinners)
                {
                    PrintToChat(PlayerEqualNull(player, "Winners"));
                    string winnersString = "";

                    foreach (ulong win in winners)
                    {
                        winnersString += BasePlayer.Find(win.ToString()).displayName + ", ";
                    }


                    PrintToChat(winnersString.Remove(winnersString.Length - 2));//deletes the last comma+space and prints
                }
            }
            else//no one won
            {
                AddToPreservedPot(gamble.item, gamble.itemAmount * gamble.bets.Count + gamble.preservedPot);

                PrintToChat(PlayerEqualNull(player, "GamblingFinishedNoWinner", name, winnerNumber));
            }

            Puts("Gamble " + gamble.name + " finished");
            storedData.gambles.RemoveAt(index);
        }
Exemplo n.º 2
0
        public async Task Roll(int max, int guess, double bid, int times = 1)
        {
            LevelUser user = new LevelUser();

            user.Load(Context.User.Id);
            if (times > 10)
            {
                await ReplyAsync("I can't handle that many times");
            }
            else if (max <= 1)
            {
                await ReplyAsync("I won't allowe you to do that");
            }
            else if (guess < 1 || guess > max)
            {
                await ReplyAsync($"the number you guessed isn't even betwean 1-{max}");
            }
            else if (user.Credits < bid * double.Parse(times.ToString()))
            {
                await ReplyAsync("you don't even have that much credits");
            }
            else
            {
                await ReplyAsync("", false, Gamble.Roll(Context.User, max, guess, bid, times).Build());
            }
        }
Exemplo n.º 3
0
        public void Gamble_GiveCash_Test()
        {
            //Set
            Gamble g = new Gamble(50, 1, new Person("Pari", 50, null, null));
            // act
            int result = g.GiveCash(1);

            //asset
            Assert.AreEqual(result, 100);
        }
Exemplo n.º 4
0
        public void Payout()
        {
            // Arrange
            var bet = new Gamble();

            // Act
            var actual = unitTestObj.Payout(1);

            // Assert
            Assert.AreEqual(expected: 0, actual);
        }
Exemplo n.º 5
0
        internal static decimal CalcRemainingLimit(Gamble thisGamble)
        {
            using SQLiteConnection db = new(AppSettings.DatabaseFilePath);

            var limitsBeforeGamble = db.Table <Limit>().Where(limit => limit.Time < thisGamble.Time);
            var priorLimit         = limitsBeforeGamble.OrderByDescending(limit => limit.Time).First();

            Func <Gamble, bool> inRange = gamble => gamble.Time > priorLimit.Time && gamble.Time <= thisGamble.Time;
            var gamblesInRange          = db.Table <Gamble>().Where(inRange);

            Func <decimal, Gamble, decimal> subtract = (priorLimitAmount, gamble) => priorLimitAmount - gamble.Amount;

            return(gamblesInRange.Aggregate(priorLimit.Amount, subtract));
        }
        void ShowCurrentGambles(BasePlayer player)
        {
            if (storedData.gambles.Count == 0)
            {
                ReplyOrPutLang(player, "NoGambles");
                return;
            }

            for (int i = 0; i < storedData.gambles.Count; i++)
            {
                Gamble gamble = storedData.gambles[i];
                ReplyOrPutLang(player, "CurrentGambles", gamble.name, (gamble.bets.Count * gamble.itemAmount + gamble.preservedPot).ToString(), gamble.name, gamble.numbers, gamble.itemAmount, GetItemName(gamble.item));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Injected to TownRun Composite after Stash/Sell/Salvage
        /// </summary>
        public async static Task <bool> ExecutePostVendor()
        {
            // Task returning True = We're done, move on.
            // Task returning False = Re-execute from start.

            if (!ZetaDia.IsInTown)
            {
                return(false);
            }

            Logger.LogVerbose("PostVendor Hook Started");

            try
            {
                if (ZetaDia.Me.IsParticipatingInTieredLootRun)
                {
                    return(false);
                }

                // Run again in case we missed first time due to full bags.
                if (!await Gamble.Execute())
                {
                    return(true);
                }

                // Destroy white/blue/yellow items to convert crafting materials.
                if (!await CubeItemsToMaterials.Execute())
                {
                    return(true);
                }

                // Run again in case we just gambled
                if (!await CubeRaresToLegendary.Execute())
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("Exception in VendorHook {0}", ex);

                if (ex is CoroutineStoppedException)
                {
                    throw;
                }
            }

            return(false);
        }
Exemplo n.º 8
0
        public async Task Slot(double amount)
        {
            LevelUser user = new LevelUser();

            user.Load(Context.User.Id);
            if (user.Credits < amount)
            {
                await ReplyAsync("you don't even have that many credits");
            }
            else
            {
                await ReplyAsync("", false, Gamble.Slot(user, amount));

                user.Save(Context.User.Id);
            }
        }
Exemplo n.º 9
0
        public virtual Player WhoIsWinner(Player player)
        {
            Gamble winner = Gamble.whoIsWinner(player.Gamble);

            if (winner == Gamble)
            {
                return(this);
            }
            else if (winner == player.Gamble)
            {
                return(player);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 10
0
        internal static void Insert(Gamble newGamble)
        {
            using SQLiteConnection db = new(AppSettings.DatabaseFilePath);

            if (!db.Table <Limit>().Any(limit => limit.Time < newGamble.Time))
            {
                throw new ArgumentException(Text.GambleMustBeAfterFirstLimit);
            }

            // Ensures any new gamble is unique, given their time is the primary key.
            var gambles = db.Table <Gamble>();

            while (gambles.Any(gamble => gamble.Time == newGamble.Time))
            {
                newGamble.Time = newGamble.Time.AddMilliseconds(1);
            }

            _ = db.Insert(newGamble);
        }
Exemplo n.º 11
0
        public bool betting(int amount, int bittingWagon)
        {
            this.currentBet = new Gamble()
            {
                BetAmount = amount, wagon = bittingWagon
            };

            if (amount <= balance)
            {
                balance      -= amount;
                activity.Text = this.name + " has placed $" + amount + " on Wagon #" + bittingWagon;
                this.UpdateActivity();
                return(true);
            }
            else
            {
                MessageBox.Show(this.name + " doesn't have enough money to cover for the bet!");
                this.currentBet = null;
                return(false);
            }
        }
Exemplo n.º 12
0
 internal GambleInspector(Gamble gamble)
 {
     InitializeComponent();
     BindingContext = new GambleViewModel(this, gamble);
 }
Exemplo n.º 13
0
 private void OnGambleButtonClicked()
 {
     Gamble?.Invoke();
 }
Exemplo n.º 14
0
 public void ResetStats()
 {
     currentBet    = null;
     activity.Text = name + " has't placed a bet.";
 }
Exemplo n.º 15
0
        public void Execute(IRocketPlayer caller, string[] command)
        {
            UnturnedPlayer player = caller as UnturnedPlayer;

            // Check Command Syntax
            if (command.Length > 2 || command.Length == 0 || command.Length == 1)
            {
                UnturnedChat.Say(caller, $"Correct Usage: {Syntax}");
                return;
            }

            // Check if both are integer
            if (!int.TryParse(command[0], out int amount))
            {
                UnturnedChat.Say(caller, Main.Instance.Translate("OnlyInteger", "Amount"));
                return;
            }
            if (!int.TryParse(command[1], out int multiplier))
            {
                UnturnedChat.Say(caller, Main.Instance.Translate("OnlyInteger", "Multiplier"));
                return;
            }

            // Check if amount is under the max bet amount
            if (amount > Main.Instance.Configuration.Instance.MaxBet)
            {
                UnturnedChat.Say(caller, Main.Instance.Translate("MaxBet", Main.Instance.Configuration.Instance.MaxBet));
                return;
            }

            // Check if player can afford bet
            if (amount > Uconomy.Instance.Database.GetBalance(player.CSteamID.ToString()))
            {
                UnturnedChat.Say(caller, Main.Instance.Translate("NotEnoughBalance"));
                return;
            }

            // Check if that multiplier is in that config (if it is, store it)
            Gamble gamble = null;
            bool   found  = false;

            foreach (Gamble temp in Main.Instance.Configuration.Instance.gambles)
            {
                if (temp.Multiplier == multiplier)
                {
                    found  = true;
                    gamble = temp;
                    break;
                }
            }
            if (!found)
            {
                UnturnedChat.Say(caller, Main.Instance.Translate("CantMultiplyThatMuch"));
                return;
            }

            // Calculate the chance and multiply the money and give it to the player
            if (gamble.Chance >= UnityEngine.Random.Range(1, 101))
            {
                int multipliedAmount = (amount * multiplier) - amount;
                Uconomy.Instance.Database.IncreaseBalance(player.CSteamID.ToString(), multipliedAmount);
                UnturnedChat.Say(caller, Main.Instance.Translate("Won", multipliedAmount));
            }
            else
            {
                Uconomy.Instance.Database.IncreaseBalance(player.CSteamID.ToString(), -amount);
                UnturnedChat.Say(caller, Main.Instance.Translate("Lost", amount));
            }
        }
Exemplo n.º 16
0
 internal static void Update(Gamble gamble)
 {
     using SQLiteConnection db = new(AppSettings.DatabaseFilePath);
     _ = db.Update(gamble);
 }
Exemplo n.º 17
0
        /// <summary>
        /// Receive Pulse event from DemonBuddy.
        /// </summary>
        public void OnPulse()
        {
            try
            {
                if (ZetaDia.Me == null)
                {
                    return;
                }

                if (!ZetaDia.IsInGame || !ZetaDia.Me.IsValid || ZetaDia.IsLoadingWorld)
                {
                    return;
                }

                //ScenesStorage.Update();

                using (new PerformanceLogger("OnPulse"))
                {
                    //if (IsMoveRequested)
                    //    NavServerReport();

                    GameUI.SafeClickUIButtons();

                    if (ZetaDia.Me.IsDead)
                    {
                        return;
                    }

                    using (new PerformanceLogger("LazyRaiderClickToPause"))
                    {
                        if (Settings.Advanced.LazyRaiderClickToPause && !BotMain.IsPaused)
                        {
                            BotMain.PauseWhile(MouseLeft);
                        }
                    }

                    // See if we should update the stats file
                    if (DateTime.UtcNow.Subtract(ItemDropStats.ItemStatsLastPostedReport).TotalSeconds > 10)
                    {
                        ItemDropStats.ItemStatsLastPostedReport = DateTime.UtcNow;
                        ItemDropStats.OutputReport();
                    }

                    // Recording of all the XML's in use this run
                    UsedProfileManager.RecordProfile();

                    DebugUtil.LogOnPulse();

                    Gamble.CheckShouldTownRunForGambling();

                    MonkCombat.RunOngoingPowers();
                }
            }
            catch (AccessViolationException)
            {
                // woof!
            }
            catch (Exception ex)
            {
                Logger.Log(LogCategory.UserInformation, "Exception in Pulse: {0}", ex.ToString());
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Injected to TownRun Composite at Step3 (just after identifying legendaries).
        /// </summary>
        public async static Task <bool> ExecutePreVendor()
        {
            // Task returning True = We're done, move on.
            // Task returning False = Re-execute from start.

            if (!ZetaDia.IsInTown)
            {
                return(false);
            }

            Logger.LogVerbose("PreVendor Hook Started");

            try
            {
                var quest = new RiftQuest();
                if (ZetaDia.IsInTown && quest.State == QuestState.NotStarted && quest.Step == RiftStep.Completed && ZetaDia.Me.IsParticipatingInTieredLootRun)
                {
                    Logger.Log("Waiting...");
                    await Coroutine.Sleep(500);
                }

                if (ZetaDia.Me.IsParticipatingInTieredLootRun)
                {
                    return(false);
                }

                // Learn some recipies.
                if (!await UseCraftingRecipes.Execute())
                {
                    return(true);
                }

                // Destroy white/blue/yellow items to convert crafting materials.
                if (!await CubeItemsToMaterials.Execute())
                {
                    return(true);
                }

                // Gamble first for cube legendary rares, bag space permitting.
                if (!await Gamble.Execute())
                {
                    return(true);
                }

                // Run this before vendoring to use the rares we picked up.
                if (!await CubeRaresToLegendary.Execute())
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("Exception in VendorHook {0}", ex);

                if (ex is CoroutineStoppedException)
                {
                    throw;
                }
            }

            return(false);
        }