Example #1
0
        /// <summary>
        /// Gets whether this <see cref = "ExchangeComponent">ExchangeComponent</see> is able to purchase a given amount
        /// of a given <see cref = "Item">Item</see> from the provided other ExchangeComponent.
        /// </summary>
        /// <remarks>
        /// This depends on whether this ExchangeComponent <see cref = "ExchangeComponent.CanExchangeWith">can exchange with</see> the other ExchangeComponent,
        /// whether the other ExchangeComponent <see cref = "ExchangeComponent.IsSelling">is generally selling</see> (or this is a same-owner exchange),
        /// whether this ExchangeComponent's <see cref = "ExchangeComponent.GetTargetInventory">target inventory</see>
        /// <see cref = "InventoryComponent.CanIncreaseSupply">is able to register</see> the given item
        /// and whether the other ExchangeComponent's target inventory
        /// has the requested amount of Items <see cref = "InventoryComponent.IsInStock">in stock</see>.
        /// </remarks>
        /// <param name="item">The item to check.</param>
        /// <param name="other">The other ExchangeComponent to check against.</param>
        /// <param name="amount">The amount to check.</param>
        public bool CanPurchaseFrom(Item item, ExchangeComponent other, int amount = 1)
        {
            if (!CanExchangeWith(other))
            {
                this.Log($"Exchange can't purchase {amount} {item} from {other}: Can't exchange with other",
                         LogType.Warning);
                return(false);
            }

            var targetInventory = GetTargetInventory(item);

            if (!targetInventory.CanIncreaseSupply(item))
            {
                this.Log($"Exchange can't purchase {amount} {item} from {other}: Can't add item to inventory.", LogType.Warning);
                return(false);
            }

            var otherTargetInventory = other.GetTargetInventory(item);

            if (!otherTargetInventory.IsInStock(item, amount))
            {
                this.Log($"Exchange can't purchase {amount} {item} from {other}: Other does not have item in stock", LogType.Warning);
                return(false);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Gets whether this <see cref = "ExchangeComponent">ExchangeComponent</see> is able to sell a given amount
        /// of a given <see cref = "Item">Item</see> to the provided other ExchangeComponent.
        /// </summary>
        /// <remarks>
        /// This depends on whether this ExchangeComponent <see cref = "ExchangeComponent.CanExchangeWith">can exchange with</see> the other ExchangeComponent,
        /// whether the other ExchangeComponent <see cref = "ExchangeComponent.IsPurchasing">is generally purchasing</see> (or this is a same-owner exchange),
        /// whether this ExchangeComponent's <see cref = "ExchangeComponent.GetTargetInventory">target inventory</see>
        /// has the requested amount of Items <see cref = "InventoryComponent.IsInStock">in stock</see>
        /// and whether the other ExchangeComponent's target inventory
        /// <see cref = "InventoryComponent.CanIncreaseSupply">is able to register</see> the given Item.
        /// </remarks>
        /// <param name="item">The item to check.</param>
        /// <param name="other">The other ExchangeComponent to check against.</param>
        /// <param name="amount">The amount to check.</param>
        public bool CanSellTo(Item item, ExchangeComponent other, int amount = 1)
        {
            if (!CanExchangeWith(other))
            {
                this.Log($"Exchange can't sell {amount} {item} to {other}: Can't exchange with partner.", LogType.Warning);
                return(false);
            }

            if (!(other.IsPurchasing || other.Owner == Owner))
            {
                this.Log($"Exchange can't sell {amount} {item} to {other}: Other is not purchasing.", LogType.Warning);
                return(false);
            }

            var targetInventory = GetTargetInventory(item);

            if (!targetInventory.IsInStock(item, amount))
            {
                this.Log($"Exchange can't sell {amount} {item} to {other}: Item is not in stock.", LogType.Warning);
                return(false);
            }

            var otherTargetInventory = other.GetTargetInventory(item);

            if (!otherTargetInventory.CanIncreaseSupply(item))
            {
                this.Log($"Exchange can't transfer {item}: Can't add item to other's inventory", LogType.Warning);
                return(false);
            }

            return(true);
        }