/// <summary>
        /// Returns whether the Account has enough of the currency to afford the amount
        /// </summary>
        public bool CanAfford(AccountCurrencyType currencyType, ulong amount)
        {
            if (!currencies.TryGetValue(currencyType, out AccountCurrency accountCurrency))
            {
                return(false);
            }

            return(accountCurrency.CanAfford(amount));
        }
        /// <summary>
        /// Create a new <see cref="AccountCurrency"/>
        /// </summary>
        public AccountCurrency(uint accountId, AccountCurrencyType currencyType, ulong amount)
        {
            this.accountId = accountId;
            CurrencyId     = currencyType;
            Amount         = amount;
            Entry          = GameTableManager.AccountCurrencyType.GetEntry((ulong)CurrencyId);

            saveMask = AccountCurrencySaveMask.Create;
        }
Exemple #3
0
            public void HandleCurrencyAccountAdd(ICommandContext context,
                                                 [Parameter("Account currency id to grant.", ParameterFlags.None, typeof(EnumParameterConverter <AccountCurrencyType>))]
                                                 AccountCurrencyType currencyId,
                                                 [Parameter("Amount of currency to grant.")]
                                                 uint amount)
            {
                AccountCurrencyTypeEntry entry = GameTableManager.Instance.AccountCurrencyType.GetEntry((uint)currencyId);

                if (entry == null || currencyId == AccountCurrencyType.MaxLevelToken) // Disabled Character Token for now due to causing server errors if the player tries to use it. TODO: Fix level 50 creation
                {
                    context.SendMessage("Invalid currencyId. Please try again.");
                    return;
                }

                context.GetTargetOrInvoker <Player>().Session.AccountCurrencyManager.CurrencyAddAmount(currencyId, amount);
            }
        /// <summary>
        /// Add a supplied amount to an <see cref="AccountCurrency"/>.
        /// </summary>
        public void CurrencyAddAmount(AccountCurrencyType currencyType, ulong amount, ulong reason = 0)
        {
            if (!currencies.TryGetValue(currencyType, out AccountCurrency accountCurrency))
            {
                accountCurrency = CreateAccountCurrency(currencyType, 0);
            }

            if (accountCurrency == null)
            {
                throw new ArgumentException($"Account Currency entry not found for currencyId {currencyType}.");
            }

            if (accountCurrency.AddAmount(amount))
            {
                SendAccountCurrencyUpdate(accountCurrency, reason);
            }
        }
        /// <summary>
        /// Create a new <see cref="CharacterCurrency"/>.
        /// </summary>
        private AccountCurrency CreateAccountCurrency(AccountCurrencyType currencyType, ulong amount = 0)
        {
            AccountCurrencyTypeEntry currencyEntry = GameTableManager.AccountCurrencyType.GetEntry((ulong)currencyType);

            if (currencyEntry == null)
            {
                throw new ArgumentNullException($"AccountCurrencyTypeEntry not found for currencyId {currencyType}");
            }

            if (currencies.TryAdd(currencyType, new AccountCurrency(session.Account.Id, currencyType, amount)))
            {
                return(currencies[currencyType]);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Subtract a supplied amount to an <see cref="AccountCurrency"/>.
        /// </summary>
        public void CurrencySubtractAmount(AccountCurrencyType currencyType, ulong amount, ulong reason = 0)
        {
            if (!currencies.TryGetValue(currencyType, out AccountCurrency accountCurrency))
            {
                accountCurrency = CreateAccountCurrency(currencyType, 0);
            }

            if (accountCurrency == null)
            {
                throw new ArgumentException($"Account Currency entry not found for currencyId {currencyType}.");
            }

            if (!accountCurrency.CanAfford(amount))
            {
                throw new ArgumentException($"Trying to remove more currency {accountCurrency.CurrencyId} than the player has!");
            }

            // TODO: Ensure that we're not at cap - is there a cap?
            if (accountCurrency.SubtractAmount(amount))
            {
                SendAccountCurrencyUpdate(accountCurrency, reason);
            }
        }
Exemple #7
0
 /// <summary>
 /// Get the <see cref="OfferItemPrice"/> associated with this <see cref="OfferItem"/> for the given account currency ID
 /// </summary>
 public OfferItemPrice GetPriceDataForCurrency(AccountCurrencyType currencyId)
 {
     return(prices.TryGetValue(currencyId, out OfferItemPrice itemPrice) ? itemPrice : null);
 }