Jump to content
  • Sign Up

How i can calculate total ectoplasm on account? C#


Morozzko.2136

Recommended Posts

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};

VoKATfZ.png

Link to comment
Share on other sites

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

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

@"Mighty Cole.7849" said:Are you looking for something like this?

https://gist.github.com/GorillaNuggets/db013c0f09c7281761c19bdfe7999cd9

It 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

  • 1 month later...

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...