コード例 #1
0
ファイル: TradeHelper.cs プロジェクト: AbnerSquared/Orikivo
        public static bool IsOfferValid(ArcadeUser author, ArcadeUser target, TradeOffer offer)
        {
            if (DateTime.UtcNow - offer.CreatedAt >= TimeSpan.FromHours(24))
            {
                return(false);
            }

            foreach ((string itemId, int amount) in offer.ItemIds)
            {
                if (ItemHelper.GetOwnedAmount(author, itemId) < amount)
                {
                    return(false);
                }
            }

            foreach ((string itemId, int amount) in offer.RequestedItemIds)
            {
                if (ItemHelper.GetOwnedAmount(target, itemId) < amount)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        public static bool CanCraft(ArcadeUser user, Recipe recipe)
        {
            if (recipe == null)
            {
                throw new Exception("Could not find a recipe with the specified ID");
            }

            foreach ((string itemId, int amount) in recipe.Components)
            {
                if (!ItemHelper.HasItem(user, itemId) || ItemHelper.GetOwnedAmount(user, itemId) != amount)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #3
0
        public static Dictionary <string, int> GetMissingFromRecipe(ArcadeUser user, Recipe recipe)
        {
            if (recipe == null)
            {
                throw new Exception("Could not find a recipe with the specified ID");
            }

            var missing = new Dictionary <string, int>();

            foreach ((string itemId, int amount) in recipe.Components)
            {
                int owned = ItemHelper.GetOwnedAmount(user, itemId);

                if (owned < amount)
                {
                    missing[itemId] = amount - owned;
                }
            }

            return(missing);
        }
コード例 #4
0
ファイル: TradeHelper.cs プロジェクト: AbnerSquared/Orikivo
        public static string SendOffer(ArcadeUser author, ArcadeUser target, TradeOffer offer)
        {
            if (author.Offers.Count(x => x.Target.Id == target.Id) == 1)
            {
                return(Format.Warning($"You already have an active trade offer to **{target.Username}**. Please cancel your current offer to this user before sending a new one."));
            }

            if (author.Offers.Count == 5)
            {
                return(Format.Warning("You already have too many active trade offers. Try again later."));
            }

            foreach ((string itemId, int amount) in offer.ItemIds)
            {
                if (ItemHelper.GetOwnedAmount(author, itemId) < amount)
                {
                    return(Format.Warning("You do not own one of the specified items in your trade offer."));
                }
            }

            foreach ((string itemId, int amount) in offer.RequestedItemIds)
            {
                if (ItemHelper.GetOwnedAmount(target, itemId) < amount)
                {
                    return(Format.Warning($"**{target.Username}** does not own one of the specified items in your trade offer."));
                }
            }

            if (target.Offers.Count == 5)
            {
                return(Format.Warning(
                           $"**{target.Username}** already has too many pending trade offers. Try again later."));
            }

            target.Offers.Add(offer);
            author.Offers.Add(TradeOffer.CloneAsOutbound(offer));

            return($"Successfully sent **{target.Username}** a trade offer.");
        }