예제 #1
0
        public void UpdateInventoryCategories()
        {
            MediPack.Clear();
            Weapons.Clear();
            Currency.Clear();
            Clue.Clear();

            foreach (var gameItem in _inventory)
            {
                if (gameItem is Potion)
                {
                    MediPack.Add(gameItem);
                }
                if (gameItem is Weapon)
                {
                    Weapons.Add(gameItem);
                }
                if (gameItem is Coin)
                {
                    Currency.Add(gameItem);
                }
                if (gameItem is Clues)
                {
                    Clue.Add(gameItem);
                }
            }
        }
예제 #2
0
        public void 金額種別ごとの合計金額計算(CurrencyKind.Kind kind, int addCount, int sum)
        {
            var target = new Currency(kind);

            target.Add(addCount);
            Assert.AreEqual(target.Sum(), sum);
        }
예제 #3
0
 private void Init()
 {
     foreach (String str in CurrencyTypes)
     {
         Currency.Add(str, 0);
     }
 }
예제 #4
0
        public static bool Cancel(bool Announce = false)
        {
            lock (Options)
            {
                if (Options.Count < 2)
                {
                    if (Announce)
                    {
                        Chat.SendMessage("A poll must be started first.");
                    }

                    return(false);
                }

                IsOpen         = false;
                VotesGoal      = 0;
                TotalVotesGoal = 0;
                Options.Clear();

                foreach (string voter in Voters.Keys)
                {
                    Currency.Add(voter, VoteCost);
                }

                VoteCost = 5;
                Voters.Clear();

                if (Announce)
                {
                    Chat.SendMessage("The poll has been cancelled. All votes have been refunded.");
                }

                return(true);
            }
        }
예제 #5
0
        public void TestAdd()
        {
            var a = new Currency(1);
            var b = new Currency(2);

            Assert.Equal(3, a.Add(b).Value);
        }
예제 #6
0
    public void AddCurrency(int amount, CurrencyType currencyType)
    {
        Currency currency = GetCurrency(currencyType);

        if (currency != null)
        {
            currency.Add(amount);
        }
    }
예제 #7
0
 internal bool AddCurrencyItem(TradeAsset asset)
 {
     if (!Currency.Contains(asset))
     {
         Currency.Add(asset);
         return(true);
     }
     return(false);
 }
예제 #8
0
        public void ドリンクが購入可能か判定テスト(CurrencyKind.Kind kind,int num,bool expected)
        {
            //お金を投入
            var money = new Currency(kind);
            money.Add(num);
            this.target.ReceiptMoney(money);

            var actual = this.target.IsBuy();
            Assert.AreEqual(expected, actual);
        }
예제 #9
0
 public static void Cancel()
 {
     lock (bets) foreach (string nick in bets.Keys)
         {
             Currency.Add(nick, bets[nick].Value);
         }
     Clear();
     Running = false;
     Locked  = false;
 }
예제 #10
0
        public void ドリンクが購入可能か判定テスト(CurrencyKind.Kind kind, int num, bool expected)
        {
            //お金を投入
            var money = new Currency(kind);

            money.Add(num);
            this.target.ReceiptMoney(money);

            var actual = this.target.IsBuy();

            Assert.AreEqual(expected, actual);
        }
예제 #11
0
        public static void Cancel()
        {
            if (highBidder != "")
            {
                Currency.Add(highBidder, highBid);
            }

            Open = false;

            highBidder = "";
            highBid    = 0;
        }
예제 #12
0
 /// <summary>
 /// 投入するお金ごとの金額指定
 /// </summary>
 /// <param name="num"></param>
 public void SetMoneyNum(int num)
 {
     yen1.Add(num);
     yen5.Add(num);
     yen10.Add(num);
     yen50.Add(num);
     yen100.Add(num);
     yen500.Add(num);
     yen1000.Add(num);
     yen2000.Add(num);
     yen5000.Add(num);
     yen10000.Add(num);
 }
예제 #13
0
        public static bool Bid(string nick, int amount)
        {
            if (Open && amount > 0 && Currency.Check(nick) >= amount)
            {
                if (amount > highBid)
                {
                    if (highBidder != "")
                    {
                        Currency.Add(highBidder, highBid);
                    }

                    highBid    = amount;
                    highBidder = nick;
                    Currency.Remove(nick, amount);

                    return(true);
                }
            }

            return(false);
        }
예제 #14
0
 private void _OnComplete(object sender, bool b)
 {
     if (!_isShowing)
     {
         return;
     }
     _isShowing = false;
     if (!b)
     {
         return;
     }
     _lobbing = true;
     if (OptionalLobber == null)
     {
         Currency.Add(Amount).AndSave();
         _lobbing = false;
     }
     else
     {
         StartCoroutine(Lob());
     }
 }
예제 #15
0
        public HttpResponseMessage add(Currency post)
        {
            // Check for errors
            if (post == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null"));
            }

            // Make sure that the data is valid
            post.currency_code   = AnnytabDataValidation.TruncateString(post.currency_code, 3);
            post.conversion_rate = AnnytabDataValidation.TruncateDecimal(post.conversion_rate, 0, 9999.999999M);

            // Check if the currency exists
            if (Currency.MasterPostExists(post.currency_code) == true)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The currency already exists"));
            }

            // Add the post
            Currency.Add(post);

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The post has been added"));
        } // End of the add method
예제 #16
0
        private static void Command_Gamble(string user, Command cmd, string[] args, string origin)
        {
            if (args.Length > 0)
            {
                if (args[0].ToLower() == "open" && args.Length > 4)
                {
                    if (!Running)
                    {
                        int min, max, reward;
                        if (int.TryParse(args[1], out min) && int.TryParse(args[2], out max) && int.TryParse(args[3], out reward))
                        {
                            if (min > 0)
                            {
                                if (max >= min)
                                {
                                    if (reward >= 0)
                                    {
                                        List <string> lOptions = buildBetOptions(args, 4);
                                        if (lOptions.Count > 1)
                                        {
                                            LastUsedHelp = Api.GetUnixTimeNow();

                                            CreatePool(min, max, reward, lOptions);
                                            Chat.SendMessage("New betting pool opened! Min bet: " + MinBet + " " + Currency.Name + ", Max bet: " + MaxBet + " " + Currency.Name + ".");
                                            string temp = "Betting open for: ";
                                            for (int i = 0; i < lOptions.Count; i++)
                                            {
                                                temp += "(" + (i + 1).ToString() + ") " + lOptions[i];
                                                if (i + 1 < lOptions.Count)
                                                {
                                                    temp += ", ";
                                                }
                                            }
                                            Chat.SendMessage(temp + ".");
                                            Chat.SendMessage("Bet by typing \"!bet 50 #1\" to bet 50 " + Currency.Name + " on option 1, \"!bet 25 #2\" to bet 25 " + Currency.Name + " on option 2, etc.");
                                        }
                                        else
                                        {
                                            Chat.SendMessage("You need at least two betting options in order to start a betting pool!");
                                        }
                                    }
                                    else
                                    {
                                        Chat.SendMessage("WinReward can not be lower than 0!");
                                    }
                                }
                                else
                                {
                                    Chat.SendMessage("MaxBet can not be lower than MinBet!");
                                }
                            }
                            else
                            {
                                Chat.SendMessage("MinBet can not be lower than 1!");
                            }
                        }
                        else
                        {
                            Chat.SendMessage("Invalid syntax. Open a betting pool with: !gamble open {MinBet} {MaxBet} {WinReward} {option1} {option2} ... {optionN} (space delimited options)");
                        }
                    }
                    else
                    {
                        Chat.SendMessage("Betting pool already opened. Close or cancel the current one before starting a new one.");
                    }
                }
                else if (args[0].ToLower() == "close")
                {
                    if (Running)
                    {
                        if (!Locked)
                        {
                            Locked = true;
                            BetQueue.Change(0, Timeout.Infinite);
                            Chat.SendMessage("Bets locked in. Good luck everyone!");
                            string temp = "The following options were open for betting: ";
                            lock (Options) for (int i = 0; i < Options.Count; i++)
                                {
                                    temp += "(" + (i + 1).ToString() + ") " + Options[i] + " - " + getNumberOfBets(Options[i]) + " bets (" + getTotalBetsOn(Options[i]) + " " + Currency.Name + ")" + (i + 1 < Options.Count ? ", " : "");
                                }
                            Chat.SendMessage(temp + ".");
                        }
                        else
                        {
                            Chat.SendMessage("Pool is already locked.");
                        }
                    }
                    else
                    {
                        Chat.SendMessage("The betting pool is not running.");
                    }
                }
                else if (args[0].ToLower() == "winner" && args.Length > 1)
                {
                    if (Running && Locked)
                    {
                        string        option       = "";
                        List <string> compiledargs = Commands.GetArgs(args, 1).ToList();
                        if (compiledargs.Count > 0)
                        {
                            option = compiledargs[0];
                        }

                        if (option.ToLower() == args[1].ToLower())
                        {
                            if (option.StartsWith("#"))
                            {
                                int optionnumber = 0;
                                if (int.TryParse(option.Substring(1), out optionnumber))
                                {
                                    option = GetOptionFromNumber(optionnumber);
                                }
                            }
                        }

                        lock (Options)
                        {
                            if (Options.Contains(option))
                            {
                                closePool(option);
                                Chat.SendMessage("Betting pool closed! A total of " + getTotalBets() + " " + Currency.Name + " were bet.");
                                string output = "Bets for:";
                                for (int i = 0; i < Options.Count; i++)
                                {
                                    double x = ((double)getTotalBetsOn(Options[i]) / getTotalBets()) * 100;
                                    output += " " + Options[i] + " - " + getNumberOfBets(Options[i]) + " (" + Math.Round(x) + "%);";
                                    //Console.WriteLine("TESTING: getTotalBetsOn(" + i + ") = " + getTotalBetsOn(i) + " --- getTotalBets() = " + getTotalBets() + " ---  (double)betsOn(i)/totalBets() = " + (double)(getTotalBetsOn(i) / getTotalBets()) + " --- *100 = " + (double)(getTotalBetsOn(i) / getTotalBets()) * 100 + " --- Converted to a double = " + (double)((getTotalBetsOn(i) / getTotalBets()) * 100) + " --- Rounded double = " + Math.Round((double)((getTotalBetsOn(i) / getTotalBets()) * 100)));
                                }
                                Chat.SendMessage(output);
                                Dictionary <string, int> wins = Winners;
                                output = "Winners:";
                                if (wins.Count == 0)
                                {
                                    output = "No one won!";
                                    //output += " No One!";
                                }
                                else if (wins.Count <= 20)
                                {
                                    for (int i = 0; i < wins.Count; i++)
                                    {
                                        Currency.Add(wins.ElementAt(i).Key, wins.ElementAt(i).Value);
                                        string msg = " " + wins.ElementAt(i).Key + " - " + wins.ElementAt(i).Value + " (Bet " + bets[wins.ElementAt(i).Key].Value + ")";
                                        if (output.Length + msg.Length > 996)
                                        {
                                            Chat.SendMessage(output);
                                            output = "Winners:";
                                        }
                                        output += msg;
                                    }
                                }
                                else
                                {
                                    output = wins.Count + " gamblers have won!";
                                }

                                Chat.SendMessage(output);

                                Clear();
                            }
                            else
                            {
                                Chat.SendMessage("The option you specified is not available in the current pool!");
                            }
                        }
                    }
                    else
                    {
                        Chat.SendMessage("Betting pool must be running and bets must be locked before you can specify a winner, lock the bets by using \"!gamble close\".");
                        Chat.SendMessage("Pick a winning option by typing \"!gamble winner #1\" if option 1 won, \"!gamble winner #2\" for option 2, etc.");
                        Chat.SendMessage("You can type \"!bet help\" to get a list of the options as a reminder.");
                    }
                }
                else if (args[0].ToLower() == "cancel")
                {
                    if (Running)
                    {
                        Cancel();
                        Chat.SendMessage("Betting pool canceled. All bets refunded");
                    }
                    else
                    {
                        Chat.SendMessage("The betting pool is not running.");
                    }
                }
            }
        }
        public ActionResult edit(FormCollection collection)
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();
            ViewBag.CurrentDomain = currentDomain;

            // Get the return url
            string returnUrl = collection["returnUrl"];
            ViewBag.QueryParams = new QueryParams(returnUrl);

            // Check if the administrator is authorized
            if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor" }) == true)
            {
                ViewBag.AdminSession = true;
            }
            else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true)
            {
                ViewBag.AdminSession = true;
                ViewBag.AdminErrorCode = 1;
                ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC");
                return View("index");
            }
            else
            {
                // Redirect the user to the start page
                return RedirectToAction("index", "admin_login");
            }

            // Get all the form values
            string currency_code = collection["txtCurrencyCode"];
            decimal conversion_rate = 0;
            decimal.TryParse(collection["txtConversionRate"].Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture, out conversion_rate);
            Int16 currency_base = 0;
            Int16.TryParse(collection["txtCurrencyBase"].Replace(",", "."), out currency_base);
            byte decimals = 0;
            byte.TryParse(collection["txtDecimals"].Replace(",", "."), out decimals);

            // Get the default admin language id
            Int32 adminLanguageId = currentDomain.back_end_language;

            // Get translated texts
            KeyStringList tt = StaticText.GetAll(adminLanguageId, "id", "ASC");

            // Get the currency
            Currency currency = Currency.GetOneById(currency_code);
            bool postExists = true;

            // Check if the static text exists
            if (currency == null)
            {
                // Create an empty currency
                currency = new Currency();
                postExists = false;
            }

            // Update values
            currency.currency_code = currency_code;
            currency.conversion_rate = conversion_rate;
            currency.currency_base = currency_base;
            currency.decimals = decimals;

            // Create a error message
            string errorMessage = string.Empty;

            // Check for errors in the currency
            if (currency.currency_code.Length != 3)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_certain_length"), tt.Get("currency_code"), "3", "3") + "<br/>";
            }
            if (currency.conversion_rate < 0 || currency.conversion_rate > 9999.999999M)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_range"), tt.Get("conversion_rate"), "9 999.999999") + "<br/>";
            }
            if (currency.decimals < 0 || currency.decimals > 2)
            {
                errorMessage += "&#149; " + String.Format(tt.Get("error_field_range"), tt.Get("number_of_decimals"), "3") + "<br/>";
            }

            // Check if there is errors
            if (errorMessage == string.Empty)
            {
                // Check if we should add or update the static text
                if (postExists == false)
                {
                    // Add the currency
                    Currency.Add(currency);
                }
                else
                {
                    // Update the currency
                    Currency.Update(currency);
                }

                // Redirect the user to the list
                return Redirect("/admin_currencies" + returnUrl);
            }
            else
            {
                // Set form values
                ViewBag.ErrorMessage = errorMessage;
                ViewBag.Currency = currency;
                ViewBag.TranslatedTexts = tt;
                ViewBag.ReturnUrl = returnUrl;

                // Return the edit view
                return View("edit");
            }

        } // End of the edit method
예제 #18
0
        public static bool placeBet(string user, string option, int amount)
        {
            if (Running && !Locked)
            {
                lock (bets)
                {
                    lock (FalseEntries)
                    {
                        lock (Options)
                        {
                            if (!FalseEntries.ContainsKey(user) && !bets.ContainsKey(user))
                            {
                                BetQueue.Change(10000, Timeout.Infinite);
                            }

                            if (Options.Contains(option))
                            {
                                if (amount >= MinBet && amount <= MaxBet)
                                {
                                    int paid = 0;
                                    if (bets.ContainsKey(user))
                                    {
                                        paid = bets[user].Value;
                                    }

                                    if (Currency.Check(user) + paid >= amount)
                                    {
                                        if (bets.ContainsKey(user))
                                        {
                                            bets.Remove(user);
                                        }

                                        Currency.Add(user, paid);
                                        Currency.Remove(user, amount);
                                        bets.Add(user, new KeyValuePair <string, int>(option, amount));

                                        if (FalseEntries.ContainsKey(user))
                                        {
                                            FalseEntries.Remove(user);
                                        }

                                        return(true);
                                    }
                                    else
                                    {
                                        if (!FalseEntries.ContainsKey(user))
                                        {
                                            FalseEntries.Add(user, 3);
                                        }
                                    }
                                }
                                else
                                {
                                    if (!FalseEntries.ContainsKey(user))
                                    {
                                        FalseEntries.Add(user, 2);
                                    }
                                }
                            }
                            else
                            {
                                if (!FalseEntries.ContainsKey(user))
                                {
                                    FalseEntries.Add(user, 1);
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }