diff --git a/dataimporter/factions.py b/dataimporter/factions.py index 4d213d2e..df0fe49b 100644 --- a/dataimporter/factions.py +++ b/dataimporter/factions.py @@ -8,6 +8,7 @@ IGNORE_FACTION_ID = [ 949, # Test Faction 1 + 1072, # [DNT] AC Major Faction Child Renown Test # Never implemented 1351, # The Brewmasters @@ -139,7 +140,53 @@ def fix_types_data(self): else: faction['id'] = int(faction['id']) + def fix_max_renown(self): + # Add renown information to reputations with a renown system + # such as the main factions in Dragonflight. + dbc_faction_to_covenant = { + int(e['FactionID']): int(e['ID']) for e in self.dbc_get_table('covenant') + } + + # Compute the maximum renown for each covenant + max_reward_for_covenant = {} + for row in self.dbc_get_table('renownrewards'): + covenant_id = int(row['CovenantID']) + if covenant_id not in max_reward_for_covenant: + max_reward_for_covenant[covenant_id] = int(row['Level']) + else: + max_reward_for_covenant[covenant_id] = max(int(row['Level']), max_reward_for_covenant[covenant_id]) + + # Populate the 'renown' object for every renown faction + for cat in self.factions: + for faction in cat['factions']: + faction_id = faction['id'] + + # DBC faction flag 2 indicates that it is a "renown faction". + # Some valid renown factions filtered from the self.dbc_faction + # (e.g. Maruuk Centaur and Valdrakken Accord which have child factions) + # but can still be computed automatically if they have a 'renown' + # property in the JSON. + if ( + faction_id in dbc_faction_to_covenant + and ( + ( + faction_id in self.dbc_faction + and int(self.dbc_faction[faction_id]['Flags']) == 2 + ) + + or 'renown' in faction + ) + ): + if 'renown' not in faction: + faction['renown'] = dict() + + if faction_id in self.dbc_faction: + faction['renown']['step'] = int(self.dbc_faction[faction_id]['ReputationMax[0]']) + + faction['renown']['max'] = max_reward_for_covenant[dbc_faction_to_covenant[faction_id]] + def run(self): self.fix_missing_factions() self.fix_types_data() + self.fix_max_renown() return [self.factions] diff --git a/src/api/reputations.js b/src/api/reputations.js index 2738becd..69868009 100644 --- a/src/api/reputations.js +++ b/src/api/reputations.js @@ -44,7 +44,8 @@ function parseFactions(all_factions, my_reputations) { var calculatedPerc = (rep.standing.value / rep.standing.max) * 100; standing[rep.faction.id] = { - level: rep.standing.tier, + // tier is called renown_level for renown factions such as those in dragonflight + level: rep.standing.tier != undefined ? rep.standing.tier : rep.standing.renown_level, perc: (isNaN(calculatedPerc) ? 100 : calculatedPerc), value: rep.standing.value, max: rep.standing.max @@ -70,6 +71,13 @@ function parseFactions(all_factions, my_reputations) { levels: levelsAsList(faction.levels ? faction.levels : defaultLevels), }; + // If it's a faction with renown such as Dragonflight factions + if (faction.renown) { + const step = faction.renown.step || 2500; + f.levels = renownToLevels(faction.renown.max, step); + f.renown = true; + } + var stand = standing[faction.id]; if (stand) { @@ -102,3 +110,11 @@ function levelsAsList(levelsDict) { } return items; } + +function renownToLevels(max, step) { + var items = []; + for (i = 0; i <= max; i++) { + items.push([i * step, "Renown " + i]) + } + return items; +} diff --git a/src/components/ReputationRow.svelte b/src/components/ReputationRow.svelte index 4e6716ae..dad3ac94 100644 --- a/src/components/ReputationRow.svelte +++ b/src/components/ReputationRow.svelte @@ -17,7 +17,9 @@ return levelColors[ Math.max( 0, - levelColors.length - (faction.levels.length - level) + faction.renown ? + Math.floor((level / faction.levels.length) * (levelColors.length - 1)) : + levelColors.length - (faction.levels.length - level) ) ]; } diff --git a/static/data/factions.json b/static/data/factions.json index 5644db78..c2b6cf78 100644 --- a/static/data/factions.json +++ b/static/data/factions.json @@ -8,6 +8,113 @@ ], "name": "Guild" }, + { + "factions": [ + { + "id": 2507, + "name": "Dragonscale Expedition", + "renown": { + "max": 25, + "step": 2500 + } + }, + { + "id": 2503, + "name": "Maruuk Centaur", + "renown": { + "max": 25, + "step": 2500 + } + }, + { + "id": 2511, + "name": "Iskaara Tuskarr", + "renown": { + "max": 30, + "step": 2500 + } + }, + { + "id": 2510, + "name": "Valdrakken Accord", + "renown": { + "max": 30, + "step": 2500 + } + }, + { + "id": 2523, + "name": "Dark Talons" + }, + { + "id": 2524, + "name": "Obsidian Warders" + }, + { + "id": 2517, + "levels": { + "0": "Acquaintance", + "8400": "Cohort", + "16800": "Ally", + "25200": "Fang", + "33600": "Friend", + "42000": "True Friend" + }, + "name": "Wrathion" + }, + { + "id": 2518, + "levels": { + "0": "Acquaintance", + "8400": "Cohort", + "16800": "Ally", + "25200": "Fang", + "33600": "Friend", + "42000": "True Friend" + }, + "name": "Sabellian" + }, + { + "id": 2544, + "levels": { + "0": "Neutral", + "500": "Preferred", + "2500": "Respected", + "5500": "Valued", + "12500": "Esteemed" + }, + "name": "Artisan's Consortium - Dragon Isles Branch" + }, + { + "id": 2550, + "levels": { + "0": "Empty", + "300": "Low", + "1200": "Medium", + "3600": "High", + "10000": "Maximum" + }, + "name": "Cobalt Assembly" + }, + { + "id": 2520, + "name": "Clan Nokhud" + }, + { + "id": 2526, + "name": "Winterpelt Furbolg" + }, + { + "id": 2542, + "name": "Clan Ukhel" + }, + { + "id": 2555, + "name": "Clan Kaighan" + } + ], + "name": "Dragonflight" + }, { "factions": [ {