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}")); }
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); }
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(); } }
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!"); }
public CraftingEmbed(SocketCommandContext ctx) { SetCtx(ctx); User = BotUtils.GetGUser(ctx); Inventory = UserInventoryManager.GetInventory(User.Id); CraftItems = GetCraftableItems(); if (CraftItems.Count > 0) { SelectedItem = CraftItems[0]; } AddMenuOptions(ReactionHandler.SELECT, ReactionHandler.UP, ReactionHandler.DOWN, ReactionHandler.BACK); }
/// <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); }
public bool HasItem(uint id) { if (!Items.ContainsKey(id)) { return(false); } if (Items[id] <= 0) { Items.Remove(id); UserInventoryManager.SaveInventories(); return(false); } return(true); }
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); }
public InventoryEmbed(SocketCommandContext ctx) { SetCtx(ctx); User = BotUtils.GetGUser(ctx); UserData = UserDataManager.GetUserData(User); Inventory = UserInventoryManager.GetInventory(User.Id); List <uint> Items = Inventory.Items.Keys.ToList(); Items.Sort(); if (Items.Count != 0) { SelectedItem = Items[0]; } AddMenuOptions(ReactionHandler.SELECT, ReactionHandler.BACK, ReactionHandler.UP, ReactionHandler.DOWN); }
/// <summary> /// Called after OnReady. For anything that needs discord user info /// </summary> private static void SetupGeneral() { ServerData.SetupServerData(Settings); UserInventoryManager.LoadInventories(); ReminderManager.LoadReminders(); }