Пример #1
0
        /// <summary>
        /// Attempts to purchase <paramref name="amount"/> items at the given <paramref name="slot"/> from the
        /// shop that the shopper is currently shopping at.
        /// </summary>
        /// <param name="slot">The index of the shop item to purchase.</param>
        /// <param name="amount">The amount of the item to purchase.</param>
        /// <returns>True if the purchase was successful; otherwise false.</returns>
        public bool TryPurchase(ShopItemIndex slot, byte amount)
        {
            ThreadAsserts.IsMainThread();

            if (!slot.IsLegalValue())
            {
                return(false);
            }

            // Get the shop
            ValidateShop();
            if (_shoppingAt == null)
            {
                return(false);
            }

            // Get and validate the item
            var shopItem = _shoppingAt.GetShopItem(slot);

            if (Equals(shopItem, null))
            {
                return(false);
            }

            // Try to buy the item
            return(HandleBuyShopItem(Character, shopItem, amount));
        }
Пример #2
0
        /// <summary>
        /// Gets the item at the specified <paramref name="slot"/>.
        /// </summary>
        /// <param name="slot">The slot of the shop item.</param>
        /// <returns>The shop item at the specified <paramref name="slot"/>, or null if
        /// the slot was invalid or contains no item.</returns>
        public TShopItem GetShopItem(ShopItemIndex slot)
        {
            if (slot < 0 || slot >= _shopItems.Length)
            {
                return(default(TShopItem));
            }

            return(_shopItems[slot]);
        }
Пример #3
0
        /// <summary>
        /// Gets the item at the specified <paramref name="slot"/>.
        /// </summary>
        /// <param name="slot">The slot of the shop item.</param>
        /// <returns>The shop item at the specified <paramref name="slot"/>, or null if
        /// the slot was invalid or contains no item.</returns>
        public TShopItem GetShopItem(ShopItemIndex slot)
        {
            var i = slot.GetRawValue();

            if (i < 0 || i >= _shopItems.Length)
            {
                return(default(TShopItem));
            }

            return(_shopItems[i]);
        }
Пример #4
0
        /// <summary>
        /// Gets the item info at the given <paramref name="slot"/>.
        /// </summary>
        /// <param name="slot">The slot of the item.</param>
        /// <returns>The item info at the given <paramref name="slot"/>, or null if the
        /// <see cref="slot"/> was invalid or not item was in the specified slot.</returns>
        public TItemInfo GetItemInfo(ShopItemIndex slot)
        {
            if (_items == null)
            {
                return(default(TItemInfo));
            }

            if (slot < 0 || slot >= _items.Length)
            {
                return(default(TItemInfo));
            }

            return(_items[slot]);
        }
Пример #5
0
        /// <summary>
        /// Gets the item info at the given <paramref name="slot"/>.
        /// </summary>
        /// <param name="slot">The slot of the item.</param>
        /// <returns>The item info at the given <paramref name="slot"/>, or null if the
        /// <see cref="slot"/> was invalid or not item was in the specified slot.</returns>
        public TItemInfo GetItemInfo(ShopItemIndex slot)
        {
            if (_items == null)
            {
                return(default(TItemInfo));
            }

            var i = slot.GetRawValue();

            if (i < 0 || i >= _items.Length)
            {
                return(default(TItemInfo));
            }

            return(_items[i]);
        }
 public static void Write(this IValueWriter writer, string name, ShopItemIndex value)
 {
     writer.Write(name, value);
 }
 /// <summary>
 /// Checks if the given <see cref="ShopItemIndex"/> is in legal range.
 /// </summary>
 /// <param name="index">The ShopItemIndex.</param>
 /// <returns>True if the <paramref name="index"/> is in legal range; otherwise false.</returns>
 public static bool IsLegalValue(this ShopItemIndex index)
 {
     return(index >= 0 && index < _shopSettings.MaxShopItems);
 }
Пример #8
0
        /// <summary>
        /// Checks if the given <see cref="ShopItemIndex"/> is in legal range.
        /// </summary>
        /// <param name="index">The ShopItemIndex.</param>
        /// <returns>True if the <paramref name="index"/> is in legal range; otherwise false.</returns>
        public static bool IsLegalValue(this ShopItemIndex index)
        {
            int i = (int)index;

            return(i >= 0 && i < _shopSettings.MaxShopItems);
        }