Esempio n. 1
0
        public void Apply(ArcadeUser user)
        {
            if (Money > 0)
            {
                user.Give(Money);
            }

            ulong oldExp = user.Exp;

            if (Exp > 0)
            {
                user.Exp += Exp;
            }

            if (user.Config.Notifier.HasFlag(NotifyAllow.Level))
            {
                int oldLevel = ExpConvert.AsLevel(oldExp, user.Ascent);
                int level    = user.Level;
                if (level > oldLevel)
                {
                    user.Notifier.Append($"Level up! ({LevelViewer.GetLevel(oldLevel, user.Ascent)} to {LevelViewer.GetLevel(level, user.Ascent)})");
                }
            }

            if (!Check.NotNullOrEmpty(ItemIds))
            {
                return;
            }

            foreach ((string itemId, int amount) in ItemIds)
            {
                ItemHelper.GiveItem(user, itemId, amount);
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
                }
            }
        }
Esempio n. 4
0
        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)))}" : "")}");
        }