public decimal GetCarryAmount(Profile profile) { using var context = new RPGContext(_options); ItemsJson itemsJson = JsonConvert.DeserializeObject <ItemsJson>(profile.ItemJson); decimal carryAmount = .05M * Convert.ToDecimal(itemsJson.Robbing.First(x => x.Id == 12).Count); return(carryAmount); }
public async Task GiveUserItem(Profile profile, Profile botProfile, string itemName) { using var context = new RPGContext(_options); RobbingItems item = context.RobbingItems.First(x => x.Name.ToLower() == itemName.ToLower()); if (profile.Gold < item.Cost) { throw new Exception("User cannot afford the item."); } if (profile.Level < item.LvlRequired) { throw new Exception("User is not the right level"); } ItemsJson itemsJson = JsonConvert.DeserializeObject <ItemsJson>(profile.ItemJson); string newItemsJson; if (itemsJson.Robbing.Exists(x => x.Id == item.Id)) { if (itemsJson.Robbing.SingleOrDefault(x => x.Id == item.Id).Count >= item.MaxAllowed) { throw new Exception("user already owns max amount of items."); } itemsJson.Robbing.SingleOrDefault(x => x.Id == item.Id).Count++; newItemsJson = JsonConvert.SerializeObject(itemsJson); } else { Robbing newRobbing = new Robbing { Id = item.Id, Count = 1 }; itemsJson.Robbing.Add(newRobbing); newItemsJson = JsonConvert.SerializeObject(itemsJson); } profile.ItemJson = newItemsJson; profile.Gold -= item.Cost; context.Profiles.Update(profile); botProfile.Gold += item.Cost; context.Profiles.Update(botProfile); await context.SaveChangesAsync().ConfigureAwait(false); }
public Item(SlotType slotType, ushort slot, ushort itemId, bool loadData = true) { SlotType = slotType; Slot = slot; ItemId = itemId; if (loadData) { ItemData = DataManager.Instance.ItemsData.GetData(ItemId); } }
public async Task GiveUserItem(Profile profile, Profile botProfile, int itemId) { using var context = new RPGContext(_options); RobbingItems item = context.RobbingItems.SingleOrDefault(x => x.Id == itemId); if (profile.Gold < item.Cost) { throw new InvalidOperationException("The user cannot afford to purchase this item."); } if (profile.Level < item.LvlRequired) { throw new InvalidOperationException("The user is not the correct level to purchase this item."); } ItemsJson itemsJson = JsonConvert.DeserializeObject <ItemsJson>(profile.ItemJson); if (itemsJson.Robbing.SingleOrDefault(x => x.Id == itemId).Count >= item.MaxAllowed) { throw new InvalidOperationException("The user already owns the maximum number of items allowed."); } string newItemsJson; if (itemsJson.Robbing.Exists(x => x.Id == itemId)) { itemsJson.Robbing.SingleOrDefault(x => x.Id == itemId).Count++; newItemsJson = JsonConvert.SerializeObject(itemsJson); } else { Robbing newRobbing = new Robbing { Id = itemId, Count = 1 }; itemsJson.Robbing.Add(newRobbing); newItemsJson = JsonConvert.SerializeObject(itemsJson); } profile.ItemJson = newItemsJson; profile.Gold -= item.Cost; context.Profiles.Update(profile); botProfile.Gold += item.Cost; context.Profiles.Update(botProfile); await context.SaveChangesAsync().ConfigureAwait(false); }
public async Task buyItem(CommandContext ctx, [RemainingText, Description("item name")] string itemName) { Profile profile = await _profileService.GetOrCreateProfileAsync(ctx.Member.Id, ctx.Guild.Id).ConfigureAwait(false); Profile botProfile = await _profileService.GetOrCreateProfileAsync(ctx.Client.CurrentUser.Id, ctx.Guild.Id).ConfigureAwait(false); var AllRobbingItmes = _robbingItemService.GetAllRobbingItems(); try { var itemByName = AllRobbingItmes.SingleOrDefault(x => x.Name.ToLower() == itemName.ToLower()); ItemsJson itemsJson = JsonConvert.DeserializeObject <ItemsJson>(profile.ItemJson); try { if (itemsJson.Robbing.SingleOrDefault(x => x.Id == itemByName.Id).Count >= itemByName.MaxAllowed) { await ctx.Channel.SendMessageAsync($"You already have the maximum amount possible for this item.").ConfigureAwait(false); return; } } catch { } if (itemByName.Cost > profile.Gold) { await ctx.Channel.SendMessageAsync($"You cannot afford this item you only have {profile.Gold} gold and need {itemByName.Cost} gold.").ConfigureAwait(false); return; } if (itemByName.LvlRequired > profile.Level) { await ctx.Channel.SendMessageAsync($"You are not the right level for this item, you need to be level {itemByName.LvlRequired} and are level {profile.Level}").ConfigureAwait(false); return; } } catch { await ctx.Channel.SendMessageAsync("Please make sure this item actually exists."); return; } await _robbingItemService.GiveUserItem(profile, botProfile, itemName).ConfigureAwait(false); await ctx.RespondAsync($"You successfully bought {itemName}!"); }
public async Task RemoveUserItemById(Profile profile, int itemId, bool refundGold) { using var context = new RPGContext(_options); ItemsJson itemsJson = JsonConvert.DeserializeObject <ItemsJson>(profile.ItemJson); RobbingItems item = context.RobbingItems.SingleOrDefault(x => x.Id == itemId); itemsJson.Robbing[itemId].Count--; if (refundGold) { profile.Gold = +item.Cost; } string newItemsJson = JsonConvert.SerializeObject(itemsJson); profile.ItemJson = newItemsJson; context.Profiles.Update(profile); await context.SaveChangesAsync().ConfigureAwait(false); }
// ####### Tasks ######## public async Task showShop(CommandContext ctx) { Profile profile = await _profileService.GetOrCreateProfileAsync(ctx.Member.Id, ctx.Guild.Id).ConfigureAwait(false); ItemsJson itemsJson = JsonConvert.DeserializeObject <ItemsJson>(profile.ItemJson); List <RobbingItems> robbingItems = _robbingItemService.GetAllRobbingItems(); var sortedList = robbingItems.OrderBy(x => x.LvlRequired); StringBuilder sb = new StringBuilder(); foreach (var item in sortedList) { if (item.MaxAllowed > 1) { try { if (itemsJson.Robbing.FirstOrDefault(x => x.Id == item.Id).Count == item.MaxAllowed) { sb.Append($"#[already own max allowed] {item.Name}\n\n"); } else { sb.Append($"@[{item.Cost} gold] {item.Name} - Level required: {item.LvlRequired}\nItem buffs: defense: '{item.DefenseBuff * 100}%'\tattack: '{item.AttackBuff * 100}%'\n#{itemsJson.Robbing.FirstOrDefault(x => x.Id == item.Id).Count} out of {item.MaxAllowed} owned.\n\n"); } } catch { try { sb.Append($"@[{item.Cost} gold] {item.Name} - Level required: {item.LvlRequired}\nItem buffs: defense: '{item.DefenseBuff * 100}%'\tattack: '{item.AttackBuff * 100}%'\n#0 out of {item.MaxAllowed} owned.\n\n"); } catch { sb.Append("#An error occurred.\n\n"); } } } else { try { if (itemsJson.Robbing.FirstOrDefault(x => x.Id == item.Id).Count == item.MaxAllowed) { sb.Append($"#[already own max allowed] {item.Name}\n\n"); } else { sb.Append($"@[{item.Cost} gold] {item.Name} - Level required: {item.LvlRequired}\nItem buffs: defense: '{item.DefenseBuff * 100}%'\tattack: '{item.AttackBuff * 100}%'\n\n"); } } catch { try { sb.Append($"@[{item.Cost} gold] {item.Name} - Level required: {item.LvlRequired}\nItem buffs: defense: '{item.DefenseBuff * 100}%'\tattack: '{item.AttackBuff * 100}%'\n\n"); } catch { sb.Append("#An error occurred.\n\n"); } } } } await ctx.Channel.SendMessageAsync($"```py\n@To find more information or purchase an item use `w!item info [item name]` and `w!item buy [Item Name]`\n\nYou currently have {profile.Gold} Gold are level {profile.Level}.\n\n{sb.ToString()}\n```").ConfigureAwait(false); }
public Item(ushort itemId) { ItemId = itemId; ItemData = DataManager.Instance.ItemsData.GetData(ItemId); }
public async Task showShop(CommandContext ctx, DiscordMessage message, Profile profile, DiscordMember member) { await message.DeleteAllReactionsAsync(); ItemsJson itemsJson = JsonConvert.DeserializeObject <ItemsJson>(profile.ItemJson); var invworth = _robbingItemService.GetInvWorth(profile); List <RobbingItems> robbingItems = _robbingItemService.GetAllRobbingItems(); var sortedList = robbingItems.OrderBy(x => x.LvlRequired); StringBuilder sb = new StringBuilder(); foreach (var item in sortedList) { if (item.MaxAllowed > 1) { try { if (itemsJson.Robbing.FirstOrDefault(x => x.Id == item.Id).Count == item.MaxAllowed) { sb.Append($"#[already own max allowed] {item.Name}\n\n"); } else { sb.Append($"@[{item.Cost} gold] {item.Name} - Level required: {item.LvlRequired}\nItem buffs: defense: '{item.DefenseBuff * 100}%'\tattack: '{item.AttackBuff * 100}%'\n#{itemsJson.Robbing.FirstOrDefault(x => x.Id == item.Id).Count} out of {item.MaxAllowed} owned.\n\n"); } } catch { try { sb.Append($"@[{item.Cost} gold] {item.Name} - Level required: {item.LvlRequired}\nItem buffs: defense: '{item.DefenseBuff * 100}%'\tattack: '{item.AttackBuff * 100}%'\n#0 out of {item.MaxAllowed} owned.\n\n"); } catch { sb.Append("#An error occurred.\n\n"); } } } else { try { if (itemsJson.Robbing.FirstOrDefault(x => x.Id == item.Id).Count == item.MaxAllowed) { sb.Append($"#[already own max allowed] {item.Name}\n\n"); } else { sb.Append($"@[{item.Cost} gold] {item.Name} - Level required: {item.LvlRequired}\nItem buffs: defense: '{item.DefenseBuff * 100}%'\tattack: '{item.AttackBuff * 100}%'\n\n"); } } catch { try { sb.Append($"@[{item.Cost} gold] {item.Name} - Level required: {item.LvlRequired}\nItem buffs: defense: '{item.DefenseBuff * 100}%'\tattack: '{item.AttackBuff * 100}%'\n\n"); } catch { sb.Append("#An error occurred.\n\n"); } } } } await message.ModifyAsync($"```py\n@To find more information or purchase an item use `w!item info [item name]` and `w!item buy [Item Name]`\n\nYou currently have {profile.Gold} Gold are level {profile.Level}.\nInventory is currently worth: {invworth}\n{sb.ToString()}\n```", null).ConfigureAwait(false); var emojiList = new List <DiscordEmoji>(); emojiList.Add(DiscordEmoji.FromName(ctx.Client, ":smiley:")); emojiList.Add(DiscordEmoji.FromName(ctx.Client, ":abc:")); emojiList.Add(DiscordEmoji.FromName(ctx.Client, ":joystick:")); emojiList.Add(DiscordEmoji.FromName(ctx.Client, ":gear:")); emojiList.Add(DiscordEmoji.FromName(ctx.Client, ":scroll:")); foreach (var emoji in emojiList) { await message.CreateReactionAsync(emoji); } await AwaitReaction(ctx, message, profile, member, emojiList).ConfigureAwait(false); }
public async Task SendUserInventory(CommandContext ctx, DiscordMessage message, Profile profile, DiscordMember member) { await message.DeleteAllReactionsAsync(); ItemsJson itemsJson = JsonConvert.DeserializeObject <ItemsJson>(profile.ItemJson); var ItemsIdList = new List <int>(); foreach (var item in itemsJson.Robbing) { ItemsIdList.Add(item.Id); } var items = _robbingItemService.GetRobbingItems(ItemsIdList); var userBuffStats = _robbingItemService.GetBuffStats(profile); var profileEmbed = new DiscordEmbedBuilder { Title = $"{member.DisplayName}'s Inventory.", Description = $"Current robbing strength:\nAttack: {userBuffStats.attack * 100}%\nDefense: {userBuffStats.defense*100}%\nInventory is worth {_robbingItemService.GetInvWorth(profile)} Gold.", Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail { Url = member.AvatarUrl }, Color = member.Color, Timestamp = System.DateTime.Now }; string itemTitle = new string(string.Empty); foreach (var item in items) { if (item.MaxAllowed > 1) { var count = itemsJson.Robbing.SingleOrDefault(x => x.Id == item.Id).Count; itemTitle = $"{item.Name} - {count} out of {item.MaxAllowed} in inventory"; } else { itemTitle = $"{item.Name}"; } profileEmbed.AddField(itemTitle, $"{item.Description} \n Attack: {item.AttackBuff * 100}%\tDefense: {item.DefenseBuff * 100}", false); } await message.ModifyAsync(content : " ", embed : profileEmbed.Build()); var emojiList = new List <DiscordEmoji>(); emojiList.Add(DiscordEmoji.FromName(ctx.Client, ":abc:")); emojiList.Add(DiscordEmoji.FromName(ctx.Client, ":joystick:")); emojiList.Add(DiscordEmoji.FromName(ctx.Client, ":gear:")); emojiList.Add(DiscordEmoji.FromName(ctx.Client, ":smiley:")); if (member.Id == ctx.Member.Id) { emojiList.Add(DiscordEmoji.FromName(ctx.Client, ":shopping_cart:")); } foreach (var emoji in emojiList) { await message.CreateReactionAsync(emoji); } await AwaitReaction(ctx, message, profile, member, emojiList).ConfigureAwait(false); }
public override void Convert() { using (var stream = new BinaryReader(File.OpenRead(Path), Encode)) { var size = stream.BaseStream.Length; ushort i = 0; var list = new List <ItemsJson>(); while (stream.BaseStream.Position < size - 4) { var temp = new ItemsJson(); temp.LoopId = i; temp.ItemName = Encode.GetString(stream.ReadBytes(64)).Trim('\u0000'); temp.ItemName2 = Encode.GetString(stream.ReadBytes(64)).Trim('\u0000'); temp.Description = Encode.GetString(stream.ReadBytes(128)).Trim('\u0000'); temp.IsStackable = stream.ReadUInt16() == 1; temp.ItemType = stream.ReadUInt16(); temp.CaeliumId = stream.ReadUInt32(); temp.SubType = stream.ReadInt32(); temp.GearCoreLevel = stream.ReadUInt32(); temp.Unk6 = stream.ReadUInt32(); // buff related temp.Unk7 = stream.ReadUInt32(); // buff related temp.Unk8 = stream.ReadUInt32(); // buff related temp.HonorCost = stream.ReadUInt32(); temp.MedalCost = stream.ReadUInt32(); temp.BuyPrice = stream.ReadUInt32(); temp.SellPrice = stream.ReadUInt32(); temp.Profession = stream.ReadUInt16(); temp.Unk9 = stream.ReadUInt16(); // kind of face / monster / mount temp.Unk10 = stream.ReadUInt16(); temp.Unk11 = stream.ReadUInt16(); temp.Unk12 = stream.ReadUInt16(); temp.Unk13 = stream.ReadByte(); temp.Unk14 = stream.ReadByte(); temp.Unk15 = stream.ReadUInt16(); temp.Unk16 = stream.ReadUInt16(); temp.Unk17 = stream.ReadUInt16(); temp.Unk18 = stream.ReadUInt16(); temp.ImageId = stream.ReadUInt16(); temp.Unk19 = stream.ReadUInt16(); // 68 temp.Unk20 = stream.ReadUInt16(); temp.Unk21 = stream.ReadUInt16(); temp.Unk22 = stream.ReadUInt16(); // 74 temp.MinLevel = stream.ReadUInt16(); temp.Unk23 = stream.ReadByte(); temp.Unk24 = stream.ReadByte(); stream.ReadInt16(); // empty //80 temp.TimeLimit = stream.ReadInt32(); stream.ReadByte(); // empty temp.Unk25 = stream.ReadByte() == 1; // consumable / food temp.DressId = stream.ReadByte(); temp.IsHolyWater = stream.ReadByte() == 1; stream.ReadUInt32(); // empty stream.ReadUInt32(); // empty temp.Unk28 = stream.ReadUInt16(); stream.ReadUInt32(); // empty temp.PAtk = stream.ReadUInt16(); temp.PDef = stream.ReadUInt16(); temp.MAtk = stream.ReadUInt16(); temp.MDef = stream.ReadUInt16(); stream.ReadUInt16(); // empty temp.Always30 = stream.ReadUInt16(); // potions food and boxes, always 30 temp.Unk30 = stream.ReadUInt16(); stream.ReadUInt32(); // empty temp.Unk31 = stream.ReadUInt16(); temp.Unk32 = stream.ReadUInt16(); // only no image item stream.ReadUInt16(); // empty temp.Unk33 = stream.ReadUInt16(); // colored sets with more parts stream.ReadUInt16(); // empty stream.ReadUInt16(); // empty stream.ReadUInt16(); // empty temp.Quality = stream.ReadUInt16(); // 136 temp.Tradeable = (stream.ReadUInt16() & 256) == 0; stream.ReadUInt32(); // empty stream.ReadUInt32(); // empty stream.ReadUInt32(); // empty temp.Durability = stream.ReadUInt16(); stream.ReadUInt16(); // empty stream.ReadUInt16(); // empty temp.Effect1 = stream.ReadUInt16(); temp.Effect2 = stream.ReadUInt16(); temp.Effect3 = stream.ReadUInt16(); temp.Effect1Value = stream.ReadUInt16(); temp.Effect2Value = stream.ReadUInt16(); temp.Effect3Value = stream.ReadUInt16(); temp.Unk37 = stream.ReadByte() == 1; temp.Unk38 = stream.ReadByte() == 1; //170 temp.Reinforceable = (stream.ReadByte() & 1) == 0; temp.Rank = stream.ReadByte(); temp.Unk41 = stream.ReadByte(); temp.Unk42 = stream.ReadByte(); temp.TestItem = stream.ReadByte(); // item test, only one stream.ReadByte(); temp.MaxLevel = stream.ReadUInt16(); stream.ReadUInt16(); // empty temp.Unk44 = stream.ReadUInt16(); stream.ReadUInt16(); // empty temp.Unk45 = stream.ReadByte(); temp.Unk46 = stream.ReadByte(); temp.Unk47 = stream.ReadUInt16(); temp.Unk48 = stream.ReadByte(); temp.Unk49 = stream.ReadByte(); temp.Unk50 = stream.ReadByte(); temp.Unk51 = stream.ReadByte(); temp.Unk52 = stream.ReadInt32(); temp.Unk53 = stream.ReadByte(); temp.Unk54 = stream.ReadByte(); temp.Always15 = stream.ReadUInt16(); // potions and bullet, always 15 temp.Unk56 = stream.ReadByte(); temp.Unk57 = stream.ReadByte(); temp.Unk58 = stream.ReadUInt16(); temp.Unk59 = stream.ReadByte() == 1; temp.Unk60 = stream.ReadByte(); stream.ReadByte(); temp.Unk61 = stream.ReadByte() == 1; i++; if (!string.IsNullOrEmpty(temp.ItemName)) { list.Add(temp); } } JsonData = JsonConvert.SerializeObject(list, Formatting.Indented); } }