Beispiel #1
0
        public static async Task <bool> BuyItem(ulong userid, int shopSlot, int quantity)
        {
            if (shopSlot > Shop.Count || shopSlot < 0)
            {
                return(false);
            }

            SocketGuildUser user     = BotUtils.GetGUser(userid);
            UserDataNode    customer = UserDataManager.GetUserData(user);
            ShopNode        item     = Shop[shopSlot];

            if (quantity > 0 && customer.Kamtrokens >= item.Price * quantity)
            {
                customer.Kamtrokens      -= item.Price * quantity;
                customer.KamtrokensSpent += item.Price * quantity;

                UserInventoryManager.GetInventory(userid).AddItem(item.ItemID, quantity);

                await AchievementManager.OnBuy(user);

                UserDataManager.SaveUserData();
                UserInventoryManager.SaveInventories();
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        private async Task GiveItem(SocketGuildUser user)
        {
            UserInventoryManager.GetInventory(user.Id).AddItem(ItemId, Count);
            UserInventoryManager.SaveInventories();

            await ReplyAsync(BotUtils.KamtroText($"Successfully given {user.GetDisplayName()} {Count} of {ItemManager.GetItem(ItemId).Name}"));
        }
Beispiel #3
0
        private void ParseInventory()
        {
            bool save = false;

            List <uint> remove = new List <uint>();

            foreach (uint k in Items.Keys)
            {
                if (Items[k] <= 0)
                {
                    remove.Add(k);
                    save = true;
                }
            }

            foreach (uint k in remove)
            {
                Items.Remove(k);
            }

            if (save)
            {
                UserInventoryManager.SaveInventories();
            }
        }
Beispiel #4
0
        public async Task Use(SocketGuildUser user, SocketCommandContext ctx, params object[] args)
        {
            UserDataManager.GetUserData(user).ReputationToGive += 3; // give rep
            UserInventoryManager.GetInventory(user.Id).LoseItem(Id); // consume the item
            UserInventoryManager.SaveInventories();                  // now save

            await NotifyChannel(ctx, $"{user.GetDisplayName()} used a Breadstick giving them 3 single-use extra rep points to give!");
        }
Beispiel #5
0
        /// <summary>
        /// Attempts to craft an item
        /// </summary>
        /// <remarks>
        /// Only saves on successful crafting
        /// </remarks>
        /// <param name="toCraft">The ID of the item to be crafted</param>
        /// <returns>True if crafting was successful, false otherwise</returns>
        public bool TryCraft(uint toCraft)
        {
            Item i = ItemManager.GetItem(toCraft);

            if (i.IsCraftable() && CanCraft(toCraft))
            {
                Craft(toCraft);
                UserInventoryManager.SaveInventories();
            }
            else
            {
                return(false);
            }

            return(true);
        }
Beispiel #6
0
        public bool HasItem(uint id)
        {
            if (!Items.ContainsKey(id))
            {
                return(false);
            }

            if (Items[id] <= 0)
            {
                Items.Remove(id);
                UserInventoryManager.SaveInventories();
                return(false);
            }

            return(true);
        }
Beispiel #7
0
        public static bool SellItem(ulong userid, uint itemid, int quantity)
        {
            UserInventoryNode i = UserInventoryManager.GetInventory(userid);

            if (i.ItemCount(itemid) < quantity)
            {
                return(false);
            }

            int total = ItemManager.GetItem(itemid).GetSellPrice() * quantity;

            UserDataManager.GetUserData(BotUtils.GetGUser(userid)).Kamtrokens += total;
            i.LoseItem(itemid, quantity);
            UserDataManager.SaveUserData();
            UserInventoryManager.SaveInventories();
            return(true);
        }