Changes to new Gold Ledger system (#3)
Changes new gold system to use separate gold/platinum with DivRem instead of relying on doubles.
This commit is contained in:
parent
1030bb7675
commit
d8ed7c1da9
7 changed files with 68 additions and 438 deletions
|
|
@ -25,136 +25,6 @@ namespace Server.Accounting
|
||||||
|
|
||||||
public static readonly TimeSpan EmptyInactiveDuration = TimeSpan.FromDays(30.0);
|
public static readonly TimeSpan EmptyInactiveDuration = TimeSpan.FromDays(30.0);
|
||||||
|
|
||||||
public static void Configure()
|
|
||||||
{
|
|
||||||
CommandSystem.Register("ConvertCurrency", AccessLevel.Owner, ConvertCurrency);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void ConvertCurrency(CommandEventArgs e)
|
|
||||||
{
|
|
||||||
e.Mobile.SendMessage(
|
|
||||||
"Converting All Banked Gold from {0} to {1}. Please wait...",
|
|
||||||
AccountGold.Enabled ? "checks and coins" : "account treasury",
|
|
||||||
AccountGold.Enabled ? "account treasury" : "checks and coins");
|
|
||||||
|
|
||||||
NetState.Pause();
|
|
||||||
|
|
||||||
double found = 0.0, converted = 0.0;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
BankBox box;
|
|
||||||
List<Gold> gold;
|
|
||||||
List<BankCheck> checks;
|
|
||||||
long share = 0, shared;
|
|
||||||
int diff;
|
|
||||||
|
|
||||||
foreach (var a in Accounts.GetAccounts().OfType<Account>().Where(a => a.Count > 0))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!AccountGold.Enabled)
|
|
||||||
{
|
|
||||||
share = (int)Math.Truncate((a.TotalCurrency / a.Count) * CurrencyThreshold);
|
|
||||||
found += a.TotalCurrency * CurrencyThreshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var m in a.m_Mobiles.Where(m => m != null))
|
|
||||||
{
|
|
||||||
box = m.FindBankNoCreate();
|
|
||||||
|
|
||||||
if (box == null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AccountGold.Enabled)
|
|
||||||
{
|
|
||||||
foreach (var o in checks = box.FindItemsByType<BankCheck>())
|
|
||||||
{
|
|
||||||
found += o.Worth;
|
|
||||||
|
|
||||||
if (!a.DepositGold(o.Worth))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
converted += o.Worth;
|
|
||||||
o.Delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
checks.Clear();
|
|
||||||
checks.TrimExcess();
|
|
||||||
|
|
||||||
foreach (var o in gold = box.FindItemsByType<Gold>())
|
|
||||||
{
|
|
||||||
found += o.Amount;
|
|
||||||
|
|
||||||
if (!a.DepositGold(o.Amount))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
converted += o.Amount;
|
|
||||||
o.Delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
gold.Clear();
|
|
||||||
gold.TrimExcess();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
shared = share;
|
|
||||||
|
|
||||||
while (shared > 0)
|
|
||||||
{
|
|
||||||
if (shared > 60000)
|
|
||||||
{
|
|
||||||
diff = (int)Math.Min(10000000, shared);
|
|
||||||
|
|
||||||
if (a.WithdrawGold(diff))
|
|
||||||
{
|
|
||||||
box.DropItem(new BankCheck(diff));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
diff = (int)Math.Min(60000, shared);
|
|
||||||
|
|
||||||
if (a.WithdrawGold(diff))
|
|
||||||
{
|
|
||||||
box.DropItem(new Gold(diff));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
converted += diff;
|
|
||||||
shared -= diff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
box.UpdateTotals();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{ }
|
|
||||||
|
|
||||||
NetState.Resume();
|
|
||||||
|
|
||||||
e.Mobile.SendMessage("Operation complete: {0:#,0} of {1:#,0} Gold has been converted in total.", converted, found);
|
|
||||||
}
|
|
||||||
|
|
||||||
private string m_Username, m_Email, m_PlainPassword, m_CryptPassword, m_NewCryptPassword;
|
private string m_Username, m_Email, m_PlainPassword, m_CryptPassword, m_NewCryptPassword;
|
||||||
private AccessLevel m_AccessLevel;
|
private AccessLevel m_AccessLevel;
|
||||||
private int m_Flags;
|
private int m_Flags;
|
||||||
|
|
@ -816,7 +686,8 @@ namespace Server.Accounting
|
||||||
m_Created = Utility.GetXMLDateTime( Utility.GetText( node["created"], null ), DateTime.UtcNow );
|
m_Created = Utility.GetXMLDateTime( Utility.GetText( node["created"], null ), DateTime.UtcNow );
|
||||||
m_LastLogin = Utility.GetXMLDateTime( Utility.GetText( node["lastLogin"], null ), DateTime.UtcNow );
|
m_LastLogin = Utility.GetXMLDateTime( Utility.GetText( node["lastLogin"], null ), DateTime.UtcNow );
|
||||||
|
|
||||||
TotalCurrency = Utility.GetXMLDouble( Utility.GetText(node["totalCurrency"], "0" ), 0 );
|
TotalGold = Utility.GetXMLInt32( Utility.GetText(node["totalGold"], "0" ), 0 );
|
||||||
|
TotalPlat = Utility.GetXMLInt32(Utility.GetText(node["totalPlat"], "0"), 0);
|
||||||
|
|
||||||
m_Mobiles = LoadMobiles( node );
|
m_Mobiles = LoadMobiles( node );
|
||||||
m_Comments = LoadComments( node );
|
m_Comments = LoadComments( node );
|
||||||
|
|
@ -1244,8 +1115,12 @@ namespace Server.Accounting
|
||||||
xml.WriteEndElement();
|
xml.WriteEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
xml.WriteStartElement("totalCurrency");
|
xml.WriteStartElement("totalGold");
|
||||||
xml.WriteString(XmlConvert.ToString(TotalCurrency));
|
xml.WriteString(XmlConvert.ToString(TotalGold));
|
||||||
|
xml.WriteEndElement();
|
||||||
|
|
||||||
|
xml.WriteStartElement("totalPlat");
|
||||||
|
xml.WriteString(XmlConvert.ToString(TotalPlat));
|
||||||
xml.WriteEndElement();
|
xml.WriteEndElement();
|
||||||
|
|
||||||
xml.WriteEndElement();
|
xml.WriteEndElement();
|
||||||
|
|
@ -1353,36 +1228,13 @@ namespace Server.Accounting
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Gold Account
|
#region Gold Account
|
||||||
/// <summary>
|
|
||||||
/// This amount specifies the value at which point Gold turns to Platinum.
|
|
||||||
/// By default, when 1,000,000,000 Gold is accumulated, it will transform
|
|
||||||
/// into 1 Platinum.
|
|
||||||
/// </summary>
|
|
||||||
public static int CurrencyThreshold
|
|
||||||
{
|
|
||||||
get { return AccountGold.CurrencyThreshold; }
|
|
||||||
set { AccountGold.CurrencyThreshold = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This amount represents the total amount of currency owned by the player.
|
|
||||||
/// It is cumulative of both Gold and Platinum, the absolute total amount of
|
|
||||||
/// Gold owned by the player can be found by multiplying this value by the
|
|
||||||
/// CurrencyThreshold value.
|
|
||||||
/// </summary>
|
|
||||||
[CommandProperty(AccessLevel.Administrator, true)]
|
|
||||||
public double TotalCurrency { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This amount represents the current amount of Gold owned by the player.
|
/// This amount represents the current amount of Gold owned by the player.
|
||||||
/// The value does not include the value of Platinum and ranges from
|
/// The value does not include the value of Platinum and ranges from
|
||||||
/// 0 to 999,999,999 by default.
|
/// 0 to 999,999,999 by default.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[CommandProperty(AccessLevel.Administrator)]
|
[CommandProperty(AccessLevel.Administrator)]
|
||||||
public int TotalGold
|
public int TotalGold { get; private set; }
|
||||||
{
|
|
||||||
get { return (int)Math.Floor((TotalCurrency - Math.Truncate(TotalCurrency)) * Math.Max(1.0, CurrencyThreshold)); }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This amount represents the current amount of Platinum owned by the player.
|
/// This amount represents the current amount of Platinum owned by the player.
|
||||||
|
|
@ -1391,23 +1243,7 @@ namespace Server.Accounting
|
||||||
/// One Platinum represents the value of CurrencyThreshold in Gold.
|
/// One Platinum represents the value of CurrencyThreshold in Gold.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[CommandProperty(AccessLevel.Administrator)]
|
[CommandProperty(AccessLevel.Administrator)]
|
||||||
public int TotalPlat { get { return (int)Math.Truncate(TotalCurrency); } }
|
public int TotalPlat { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Attempts to deposit the given amount of Gold and Platinum into this account.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="amount">Amount to deposit.</param>
|
|
||||||
/// <returns>True if successful, false if amount given is less than or equal to zero.</returns>
|
|
||||||
public bool DepositCurrency(double amount)
|
|
||||||
{
|
|
||||||
if (amount <= 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
TotalCurrency += amount;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attempts to deposit the given amount of Gold into this account.
|
/// Attempts to deposit the given amount of Gold into this account.
|
||||||
|
|
@ -1418,19 +1254,14 @@ namespace Server.Accounting
|
||||||
/// <returns>True if successful, false if amount given is less than or equal to zero.</returns>
|
/// <returns>True if successful, false if amount given is less than or equal to zero.</returns>
|
||||||
public bool DepositGold(int amount)
|
public bool DepositGold(int amount)
|
||||||
{
|
{
|
||||||
return DepositCurrency(amount / Math.Max(1.0, CurrencyThreshold));
|
if (amount <= 0) { return false; }
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
int gold;
|
||||||
/// Attempts to deposit the given amount of Gold into this account.
|
int plat = Math.DivRem(amount, AccountGold.CurrencyThreshold, out gold);
|
||||||
/// If the given amount is greater than the CurrencyThreshold,
|
TotalPlat += plat;
|
||||||
/// Platinum will be deposited to offset the difference.
|
TotalGold += gold;
|
||||||
/// </summary>
|
|
||||||
/// <param name="amount">Amount to deposit.</param>
|
return true;
|
||||||
/// <returns>True if successful, false if amount given is less than or equal to zero.</returns>
|
|
||||||
public bool DepositGold(long amount)
|
|
||||||
{
|
|
||||||
return DepositCurrency(amount / Math.Max(1.0, CurrencyThreshold));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1440,37 +1271,9 @@ namespace Server.Accounting
|
||||||
/// <returns>True if successful, false if amount given is less than or equal to zero.</returns>
|
/// <returns>True if successful, false if amount given is less than or equal to zero.</returns>
|
||||||
public bool DepositPlat(int amount)
|
public bool DepositPlat(int amount)
|
||||||
{
|
{
|
||||||
return DepositCurrency(amount);
|
if (amount <= 0) { return false; }
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
TotalPlat += amount;
|
||||||
/// Attempts to deposit the given amount of Platinum into this account.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="amount">Amount to deposit.</param>
|
|
||||||
/// <returns>True if successful, false if amount given is less than or equal to zero.</returns>
|
|
||||||
public bool DepositPlat(long amount)
|
|
||||||
{
|
|
||||||
return DepositCurrency(amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Attempts to withdraw the given amount of Platinum and Gold from this account.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="amount">Amount to withdraw.</param>
|
|
||||||
/// <returns>True if successful, false if balance was too low.</returns>
|
|
||||||
public bool WithdrawCurrency(double amount)
|
|
||||||
{
|
|
||||||
if (amount <= 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (amount > TotalCurrency)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
TotalCurrency -= amount;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1483,19 +1286,12 @@ namespace Server.Accounting
|
||||||
/// <returns>True if successful, false if balance was too low.</returns>
|
/// <returns>True if successful, false if balance was too low.</returns>
|
||||||
public bool WithdrawGold(int amount)
|
public bool WithdrawGold(int amount)
|
||||||
{
|
{
|
||||||
return WithdrawCurrency(amount / Math.Max(1.0, CurrencyThreshold));
|
if (amount <= 0) { return true; }
|
||||||
}
|
if (amount > TotalGold) { return false; }
|
||||||
|
|
||||||
/// <summary>
|
TotalGold -= amount;
|
||||||
/// Attempts to withdraw the given amount of Gold from this account.
|
|
||||||
/// If the given amount is greater than the CurrencyThreshold,
|
return true;
|
||||||
/// Platinum will be withdrawn to offset the difference.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="amount">Amount to withdraw.</param>
|
|
||||||
/// <returns>True if successful, false if balance was too low.</returns>
|
|
||||||
public bool WithdrawGold(long amount)
|
|
||||||
{
|
|
||||||
return WithdrawCurrency(amount / Math.Max(1.0, CurrencyThreshold));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1505,87 +1301,22 @@ namespace Server.Accounting
|
||||||
/// <returns>True if successful, false if balance was too low.</returns>
|
/// <returns>True if successful, false if balance was too low.</returns>
|
||||||
public bool WithdrawPlat(int amount)
|
public bool WithdrawPlat(int amount)
|
||||||
{
|
{
|
||||||
return WithdrawCurrency(amount);
|
if (amount <= 0) { return true; }
|
||||||
|
if (amount > TotalPlat) { return false; }
|
||||||
|
|
||||||
|
TotalPlat -= amount;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attempts to withdraw the given amount of Platinum from this account.
|
/// Returns total gold inclusive of platinum.
|
||||||
|
/// This is strictly for backwards compatibility
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="amount">Amount to withdraw.</param>
|
/// <returns>Total gold, capped at Int32.MaxValue</returns>
|
||||||
/// <returns>True if successful, false if balance was too low.</returns>
|
public long GetTotalGold()
|
||||||
public bool WithdrawPlat(long amount)
|
|
||||||
{
|
{
|
||||||
return WithdrawCurrency(amount);
|
return TotalGold + TotalPlat * AccountGold.CurrencyThreshold;
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the total balance of Gold for this account.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="gold">Gold value, Platinum exclusive</param>
|
|
||||||
/// <param name="totalGold">Gold value, Platinum inclusive</param>
|
|
||||||
public void GetGoldBalance(out int gold, out double totalGold)
|
|
||||||
{
|
|
||||||
gold = TotalGold;
|
|
||||||
totalGold = TotalCurrency * Math.Max(1.0, CurrencyThreshold);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the total balance of Gold for this account.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="gold">Gold value, Platinum exclusive</param>
|
|
||||||
/// <param name="totalGold">Gold value, Platinum inclusive</param>
|
|
||||||
public void GetGoldBalance(out long gold, out double totalGold)
|
|
||||||
{
|
|
||||||
gold = TotalGold;
|
|
||||||
totalGold = TotalCurrency * Math.Max(1.0, CurrencyThreshold);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the total balance of Platinum for this account.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="plat">Platinum value, Gold exclusive</param>
|
|
||||||
/// <param name="totalPlat">Platinum value, Gold inclusive</param>
|
|
||||||
public void GetPlatBalance(out int plat, out double totalPlat)
|
|
||||||
{
|
|
||||||
plat = TotalPlat;
|
|
||||||
totalPlat = TotalCurrency;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the total balance of Platinum for this account.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="plat">Platinum value, Gold exclusive</param>
|
|
||||||
/// <param name="totalPlat">Platinum value, Gold inclusive</param>
|
|
||||||
public void GetPlatBalance(out long plat, out double totalPlat)
|
|
||||||
{
|
|
||||||
plat = TotalPlat;
|
|
||||||
totalPlat = TotalCurrency;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the total balance of Gold and Platinum for this account.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="gold">Gold value, Platinum exclusive</param>
|
|
||||||
/// <param name="totalGold">Gold value, Platinum inclusive</param>
|
|
||||||
/// <param name="plat">Platinum value, Gold exclusive</param>
|
|
||||||
/// <param name="totalPlat">Platinum value, Gold inclusive</param>
|
|
||||||
public void GetBalance(out int gold, out double totalGold, out int plat, out double totalPlat)
|
|
||||||
{
|
|
||||||
GetGoldBalance(out gold, out totalGold);
|
|
||||||
GetPlatBalance(out plat, out totalPlat);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the total balance of Gold and Platinum for this account.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="gold">Gold value, Platinum exclusive</param>
|
|
||||||
/// <param name="totalGold">Gold value, Platinum inclusive</param>
|
|
||||||
/// <param name="plat">Platinum value, Gold exclusive</param>
|
|
||||||
/// <param name="totalPlat">Platinum value, Gold inclusive</param>
|
|
||||||
public void GetBalance(out long gold, out double totalGold, out long plat, out double totalPlat)
|
|
||||||
{
|
|
||||||
GetGoldBalance(out gold, out totalGold);
|
|
||||||
GetPlatBalance(out plat, out totalPlat);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -134,9 +134,8 @@ namespace Server.Items
|
||||||
{
|
{
|
||||||
if (owner.NetState != null && !owner.NetState.NewSecureTrading)
|
if (owner.NetState != null && !owner.NetState.NewSecureTrading)
|
||||||
{
|
{
|
||||||
var total = Worth / Math.Max(1.0, Account.CurrencyThreshold);
|
int gold;
|
||||||
var plat = (int)Math.Truncate(total);
|
int plat = Math.DivRem(Worth, AccountGold.CurrencyThreshold, out gold);
|
||||||
var gold = (int)((total - plat) * Account.CurrencyThreshold);
|
|
||||||
|
|
||||||
tradeInfo.Plat += plat;
|
tradeInfo.Plat += plat;
|
||||||
tradeInfo.Gold += gold;
|
tradeInfo.Gold += gold;
|
||||||
|
|
|
||||||
|
|
@ -103,9 +103,8 @@ namespace Server.Items
|
||||||
{
|
{
|
||||||
if (owner.NetState != null && !owner.NetState.NewSecureTrading)
|
if (owner.NetState != null && !owner.NetState.NewSecureTrading)
|
||||||
{
|
{
|
||||||
var total = Amount / Math.Max(1.0, Account.CurrencyThreshold);
|
int gold;
|
||||||
var plat = (int)Math.Truncate(total);
|
int plat = Math.DivRem(Amount, AccountGold.CurrencyThreshold, out gold);
|
||||||
var gold = (int)((total - plat) * Account.CurrencyThreshold);
|
|
||||||
|
|
||||||
tradeInfo.Plat += plat;
|
tradeInfo.Plat += plat;
|
||||||
tradeInfo.Gold += gold;
|
tradeInfo.Gold += gold;
|
||||||
|
|
|
||||||
|
|
@ -29,17 +29,12 @@ namespace Server.Mobiles
|
||||||
|
|
||||||
public static int GetBalance(Mobile m)
|
public static int GetBalance(Mobile m)
|
||||||
{
|
{
|
||||||
double balance = 0;
|
long balance = 0;
|
||||||
|
|
||||||
if (AccountGold.Enabled && m.Account != null)
|
if (AccountGold.Enabled && m.Account != null)
|
||||||
{
|
{
|
||||||
int goldStub;
|
balance = m.Account.GetTotalGold();
|
||||||
m.Account.GetGoldBalance(out goldStub, out balance);
|
if (balance >= Int32.MaxValue) { return Int32.MaxValue; }
|
||||||
|
|
||||||
if (balance > Int32.MaxValue)
|
|
||||||
{
|
|
||||||
return Int32.MaxValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Container bank = m.FindBankNoCreate();
|
Container bank = m.FindBankNoCreate();
|
||||||
|
|
@ -49,21 +44,21 @@ namespace Server.Mobiles
|
||||||
var gold = bank.FindItemsByType<Gold>();
|
var gold = bank.FindItemsByType<Gold>();
|
||||||
var checks = bank.FindItemsByType<BankCheck>();
|
var checks = bank.FindItemsByType<BankCheck>();
|
||||||
|
|
||||||
balance += gold.Aggregate(0.0, (c, t) => c + t.Amount);
|
balance += gold.Aggregate(0L, (c, t) => c + t.Amount);
|
||||||
balance += checks.Aggregate(0.0, (c, t) => c + t.Worth);
|
if (balance >= Int32.MaxValue) { return Int32.MaxValue; }
|
||||||
|
balance += checks.Aggregate(0L, (c, t) => c + t.Worth);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)Math.Max(0, Math.Min(Int32.MaxValue, balance));
|
return Math.Max(0, (int)Math.Min(Int32.MaxValue, balance));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetBalance(Mobile m, out Item[] gold, out Item[] checks)
|
public static int GetBalance(Mobile m, out Item[] gold, out Item[] checks)
|
||||||
{
|
{
|
||||||
double balance = 0;
|
long balance = 0;
|
||||||
|
|
||||||
if (AccountGold.Enabled && m.Account != null)
|
if (AccountGold.Enabled && m.Account != null)
|
||||||
{
|
{
|
||||||
int goldStub;
|
balance = m.Account.GetTotalGold();
|
||||||
m.Account.GetGoldBalance(out goldStub, out balance);
|
|
||||||
|
|
||||||
if (balance > Int32.MaxValue)
|
if (balance > Int32.MaxValue)
|
||||||
{
|
{
|
||||||
|
|
@ -79,15 +74,15 @@ namespace Server.Mobiles
|
||||||
gold = bank.FindItemsByType(typeof(Gold));
|
gold = bank.FindItemsByType(typeof(Gold));
|
||||||
checks = bank.FindItemsByType(typeof(BankCheck));
|
checks = bank.FindItemsByType(typeof(BankCheck));
|
||||||
|
|
||||||
balance += gold.OfType<Gold>().Aggregate(0.0, (c, t) => c + t.Amount);
|
balance += gold.OfType<Gold>().Aggregate(0L, (c, t) => c + t.Amount);
|
||||||
balance += checks.OfType<BankCheck>().Aggregate(0.0, (c, t) => c + t.Worth);
|
balance += checks.OfType<BankCheck>().Aggregate(0L, (c, t) => c + t.Worth);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gold = checks = new Item[0];
|
gold = checks = new Item[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)Math.Max(0, Math.Min(Int32.MaxValue, balance));
|
return Math.Max(0, (int)Math.Min(Int32.MaxValue, balance));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Withdraw(Mobile from, int amount)
|
public static bool Withdraw(Mobile from, int amount)
|
||||||
|
|
|
||||||
|
|
@ -51,15 +51,6 @@ namespace Server.Accounting
|
||||||
|
|
||||||
public interface IGoldAccount
|
public interface IGoldAccount
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// This amount represents the total amount of currency owned by the player.
|
|
||||||
/// It is cumulative of both Gold and Platinum, the absolute total amount of
|
|
||||||
/// Gold owned by the player can be found by multiplying this value by the
|
|
||||||
/// CurrencyThreshold value.
|
|
||||||
/// </summary>
|
|
||||||
[CommandProperty(AccessLevel.Administrator)]
|
|
||||||
double TotalCurrency { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This amount represents the current amount of Gold owned by the player.
|
/// This amount represents the current amount of Gold owned by the player.
|
||||||
/// The value does not include the value of Platinum and ranges from
|
/// The value does not include the value of Platinum and ranges from
|
||||||
|
|
@ -77,13 +68,6 @@ namespace Server.Accounting
|
||||||
[CommandProperty(AccessLevel.Administrator)]
|
[CommandProperty(AccessLevel.Administrator)]
|
||||||
int TotalPlat { get; }
|
int TotalPlat { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Attempts to deposit the given amount of Gold and Platinum into this account.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="amount">Amount to deposit.</param>
|
|
||||||
/// <returns>True if successful, false if amount given is less than or equal to zero.</returns>
|
|
||||||
bool DepositCurrency(double amount);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attempts to deposit the given amount of Gold into this account.
|
/// Attempts to deposit the given amount of Gold into this account.
|
||||||
/// If the given amount is greater than the CurrencyThreshold,
|
/// If the given amount is greater than the CurrencyThreshold,
|
||||||
|
|
@ -93,15 +77,6 @@ namespace Server.Accounting
|
||||||
/// <returns>True if successful, false if amount given is less than or equal to zero.</returns>
|
/// <returns>True if successful, false if amount given is less than or equal to zero.</returns>
|
||||||
bool DepositGold(int amount);
|
bool DepositGold(int amount);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Attempts to deposit the given amount of Gold into this account.
|
|
||||||
/// If the given amount is greater than the CurrencyThreshold,
|
|
||||||
/// Platinum will be deposited to offset the difference.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="amount">Amount to deposit.</param>
|
|
||||||
/// <returns>True if successful, false if amount given is less than or equal to zero.</returns>
|
|
||||||
bool DepositGold(long amount);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attempts to deposit the given amount of Platinum into this account.
|
/// Attempts to deposit the given amount of Platinum into this account.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -109,20 +84,6 @@ namespace Server.Accounting
|
||||||
/// <returns>True if successful, false if amount given is less than or equal to zero.</returns>
|
/// <returns>True if successful, false if amount given is less than or equal to zero.</returns>
|
||||||
bool DepositPlat(int amount);
|
bool DepositPlat(int amount);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Attempts to deposit the given amount of Platinum into this account.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="amount">Amount to deposit.</param>
|
|
||||||
/// <returns>True if successful, false if amount given is less than or equal to zero.</returns>
|
|
||||||
bool DepositPlat(long amount);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Attempts to withdraw the given amount of Platinum and Gold from this account.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="amount">Amount to withdraw.</param>
|
|
||||||
/// <returns>True if successful, false if balance was too low.</returns>
|
|
||||||
bool WithdrawCurrency(double amount);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attempts to withdraw the given amount of Gold from this account.
|
/// Attempts to withdraw the given amount of Gold from this account.
|
||||||
/// If the given amount is greater than the CurrencyThreshold,
|
/// If the given amount is greater than the CurrencyThreshold,
|
||||||
|
|
@ -132,15 +93,6 @@ namespace Server.Accounting
|
||||||
/// <returns>True if successful, false if balance was too low.</returns>
|
/// <returns>True if successful, false if balance was too low.</returns>
|
||||||
bool WithdrawGold(int amount);
|
bool WithdrawGold(int amount);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Attempts to withdraw the given amount of Gold from this account.
|
|
||||||
/// If the given amount is greater than the CurrencyThreshold,
|
|
||||||
/// Platinum will be withdrawn to offset the difference.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="amount">Amount to withdraw.</param>
|
|
||||||
/// <returns>True if successful, false if balance was too low.</returns>
|
|
||||||
bool WithdrawGold(long amount);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attempts to withdraw the given amount of Platinum from this account.
|
/// Attempts to withdraw the given amount of Platinum from this account.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -149,57 +101,11 @@ namespace Server.Accounting
|
||||||
bool WithdrawPlat(int amount);
|
bool WithdrawPlat(int amount);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attempts to withdraw the given amount of Platinum from this account.
|
/// Returns total gold inclusive of platinum, capped to Int32.
|
||||||
|
/// This is strictly for backwards compatibility
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="amount">Amount to withdraw.</param>
|
/// <returns>Total gold, capped at Int32.MaxValue</returns>
|
||||||
/// <returns>True if successful, false if balance was too low.</returns>
|
long GetTotalGold();
|
||||||
bool WithdrawPlat(long amount);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the total balance of Gold for this account.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="gold">Gold value, Platinum exclusive</param>
|
|
||||||
/// <param name="totalGold">Gold value, Platinum inclusive</param>
|
|
||||||
void GetGoldBalance(out int gold, out double totalGold);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the total balance of Gold for this account.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="gold">Gold value, Platinum exclusive</param>
|
|
||||||
/// <param name="totalGold">Gold value, Platinum inclusive</param>
|
|
||||||
void GetGoldBalance(out long gold, out double totalGold);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the total balance of Platinum for this account.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="plat">Platinum value, Gold exclusive</param>
|
|
||||||
/// <param name="totalPlat">Platinum value, Gold inclusive</param>
|
|
||||||
void GetPlatBalance(out int plat, out double totalPlat);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the total balance of Platinum for this account.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="plat">Platinum value, Gold exclusive</param>
|
|
||||||
/// <param name="totalPlat">Platinum value, Gold inclusive</param>
|
|
||||||
void GetPlatBalance(out long plat, out double totalPlat);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the total balance of Gold and Platinum for this account.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="gold">Gold value, Platinum exclusive</param>
|
|
||||||
/// <param name="totalGold">Gold value, Platinum inclusive</param>
|
|
||||||
/// <param name="plat">Platinum value, Gold exclusive</param>
|
|
||||||
/// <param name="totalPlat">Platinum value, Gold inclusive</param>
|
|
||||||
void GetBalance(out int gold, out double totalGold, out int plat, out double totalPlat);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the total balance of Gold and Platinum for this account.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="gold">Gold value, Platinum exclusive</param>
|
|
||||||
/// <param name="totalGold">Gold value, Platinum inclusive</param>
|
|
||||||
/// <param name="plat">Platinum value, Gold exclusive</param>
|
|
||||||
/// <param name="totalPlat">Platinum value, Gold inclusive</param>
|
|
||||||
void GetBalance(out long gold, out double totalGold, out long plat, out double totalPlat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IAccount : IGoldAccount, IComparable<IAccount>
|
public interface IAccount : IGoldAccount, IComparable<IAccount>
|
||||||
|
|
|
||||||
|
|
@ -344,10 +344,10 @@ namespace Server
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var cur = User.Account.TotalCurrency;
|
int totalPlat = User.Account.TotalPlat;
|
||||||
var off = _Plat + (_Gold / Math.Max(1.0, AccountGold.CurrencyThreshold));
|
int totalGold = User.Account.TotalGold;
|
||||||
|
|
||||||
if (off > cur)
|
if (totalPlat < _Plat || totalGold < _Gold)
|
||||||
{
|
{
|
||||||
_Plat = User.Account.TotalPlat;
|
_Plat = User.Account.TotalPlat;
|
||||||
_Gold = User.Account.TotalGold;
|
_Gold = User.Account.TotalGold;
|
||||||
|
|
|
||||||
|
|
@ -282,10 +282,10 @@ namespace Server
|
||||||
{
|
{
|
||||||
if (m_From.Mobile.Account != null)
|
if (m_From.Mobile.Account != null)
|
||||||
{
|
{
|
||||||
var cur = m_From.Mobile.Account.TotalCurrency;
|
int totalPlat = m_From.Mobile.Account.TotalPlat;
|
||||||
var off = m_From.Plat + (m_From.Gold / Math.Max(1.0, AccountGold.CurrencyThreshold));
|
int totalGold = m_From.Mobile.Account.TotalGold;
|
||||||
|
|
||||||
if (off > cur)
|
if (totalPlat < m_From.Plat || totalGold < m_From.Gold)
|
||||||
{
|
{
|
||||||
allowed = false;
|
allowed = false;
|
||||||
m_From.Mobile.SendMessage("You do not have enough currency to complete this trade.");
|
m_From.Mobile.SendMessage("You do not have enough currency to complete this trade.");
|
||||||
|
|
@ -294,10 +294,10 @@ namespace Server
|
||||||
|
|
||||||
if (m_To.Mobile.Account != null)
|
if (m_To.Mobile.Account != null)
|
||||||
{
|
{
|
||||||
var cur = m_To.Mobile.Account.TotalCurrency;
|
int totalPlat = m_To.Mobile.Account.TotalPlat;
|
||||||
var off = m_To.Plat + (m_To.Gold / Math.Max(1.0, AccountGold.CurrencyThreshold));
|
int totalGold = m_To.Mobile.Account.TotalGold;
|
||||||
|
|
||||||
if (off > cur)
|
if (totalPlat < m_To.Plat || totalGold < m_To.Gold)
|
||||||
{
|
{
|
||||||
allowed = false;
|
allowed = false;
|
||||||
m_To.Mobile.SendMessage("You do not have enough currency to complete this trade.");
|
m_To.Mobile.SendMessage("You do not have enough currency to complete this trade.");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue