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
|
|
@ -29,17 +29,12 @@ namespace Server.Mobiles
|
|||
|
||||
public static int GetBalance(Mobile m)
|
||||
{
|
||||
double balance = 0;
|
||||
long balance = 0;
|
||||
|
||||
if (AccountGold.Enabled && m.Account != null)
|
||||
{
|
||||
int goldStub;
|
||||
m.Account.GetGoldBalance(out goldStub, out balance);
|
||||
|
||||
if (balance > Int32.MaxValue)
|
||||
{
|
||||
return Int32.MaxValue;
|
||||
}
|
||||
balance = m.Account.GetTotalGold();
|
||||
if (balance >= Int32.MaxValue) { return Int32.MaxValue; }
|
||||
}
|
||||
|
||||
Container bank = m.FindBankNoCreate();
|
||||
|
|
@ -49,21 +44,21 @@ namespace Server.Mobiles
|
|||
var gold = bank.FindItemsByType<Gold>();
|
||||
var checks = bank.FindItemsByType<BankCheck>();
|
||||
|
||||
balance += gold.Aggregate(0.0, (c, t) => c + t.Amount);
|
||||
balance += checks.Aggregate(0.0, (c, t) => c + t.Worth);
|
||||
balance += gold.Aggregate(0L, (c, t) => c + t.Amount);
|
||||
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)
|
||||
{
|
||||
double balance = 0;
|
||||
long balance = 0;
|
||||
|
||||
if (AccountGold.Enabled && m.Account != null)
|
||||
{
|
||||
int goldStub;
|
||||
m.Account.GetGoldBalance(out goldStub, out balance);
|
||||
balance = m.Account.GetTotalGold();
|
||||
|
||||
if (balance > Int32.MaxValue)
|
||||
{
|
||||
|
|
@ -79,15 +74,15 @@ namespace Server.Mobiles
|
|||
gold = bank.FindItemsByType(typeof(Gold));
|
||||
checks = bank.FindItemsByType(typeof(BankCheck));
|
||||
|
||||
balance += gold.OfType<Gold>().Aggregate(0.0, (c, t) => c + t.Amount);
|
||||
balance += checks.OfType<BankCheck>().Aggregate(0.0, (c, t) => c + t.Worth);
|
||||
balance += gold.OfType<Gold>().Aggregate(0L, (c, t) => c + t.Amount);
|
||||
balance += checks.OfType<BankCheck>().Aggregate(0L, (c, t) => c + t.Worth);
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue