Kelsidavis-WoWee/tools/editor/cli_conditions_catalog.cpp

389 lines
15 KiB
C++
Raw Normal View History

feat(pipeline): add WPCD (Wowee Player Condition) format Novel open replacement for Blizzard's PlayerCondition.dbc + the AzerothCore-style condition_template SQL tables. The 37th open format added to the editor. Defines reusable boolean conditions that other formats can reference for gating: "player has quest X completed", "player level >= N", "player class is mage", "player has item Y in inventory", "WSEA event Z is active". Conditions can be grouped and combined with AND/OR aggregators on a per-group basis: a quest-giver gossip option that says "show only to level 60 alliance mages who completed quest 1234" composes 4 conditions sharing the same groupId with AND aggregation. The runtime walks each group, applies the group's aggregator, and returns the boolean result to the caller. Cross-references with previously-added formats — the targetId field has a polymorphic interpretation by kind: WPCD.targetId (kind=QuestCompleted/Active) -> WQT.questId WPCD.targetId (kind=HasItem) -> WIT.itemId WPCD.targetId (kind=HasSpell) -> WSPL.spellId WPCD.targetId (kind=HasAchievement) -> WACH.achievementId WPCD.targetId (kind=AreaId) -> WMS.areaId WPCD.targetId (kind=EventActive) -> WSEA.eventId WPCD.targetId (kind=HasTitle) -> WTIT.titleId WPCD.targetId (kind=FactionRep) -> WFAC.factionId WPCD.targetId (kind=Class/Race) -> WCHC class/race id Future format extensions can reference WPCD.conditionId in their own gating fields — WTRG triggers gated by player state, WGSP options visible only when conditions are met, WMOU summon spells condition-gated by quest progress, etc. Format: • magic "WPCD", version 1, little-endian • per condition: conditionId / groupId (0 = standalone) / name / description / kind / aggregator / negated / targetId / minValue / maxValue Enums: • Kind (17): AlwaysTrue / AlwaysFalse / QuestCompleted / QuestActive / HasItem / HasSpell / MinLevel / MaxLevel / ClassMatch / RaceMatch / FactionRep / HasAchievement / TeamSize / GuildLevel / EventActive / AreaId / HasTitle • Aggregator (2): And / Or API: WoweeConditionLoader::save / load / exists / findById. Three preset emitters showcase typical usage: • makeStarter — 4 standalone conditions covering the most common kinds (quest-done / has-item / min-level / class) • makeGated — 5 conditions in 2 groups demonstrating AND-aggregation (alliance + mage + lvl 60) and OR-aggregation (did quest 1 OR quest 100) • makeEvent — 3 event-gated conditions cross-referencing WSEA event IDs (Hallow's End / Brewfest / Winter's Veil) CLI added (5 flags, 656 documented total now): --gen-conditions / --gen-conditions-gated / --gen-conditions-event --info-wpcd / --validate-wpcd Validator catches: conditionId=0 + duplicates, kind / aggregator out of range, kinds requiring targetId having target=0 (skips AlwaysTrue/False, MinLevel/MaxLevel, TeamSize, GuildLevel which use min/max instead), TeamSize with min > max.
2026-05-09 18:18:27 -07:00
#include "cli_conditions_catalog.hpp"
#include "cli_arg_parse.hpp"
#include "cli_box_emitter.hpp"
#include "pipeline/wowee_conditions.hpp"
#include <nlohmann/json.hpp>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <string>
#include <vector>
namespace wowee {
namespace editor {
namespace cli {
namespace {
std::string stripWpcdExt(std::string base) {
stripExt(base, ".wpcd");
return base;
}
bool saveOrError(const wowee::pipeline::WoweeCondition& c,
const std::string& base, const char* cmd) {
if (!wowee::pipeline::WoweeConditionLoader::save(c, base)) {
std::fprintf(stderr, "%s: failed to save %s.wpcd\n",
cmd, base.c_str());
return false;
}
return true;
}
void printGenSummary(const wowee::pipeline::WoweeCondition& c,
const std::string& base) {
std::printf("Wrote %s.wpcd\n", base.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" conditions : %zu\n", c.entries.size());
}
int handleGenStarter(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "StarterConditions";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWpcdExt(base);
auto c = wowee::pipeline::WoweeConditionLoader::makeStarter(name);
if (!saveOrError(c, base, "gen-conditions")) return 1;
printGenSummary(c, base);
return 0;
}
int handleGenGated(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "GatedConditions";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWpcdExt(base);
auto c = wowee::pipeline::WoweeConditionLoader::makeGated(name);
if (!saveOrError(c, base, "gen-conditions-gated")) return 1;
printGenSummary(c, base);
return 0;
}
int handleGenEvent(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "EventConditions";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWpcdExt(base);
auto c = wowee::pipeline::WoweeConditionLoader::makeEvent(name);
if (!saveOrError(c, base, "gen-conditions-event")) return 1;
printGenSummary(c, base);
return 0;
}
int handleInfo(int& i, int argc, char** argv) {
std::string base = argv[++i];
bool jsonOut = consumeJsonFlag(i, argc, argv);
base = stripWpcdExt(base);
if (!wowee::pipeline::WoweeConditionLoader::exists(base)) {
std::fprintf(stderr, "WPCD not found: %s.wpcd\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeConditionLoader::load(base);
if (jsonOut) {
nlohmann::json j;
j["wpcd"] = base + ".wpcd";
j["name"] = c.name;
j["count"] = c.entries.size();
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
arr.push_back({
{"conditionId", e.conditionId},
{"groupId", e.groupId},
{"name", e.name},
{"description", e.description},
{"kind", e.kind},
{"kindName", wowee::pipeline::WoweeCondition::kindName(e.kind)},
{"aggregator", e.aggregator},
{"aggregatorName", wowee::pipeline::WoweeCondition::aggregatorName(e.aggregator)},
{"negated", e.negated},
{"targetId", e.targetId},
{"minValue", e.minValue},
{"maxValue", e.maxValue},
});
}
j["entries"] = arr;
std::printf("%s\n", j.dump(2).c_str());
return 0;
}
std::printf("WPCD: %s.wpcd\n", base.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" conditions : %zu\n", c.entries.size());
if (c.entries.empty()) return 0;
std::printf(" id grp kind agg neg target min/max name\n");
for (const auto& e : c.entries) {
std::printf(" %4u %4u %-12s %-3s %u %5u %5d/%-5d %s\n",
e.conditionId, e.groupId,
wowee::pipeline::WoweeCondition::kindName(e.kind),
wowee::pipeline::WoweeCondition::aggregatorName(e.aggregator),
e.negated, e.targetId,
e.minValue, e.maxValue, e.name.c_str());
}
return 0;
}
int handleExportJson(int& i, int argc, char** argv) {
// Mirrors the JSON pairs added for every other novel
// open format. Each condition emits all 9 scalar fields
// plus dual int + name forms for kind and aggregator.
std::string base = argv[++i];
std::string outPath;
if (parseOptArg(i, argc, argv)) outPath = argv[++i];
base = stripWpcdExt(base);
if (outPath.empty()) outPath = base + ".wpcd.json";
if (!wowee::pipeline::WoweeConditionLoader::exists(base)) {
std::fprintf(stderr,
"export-wpcd-json: WPCD not found: %s.wpcd\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeConditionLoader::load(base);
nlohmann::json j;
j["name"] = c.name;
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
arr.push_back({
{"conditionId", e.conditionId},
{"groupId", e.groupId},
{"name", e.name},
{"description", e.description},
{"kind", e.kind},
{"kindName", wowee::pipeline::WoweeCondition::kindName(e.kind)},
{"aggregator", e.aggregator},
{"aggregatorName", wowee::pipeline::WoweeCondition::aggregatorName(e.aggregator)},
{"negated", e.negated},
{"targetId", e.targetId},
{"minValue", e.minValue},
{"maxValue", e.maxValue},
});
}
j["entries"] = arr;
std::ofstream out(outPath);
if (!out) {
std::fprintf(stderr,
"export-wpcd-json: cannot write %s\n", outPath.c_str());
return 1;
}
out << j.dump(2) << "\n";
out.close();
std::printf("Wrote %s\n", outPath.c_str());
std::printf(" source : %s.wpcd\n", base.c_str());
std::printf(" conditions : %zu\n", c.entries.size());
return 0;
}
int handleImportJson(int& i, int argc, char** argv) {
std::string jsonPath = argv[++i];
std::string outBase;
if (parseOptArg(i, argc, argv)) outBase = argv[++i];
if (outBase.empty()) {
outBase = jsonPath;
std::string suffix = ".wpcd.json";
if (outBase.size() > suffix.size() &&
outBase.substr(outBase.size() - suffix.size()) == suffix) {
outBase = outBase.substr(0, outBase.size() - suffix.size());
} else if (outBase.size() > 5 &&
outBase.substr(outBase.size() - 5) == ".json") {
outBase = outBase.substr(0, outBase.size() - 5);
}
}
outBase = stripWpcdExt(outBase);
std::ifstream in(jsonPath);
if (!in) {
std::fprintf(stderr,
"import-wpcd-json: cannot read %s\n", jsonPath.c_str());
return 1;
}
nlohmann::json j;
try { in >> j; }
catch (const std::exception& e) {
std::fprintf(stderr,
"import-wpcd-json: bad JSON in %s: %s\n",
jsonPath.c_str(), e.what());
return 1;
}
auto kindFromName = [](const std::string& s) -> uint8_t {
if (s == "true") return wowee::pipeline::WoweeCondition::AlwaysTrue;
if (s == "false") return wowee::pipeline::WoweeCondition::AlwaysFalse;
if (s == "quest-done") return wowee::pipeline::WoweeCondition::QuestCompleted;
if (s == "quest-active") return wowee::pipeline::WoweeCondition::QuestActive;
if (s == "has-item") return wowee::pipeline::WoweeCondition::HasItem;
if (s == "has-spell") return wowee::pipeline::WoweeCondition::HasSpell;
if (s == "min-level") return wowee::pipeline::WoweeCondition::MinLevel;
if (s == "max-level") return wowee::pipeline::WoweeCondition::MaxLevel;
if (s == "class") return wowee::pipeline::WoweeCondition::ClassMatch;
if (s == "race") return wowee::pipeline::WoweeCondition::RaceMatch;
if (s == "rep") return wowee::pipeline::WoweeCondition::FactionRep;
if (s == "achievement") return wowee::pipeline::WoweeCondition::HasAchievement;
if (s == "team-size") return wowee::pipeline::WoweeCondition::TeamSize;
if (s == "guild-level") return wowee::pipeline::WoweeCondition::GuildLevel;
if (s == "event") return wowee::pipeline::WoweeCondition::EventActive;
if (s == "area") return wowee::pipeline::WoweeCondition::AreaId;
if (s == "title") return wowee::pipeline::WoweeCondition::HasTitle;
return wowee::pipeline::WoweeCondition::AlwaysTrue;
};
auto aggFromName = [](const std::string& s) -> uint8_t {
if (s == "and") return wowee::pipeline::WoweeCondition::And;
if (s == "or") return wowee::pipeline::WoweeCondition::Or;
return wowee::pipeline::WoweeCondition::And;
};
wowee::pipeline::WoweeCondition c;
c.name = j.value("name", std::string{});
if (j.contains("entries") && j["entries"].is_array()) {
for (const auto& je : j["entries"]) {
wowee::pipeline::WoweeCondition::Entry e;
e.conditionId = je.value("conditionId", 0u);
e.groupId = je.value("groupId", 0u);
e.name = je.value("name", std::string{});
e.description = je.value("description", std::string{});
if (je.contains("kind") && je["kind"].is_number_integer()) {
e.kind = static_cast<uint8_t>(je["kind"].get<int>());
} else if (je.contains("kindName") && je["kindName"].is_string()) {
e.kind = kindFromName(je["kindName"].get<std::string>());
}
if (je.contains("aggregator") && je["aggregator"].is_number_integer()) {
e.aggregator = static_cast<uint8_t>(je["aggregator"].get<int>());
} else if (je.contains("aggregatorName") &&
je["aggregatorName"].is_string()) {
e.aggregator = aggFromName(je["aggregatorName"].get<std::string>());
}
e.negated = static_cast<uint8_t>(je.value("negated", 0));
e.targetId = je.value("targetId", 0u);
e.minValue = je.value("minValue", 0);
e.maxValue = je.value("maxValue", 0);
c.entries.push_back(std::move(e));
}
}
if (!wowee::pipeline::WoweeConditionLoader::save(c, outBase)) {
std::fprintf(stderr,
"import-wpcd-json: failed to save %s.wpcd\n", outBase.c_str());
return 1;
}
std::printf("Wrote %s.wpcd\n", outBase.c_str());
std::printf(" source : %s\n", jsonPath.c_str());
std::printf(" conditions : %zu\n", c.entries.size());
return 0;
}
feat(pipeline): add WPCD (Wowee Player Condition) format Novel open replacement for Blizzard's PlayerCondition.dbc + the AzerothCore-style condition_template SQL tables. The 37th open format added to the editor. Defines reusable boolean conditions that other formats can reference for gating: "player has quest X completed", "player level >= N", "player class is mage", "player has item Y in inventory", "WSEA event Z is active". Conditions can be grouped and combined with AND/OR aggregators on a per-group basis: a quest-giver gossip option that says "show only to level 60 alliance mages who completed quest 1234" composes 4 conditions sharing the same groupId with AND aggregation. The runtime walks each group, applies the group's aggregator, and returns the boolean result to the caller. Cross-references with previously-added formats — the targetId field has a polymorphic interpretation by kind: WPCD.targetId (kind=QuestCompleted/Active) -> WQT.questId WPCD.targetId (kind=HasItem) -> WIT.itemId WPCD.targetId (kind=HasSpell) -> WSPL.spellId WPCD.targetId (kind=HasAchievement) -> WACH.achievementId WPCD.targetId (kind=AreaId) -> WMS.areaId WPCD.targetId (kind=EventActive) -> WSEA.eventId WPCD.targetId (kind=HasTitle) -> WTIT.titleId WPCD.targetId (kind=FactionRep) -> WFAC.factionId WPCD.targetId (kind=Class/Race) -> WCHC class/race id Future format extensions can reference WPCD.conditionId in their own gating fields — WTRG triggers gated by player state, WGSP options visible only when conditions are met, WMOU summon spells condition-gated by quest progress, etc. Format: • magic "WPCD", version 1, little-endian • per condition: conditionId / groupId (0 = standalone) / name / description / kind / aggregator / negated / targetId / minValue / maxValue Enums: • Kind (17): AlwaysTrue / AlwaysFalse / QuestCompleted / QuestActive / HasItem / HasSpell / MinLevel / MaxLevel / ClassMatch / RaceMatch / FactionRep / HasAchievement / TeamSize / GuildLevel / EventActive / AreaId / HasTitle • Aggregator (2): And / Or API: WoweeConditionLoader::save / load / exists / findById. Three preset emitters showcase typical usage: • makeStarter — 4 standalone conditions covering the most common kinds (quest-done / has-item / min-level / class) • makeGated — 5 conditions in 2 groups demonstrating AND-aggregation (alliance + mage + lvl 60) and OR-aggregation (did quest 1 OR quest 100) • makeEvent — 3 event-gated conditions cross-referencing WSEA event IDs (Hallow's End / Brewfest / Winter's Veil) CLI added (5 flags, 656 documented total now): --gen-conditions / --gen-conditions-gated / --gen-conditions-event --info-wpcd / --validate-wpcd Validator catches: conditionId=0 + duplicates, kind / aggregator out of range, kinds requiring targetId having target=0 (skips AlwaysTrue/False, MinLevel/MaxLevel, TeamSize, GuildLevel which use min/max instead), TeamSize with min > max.
2026-05-09 18:18:27 -07:00
int handleValidate(int& i, int argc, char** argv) {
std::string base = argv[++i];
bool jsonOut = consumeJsonFlag(i, argc, argv);
base = stripWpcdExt(base);
if (!wowee::pipeline::WoweeConditionLoader::exists(base)) {
std::fprintf(stderr,
"validate-wpcd: WPCD not found: %s.wpcd\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeConditionLoader::load(base);
std::vector<std::string> errors;
std::vector<std::string> warnings;
if (c.entries.empty()) {
warnings.push_back("catalog has zero entries");
}
std::vector<uint32_t> idsSeen;
for (size_t k = 0; k < c.entries.size(); ++k) {
const auto& e = c.entries[k];
std::string ctx = "entry " + std::to_string(k) +
" (id=" + std::to_string(e.conditionId);
if (!e.name.empty()) ctx += " " + e.name;
ctx += ")";
if (e.conditionId == 0) {
errors.push_back(ctx + ": conditionId is 0");
}
if (e.kind > wowee::pipeline::WoweeCondition::HasTitle) {
errors.push_back(ctx + ": kind " +
std::to_string(e.kind) + " not in 0..16");
}
if (e.aggregator > wowee::pipeline::WoweeCondition::Or) {
errors.push_back(ctx + ": aggregator " +
std::to_string(e.aggregator) + " not in 0..1");
}
// Most kinds need a non-zero targetId. Exceptions:
// AlwaysTrue / AlwaysFalse (no target), MinLevel /
// MaxLevel (use minValue), TeamSize (uses min/max),
// GuildLevel (uses minValue).
bool needsTarget =
e.kind != wowee::pipeline::WoweeCondition::AlwaysTrue &&
e.kind != wowee::pipeline::WoweeCondition::AlwaysFalse &&
e.kind != wowee::pipeline::WoweeCondition::MinLevel &&
e.kind != wowee::pipeline::WoweeCondition::MaxLevel &&
e.kind != wowee::pipeline::WoweeCondition::TeamSize &&
e.kind != wowee::pipeline::WoweeCondition::GuildLevel;
if (needsTarget && e.targetId == 0) {
errors.push_back(ctx +
": kind needs a non-zero targetId");
}
if (e.kind == wowee::pipeline::WoweeCondition::TeamSize &&
e.minValue > 0 && e.maxValue > 0 &&
e.minValue > e.maxValue) {
errors.push_back(ctx + ": team-size minValue > maxValue");
}
for (uint32_t prev : idsSeen) {
if (prev == e.conditionId) {
errors.push_back(ctx + ": duplicate conditionId");
break;
}
}
idsSeen.push_back(e.conditionId);
}
bool ok = errors.empty();
if (jsonOut) {
nlohmann::json j;
j["wpcd"] = base + ".wpcd";
j["ok"] = ok;
j["errors"] = errors;
j["warnings"] = warnings;
std::printf("%s\n", j.dump(2).c_str());
return ok ? 0 : 1;
}
std::printf("validate-wpcd: %s.wpcd\n", base.c_str());
if (ok && warnings.empty()) {
std::printf(" OK — %zu conditions, all conditionIds unique\n",
c.entries.size());
return 0;
}
if (!warnings.empty()) {
std::printf(" warnings (%zu):\n", warnings.size());
for (const auto& w : warnings)
std::printf(" - %s\n", w.c_str());
}
if (!errors.empty()) {
std::printf(" ERRORS (%zu):\n", errors.size());
for (const auto& e : errors)
std::printf(" - %s\n", e.c_str());
}
return ok ? 0 : 1;
}
} // namespace
bool handleConditionsCatalog(int& i, int argc, char** argv, int& outRc) {
if (std::strcmp(argv[i], "--gen-conditions") == 0 && i + 1 < argc) {
outRc = handleGenStarter(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--gen-conditions-gated") == 0 && i + 1 < argc) {
outRc = handleGenGated(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--gen-conditions-event") == 0 && i + 1 < argc) {
outRc = handleGenEvent(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--info-wpcd") == 0 && i + 1 < argc) {
outRc = handleInfo(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--validate-wpcd") == 0 && i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--export-wpcd-json") == 0 && i + 1 < argc) {
outRc = handleExportJson(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--import-wpcd-json") == 0 && i + 1 < argc) {
outRc = handleImportJson(i, argc, argv); return true;
}
feat(pipeline): add WPCD (Wowee Player Condition) format Novel open replacement for Blizzard's PlayerCondition.dbc + the AzerothCore-style condition_template SQL tables. The 37th open format added to the editor. Defines reusable boolean conditions that other formats can reference for gating: "player has quest X completed", "player level >= N", "player class is mage", "player has item Y in inventory", "WSEA event Z is active". Conditions can be grouped and combined with AND/OR aggregators on a per-group basis: a quest-giver gossip option that says "show only to level 60 alliance mages who completed quest 1234" composes 4 conditions sharing the same groupId with AND aggregation. The runtime walks each group, applies the group's aggregator, and returns the boolean result to the caller. Cross-references with previously-added formats — the targetId field has a polymorphic interpretation by kind: WPCD.targetId (kind=QuestCompleted/Active) -> WQT.questId WPCD.targetId (kind=HasItem) -> WIT.itemId WPCD.targetId (kind=HasSpell) -> WSPL.spellId WPCD.targetId (kind=HasAchievement) -> WACH.achievementId WPCD.targetId (kind=AreaId) -> WMS.areaId WPCD.targetId (kind=EventActive) -> WSEA.eventId WPCD.targetId (kind=HasTitle) -> WTIT.titleId WPCD.targetId (kind=FactionRep) -> WFAC.factionId WPCD.targetId (kind=Class/Race) -> WCHC class/race id Future format extensions can reference WPCD.conditionId in their own gating fields — WTRG triggers gated by player state, WGSP options visible only when conditions are met, WMOU summon spells condition-gated by quest progress, etc. Format: • magic "WPCD", version 1, little-endian • per condition: conditionId / groupId (0 = standalone) / name / description / kind / aggregator / negated / targetId / minValue / maxValue Enums: • Kind (17): AlwaysTrue / AlwaysFalse / QuestCompleted / QuestActive / HasItem / HasSpell / MinLevel / MaxLevel / ClassMatch / RaceMatch / FactionRep / HasAchievement / TeamSize / GuildLevel / EventActive / AreaId / HasTitle • Aggregator (2): And / Or API: WoweeConditionLoader::save / load / exists / findById. Three preset emitters showcase typical usage: • makeStarter — 4 standalone conditions covering the most common kinds (quest-done / has-item / min-level / class) • makeGated — 5 conditions in 2 groups demonstrating AND-aggregation (alliance + mage + lvl 60) and OR-aggregation (did quest 1 OR quest 100) • makeEvent — 3 event-gated conditions cross-referencing WSEA event IDs (Hallow's End / Brewfest / Winter's Veil) CLI added (5 flags, 656 documented total now): --gen-conditions / --gen-conditions-gated / --gen-conditions-event --info-wpcd / --validate-wpcd Validator catches: conditionId=0 + duplicates, kind / aggregator out of range, kinds requiring targetId having target=0 (skips AlwaysTrue/False, MinLevel/MaxLevel, TeamSize, GuildLevel which use min/max instead), TeamSize with min > max.
2026-05-09 18:18:27 -07:00
return false;
}
} // namespace cli
} // namespace editor
} // namespace wowee