/// <summary> /// Add supplied amount of <see cref="CurrencyType"/> currency. /// </summary> public void CurrencyAddAmount(CurrencyType currencyId, ulong amount, bool isLoot = false) { CurrencyTypeEntry currencyEntry = GameTableManager.Instance.CurrencyType.GetEntry((ulong)currencyId); if (currencyEntry == null) { throw new ArgumentNullException(); } CurrencyAddAmount(currencyEntry, amount, isLoot); }
/// <summary> /// Create a new <see cref="CharacterCurrency"/>. /// </summary> public void CurrencyAddAmount(byte currencyId, ulong amount) { CurrencyTypeEntry currencyEntry = GameTableManager.CurrencyType.GetEntry(currencyId); if (currencyEntry == null) { throw new ArgumentNullException(); } CurrencyAddAmount(currencyEntry, amount); }
/// <summary> /// Create a new <see cref="CharacterCurrency"/>. /// </summary> public Currency CurrencyCreate(byte currencyId, ulong amount = 0) { CurrencyTypeEntry currencyEntry = GameTableManager.CurrencyType.GetEntry(currencyId); if (currencyEntry == null) { return(null); } return(CurrencyCreate(currencyEntry)); }
private Currency CurrencyCreate(CurrencyTypeEntry currencyEntry) { if (currencyEntry == null) { return(null); } if (currencies.ContainsKey((CurrencyType)currencyEntry.Id)) { throw new ArgumentException($"Currency {currencyEntry.Id} is already added to the player!"); } var currency = new Currency(player.CharacterId, currencyEntry); currencies.Add(currency.Id, currency); return(currency); }
/// <summary> /// Create a new <see cref="CharacterCurrency"/>. /// </summary> public void CurrencySubtractAmount(CurrencyTypeEntry currencyEntry, ulong amount) { if (currencyEntry == null) { throw new ArgumentNullException(); } if (!currencies.TryGetValue((byte)currencyEntry.Id, out Currency currency)) { throw new ArgumentException($"Cannot create currency {currencyEntry.Id} with a negative amount!"); } if (currency.Amount < amount) { throw new ArgumentException($"Trying to remove more currency {currencyEntry.Id} than the player has!"); } CurrencyAmountUpdate(currency, currency.Amount - amount); }
private void CurrencyAddAmount(CurrencyTypeEntry currencyEntry, ulong amount, bool isLoot = false) { if (currencyEntry == null) { throw new ArgumentNullException(); } if (!currencies.TryGetValue((CurrencyType)currencyEntry.Id, out Currency currency)) { currency = CurrencyCreate(currencyEntry); } amount += currency.Amount; if (currency.Entry.CapAmount > 0) { amount = Math.Min(amount, currency.Entry.CapAmount); } CurrencyAmountUpdate(currency, amount, isLoot); }
/// <summary> /// Create a new <see cref="CharacterCurrency"/>. /// </summary> public Currency CurrencyCreate(CurrencyTypeEntry currencyEntry, ulong amount = 0) { if (currencyEntry == null) { return(null); } if (currencies.ContainsKey((byte)currencyEntry.Id)) { throw new ArgumentException($"Currency {currencyEntry.Id} is already added to the player!"); } Currency currency = new Currency( player.CharacterId, currencyEntry, amount ); currencies.Add((byte)currencyEntry.Id, currency); return(currency); }
/// <summary> /// Create a new <see cref="CharacterCurrency"/>. /// </summary> public void CurrencyAddAmount(CurrencyTypeEntry currencyEntry, ulong amount) { if (currencyEntry == null) { throw new ArgumentNullException(); } if (!currencies.TryGetValue((byte)currencyEntry.Id, out Currency currency)) { CurrencyCreate(currencyEntry, (ulong)amount); } else { amount += currency.Amount; if (currency.Entry.CapAmount > 0) { amount = Math.Min(amount + currency.Amount, currency.Entry.CapAmount); } CurrencyAmountUpdate(currency, amount); } }