コード例 #1
0
        public static bool Craft(ArcadeUser user, Recipe recipe)
        {
            if (GetRecipeStatus(user, recipe) == RecipeStatus.Unknown)
            {
                return(false);
            }

            if (!CanCraft(user, recipe))
            {
                return(false);
            }

            if (recipe.Result == null)
            {
                throw new Exception("Expected recipe result but returned null");
            }

            foreach ((string itemId, int amount) in recipe.Components)
            {
                ItemHelper.TakeItem(user, itemId, amount);
            }

            ItemHelper.GiveItem(user, recipe.Result.ItemId, recipe.Result.Amount);

            user.AddToVar(Stats.ItemsCrafted);
            return(true);
        }
コード例 #2
0
        // Invokes the trade, and lets everything go through
        private void Trade()
        {
            if (HostReady && ParticipantReady)
            {
                // This needs to handle unique item data.
                foreach ((string itemId, int amount) in HostOffer)
                {
                    ItemHelper.TakeItem(Host, itemId, amount);
                    ItemHelper.GiveItem(Participant, itemId, amount);
                }

                foreach ((string itemId, int amount) in ParticipantOffer)
                {
                    ItemHelper.TakeItem(Participant, itemId, amount);
                    ItemHelper.GiveItem(Host, itemId, amount);
                }
            }
        }
コード例 #3
0
        public static string Sell(Shop shop, ItemData data, ArcadeUser user)
        {
            if (!CanSell(shop, data))
            {
                return(Format.Warning($"**{shop.Name}** does not accept this item."));
            }

            Item item = ItemHelper.GetItem(data.Id);

            ItemHelper.TakeItem(user, data);

            long value = shop.SellDeduction > 0
                ? (long)Math.Floor(item.Value * (1 - shop.SellDeduction / (double)100))
                : item.Value;

            user.Give(value, item.Currency);
            string icon = (Check.NotNull(item.GetIcon()) ? $"{item.GetIcon()} " : "");
            string name = $"{icon}**{(Check.NotNull(icon) ? item.Name : item.GetName())}**";

            return($"> You have received {Icons.IconOf(item.Currency)} **{value:##,0}** for {name}.");
        }
コード例 #4
0
ファイル: TradeHelper.cs プロジェクト: AbnerSquared/Orikivo
        public static string AcceptOffer(ArcadeUser target, ArcadeUser author, TradeOffer offer)
        {
            // Get the author in the command
            if (offer.Author.Id != author.Id)
            {
                throw new Exception("Expected author to match offer author");
            }

            if (offer.Type == OfferType.Outbound)
            {
                return(Format.Warning("You cannot accept outbound trade offers."));
            }

            if (!IsOfferValid(author, target, offer))
            {
                author.Offers.RemoveAll(x => x.Id == offer.Id);
                target.Offers.RemoveAll(x => x.Id == offer.Id);
                return(Format.Warning("This trade offer has expired or is invalid due to missing items."));
            }

            foreach ((string itemId, int amount) in offer.ItemIds)
            {
                ItemHelper.TakeItem(author, itemId, amount);
                ItemHelper.GiveItem(target, itemId, amount);
            }

            foreach ((string itemId, int amount) in offer.RequestedItemIds)
            {
                ItemHelper.TakeItem(target, itemId, amount);
                ItemHelper.GiveItem(author, itemId, amount);
            }

            target.Offers.RemoveAll(x => x.Id == offer.Id);
            author.Offers.RemoveAll(x => x.Id == offer.Id);
            return($"Successfully accepted offer `{offer.Id}` from **{offer.Author.ToString("Unknown User")}**.{(offer.ItemIds.Count > 0 ? $"\nYou have received:\n{string.Join("\n", offer.ItemIds.Select(x => WriteItem(x.Key, x.Value)))}" : "")}");
        }