Created
August 14, 2019 22:37
-
-
Save GorillaNuggets/763a3506eecaf0f4b5fec550cefae998 to your computer and use it in GitHub Desktop.
This will check a single 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 CheckCharacterAccessory | |
{ | |
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 characterName = "PASTE YOUR CHARACTER NAME HERE"; | |
Console.WriteLine($"Item {itemId} is in Accessory slot #1? {CheckAccessory(characterName, "Accessory1", itemId)}"); | |
Console.WriteLine($"Item {itemId} is in Accessory slot #2? {CheckAccessory(characterName, "Accessory2", itemId)}"); | |
Console.ReadLine(); | |
} | |
private static bool CheckAccessory(string characterName, string slot, int itemId) | |
{ | |
var url = $"https://api.guildwars2.com/v2/characters/{characterName}?access_token={ApiKey}"; | |
var json = HttpClient.DownloadString(url); | |
var character = JObject.Parse(json); | |
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