Last active
August 15, 2019 03:09
-
-
Save GorillaNuggets/db013c0f09c7281761c19bdfe7999cd9 to your computer and use it in GitHub Desktop.
Check each characters accessory slots for item #81908
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json.Linq; | |
using System; | |
using System.Linq; | |
using System.Net; | |
using System.Text; | |
namespace CheckAllAccessories | |
{ | |
class Program | |
{ | |
private const string apiKey = "PASTE YOUR API KEY HERE"; | |
private static readonly WebClient HttpClient = new WebClient { Encoding = Encoding.UTF8 }; | |
static void Main(string[] args) | |
{ | |
var itemId = 81908; | |
var url = $"https://api.guildwars2.com/v2/characters?ids=all&&access_token={apiKey}"; | |
var json = HttpClient.DownloadString(url); | |
var characters = JArray.Parse(json); | |
foreach (var character in characters) | |
{ | |
Console.WriteLine((string)character["name"]); | |
Console.WriteLine($"Item {itemId} is in Accessory slot #1? {CheckAccessory(character, "Accessory1", itemId)}"); | |
Console.WriteLine($"Item {itemId} is in Accessory slot #2? {CheckAccessory(character, "Accessory2", itemId)}"); | |
Console.WriteLine(); | |
} | |
Console.ReadLine(); | |
} | |
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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment