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:
Kamron Batman 2018-02-20 22:47:16 -08:00 committed by GitHub
parent 1030bb7675
commit d8ed7c1da9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 68 additions and 438 deletions

View file

@ -51,15 +51,6 @@ namespace Server.Accounting
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>
/// This amount represents the current amount of Gold owned by the player.
/// The value does not include the value of Platinum and ranges from
@ -77,13 +68,6 @@ namespace Server.Accounting
[CommandProperty(AccessLevel.Administrator)]
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>
/// Attempts to deposit the given amount of Gold into this account.
/// 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>
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>
/// Attempts to deposit the given amount of Platinum into this account.
/// </summary>
@ -109,20 +84,6 @@ namespace Server.Accounting
/// <returns>True if successful, false if amount given is less than or equal to zero.</returns>
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>
/// Attempts to withdraw the given amount of Gold from this account.
/// 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>
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>
/// Attempts to withdraw the given amount of Platinum from this account.
/// </summary>
@ -149,57 +101,11 @@ namespace Server.Accounting
bool WithdrawPlat(int amount);
/// <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>
/// <param name="amount">Amount to withdraw.</param>
/// <returns>True if successful, false if balance was too low.</returns>
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);
/// <returns>Total gold, capped at Int32.MaxValue</returns>
long GetTotalGold();
}
public interface IAccount : IGoldAccount, IComparable<IAccount>

View file

@ -344,10 +344,10 @@ namespace Server
}
else
{
var cur = User.Account.TotalCurrency;
var off = _Plat + (_Gold / Math.Max(1.0, AccountGold.CurrencyThreshold));
int totalPlat = User.Account.TotalPlat;
int totalGold = User.Account.TotalGold;
if (off > cur)
if (totalPlat < _Plat || totalGold < _Gold)
{
_Plat = User.Account.TotalPlat;
_Gold = User.Account.TotalGold;
@ -392,4 +392,4 @@ namespace Server
}
}
}
}
}

View file

@ -282,10 +282,10 @@ namespace Server
{
if (m_From.Mobile.Account != null)
{
var cur = m_From.Mobile.Account.TotalCurrency;
var off = m_From.Plat + (m_From.Gold / Math.Max(1.0, AccountGold.CurrencyThreshold));
int totalPlat = m_From.Mobile.Account.TotalPlat;
int totalGold = m_From.Mobile.Account.TotalGold;
if (off > cur)
if (totalPlat < m_From.Plat || totalGold < m_From.Gold)
{
allowed = false;
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)
{
var cur = m_To.Mobile.Account.TotalCurrency;
var off = m_To.Plat + (m_To.Gold / Math.Max(1.0, AccountGold.CurrencyThreshold));
int totalPlat = m_To.Mobile.Account.TotalPlat;
int totalGold = m_To.Mobile.Account.TotalGold;
if (off > cur)
if (totalPlat < m_To.Plat || totalGold < m_To.Gold)
{
allowed = false;
m_To.Mobile.SendMessage("You do not have enough currency to complete this trade.");
@ -505,4 +505,4 @@ namespace Server
IsDisposed = true;
}
}
}
}