Skip to content

Instantly share code, notes, and snippets.

@GorillaNuggets
Created August 14, 2019 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GorillaNuggets/763a3506eecaf0f4b5fec550cefae998 to your computer and use it in GitHub Desktop.
Save GorillaNuggets/763a3506eecaf0f4b5fec550cefae998 to your computer and use it in GitHub Desktop.
This will check a single characters Accessory slots for item #81908
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