LionelBergen / MundoScript

Node.js League/LoL/League Of Legends API wrapper, Focus is to be easy to use
34 stars 7 forks source link

Translating item and rune id numbers to names #7

Open eazimmer opened 3 years ago

eazimmer commented 3 years ago

More of a question than an issue:

Regarding items, I know within 'participants' each entry has 'item0', 'item1', etc, but how would one go about translating those ids into item names? Similarly, when it comes to runes I can see entries regarding perk0, perk0var1, etc, but where can we translate those id values into the corresponding rune names?

Thanks.

LionelBergen commented 3 years ago

If you run initialize, the data will come back with the actual data rather than the ids. For example: await LeagueAPI.initialize();

eazimmer commented 3 years ago

Hmm, strange. I'm already running initialize. I can tell for sure as I'm getting the "set fully loaded classes" note in my console output. It successfully expanded most ids into objects, but I still see only ids for items and runes. I had to match those ids against current ddragon jsons in order to get the names I was looking for.

LionelBergen commented 3 years ago

Can you show me a code example? It's been a while since I used this

eazimmer commented 3 years ago

Here's a snippet from the relevant function. It grabs a summoner's recent games, chooses the most recent, and throws me a JSON file with the data provided via the gameInfo object.

return await LeagueAPI.initialize()
        .then(async function() {
            return await LeagueAPI.getSummonerByName(player_name)
                .then(async function (accountInfo) {
                    return await LeagueAPI.getMatchList(accountInfo);

                })
                .then(async function (activeGames) {

                    let game_id = await activeGames["matches"][0]["gameId"]; // Grab most recent game
                    return await LeagueAPI.getMatch(game_id)
                        .then(async function (gameInfo) {

                            const jsonString = JSON.stringify(gameInfo)
                            await fs.writeFile('./gameData.json', jsonString, err => {
                                if (err) {
                                    console.log('Error writing file', err)
                                } else {
                                    console.log('Successfully wrote file')
                                }
                            })

If you clean up that output document so it's legible you'll see this:

"participants": [ { "participantId": 1, "stats": { "participantId": 1, "win": true, "item0": 6672, "item1": 3033, "item2": 3031, "item3": 3006, "item4": 1038, "item5": 1029, "item6": 3340, "kills": 10, "deaths": 8, "assists": 11, "largestKillingSpree": 4, "largestMultiKill": 1, "killingSprees": 3, "longestTimeSpentLiving": 254, "doubleKills": 0, "tripleKills": 0, "quadraKills": 0, "pentaKills": 0, "unrealKills": 0, "totalDamageDealt": 88947, "magicDamageDealt": 2633, "physicalDamageDealt": 82667, "trueDamageDealt": 3646, "largestCriticalStrike": 669, "totalDamageDealtToChampions": 22377, "magicDamageDealtToChampions": 1793, "physicalDamageDealtToChampions": 19277, "trueDamageDealtToChampions": 1306, "totalHeal": 3752, "totalUnitsHealed": 4, "damageSelfMitigated": 11448, "damageDealtToObjectives": 10230, "damageDealtToTurrets": 8083, "visionScore": 8, "timeCCingOthers": 35, "totalDamageTaken": 18788, "magicalDamageTaken": 2555, "physicalDamageTaken": 14965, "trueDamageTaken": 1267, "goldEarned": 14560, "goldSpent": 12950, "turretKills": 1, "inhibitorKills": 0, "totalMinionsKilled": 91, "neutralMinionsKilled": 0, "neutralMinionsKilledTeamJungle": 0, "neutralMinionsKilledEnemyJungle": 0, "totalTimeCrowdControlDealt": 422, "champLevel": 16, "visionWardsBoughtInGame": 0, "sightWardsBoughtInGame": 0, "wardsPlaced": 2, "wardsKilled": 1, "firstBloodKill": false, "firstBloodAssist": false, "firstTowerKill": false, "firstTowerAssist": false, "firstInhibitorKill": false, "firstInhibitorAssist": true, "combatPlayerScore": 0, "objectivePlayerScore": 0, "totalPlayerScore": 0, "totalScoreRank": 0, "playerScore0": 0, "playerScore1": 0, "playerScore2": 0, "playerScore3": 0, "playerScore4": 0, "playerScore5": 0, "playerScore6": 0, "playerScore7": 0, "playerScore8": 0, "playerScore9": 0, "perk0": 8214, "perk0Var1": 1122, "perk0Var2": 0, "perk0Var3": 0, "perk1": 8224, "perk1Var1": 460, "perk1Var2": 0, "perk1Var3": 0, "perk2": 8210, "perk2Var1": 0, "perk2Var2": 0, "perk2Var3": 0, "perk3": 8232, "perk3Var1": 0, "perk3Var2": 50, "perk3Var3": 0, "perk4": 8463, "perk4Var1": 201, "perk4Var2": 0, "perk4Var3": 0, "perk5": 8453, "perk5Var1": 733, "perk5Var2": 97, "perk5Var3": 0, "perkPrimaryStyle": 8200, "perkSubStyle": { "id": 8400, "key": "Resolve", "icon": "perk-images/Styles/7204_Resolve.png", "name": "Resolve", "slots": [ { "runes": [ { "id": 8437, "key": "GraspOfTheUndying", "icon": "perk-images/Styles/Resolve/GraspOfTheUndying/GraspOfTheUndying.png", "name": "Grasp of the Undying", "shortDesc": "Every 4s your next attack on a champion deals bonus magic damage, heals you, and permanently increases your health.", "longDesc": "Every 4s in combat, your next basic attack on a champion will:

  • Deal bonus magic damage equal to 4% of your max health
  • Heals you for 2% of your max health
  • Permanently increase your health by 5

  • Ranged Champions: Damage, healing, and permanent health gained reduced by 40%.
    " }, { "id": 8439, "key": "Aftershock", "icon": "perk-images/Styles/Resolve/VeteranAftershock/VeteranAftershock.png", "name": "Aftershock", "shortDesc": "After immobilizing an enemy champion gain defenses and later deal a burst of magic damage around you.", "longDesc": "After immobilizing an enemy champion, increase your Armor and Magic Resist by 35 + 80% of your Bonus Resists for 2.5s. Then explode, dealing magic damage to nearby enemies.

    Damage: 25 - 120 (+8% of your bonus health)
    Cooldown: 20s

    Resistance bonus from Aftershock capped at: 80-150 (based on level)
    " }, { "id": 8465, "key": "Guardian", "icon": "perk-images/Styles/Resolve/Guardian/Guardian.png", "name": "Guardian", "shortDesc": "Guard allies you cast spells on and those that are very nearby. If you or a guarded ally would take damage based on level, you're both granted a shield.", "longDesc": "Guard allies within 350 units of you, and allies you target with spells for 2.5s. While Guarding, if you or the ally take more than a small amount of damage over the duration of the Guard, both of you gain a shield for 1.5s.

    Cooldown: 70 - 40 seconds
    Shield: 70 - 150 + 15% of your ability power + 9% of your bonus health
    Proc Threshold: 90 - 250 postmitigation damage" } ] }, { "runes": [ { "id": 8446, "key": "Demolish", "icon": "perk-images/Styles/Resolve/Demolish/Demolish.png", "name": "Demolish", "shortDesc": "Charge up a powerful attack against a tower while near it.", "longDesc": "Charge up a powerful attack against a tower over 3s, while within 600 range of it. The charged attack deals 100 (+35% of your max health) bonus physical damage.

    Cooldown: 45s" }, { "id": 8463, "key": "FontOfLife", "icon": "perk-images/Styles/Resolve/FontOfLife/FontOfLife.png", "name": "Font of Life", "shortDesc": "Impairing the movement of an enemy champion marks them. Your allies heal when attacking champions you've marked. ", "longDesc": "Impairing the movement of an enemy champion marks them for 4s.

    Ally champions who attack marked enemies heal for 5 + 1% of your max health over 2s. " }, { "id": 8401, "key": "ShieldBash", "icon": "perk-images/Styles/Resolve/MirrorShell/MirrorShell.png", "name": "Shield Bash", "shortDesc": "Whenever you gain a shield, your next basic attack against a champion deals bonus adaptive damage.", "longDesc": "While shielded, gain 1 - 10 Armor and Magic Resist based on Level.

    Whenever you gain a new shield, your next basic attack against a champion deals 5 - 30 (+1.5% Bonus Health) (+8.5% New Shield Amount) bonus adaptive damage.

    You have up to 2s after the shield expires to use this effect." } ] }, { "runes": [ { "id": 8429, "key": "Conditioning", "icon": "perk-images/Styles/Resolve/Conditioning/Conditioning.png", "name": "Conditioning", "shortDesc": "After 12 min gain +9 Armor and +9 Magic Resist and increase your Armor and Magic Resist by 5%.", "longDesc": "After 12 min gain +9 Armor and +9 Magic Resist and increase your Armor and Magic Resist by 5%." }, { "id": 8444, "key": "SecondWind", "icon": "perk-images/Styles/Resolve/SecondWind/SecondWind.png", "name": "Second Wind", "shortDesc": "After taking damage from an enemy champion heal back some missing health over time. ", "longDesc": "After taking damage from an enemy champion, heal for 4% of your missing health +6 over 10s." }, { "id": 8473, "key": "BonePlating", "icon": "perk-images/Styles/Resolve/BonePlating/BonePlating.png", "name": "Bone Plating", "shortDesc": "After taking damage from an enemy champion, the next 3 spells or attacks you receive from them deal 30-60 less damage.


    Duration: 1.5s
    Cooldown: 45s", "longDesc": "After taking damage from an enemy champion, the next 3 spells or attacks you receive from them deal 30-60 less damage.


    Duration: 1.5s
    Cooldown: 45s" } ] }, { "runes": [ { "id": 8451, "key": "Overgrowth", "icon": "perk-images/Styles/Resolve/Overgrowth/Overgrowth.png", "name": "Overgrowth", "shortDesc": "Gain permanent max health when minions or monsters die near you.", "longDesc": "Absorb life essence from monsters or enemy minions that die near you, permanently gaining 3 maximum health for every 8.

    When you've absorbed 120 monsters or enemy minions, gain an additional 3.5% maximum health." }, { "id": 8453, "key": "Revitalize", "icon": "perk-images/Styles/Resolve/Revitalize/Revitalize.png", "name": "Revitalize", "shortDesc": "Gain 5% Heal and Shield Power.

    Heals and shields you cast or receive are 10% stronger on targets below 40% health.", "longDesc": "Gain 5% Heal and Shield Power.

    Heals and shields you cast or receive are 10% stronger on targets below 40% health." }, { "id": 8242, "key": "Unflinching", "icon": "perk-images/Styles/Sorcery/Unflinching/Unflinching.png", "name": "Unflinching", "shortDesc": "Gain a small amount of tenacity that increases with missing health. ", "longDesc": "Gain 10% Tenacity and 10% Slow Resist. These values increase by up to an additional 20% Tenacity and 20% Slow Resist based on missing health. Maximum value achieved at 30% health. " } ] } ] }, "statPerk0": 5008, "statPerk1": 5008, "statPerk2": 5002 },

    In this example you can see we're only getting item and rune ids instead of full objects. Now, that said, within the "perkSubStyle" section immediately you ARE giving us a full listing of every rune in the user's secondary rune tree, which we could in theory match against the "perk4" and "perk5" ids above - but even then it's a really gnarly dictionary structure - and it only contains information about the secondary tree runes. It looks to be somewhat of a copy paste from the runesReforged.json file. Maybe there's some issue with how you were splicing in data from that file into the gameInfo object against the rune/item ids? Either way, we don't have any way of matching any of the user's primary-tree rune ids (perk 1, perk 2, perk3) against their full objects since we don't have a similar "perkPrimaryStyle" object to what we get in "perkSubStyle".

    That all said, within the same JSON output, lower down, you get:

    "mapObject": { "MapName": "Summoner's Rift", "MapId": "11", "image": { "full": "map11.png", "sprite": "map0.png", "group": "map", "x": 0, "y": 0, "w": 48, "h": 48 } }

    This is important because it was the example you used in your description of the initialize() function on your GitHub page. If initialize() wasn't set, I shouldn't be getting an entire object here, only a map id. The fact we see the entire object hopefully proves that the function has been set correctly on my end.

    Hopefully this helps, if the formatting is too ugly here or you need more information please let me know. I'd be happy to try and help however possible, I'm super thankful for what you've built here and have been using it for a couple months now. I've only now ran into the issue.

    LionelBergen commented 3 years ago

    Sorry I don't understand the issue, you are setting initialize() and looks like you are getting the full objects returned.

    The full object's also have the ID

    eazimmer commented 3 years ago

    Look specifically at item0, item1, item2, item3, item4, item5, item6, and perkPrimaryStyle. They provide only ids, not full objects.

    LionelBergen commented 3 years ago

    Thanks for pointing out this issue. Item0 - item6 have been fixed with the latest version (2.3). I'm going to look at 'statperk0-5' and 'perkPrimaryStyle' etc next

    eazimmer commented 3 years ago

    Thanks, I look forward to seeing the rest of the changes.