feat(editor): add WTBR (Token Reward) open catalog format

Open replacement for AzerothCore's currency_token_reward SQL
table plus the per-vendor token redemption rows in npc_vendor.
Each entry says "spend N copies of token X to receive reward Y",
with reward type polymorphism: Y can be an item, a spell (taught
to the character), a title, a mount, a companion pet, a currency
conversion, an heirloom unlock, or a cosmetic (tabard / pennant /
fluff). The rewardId field's interpretation depends on the
rewardKind enum.

Distinct from WTKN (Token catalog) which defines the token
currency items themselves. WTKN says "the Champion's Seal exists
as item 44990"; WTBR says "spend 25 Champion's Seals at Argent
Tournament for the Squire's Belt (item 45517)".

Eight rewardKind values cover the full reward space (Item / Spell
/ Title / Mount / Pet / Currency / Heirloom / Cosmetic), and an
8-tier requiredFactionStanding gates by reputation
(Hated / Hostile / Unfriendly / Neutral / Friendly / Honored /
Revered / Exalted) when paired with a non-zero requiredFactionId.

Cross-references back to WTKN (spentTokenItemId), WIT (Item
rewards), WSPL (Spell rewards), WTIT (Title rewards), WMOU
(Mount rewards), WCMP (Pet rewards), WCTR (Currency conversion
rewards), and WFAC (faction-rep gating). findByToken(itemId)
is the engine helper used by vendor frames to populate the
"what can I buy with these?" list.

Three preset emitters: --gen-tbr (5 raid tier-token redemptions
consuming Trophy of the Crusade and Emblem of Frost),
--gen-tbr-pvp (5 PvP rewards spanning honor / arena / conquest
plus title and tabard kinds), --gen-tbr-faction (5 faction-
gated rewards demonstrating each standing tier from Honored
through Exalted).

Validation enforces id+name+spentTokenItemId+spentTokenCount
presence, rewardKind 0..7, requiredFactionStanding 0..7, no
duplicate ids; warns on:
  - rewardId=0 (no actual reward, vendor offers entry but
    grants nothing)
  - requiredFactionStanding > Neutral with requiredFactionId=0
    (rep gate has no faction to check)
  - Currency conversion item -> itself (typo / config bug)

Wired through the cross-format table; WTBR appears automatically
in all 18 cross-format utilities. Format count 87 -> 88; CLI
flag count 1034 -> 1039.
This commit is contained in:
Kelsi 2026-05-09 23:26:13 -07:00
parent 69857eea18
commit c1c4b8fa12
10 changed files with 711 additions and 0 deletions

View file

@ -0,0 +1,285 @@
#include "pipeline/wowee_token_rewards.hpp"
#include <cstdio>
#include <cstring>
#include <fstream>
namespace wowee {
namespace pipeline {
namespace {
constexpr char kMagic[4] = {'W', 'T', 'B', 'R'};
constexpr uint32_t kVersion = 1;
template <typename T>
void writePOD(std::ofstream& os, const T& v) {
os.write(reinterpret_cast<const char*>(&v), sizeof(T));
}
template <typename T>
bool readPOD(std::ifstream& is, T& v) {
is.read(reinterpret_cast<char*>(&v), sizeof(T));
return is.gcount() == static_cast<std::streamsize>(sizeof(T));
}
void writeStr(std::ofstream& os, const std::string& s) {
uint32_t n = static_cast<uint32_t>(s.size());
writePOD(os, n);
if (n > 0) os.write(s.data(), n);
}
bool readStr(std::ifstream& is, std::string& s) {
uint32_t n = 0;
if (!readPOD(is, n)) return false;
if (n > (1u << 20)) return false;
s.resize(n);
if (n > 0) {
is.read(s.data(), n);
if (is.gcount() != static_cast<std::streamsize>(n)) {
s.clear();
return false;
}
}
return true;
}
std::string normalizePath(std::string base) {
if (base.size() < 5 || base.substr(base.size() - 5) != ".wtbr") {
base += ".wtbr";
}
return base;
}
uint32_t packRgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0xFF) {
return (static_cast<uint32_t>(a) << 24) |
(static_cast<uint32_t>(b) << 16) |
(static_cast<uint32_t>(g) << 8) |
static_cast<uint32_t>(r);
}
} // namespace
const WoweeTokenReward::Entry*
WoweeTokenReward::findById(uint32_t tokenRewardId) const {
for (const auto& e : entries)
if (e.tokenRewardId == tokenRewardId) return &e;
return nullptr;
}
std::vector<const WoweeTokenReward::Entry*>
WoweeTokenReward::findByToken(uint32_t tokenItemId) const {
std::vector<const Entry*> out;
for (const auto& e : entries) {
if (e.spentTokenItemId == tokenItemId) out.push_back(&e);
}
return out;
}
const char* WoweeTokenReward::rewardKindName(uint8_t k) {
switch (k) {
case Item: return "item";
case Spell: return "spell";
case Title: return "title";
case Mount: return "mount";
case Pet: return "pet";
case Currency: return "currency";
case Heirloom: return "heirloom";
case Cosmetic: return "cosmetic";
default: return "unknown";
}
}
const char* WoweeTokenReward::factionStandingName(uint8_t s) {
switch (s) {
case Hated: return "hated";
case Hostile: return "hostile";
case Unfriendly: return "unfriendly";
case Neutral: return "neutral";
case Friendly: return "friendly";
case Honored: return "honored";
case Revered: return "revered";
case Exalted: return "exalted";
default: return "unknown";
}
}
bool WoweeTokenRewardLoader::save(const WoweeTokenReward& cat,
const std::string& basePath) {
std::ofstream os(normalizePath(basePath), std::ios::binary);
if (!os) return false;
os.write(kMagic, 4);
writePOD(os, kVersion);
writeStr(os, cat.name);
uint32_t entryCount = static_cast<uint32_t>(cat.entries.size());
writePOD(os, entryCount);
for (const auto& e : cat.entries) {
writePOD(os, e.tokenRewardId);
writeStr(os, e.name);
writeStr(os, e.description);
writePOD(os, e.spentTokenItemId);
writePOD(os, e.spentTokenCount);
writePOD(os, e.rewardKind);
writePOD(os, e.requiredFactionStanding);
writePOD(os, e.pad0);
writePOD(os, e.pad1);
writePOD(os, e.rewardId);
writePOD(os, e.rewardCount);
writePOD(os, e.requiredFactionId);
writePOD(os, e.iconColorRGBA);
}
return os.good();
}
WoweeTokenReward WoweeTokenRewardLoader::load(
const std::string& basePath) {
WoweeTokenReward out;
std::ifstream is(normalizePath(basePath), std::ios::binary);
if (!is) return out;
char magic[4];
is.read(magic, 4);
if (std::memcmp(magic, kMagic, 4) != 0) return out;
uint32_t version = 0;
if (!readPOD(is, version) || version != kVersion) return out;
if (!readStr(is, out.name)) return out;
uint32_t entryCount = 0;
if (!readPOD(is, entryCount)) return out;
if (entryCount > (1u << 20)) return out;
out.entries.resize(entryCount);
for (auto& e : out.entries) {
if (!readPOD(is, e.tokenRewardId)) {
out.entries.clear(); return out;
}
if (!readStr(is, e.name) || !readStr(is, e.description)) {
out.entries.clear(); return out;
}
if (!readPOD(is, e.spentTokenItemId) ||
!readPOD(is, e.spentTokenCount) ||
!readPOD(is, e.rewardKind) ||
!readPOD(is, e.requiredFactionStanding) ||
!readPOD(is, e.pad0) ||
!readPOD(is, e.pad1) ||
!readPOD(is, e.rewardId) ||
!readPOD(is, e.rewardCount) ||
!readPOD(is, e.requiredFactionId) ||
!readPOD(is, e.iconColorRGBA)) {
out.entries.clear(); return out;
}
}
return out;
}
bool WoweeTokenRewardLoader::exists(const std::string& basePath) {
std::ifstream is(normalizePath(basePath), std::ios::binary);
return is.good();
}
WoweeTokenReward WoweeTokenRewardLoader::makeRaidTokens(
const std::string& catalogName) {
using T = WoweeTokenReward;
WoweeTokenReward c;
c.name = catalogName;
auto add = [&](uint32_t id, const char* name, uint32_t tokenItem,
uint32_t tokenCount, uint32_t rewardItem,
const char* desc) {
T::Entry e;
e.tokenRewardId = id; e.name = name; e.description = desc;
e.spentTokenItemId = tokenItem;
e.spentTokenCount = tokenCount;
e.rewardKind = T::Item;
e.rewardId = rewardItem;
e.rewardCount = 1;
e.iconColorRGBA = packRgba(180, 100, 240); // raid epic purple
c.entries.push_back(e);
};
// Item 47241 = Trophy of the Crusade (T9 redeem token).
// Item 49426 = Emblem of Frost (T10 redeem token).
// Item ids on the right are illustrative tier-set helms.
add(1, "T9_Conqueror_Helm", 47241, 1, 47242,
"T9 Conqueror's Helm — 1 Trophy of the Crusade.");
add(2, "T9_Vanquisher_Chest",47241, 1, 47243,
"T9 Vanquisher's Chest — 1 Trophy of the Crusade.");
add(3, "T10_Protector_Legs", 49426, 95, 50688,
"T10 Protector's Greaves — 95 Emblem of Frost.");
add(4, "T10_Trophy_Gloves", 49426, 60, 50689,
"T10 Trophy Gauntlets — 60 Emblem of Frost.");
add(5, "T10_Helm_Crusader", 49426, 95, 50690,
"T10 Crusader's Helm — 95 Emblem of Frost.");
return c;
}
WoweeTokenReward WoweeTokenRewardLoader::makePvP(
const std::string& catalogName) {
using T = WoweeTokenReward;
WoweeTokenReward c;
c.name = catalogName;
auto add = [&](uint32_t id, const char* name, uint32_t tokenItem,
uint32_t tokenCount, uint8_t rewardKind,
uint32_t rewardId, const char* desc) {
T::Entry e;
e.tokenRewardId = id; e.name = name; e.description = desc;
e.spentTokenItemId = tokenItem;
e.spentTokenCount = tokenCount;
e.rewardKind = rewardKind;
e.rewardId = rewardId;
e.rewardCount = 1;
e.iconColorRGBA = packRgba(220, 80, 100); // pvp red
c.entries.push_back(e);
};
// Honor Points = 43308; Arena Points = 29024 (item form).
add(100, "PvPMount_Stallion", 43308, 50000, T::Mount,
4806, "PvP Stallion — 50000 honor points.");
add(101, "ArenaWeapon_Sword", 29024, 3650, T::Item,
51811, "Arena Season 8 Sword — 3650 Arena Points.");
add(102, "PvPHelm_Wrathful", 29024, 1650, T::Item,
51812, "Wrathful Gladiator's Helm — 1650 Arena Points.");
add(103, "ConquestTitle_Combatant",29024, 50, T::Title,
38, "Combatant title — 50 Arena Points.");
add(104, "PvPTabard", 43308, 3000, T::Cosmetic,
45984, "PvP Tabard — 3000 honor points.");
return c;
}
WoweeTokenReward WoweeTokenRewardLoader::makeFaction(
const std::string& catalogName) {
using T = WoweeTokenReward;
WoweeTokenReward c;
c.name = catalogName;
auto add = [&](uint32_t id, const char* name, uint32_t tokenItem,
uint32_t tokenCount, uint8_t rewardKind,
uint32_t rewardId, uint32_t factionId,
uint8_t standing, const char* desc) {
T::Entry e;
e.tokenRewardId = id; e.name = name; e.description = desc;
e.spentTokenItemId = tokenItem;
e.spentTokenCount = tokenCount;
e.rewardKind = rewardKind;
e.rewardId = rewardId;
e.rewardCount = 1;
e.requiredFactionId = factionId;
e.requiredFactionStanding = standing;
e.iconColorRGBA = packRgba(100, 200, 100); // faction green
c.entries.push_back(e);
};
// Token items: Champion's Seal (44990, Argent Tournament),
// Spear-fragment of Hodir (41511, Sons of Hodir).
add(200, "ArgentTabard", 44990, 25, T::Cosmetic, 45984, 1106, T::Honored,
"Argent Tournament tabard — 25 Champion's Seals "
"@ Honored with Argent Crusade.");
add(201, "HodirMammoth", 41511,200, T::Mount, 44171, 1119, T::Exalted,
"Sons of Hodir Mammoth — 200 Spear-fragments "
"@ Exalted with Sons of Hodir.");
add(202, "CenarionRing", 20809,150, T::Item, 19438, 609, T::Revered,
"Cenarion Ring of Casting — 150 Marks of Cenarion "
"@ Revered with Cenarion Circle.");
add(203, "ArgentTitle", 44990,250, T::Title, 149, 1106, T::Exalted,
"Crusader title — 250 Champion's Seals @ Exalted "
"with Argent Crusade.");
add(204, "WintergraspPet",43589, 30, T::Pet, 45890, 1156, T::Honored,
"Wintergrasp commemorative pet — 30 Wintergrasp "
"Marks @ Honored with The Wintergrasp Defenders.");
return c;
}
} // namespace pipeline
} // namespace wowee