Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Enhanced Mount Master List generation

Enhanced Mount Master List

Occasionally I update the Mount Master List with additional details that Blizzard doesn't include by default. Here's the quick steps I use to do so.

Requirements

Steps

  1. Download Blizzard's mount data from their /wow/mount/ endpoint into mounts.json
  2. Extract Mount.db2 and MountXDisplay.db2 from CASC into latest/
  3. Run the script below, php mount-json-transform.php > mounts.full.json

Notes

  • Blizzard may change the column order in the DB2 files between patches.
  • Some mounts are found in the API that aren't in game data, and vice-versa.
  • This may stop working for any reason. Run at your own risk. There are no guarantees and no support.

License

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

<?php
require_once __DIR__ . '/vendor/autoload.php';
use Erorus\DB2\Reader;
$o = json_decode(file_get_contents(__DIR__ . '/mounts.json'), true);
if (json_last_error() != JSON_ERROR_NONE) {
fwrite(STDERR, "JSON error loading mounts.json: " . json_last_error_msg() . "\n");
exit(1);
}
$db2Mount = new Reader(__DIR__ . '/latest/Mount.db2');
$db2Mount->setFieldNames([
0 => 'name',
1 => 'source',
2 => 'description',
7 => 'spell',
]);
$mountsBySpell = [];
$seenSpells = [];
foreach ($db2Mount->generateRecords() as $id => $record) {
$record['id'] = $id;
$mountsBySpell[$record['spell']] = $record;
$seenSpells[$record['spell']] = true;
}
$db2MountXDisplay = new Reader(__DIR__ . '/latest/MountXDisplay.db2');
$db2MountXDisplay->setFieldNames([
0 => 'display',
2 => 'mount',
]);
foreach ($db2MountXDisplay->generateRecords() as $record) {
$mountRec = $db2Mount->getRecord($record['mount']);
if (!isset($mountRec)) {
continue;
}
if (!isset($mountsBySpell[$mountRec['spell']])) {
continue;
}
$mountsBySpell[$mountRec['spell']]['displayId'] = $record['display'];
}
foreach ($o['mounts'] as &$record) {
if (isset($mountsBySpell[$record['spellId']])) {
if (isset($mountsBySpell[$record['spellId']]['displayId'])) {
$record['displayId'] = $mountsBySpell[$record['spellId']]['displayId'];
} else {
fwrite(STDERR, sprintf("No display ID for spell %d - %s\n", $record['spellId'], $record['name']));
}
$record['mountId'] = $mountsBySpell[$record['spellId']]['id'];
$record['description'] = $mountsBySpell[$record['spellId']]['description'];
$record['source'] = $mountsBySpell[$record['spellId']]['source'];
unset($seenSpells[$record['spellId']]);
} else {
fwrite(STDERR, sprintf("No mount found for spell %d - %s\n", $record['spellId'], $record['name']));
}
}
unset($record);
foreach ($seenSpells as $spellId => $bool) {
$record = $mountsBySpell[$spellId];
$o['mounts'][] = [
'name' => $record['name'],
'description' => $record['description'],
'source' => $record['source'],
'mountId' => $record['id'],
'spellId' => $record['spell'],
'displayId' => $record['displayId'] ?? 0,
];
}
usort($o['mounts'], function($a, $b) {
return strcmp($a['name'], $b['name']) ?: ($a['spellId'] - $b['spellId']);
});
echo json_encode($o, JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.