clash-royale-api icon indicating copy to clipboard operation
clash-royale-api copied to clipboard

Add complete information for each card and level

Open yorkfx opened this issue 7 years ago • 24 comments

[{
"Name": "Archers",
"idName": "archers",
"Rarity": "Common",
"type": "Troop",
"Cost": "3",
"Range": "5",
"DeployTime": "1",
"HitSpeed": "1.2",
"arena": 0,
"elixirCost": 3,
"description": "A pair of unarmored ranged attackers. They'll help you with ground and air unit attacks, but you're on your own with coloring your hair.",
"statistics":   [
    {"Levels": "1", "Hitpoints":"125", "Damage": "40", "DPS": "33"},
    {"Levels": "2", "Hitpoints":"137", "Damage": "44", "DPS": "36"},
    {"Levels": "3", "Hitpoints":"151", "Damage": "48", "DPS": "40"},
    {"Levels": "4", "Hitpoints":"166", "Damage": "53", "DPS": "44"},
    {"Levels": "5", "Hitpoints":"182", "Damage": "58", "DPS": "48"},
    {"Levels": "6", "Hitpoints":"200", "Damage": "64", "DPS": "53"},
    {"Levels": "7", "Hitpoints":"220", "Damage": "70", "DPS": "56"},
    {"Levels": "8", "Hitpoints":"241", "Damage": "77", "DPS": "64"},
    {"Levels": "9", "Hitpoints":"265", "Damage": "84", "DPS": "70"},
    {"Levels": "10", "Hitpoints":"291", "Damage": "93", "DPS": "77"},
    {"Levels": "11", "Hitpoints":"320", "Damage": "102", "DPS": "85"},
    {"Levels": "12", "Hitpoints":"351", "Damage": "112", "DPS": "93"},
    {"Levels": "13", "Hitpoints":"386", "Damage": "123", "DPS": "102"}
]
}

]

yorkfx avatar Aug 10 '16 00:08 yorkfx

+1

lucascampelo avatar Sep 02 '16 13:09 lucascampelo

It is a great suggestion, but unluckily there is a LOT of different options like hitpoints, damage, dps, etc. and as Supercell updates the balance of the game really often it is quite difficult for me to keep that information updated.

I will leave this issue open, feel free to submit a pull request if you want help with this, I will try to work on this feature in the future.

Thanks!

martincarrera avatar Feb 05 '17 14:02 martincarrera

@martincarrera Yes, it's almost impossible to do so unless people can contribute info or something like that which is not needed.

Need to change the issue title to something proper.

AmirSavand avatar Feb 12 '17 17:02 AmirSavand

At least, could be possible to have cards level at tournament rules? It should be easier

barreeeiroo avatar Mar 20 '17 21:03 barreeeiroo

does anyone have an idea where the game store card stats? I can decode csv files and gather that info. another option is getting them from the wikia. I can also do that but we would echo any errors they have in their database so I'd prefer the 1st option.

MaherFa avatar Mar 21 '17 20:03 MaherFa

I'm already on it, I decoded characters.csv and found so many ordered useful information. I will not leave this issue until I have them all ordered in a table and ready to be implemented, It'll take some time tho. I will keep you guys updated here.

MaherFa avatar Mar 21 '17 20:03 MaherFa

Option 1: Getting info from Wikia

I managed to write a simple code that extracts stats and info from wikia page tables without the images in th, it also includes name, idName and statsDate to keep track of latest update.

if we agree to use this method I will write special rules store numerical values as integers instead of strings

how to test: go to http://clashroyale.wikia.com/wiki/Knight, open console and paste the following code

  var myRows = [];
  var $headers = $("#unit-statistics-table th");
  var $rows = $("#unit-statistics-table tr:not(:first-child)").each(function(index) {
      $cells = $(this).find("td");
      myRows[index] = {};
      $cells.each(function(cellIndex) {
          myRows[index][$($headers[cellIndex]).clone().children().remove().end().text().trim().toLowerCase().split(" ").join("-")] = $(this).text().trim();
      });
  });

  var myObj = {}
  myObj.name = $(".header-title h1").text().trim();
  myObj.idName = $(".header-title h1").text().trim().toLowerCase().split(" ").join("-")
  $("#unit-attributes-table tr th").each(function(index) {
      var thisTH = $(this).clone().children().remove().end().text().trim().toLowerCase().split(" ").join("-")
      var thisTD = $("#unit-attributes-table tr td").eq(index).text().trim()
      myObj[thisTH] = thisTD
  });
  myObj.stats = myRows;
  myObj.statsDate = new Date().toISOString()
  console.log(myObj);

you will get and object called myObj that looks like this:

  {
    "name": "Knight",
    "idName": "knight",
    "cost": "3",
    "hit-speed": "1.1 sec",
    "speed": "Medium (60)",
    "deploy-time": "1 sec",
    "range": "Melee",
    "target": "Ground",
    "count": "x1",
    "transport": "Ground",
    "type": "Troop",
    "rarity": "Common",
    "stats": [
        {
            "level": "1",
            "hitpoints": "660",
            "damage": "75",
            "damage-per-second": "68"
        },
        {
            "level": "2",
            "hitpoints": "726",
            "damage": "82",
            "damage-per-second": "74"
        },
        {
            "level": "3",
            "hitpoints": "798",
            "damage": "90",
            "damage-per-second": "81"
        },
        {
            "level": "4",
            "hitpoints": "877",
            "damage": "99",
            "damage-per-second": "90"
        },
        {
            "level": "5",
            "hitpoints": "963",
            "damage": "109",
            "damage-per-second": "99"
        },
        {
            "level": "6",
            "hitpoints": "1,056",
            "damage": "120",
            "damage-per-second": "109"
        },
        {
            "level": "7",
            "hitpoints": "1,161",
            "damage": "132",
            "damage-per-second": "120"
        },
        {
            "level": "8",
            "hitpoints": "1,273",
            "damage": "144",
            "damage-per-second": "130"
        },
        {
            "level": "9",
            "hitpoints": "1,399",
            "damage": "159",
            "damage-per-second": "144"
        },
        {
            "level": "10",
            "hitpoints": "1,537",
            "damage": "174",
            "damage-per-second": "158"
        },
        {
            "level": "11",
            "hitpoints": "1,689",
            "damage": "192",
            "damage-per-second": "174"
        },
        {
            "level": "12",
            "hitpoints": "1,854",
            "damage": "210",
            "damage-per-second": "190"
        },
        {
            "level": "13",
            "hitpoints": "2,039",
            "damage": "231",
            "damage-per-second": "210"
        }
    ],
    "statsDate": "2017-03-22T08:20:55.031Z"
}

MaherFa avatar Mar 22 '17 08:03 MaherFa

Option 2: Getting info from game files

I managed to extract and decode official csv files, I narrowed down related files to these:

https://github.com/MaherFa/temp-csv-files

characters.decoded.csv

includes data like Rarity SightRange DeployTime ChargeRange Speed Hitpoints HitSpeed LoadTime Damage DamageSpecial CrownTowerDamagePercent

• DPS is calculated using HitSpeed and Damage

• Ranged units doesn't have Damage value, but they have a Projectile value that can be used to get data from projectiles.decoded.csv

projectiles.decoded.csv

       includes data about ranged units and some direct damage spells

character_buffs.decoded.csv

       includes information about elements that affect characters like Rage, Heal, Poison and Freeze

buildings.decoded.csv

       buildings

area_effect_objects.decoded.csv

       area effect spells and cards

• some cards are listed with different names from game names, for example Executioner is called AxeMan • stats are listed for Level 1 cards, sowe need to figure out the formula (multiplayer) to calculate stats for each level.

I believe this method is much better than the first option but it'll require more initial work. but once we have the script that extracts data from files we can automate the whole proccess for future updates.

MaherFa avatar Mar 22 '17 09:03 MaherFa

@martincarrera I have no experience with MongoDB, but I can loop through wikia pages and generate a JSON with all the info they have, and I think it should be easy to merge the result with the existing database. what do you think?

MaherFa avatar Mar 22 '17 09:03 MaherFa

Hi, I think the best way should be the first one.

If you could provide me a JSON with the complete data of all the cards, I can update the API model to support that information and update the API.

I could try to create a tiny script to run your code, but as I don't have a lot of time this days, it may take a couple of weeks.

Thanks!

martincarrera avatar Mar 22 '17 12:03 martincarrera

already on it, I'm writing a node.js script that takes card names from an array and generate wikia links and http rquest them. I'm also using jsdom and jquery to run the code inside of node.

it should be ready within 48 hours max, depending on my free time.

Some mico issues: • should key names be like hit-speed or hitSpeed? • should I use damage-per-second/damagePerSecond or dps • should speed include an integer or a string or both? I think using a number is better for combaring cards • I'm also thinking about removing the unit sec from time values and maybe multiply by 1000 to get rid of the decimals so "1.1 sec" would become 1100

MaherFa avatar Mar 22 '17 13:03 MaherFa

  1. Use camelCase if it's possible, such as hitSpeed instead of hit-speed.
  2. dps should be ok
  3. Take into account that some cards may have a range in some attributes, such as the inferno damage 20-400 instead of a simple value, or the goblin gang hitpoints 80/52. In this cases, use a string if possible.
  4. I think the best would be to multiply it by 1000 so that all units are in milliseconds.

martincarrera avatar Mar 22 '17 14:03 martincarrera

@martincarrera Full JSON file is ready, where should I upload it?

MaherFa avatar Mar 22 '17 20:03 MaherFa

Could you create a public gist and share the url?

I can work on that.

Thanks!

martincarrera avatar Mar 23 '17 00:03 martincarrera

Here it is

it's a duplicate of your cards.json with same order and length with new keys. also I spent some time to create a help file to clear everything for users, including units, types and special cases.

one thing to note, there was two cards with "needs confirmation" tags that we might need to confirm later. Mega Minions Damage and Dark Prince Hitpoints

I hope you guys take a look at the file and point any possible issues and I'll work on them.

but YEAH we finally have it!!!!!

MaherFa avatar Mar 23 '17 09:03 MaherFa

Is there a way to get tournament standards stats? Like torLevel: 9 and we'll know to get level 9.

AmirSavand avatar Mar 23 '17 10:03 AmirSavand

@amirm3hdi I don't know if Martin have plans of implementing this but I see no point in adding this to every card, maybe a separate call with a value for each rarity?

{
    common: 9,
    rare: 7,
    epic: 4,
    legendary: 1
}

for others looking for a way to handle this, you can use conditions with hard coded indexes to get what you want for now:

console.log(getTournyStats(cardObject))

function getTournyStats(myCard) {
    switch (myCard.rarity) {
        case "Common":
            return myCard.stats[8];
            break;
        case "Rare":
            return myCard.stats[6];
            break;
        case "Epic":
            return myCard.stats[3];
            break;
        case "Legendary":
            return myCard.stats[0];
            break;
    }
}

MaherFa avatar Mar 23 '17 11:03 MaherFa

@MaherFa I agree, a tiny code can achieve that. I use a class for each card, so it'll be like: card.getTournyStats() which will do the work.

AmirSavand avatar Mar 23 '17 11:03 AmirSavand

@martincarrera

Can you add soon the levels to your API? All members of my clan are waiting for the levels of each card to add to my bot ;)

https://gist.github.com/MaherFa/2d143da0a707caa7532dfff708643a6d

barreeeiroo avatar Mar 27 '17 13:03 barreeeiroo

@martincarrera if that JSON is hard to work with I can help if you point me to the recommended format you like the data in. I'm also perfecting the StatGrab bot for future updates, requests are welcomed.

MaherFa avatar Mar 27 '17 13:03 MaherFa

added all available icons to be used with stats (https://github.com/martincarrera/clash-royale-api/pull/75/commits/1d27efaf2e9da731cb3cc69016df433bf063d8b8)

MaherFa avatar Mar 30 '17 18:03 MaherFa

  • Should be a exception for in range for Mortar

range [ number ] Except "Goblin Gang" and Mortar range [ string ] Goblin Gang, Mortar separated by a "/" min and max range values.

It says, 311 and should be "3/11" or something like that.

  • Lifetime in Barbarian Hut is 1 sec.
  • Elixir Collector lifetime is 110 sec, should be 70000 (ms).

malarau avatar Apr 13 '17 16:04 malarau

Is this still happening? Is anyone actively working on this api?

BenC14 avatar May 10 '17 17:05 BenC14

Hi @BenC14! I am working on this API on my free time - and to be honest I don't have much since a couple of months ago.

I will try to make this feature as soon as possible, but I can't promise any date or anything.

I will post any news in this thread.

Thanks!

martincarrera avatar May 10 '17 23:05 martincarrera