Jump to content
  • Sign Up

How i can calculate total ectoplasm on account? C#


Morozzko.2136

Recommended Posts

![](https://i.imgur.com/LF8WQFO.png "")

 

**Code:**

[https://gist.github.com/GorillaNuggets/e72f08c587c11b1a4a9c00527bc9d1e6](https://gist.github.com/GorillaNuggets/e72f08c587c11b1a4a9c00527bc9d1e6)

 

This 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

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:

> 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

> @"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

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 like

 

https://pastebin.com/

 

For example:

 

https://pastebin.com/G4SVsq0m

 

It'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

  • 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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...