mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-11 03:23:51 +00:00
feat(editor): add WTRD (Trade Window Rules) — 115th open format
Novel replacement for the implicit player-to-player trade policy rules vanilla WoW hardcoded across the trade-window message handlers (CMSG_INITIATE_TRADE, CMSG_SET_TRADE_ITEM, CMSG_SET_TRADE_GOLD), the soulbound-item check, the cross-faction-trade rejection, and the GM-trade audit hooks. Each entry is one trade-policy rule the trade-window state machine consults at every state transition. Seven ruleKind values (Allowed / Forbidden / SoulboundException / CrossFactionAllowed / LevelGated / GoldEscrowMax / AuditLogged) and five targetingFilter values (AnyPlayer / SameRealmOnly / SameFactionOnly / SameAccountOnly / GMOnly) cover the full trade-policy surface. Priority field resolves rule conflicts — higher priority wins (Allowed at 100 overrides Forbidden at 10). Three preset emitters cover real-world deployment patterns: makeStandard (4 baseline rules — Soulbound Forbidden globally, Quest items Forbidden, 2hr Soul- boundException for raid trade-back, SameFactionOnly), makeServerAdmin (3 server-custom overrides — GM-only escrow at priority 100, AccountBound own-character transfer, CrossFactionAllowed at level 80 for RP servers), makeRMTPrevent (4 anti-RMT rules — 10g cap for low-level trades, 500g cap for accounts < 30 days, audit log for trades > 1000g, 24hr first-trade delay). Validator's most novel check is the GoldEscrowMax / goldEscrowMaxCopper consistency rule: a GoldEscrowMax- kind rule MUST specify a non-zero gold cap (zero would mean unlimited which contradicts the rule's purpose). Also warns on GMOnly targeting with priority < 50 (GM- mediated rules typically need high priority to override player-initiated rules) and levelRequirement > 80 (exceeds current cap, rule never applies). Format count 114 -> 115. CLI flag count 1227 -> 1232.
This commit is contained in:
parent
65c51a272f
commit
05bb96d23b
10 changed files with 744 additions and 0 deletions
|
|
@ -353,6 +353,8 @@ const char* const kArgRequired[] = {
|
|||
"--gen-vox", "--gen-vox-boss", "--gen-vox-vendor",
|
||||
"--info-wvox", "--validate-wvox",
|
||||
"--export-wvox-json", "--import-wvox-json",
|
||||
"--gen-trd", "--gen-trd-admin", "--gen-trd-rmt",
|
||||
"--info-wtrd", "--validate-wtrd",
|
||||
"--gen-weather-temperate", "--gen-weather-arctic",
|
||||
"--gen-weather-desert", "--gen-weather-stormy",
|
||||
"--gen-zone-atmosphere",
|
||||
|
|
|
|||
|
|
@ -159,6 +159,7 @@
|
|||
#include "cli_movie_credits_catalog.hpp"
|
||||
#include "cli_spell_variants_catalog.hpp"
|
||||
#include "cli_voiceovers_catalog.hpp"
|
||||
#include "cli_trade_rules_catalog.hpp"
|
||||
#include "cli_catalog_pluck.hpp"
|
||||
#include "cli_catalog_find.hpp"
|
||||
#include "cli_catalog_by_name.hpp"
|
||||
|
|
@ -363,6 +364,7 @@ constexpr DispatchFn kDispatchTable[] = {
|
|||
handleMovieCreditsCatalog,
|
||||
handleSpellVariantsCatalog,
|
||||
handleVoiceoversCatalog,
|
||||
handleTradeRulesCatalog,
|
||||
handleCatalogPluck,
|
||||
handleCatalogFind,
|
||||
handleCatalogByName,
|
||||
|
|
|
|||
|
|
@ -117,6 +117,7 @@ constexpr FormatMagicEntry kFormats[] = {
|
|||
{{'W','M','V','C'}, ".wmvc", "cinematic", "--info-wmvc", "Movie credits roll catalog"},
|
||||
{{'W','S','P','V'}, ".wspv", "spells", "--info-wspv", "Spell variant catalog"},
|
||||
{{'W','V','O','X'}, ".wvox", "audio", "--info-wvox", "Voiceover audio catalog"},
|
||||
{{'W','T','R','D'}, ".wtrd", "social", "--info-wtrd", "Trade window rules catalog"},
|
||||
{{'W','F','A','C'}, ".wfac", "factions", nullptr, "Faction catalog"},
|
||||
{{'W','L','C','K'}, ".wlck", "locks", nullptr, "Lock catalog"},
|
||||
{{'W','S','K','L'}, ".wskl", "skills", nullptr, "Skill catalog"},
|
||||
|
|
|
|||
|
|
@ -2363,6 +2363,16 @@ void printUsage(const char* argv0) {
|
|||
std::printf(" Export binary .wvox to a human-editable JSON sidecar (defaults to <base>.wvox.json; emits eventKind and genderHint as both int AND name string; transcript as plain string for accessibility editing)\n");
|
||||
std::printf(" --import-wvox-json <json-path> [out-base]\n");
|
||||
std::printf(" Import a .wvox.json sidecar back into binary .wvox (eventKind int OR \"greeting\"/\"aggro\"/\"death\"/\"queststart\"/\"questprogress\"/\"questcomplete\"/\"goodbye\"/\"special\"/\"phase\"; genderHint int OR \"male\"/\"female\"/\"both\"; volumeDb is signed int8)\n");
|
||||
std::printf(" --gen-trd <wtrd-base> [name]\n");
|
||||
std::printf(" Emit .wtrd 4 standard trade rules (Soulbound Forbidden / Quest items Forbidden / 2hr SoulboundException for raid drops / SameFactionOnly default)\n");
|
||||
std::printf(" --gen-trd-admin <wtrd-base> [name]\n");
|
||||
std::printf(" Emit .wtrd 3 server-admin trade rules (GM-only escrow / AccountBound own-character transfer / CrossFactionAllowed at level 80 for custom servers)\n");
|
||||
std::printf(" --gen-trd-rmt <wtrd-base> [name]\n");
|
||||
std::printf(" Emit .wtrd 4 anti-RMT trade rules (LowLevelGoldCap 10g / NewAccountValueCap 500g for accounts <30 days / HighValueAuditLog for trades >1000g / FirstTradeMandatoryDelay 24hr)\n");
|
||||
std::printf(" --info-wtrd <wtrd-base> [--json]\n");
|
||||
std::printf(" Print WTRD entries (id / ruleKind / targetingFilter / level requirement / priority / category bitmask / gold cap / name)\n");
|
||||
std::printf(" --validate-wtrd <wtrd-base> [--json]\n");
|
||||
std::printf(" Static checks: id+name required, ruleKind 0..6, targetingFilter 0..4, no duplicate ruleIds, GoldEscrowMax kind requires goldEscrowMaxCopper > 0 (else self-contradicting); warns on levelRequirement > 80 (exceeds cap), GMOnly targeting with priority < 50 (would be overridden by player rules)\n");
|
||||
std::printf(" --catalog-pluck <wXXX-file> <id> [--json]\n");
|
||||
std::printf(" Extract one entry by id from any registered catalog format. Auto-detects magic, dispatches to the per-format --info-* handler internally, then prints just the matching entry. Primary-key field is auto-detected (first *Id field, or first numeric)\n");
|
||||
std::printf(" --catalog-find <directory> <id> [--magic <WXXX>] [--json]\n");
|
||||
|
|
|
|||
|
|
@ -139,6 +139,7 @@ constexpr FormatRow kFormats[] = {
|
|||
{"WMVC", ".wmvc", "cinematic", "embedded cinematic credit-roll blob","Movie credits roll catalog (per-cinematic)"},
|
||||
{"WSPV", ".wspv", "spells", "implicit Spell.dbc context overrides","Spell variant catalog (stance/talent/racial substitution)"},
|
||||
{"WVOX", ".wvox", "audio", "CreatureTextSounds + per-quest voice","Voiceover audio catalog (per-NPC, per-event clips)"},
|
||||
{"WTRD", ".wtrd", "social", "trade-window state machine policy", "Trade window rules catalog (P2P trade policy)"},
|
||||
|
||||
// Additional pipeline catalogs without the alternating
|
||||
// gen/info/validate CLI surface (loaded by the engine
|
||||
|
|
|
|||
282
tools/editor/cli_trade_rules_catalog.cpp
Normal file
282
tools/editor/cli_trade_rules_catalog.cpp
Normal file
|
|
@ -0,0 +1,282 @@
|
|||
#include "cli_trade_rules_catalog.hpp"
|
||||
#include "cli_arg_parse.hpp"
|
||||
#include "cli_box_emitter.hpp"
|
||||
|
||||
#include "pipeline/wowee_trade_rules.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace wowee {
|
||||
namespace editor {
|
||||
namespace cli {
|
||||
|
||||
namespace {
|
||||
|
||||
std::string stripWtrdExt(std::string base) {
|
||||
stripExt(base, ".wtrd");
|
||||
return base;
|
||||
}
|
||||
|
||||
const char* ruleKindName(uint8_t k) {
|
||||
using T = wowee::pipeline::WoweeTradeRules;
|
||||
switch (k) {
|
||||
case T::Allowed: return "allowed";
|
||||
case T::Forbidden: return "forbidden";
|
||||
case T::SoulboundException: return "soulboundexception";
|
||||
case T::CrossFactionAllowed: return "crossfactionallowed";
|
||||
case T::LevelGated: return "levelgated";
|
||||
case T::GoldEscrowMax: return "goldescrowmax";
|
||||
case T::AuditLogged: return "auditlogged";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
const char* targetingFilterName(uint8_t t) {
|
||||
using T = wowee::pipeline::WoweeTradeRules;
|
||||
switch (t) {
|
||||
case T::AnyPlayer: return "anyplayer";
|
||||
case T::SameRealmOnly: return "samerealmonly";
|
||||
case T::SameFactionOnly: return "samefactiononly";
|
||||
case T::SameAccountOnly: return "sameaccountonly";
|
||||
case T::GMOnly: return "gmonly";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
bool saveOrError(const wowee::pipeline::WoweeTradeRules& c,
|
||||
const std::string& base, const char* cmd) {
|
||||
if (!wowee::pipeline::WoweeTradeRulesLoader::save(c, base)) {
|
||||
std::fprintf(stderr, "%s: failed to save %s.wtrd\n",
|
||||
cmd, base.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void printGenSummary(const wowee::pipeline::WoweeTradeRules& c,
|
||||
const std::string& base) {
|
||||
std::printf("Wrote %s.wtrd\n", base.c_str());
|
||||
std::printf(" catalog : %s\n", c.name.c_str());
|
||||
std::printf(" rules : %zu\n", c.entries.size());
|
||||
}
|
||||
|
||||
int handleGenStandard(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
std::string name = "StandardTradeRules";
|
||||
if (parseOptArg(i, argc, argv)) name = argv[++i];
|
||||
base = stripWtrdExt(base);
|
||||
auto c = wowee::pipeline::WoweeTradeRulesLoader::makeStandard(name);
|
||||
if (!saveOrError(c, base, "gen-trd")) return 1;
|
||||
printGenSummary(c, base);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handleGenServerAdmin(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
std::string name = "ServerAdminTradeRules";
|
||||
if (parseOptArg(i, argc, argv)) name = argv[++i];
|
||||
base = stripWtrdExt(base);
|
||||
auto c = wowee::pipeline::WoweeTradeRulesLoader::makeServerAdmin(name);
|
||||
if (!saveOrError(c, base, "gen-trd-admin")) return 1;
|
||||
printGenSummary(c, base);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handleGenRMT(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
std::string name = "AntiRMTTradeRules";
|
||||
if (parseOptArg(i, argc, argv)) name = argv[++i];
|
||||
base = stripWtrdExt(base);
|
||||
auto c = wowee::pipeline::WoweeTradeRulesLoader::makeRMTPrevent(name);
|
||||
if (!saveOrError(c, base, "gen-trd-rmt")) 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 = stripWtrdExt(base);
|
||||
if (!wowee::pipeline::WoweeTradeRulesLoader::exists(base)) {
|
||||
std::fprintf(stderr, "WTRD not found: %s.wtrd\n", base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeTradeRulesLoader::load(base);
|
||||
if (jsonOut) {
|
||||
nlohmann::json j;
|
||||
j["wtrd"] = base + ".wtrd";
|
||||
j["name"] = c.name;
|
||||
j["count"] = c.entries.size();
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) {
|
||||
arr.push_back({
|
||||
{"ruleId", e.ruleId},
|
||||
{"name", e.name},
|
||||
{"description", e.description},
|
||||
{"ruleKind", e.ruleKind},
|
||||
{"ruleKindName", ruleKindName(e.ruleKind)},
|
||||
{"targetingFilter", e.targetingFilter},
|
||||
{"targetingFilterName",
|
||||
targetingFilterName(e.targetingFilter)},
|
||||
{"levelRequirement", e.levelRequirement},
|
||||
{"priority", e.priority},
|
||||
{"itemCategoryFilter", e.itemCategoryFilter},
|
||||
{"goldEscrowMaxCopper", e.goldEscrowMaxCopper},
|
||||
{"iconColorRGBA", e.iconColorRGBA},
|
||||
});
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::printf("%s\n", j.dump(2).c_str());
|
||||
return 0;
|
||||
}
|
||||
std::printf("WTRD: %s.wtrd\n", base.c_str());
|
||||
std::printf(" catalog : %s\n", c.name.c_str());
|
||||
std::printf(" rules : %zu\n", c.entries.size());
|
||||
if (c.entries.empty()) return 0;
|
||||
std::printf(" id kind targeting lvlReq prio catFilter goldMax(c) name\n");
|
||||
for (const auto& e : c.entries) {
|
||||
std::printf(" %4u %-19s %-15s %3u %3u 0x%08X %12llu %s\n",
|
||||
e.ruleId,
|
||||
ruleKindName(e.ruleKind),
|
||||
targetingFilterName(e.targetingFilter),
|
||||
e.levelRequirement, e.priority,
|
||||
e.itemCategoryFilter,
|
||||
(unsigned long long)e.goldEscrowMaxCopper,
|
||||
e.name.c_str());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handleValidate(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
bool jsonOut = consumeJsonFlag(i, argc, argv);
|
||||
base = stripWtrdExt(base);
|
||||
if (!wowee::pipeline::WoweeTradeRulesLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"validate-wtrd: WTRD not found: %s.wtrd\n",
|
||||
base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeTradeRulesLoader::load(base);
|
||||
std::vector<std::string> errors;
|
||||
std::vector<std::string> warnings;
|
||||
if (c.entries.empty()) {
|
||||
warnings.push_back("catalog has zero entries");
|
||||
}
|
||||
std::set<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.ruleId);
|
||||
if (!e.name.empty()) ctx += " " + e.name;
|
||||
ctx += ")";
|
||||
if (e.ruleId == 0)
|
||||
errors.push_back(ctx + ": ruleId is 0");
|
||||
if (e.name.empty())
|
||||
errors.push_back(ctx + ": name is empty");
|
||||
if (e.ruleKind > 6) {
|
||||
errors.push_back(ctx + ": ruleKind " +
|
||||
std::to_string(e.ruleKind) +
|
||||
" out of range (must be 0..6)");
|
||||
}
|
||||
if (e.targetingFilter > 4) {
|
||||
errors.push_back(ctx + ": targetingFilter " +
|
||||
std::to_string(e.targetingFilter) +
|
||||
" out of range (must be 0..4)");
|
||||
}
|
||||
if (e.levelRequirement > 80) {
|
||||
warnings.push_back(ctx + ": levelRequirement " +
|
||||
std::to_string(e.levelRequirement) +
|
||||
" > 80 — exceeds current cap, the rule "
|
||||
"would never apply on a WotLK realm");
|
||||
}
|
||||
// Per-kind validity: GoldEscrowMax must specify
|
||||
// a non-zero gold cap to be meaningful (zero
|
||||
// would mean unlimited which contradicts the
|
||||
// rule's purpose).
|
||||
using T = wowee::pipeline::WoweeTradeRules;
|
||||
if (e.ruleKind == T::GoldEscrowMax &&
|
||||
e.goldEscrowMaxCopper == 0) {
|
||||
errors.push_back(ctx +
|
||||
": GoldEscrowMax kind with goldEscrow"
|
||||
"MaxCopper=0 — rule contradicts itself "
|
||||
"(0 means unlimited but the rule's "
|
||||
"purpose is to cap)");
|
||||
}
|
||||
// GMOnly rules with low priority would be useless
|
||||
// (can't be triggered without GM intervention).
|
||||
if (e.targetingFilter == T::GMOnly &&
|
||||
e.priority < 50) {
|
||||
warnings.push_back(ctx +
|
||||
": GMOnly targeting with priority " +
|
||||
std::to_string(e.priority) +
|
||||
" < 50 — GM-mediated trades typically "
|
||||
"need high priority to override player-"
|
||||
"initiated rules");
|
||||
}
|
||||
if (!idsSeen.insert(e.ruleId).second) {
|
||||
errors.push_back(ctx + ": duplicate ruleId");
|
||||
}
|
||||
}
|
||||
bool ok = errors.empty();
|
||||
if (jsonOut) {
|
||||
nlohmann::json j;
|
||||
j["wtrd"] = base + ".wtrd";
|
||||
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-wtrd: %s.wtrd\n", base.c_str());
|
||||
if (ok && warnings.empty()) {
|
||||
std::printf(" OK — %zu rules, all ruleIds unique, "
|
||||
"per-kind constraints satisfied\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 handleTradeRulesCatalog(int& i, int argc, char** argv,
|
||||
int& outRc) {
|
||||
if (std::strcmp(argv[i], "--gen-trd") == 0 && i + 1 < argc) {
|
||||
outRc = handleGenStandard(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--gen-trd-admin") == 0 && i + 1 < argc) {
|
||||
outRc = handleGenServerAdmin(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--gen-trd-rmt") == 0 && i + 1 < argc) {
|
||||
outRc = handleGenRMT(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--info-wtrd") == 0 && i + 1 < argc) {
|
||||
outRc = handleInfo(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--validate-wtrd") == 0 && i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace cli
|
||||
} // namespace editor
|
||||
} // namespace wowee
|
||||
12
tools/editor/cli_trade_rules_catalog.hpp
Normal file
12
tools/editor/cli_trade_rules_catalog.hpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
namespace wowee {
|
||||
namespace editor {
|
||||
namespace cli {
|
||||
|
||||
bool handleTradeRulesCatalog(int& i, int argc, char** argv,
|
||||
int& outRc);
|
||||
|
||||
} // namespace cli
|
||||
} // namespace editor
|
||||
} // namespace wowee
|
||||
Loading…
Add table
Add a link
Reference in a new issue