コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <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));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        /// <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);
        }
コード例 #8
0
        /// <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);
            }
        }