Morozzko.2136 Posted August 7, 2019 Share Posted August 7, 2019 Any solution how to check inventory of all characters? var connect = new WebClient() { Encoding = Encoding.UTF8 }.DownloadString(url); var getid = Getid.FromJson(connect); foreach (string i in getid) { ####### } Link to comment Share on other sites More sharing options...
Gorilla.4120 Posted August 8, 2019 Share Posted August 8, 2019 Code:https://gist.github.com/GorillaNuggets/e72f08c587c11b1a4a9c00527bc9d1e6This code is split between two functions. 1) Looks for items in all characters inventories. 2) Looks for items in the material storage area.P.S. For some reason, the forums isn't redirecting to my url. You might have to copy and paste it in to your browser. Link to comment Share on other sites More sharing options...
Gorilla.4120 Posted August 8, 2019 Share Posted August 8, 2019 Also, make sure when setting up your API key, that you don't forget to include inventories and characters :) Link to comment Share on other sites More sharing options...
Morozzko.2136 Posted August 8, 2019 Author Share Posted August 8, 2019 Ty, very helpfull and how u avoid the problem with uncoding FR and DE symbols in name (Magè)? Link to comment Share on other sites More sharing options...
Gorilla.4120 Posted August 8, 2019 Share Posted August 8, 2019 Using UTF8 on your WebClient should avoid any decoding problems. If you do not specify an encoder, the program will use your default. This can cause problems with the letters in your character names.private static readonly WebClient HttpClient = new WebClient {Encoding = Encoding.UTF8}; Link to comment Share on other sites More sharing options...
Gorilla.4120 Posted August 8, 2019 Share Posted August 8, 2019 I created a new character named just to test the code. It worked fine. :) Link to comment Share on other sites More sharing options...
Morozzko.2136 Posted August 13, 2019 Author Share Posted August 13, 2019 Thank you! its work properly, and how i can do same for bank?System.InvalidOperationException: "Cannot access child value on Newtonsoft.Json.Linq.JValue."from private static int CheckBank(int itemId) { var url = @"https://api.guildwars2.com/v2/account/bank?access_token=" + ApiKey; var json = HttpClient.DownloadString(url); var bank = JArray.Parse(json); var itemCount = 0; foreach (var slot in bank) { if (int.Parse(slot["id"].ToString()) == itemId) { itemCount += int.Parse(slot["count"].ToString()); } } return itemCount;and how i can find same in eqiupment slot, for example check, if player have 81007 (druid stone) or 81908 (aurora) make += 1 Link to comment Share on other sites More sharing options...
Gorilla.4120 Posted August 13, 2019 Share Posted August 13, 2019 I think that's because you're running in to null in your json data. Try this: private static int CheckBank(int itemId) { var url = @"https://api.guildwars2.com/v2/account/bank?access_token=" + ApiKey; var json = HttpClient.DownloadString(url); var bank = JArray.Parse(json); return bank .Where(slot => slot.HasValues && (int)slot["id"] == itemId) .Sum(slot => (int)slot["count"]); } Link to comment Share on other sites More sharing options...
Gorilla.4120 Posted August 13, 2019 Share Posted August 13, 2019 As for the equipment question, just follow my first example. https://api.guildwars2.com/v2/characters?ids=all&access_token=Instead of using character["bags"] use character["equipment"] Link to comment Share on other sites More sharing options...
Gorilla.4120 Posted August 13, 2019 Share Posted August 13, 2019 Also, if you're not familiar with Language Integrated Query (LINQ), give this a read:https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/It's a powerful query tool that can be very helpful when sifting through data. Link to comment Share on other sites More sharing options...
Gorilla.4120 Posted August 13, 2019 Share Posted August 13, 2019 See how I used LINQ to find each object within this JSONYou can do the same to find your equipment :) Link to comment Share on other sites More sharing options...
Morozzko.2136 Posted August 14, 2019 Author Share Posted August 14, 2019 @"Mighty Cole.7849" said:As for the equipment question, just follow my first example. https://api.guildwars2.com/v2/characters?ids=all&access_token=Instead of using character["bags"] use character["equipment"]thanks a lot, and instead from item in bag["bag"] to from item in bag["slot"] Link to comment Share on other sites More sharing options...
Morozzko.2136 Posted August 14, 2019 Author Share Posted August 14, 2019 hmm, seems harder, it return 0, how i can check if id 81908 in "Accessory1" or "Accessory2" Link to comment Share on other sites More sharing options...
Gorilla.4120 Posted August 14, 2019 Share Posted August 14, 2019 Are you looking for something like this?https://gist.github.com/GorillaNuggets/db013c0f09c7281761c19bdfe7999cd9It will go through each of your characters and assign a true or false if Accessory1 or Accessory2 has item number 81908 in it. Link to comment Share on other sites More sharing options...
Gorilla.4120 Posted August 14, 2019 Share Posted August 14, 2019 If you want to do a individual character, you can try something like this:https://gist.github.com/GorillaNuggets/763a3506eecaf0f4b5fec550cefae998 Link to comment Share on other sites More sharing options...
Morozzko.2136 Posted August 15, 2019 Author Share Posted August 15, 2019 @"Mighty Cole.7849" said:Are you looking for something like this?https://gist.github.com/GorillaNuggets/db013c0f09c7281761c19bdfe7999cd9It will go through each of your characters and assign a true or false if Accessory1 or Accessory2 has item number 81908 in it.yeah, i make this from your code, now will try to do "quest helper" for legendarys static int CheckCharactersEquipment(int itemId) { var url = $"https://api.guildwars2.com/v2/characters?ids=all&&access_token=" + ApiKey; var json = HttpClient.DownloadString(url); var characters = JArray.Parse(json); var itemCount = 0; foreach (var character in characters) { if (CheckAccessory(character, "Accessory2", itemId) == true || CheckAccessory(character, "Accessory1", itemId) == true) { itemCount += 1; } } return itemCount; } private static bool CheckAccessory(JToken character, string slot, int itemId) { var accessory = from equipment in character["equipment"] where equipment.HasValues where (string)equipment["slot"] == slot select (int)equipment["id"]; var isInAccessory = false; foreach (var item in accessory) { if (item == itemId) { isInAccessory = true; } } return isInAccessory; } Link to comment Share on other sites More sharing options...
Morozzko.2136 Posted August 15, 2019 Author Share Posted August 15, 2019 { var itemCount = 0; itemCount += CheckCharactersInventory(itemId); itemCount += CheckMaterialStorage(itemId); itemCount += CheckBank(itemId); itemCount += CheckCharactersEquipment(itemId); return itemCount; }and full count like this, thank you very much Link to comment Share on other sites More sharing options...
Gorilla.4120 Posted August 15, 2019 Share Posted August 15, 2019 You're Welcome :)If there is anything I can help you with, just let me know.Also, if you have a lot of code and want to share it on the forums, I'd recommend using something likehttps://pastebin.com/For example:https://pastebin.com/G4SVsq0mIt's easier for people to read and creates less clutter on the forum. Plus, you can use it for free. :D Link to comment Share on other sites More sharing options...
Morozzko.2136 Posted September 25, 2019 Author Share Posted September 25, 2019 Hey it again me, How can i take all bosses names from "https://api.guildwars2.com/v2/raids?ids=all"?i did like this, but i know this i bad mechanic:var url = @"https://api.guildwars2.com/v2/raids?ids=all";var json = HttpClient.DownloadString(url);var raid = JArray.Parse(json); foreach (var raidwing in raid) { foreach (var z in raidwing) { foreach (var i in z) { foreach (var k in i) { foreach (var zk in k) { foreach (var iki in zk) { foreach (var boss in iki) { MessageBox.Show(boss.ToString()); } } } } } } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.