public List<Rank> FindNextRanks(Money value) { var list = new List<Rank>(); long stack = 0L; var rank = this; while (stack < value) { rank = rank.FindNext(); if (rank == null) return list; stack += rank.Cost(); list.Add(rank); } list.RemoveAt(list.Count - 1); return list; }
void VaultChCreate(CAPlayer player, int chID, CommandArgs args) { try { var economyPlayer = Wolfje.Plugins.SEconomy.SEconomyPlugin.Instance.GetBankAccount(player.Index); var commandCost = new Wolfje.Plugins.SEconomy.Money(config.cost); //Vault.Vault.ModifyBalance(args.Player.Name, -config.ChanelCreatingCost)) if (!economyPlayer.IsAccountEnabled) { player.TSPlayer.SendErrorMessage("You cannot use this command because your account is disabled."); } else if (economyPlayer.Balance != null && economyPlayer.Balance >= config.cost) { Wolfje.Plugins.SEconomy.Journal.BankTransferEventArgs trans = economyPlayer.TransferTo( Wolfje.Plugins.SEconomy.SEconomyPlugin.Instance.WorldAccount, commandCost, Wolfje.Plugins.SEconomy.Journal.BankAccountTransferOptions.AnnounceToSender | Wolfje.Plugins.SEconomy.Journal.BankAccountTransferOptions.IsPayment, "", string.Format("charge to {0}", player.TSPlayer.Name)); var newchannel = new Channel(chID, args.Parameters[0]); if (args.Parameters.Count > 1) newchannel.Password = args.Parameters[1]; Channels[chID] = newchannel; NetMessage.SendData((int)PacketTypes.ChatText, -1, -1, "New channel created", 255, Color.LightSalmon.R, Color.LightSalmon.G, Color.LightSalmon.B, chID + 1); Channels[chID].JoinChannel(player); } else args.Player.SendMessage(String.Format("Channel not found and insufficient founds to create a new channel. (costs: {0})", economyPlayer.Balance.ToString()), Color.LightSalmon); //Vault.Vault.MoneyToString(this.parseCost)) } catch (Exception ex) { TShock.Log.ConsoleError(ex.ToString()); } }
/// <summary> /// Initializes a new instance of Money and copies the amount specified in it. /// </summary> public Money(Money money) { _moneyValue = money._moneyValue; }
async Task SetBalanceToAsync(Money money) { await account.SyncBalanceAsync(); BankTransferEventArgs args = await account.OwningJournal.TransferBetweenAsync(parent.WorldAccount, account, money - account.Balance, BankAccountTransferOptions.AnnounceToReceiver | BankAccountTransferOptions.AnnounceToSender, "Balance Adjustment", "Balance Adjustment from bank manager."); if (args.TransferSucceeded == true) { this.MainThreadInvoke(() => this.Hide()); return; } MessageBox.Show("Transfer failed.", "Transfer failed", MessageBoxButtons.OK, MessageBoxIcon.Error); }
/// <summary> /// Tries to parse Money out of a money representation. /// </summary> /// <param name="MoneyRepresentation">The money representation string, eg "1p1g", or "30s20c"</param> /// <param name="money">Reference to the money variable to parse to.</param> /// <returns>true if the parsing succeeded.</returns> public static bool TryParse(string MoneyRepresentation, out Money Money) { try { Money = Parse(MoneyRepresentation); } catch { Money = 0; //any exception marks a failed conversion, the reference must be set to 0 return false; } return true; }
public BHItem(int id, Money money, int prefix) { this.id = id; this.money = money; this.prefix = prefix; }
/// <summary> /// Tries to parse Money out of a money representation. /// </summary> /// <param name="MoneyRepresentation">The money representation string, eg "1p1g", or "30s20c"</param> /// <param name="money">Reference to the money variable to parse to.</param> /// <returns>true if the parsing succeeded.</returns> public static bool TryParse(string MoneyRepresentation, out Money Money) { bool succeeded = false; try { Money = Parse(MoneyRepresentation); succeeded = true; } catch { //any exception marks a failed conversion, the reference must be set to 0 succeeded = false; Money = 0; } return succeeded; }
public void Seconomy_TransferToWorld(string playerName, Money amount, string journalMsg, string transactionMsg) { SEconomy seconomy = this.Seconomy_Instance(); IBankAccount account = seconomy.GetPlayerBankAccount(playerName); account.TransferTo(seconomy.WorldAccount, amount, BankAccountTransferOptions.AnnounceToSender, journalMsg, transactionMsg); }
public void Lottery(CommandArgs args) { if (Playerlist[args.Player.Index] != null) { if (args.Parameters.Count < 1) { if (args.Player.Group.HasPermission("caw.lotteryadmin")) { args.Player.SendErrorMessage("Invalid syntax! Use /lottery [start/guess/total/pastguesses/hint/help/save/lotteryreload/cancel]"); return; } else { args.Player.SendErrorMessage("Invalid syntax! Use /lottery [start/guess/total/pastguesses/hint/help]"); return; } } switch (args.Parameters[0]) { case "start": if (args.Player.Group.HasPermission("caw.startlottery")) { if (!LotteryRunning) { Random random = new Random(); LotteryWinningNumer = random.Next(Configfile.config.MinimumLotteryNumber, (Configfile.config.MaximumLotteryNumber + 1)); LotteryRunning = true; Money.TryParse(Configfile.config.LotteryTotalStartAmount, out Lotterytotalmoney); Lotterynumberhigh = (LotteryWinningNumer + random.Next(1, Configfile.config.RandomHintRange + 1)); Lotterynumberlow = (LotteryWinningNumer - random.Next(1, Configfile.config.RandomHintRange + 1)); MaxLotteryNumber = Configfile.config.MaximumLotteryNumber; MinLotteryNumber = Configfile.config.MinimumLotteryNumber; TSPlayer.All.SendSuccessMessage("[Lottery] A lottery has been started type /lottery to see how to join!"); } else { args.Player.SendErrorMessage("A lottery has already been started, please finish this one first."); } } else { args.Player.SendErrorMessage("You do not have permission to start a lottery."); } break; case "guess": var Journalpayment = Wolfje.Plugins.SEconomy.Journal.BankAccountTransferOptions.AnnounceToSender; var UserSEAccount = SEconomyPlugin.Instance.GetBankAccount(args.Player.UserAccountName); var playeramount = UserSEAccount.Balance; if (SEconomyPlugin.Instance != null) { if (args.Parameters.Count < 2) { args.Player.SendErrorMessage("Invalid syntax! Use /lottery guess <numbertoguess> <money>"); return; } if (!int.TryParse(args.Parameters[1], out numberguessed)) { args.Player.SendErrorMessage("Error: Non-Numerical Amount Detected!"); return; } if (numberguessed > Configfile.config.MaximumLotteryNumber || numberguessed < Configfile.config.MinimumLotteryNumber) { args.Player.SendErrorMessage("The number for this lottery is between {0} and {1}", Configfile.config.MinimumLotteryNumber, Configfile.config.MaximumLotteryNumber); return; } foreach (var player in Playerlist) { if (Playerlist[player.Index].guesses.Contains(numberguessed)) { args.Player.SendErrorMessage("You have already guessed {0}, please try a different number.", numberguessed); return; } break; } if (!Money.TryParse(args.Parameters[2], out amount)) { args.Player.SendErrorMessage("Error: Non-Numerical Amount Detected!"); return; } if (amount <= 0) { args.Player.SendErrorMessage("Error: Amount to put in the lottery must be greater then 0! Amount you entered = {1}", amount); return; } if (amount < Configfile.config.MinimumCashVoteAmount) { args.Player.SendErrorMessage("Error: The money you have put into the lottery does not match the minimum value to play. The minimum value is: {0}", Configfile.config.MinimumCashVoteAmount); return; } Money moneyamount2 = amount; Money moneyamount = -amount; if (playeramount < moneyamount2) { args.Player.SendErrorMessage("Payment failed! You do not have enough money to do that!"); } if (playeramount > moneyamount2) { args.Player.SendSuccessMessage("You have guessed {0} and added {1} to the lottery.", numberguessed, moneyamount2); SEconomyPlugin.Instance.WorldAccount.TransferToAsync(UserSEAccount, moneyamount, Journalpayment, string.Format("{0} has been added to the lottery.", moneyamount2, args.Player.Name), string.Format("Lottery: " + "Adding money into the pool.")); Lotterytotalmoney += amount; Playerlist[args.Player.Index].contribution += amount; Playerlist[args.Player.Index].guessedtimes++; Playerlist[args.Player.Index].guesses.Add(numberguessed); } if (numberguessed == LotteryWinningNumer) { TSPlayer.All.SendInfoMessage("[Lottery] {0} has won the lottery of {1}!", args.Player.Name, Lotterytotalmoney); SEconomyPlugin.Instance.WorldAccount.TransferToAsync(UserSEAccount, Lotterytotalmoney, Journalpayment, string.Format("{0} has won the lottery!.", args.Player.Name), string.Format("Lottery: " + "Winning")); Lotterytotalmoney = 0; LotteryRunning = false; foreach (var player in Playerlist) { if (player != null) { player.contribution = 0; player.guessedtimes = 0; player.guesses.Clear(); } } } } else { args.Player.SendErrorMessage("A lottery is not running type [/lottery start] to start one."); } break; case "pastguesses": if (LotteryRunning) { if (Playerlist[args.Player.Index].guesses.Count > 0) { args.Player.SendErrorMessage("You have guessed " + Playerlist[args.Player.Index].guessedtimes + " times. Your previous guesses are: " + string.Join(", ", Playerlist[args.Player.Index].guesses)); } else { args.Player.SendErrorMessage("You have not guessed or contributed the lottery. Type /lottery to join in!"); } } else { args.Player.SendErrorMessage("A lottery is not running type [/lottery start] to start one."); } break; case "hint": if (LotteryRunning) { if (Hint) { if (args.Player.Group.HasPermission("caw.lotteryhint")) { args.Player.SendInfoMessage("The lottery number could be any number in between {0} and {1}.", Lotterynumberlow, Lotterynumberhigh); } else { args.Player.SendErrorMessage("You do not have pemission to use this command."); } } } else { args.Player.SendErrorMessage("A lottery is not running type [/lottery start] to start one."); } break; case "total": if (LotteryRunning) { args.Player.SendInfoMessage("The current lottry total is {0}.", Lotterytotalmoney); args.Player.SendErrorMessage("The amount you have put into the pot is: " + Playerlist[args.Player.Index].contribution); if (args.Player.Group.HasPermission("caw.winningnumber")) { args.Player.SendInfoMessage("Winning number is " + LotteryWinningNumer); } } else { args.Player.SendErrorMessage("A lottery is not running type [/lottery start] to start one."); } break; case "cancel": if (LotteryRunning) { if (args.Player.Group.HasPermission("caw.cancellottery")) { Configfile.config.LotteryTotalStartAmount = Lotterytotalmoney.ToString(); TSPlayer.All.SendInfoMessage("{0} has canceled the current lottery of {1}, and saved it until the lottery restarts.", args.Player.Name, Lotterytotalmoney); Lotterytotalmoney = 0; LotteryRunning = false; foreach (var player in Playerlist) { if (player != null) { player.contribution = 0; player.guessedtimes = 0; player.guesses.Clear(); } } } else { args.Player.SendErrorMessage("You do not have permission to use this command."); } } else { args.Player.SendErrorMessage("To cancel a lottery one must be started."); } break; case "save": if (LotteryCanSave) { if (args.Player.Group.HasPermission("caw.savelottery")) { if (LotteryRunning) { Configfile.config.LotteryTotalStartAmount = Lotterytotalmoney.ToString(); args.Player.SendSuccessMessage("The config file has saved with a total lottery of {0}. Next time the lottery starts that is the starting value.", Configfile.config.LotteryTotalStartAmount); Configfile.SaveConfig(); } } else { args.Player.SendErrorMessage("You do not have permission to use this command."); } } else { args.Player.SendErrorMessage("The owner has turned the save feature off."); } break; case "help": if (LotteryRunning) { args.Player.SendSuccessMessage(Configfile.config.HelpMessage); } else { args.Player.SendErrorMessage("A lottery is not started, type /lottery start to get one going!"); } break; } } else { return; } }