mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-11 03:23:51 +00:00
feat(editor): add WSPR (Spell Reagent) — 80th open format milestone
Open replacement for the per-spell reagent fields in Spell.dbc
(Reagent[8] + ReagentCount[8]). Defines the item reagents that a
spell consumes from the caster's inventory each time it's cast —
Mage Portal needs a Rune of Portals, Resurrection needs a Holy
Candle (focused, not consumed), Warlock summons consume Soul
Shards.
One entry per reagent-using spell — most spells have no reagents
and are absent from this catalog. Each entry can list up to 8
(itemId, count) pairs which all must be present for the spell
to cast. Five reagentKind values capture the variety of reagent
semantics:
- Standard — ordinary consumed reagent
- SoulShard — warlock-specific shard tracking
- FocusedItem — required to cast but NOT consumed
(Symbol of Divinity for Resurrection)
- Catalyst — enables a stronger version of the spell
- Tradeable — crafting reagent for trade-skill recipes
Cross-references back to WSPL (every entry references a spellId)
and WIT (every reagent itemId references an item entry).
findBySpell(spellId) is the primary engine lookup.
Three preset emitters: --gen-spr (4 mage portal/teleport
reagents using Rune of Teleportation 17031), --gen-spr-warlock
(4 demon summons each consuming 1 Soul Shard 6265),
--gen-spr-rez (3 resurrection variants demonstrating each
ReagentKind including a no-reagent Druid Rebirth and a
focused-item Priest Resurrection).
Validation enforces id+name+spellId presence, reagentKind 0..4,
no duplicate ids; warns on:
- slot itemId/count mismatch (id without count or vice versa)
- SoulShard kind with non-canonical reagent (not item 6265)
- FocusedItem kind with no reagent slots set (focused-item
gating has nothing to gate)
- duplicate spellId across entries (engine honors only first)
This is the 80th open format milestone. Wired through the
cross-format table; WSPR appears automatically in all 14
cross-format utilities. Format count 79 -> 80; CLI flag count
974 -> 979.
This commit is contained in:
parent
736ec3a1c0
commit
d97f4bf5db
10 changed files with 704 additions and 0 deletions
283
tools/editor/cli_spell_reagents_catalog.cpp
Normal file
283
tools/editor/cli_spell_reagents_catalog.cpp
Normal file
|
|
@ -0,0 +1,283 @@
|
|||
#include "cli_spell_reagents_catalog.hpp"
|
||||
#include "cli_arg_parse.hpp"
|
||||
#include "cli_box_emitter.hpp"
|
||||
|
||||
#include "pipeline/wowee_spell_reagents.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 stripWsprExt(std::string base) {
|
||||
stripExt(base, ".wspr");
|
||||
return base;
|
||||
}
|
||||
|
||||
bool saveOrError(const wowee::pipeline::WoweeSpellReagent& c,
|
||||
const std::string& base, const char* cmd) {
|
||||
if (!wowee::pipeline::WoweeSpellReagentLoader::save(c, base)) {
|
||||
std::fprintf(stderr, "%s: failed to save %s.wspr\n",
|
||||
cmd, base.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void printGenSummary(const wowee::pipeline::WoweeSpellReagent& c,
|
||||
const std::string& base) {
|
||||
std::printf("Wrote %s.wspr\n", base.c_str());
|
||||
std::printf(" catalog : %s\n", c.name.c_str());
|
||||
std::printf(" sets : %zu\n", c.entries.size());
|
||||
}
|
||||
|
||||
int handleGenMage(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
std::string name = "MageReagents";
|
||||
if (parseOptArg(i, argc, argv)) name = argv[++i];
|
||||
base = stripWsprExt(base);
|
||||
auto c = wowee::pipeline::WoweeSpellReagentLoader::makeMage(name);
|
||||
if (!saveOrError(c, base, "gen-spr")) return 1;
|
||||
printGenSummary(c, base);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handleGenWarlock(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
std::string name = "WarlockReagents";
|
||||
if (parseOptArg(i, argc, argv)) name = argv[++i];
|
||||
base = stripWsprExt(base);
|
||||
auto c = wowee::pipeline::WoweeSpellReagentLoader::makeWarlock(name);
|
||||
if (!saveOrError(c, base, "gen-spr-warlock")) return 1;
|
||||
printGenSummary(c, base);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handleGenRez(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
std::string name = "ResurrectionReagents";
|
||||
if (parseOptArg(i, argc, argv)) name = argv[++i];
|
||||
base = stripWsprExt(base);
|
||||
auto c = wowee::pipeline::WoweeSpellReagentLoader::makeRez(name);
|
||||
if (!saveOrError(c, base, "gen-spr-rez")) 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 = stripWsprExt(base);
|
||||
if (!wowee::pipeline::WoweeSpellReagentLoader::exists(base)) {
|
||||
std::fprintf(stderr, "WSPR not found: %s.wspr\n", base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeSpellReagentLoader::load(base);
|
||||
if (jsonOut) {
|
||||
nlohmann::json j;
|
||||
j["wspr"] = base + ".wspr";
|
||||
j["name"] = c.name;
|
||||
j["count"] = c.entries.size();
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) {
|
||||
nlohmann::json items = nlohmann::json::array();
|
||||
nlohmann::json counts = nlohmann::json::array();
|
||||
for (int s = 0; s < wowee::pipeline::WoweeSpellReagent::kMaxReagentSlots; ++s) {
|
||||
items.push_back(e.reagentItemId[s]);
|
||||
counts.push_back(e.reagentCount[s]);
|
||||
}
|
||||
arr.push_back({
|
||||
{"reagentSetId", e.reagentSetId},
|
||||
{"name", e.name},
|
||||
{"description", e.description},
|
||||
{"spellId", e.spellId},
|
||||
{"reagentItemId", items},
|
||||
{"reagentCount", counts},
|
||||
{"reagentKind", e.reagentKind},
|
||||
{"reagentKindName", wowee::pipeline::WoweeSpellReagent::reagentKindName(e.reagentKind)},
|
||||
{"iconColorRGBA", e.iconColorRGBA},
|
||||
});
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::printf("%s\n", j.dump(2).c_str());
|
||||
return 0;
|
||||
}
|
||||
std::printf("WSPR: %s.wspr\n", base.c_str());
|
||||
std::printf(" catalog : %s\n", c.name.c_str());
|
||||
std::printf(" sets : %zu\n", c.entries.size());
|
||||
if (c.entries.empty()) return 0;
|
||||
std::printf(" id spellId kind slots reagents (item x count) name\n");
|
||||
for (const auto& e : c.entries) {
|
||||
std::string slots;
|
||||
int used = 0;
|
||||
for (int s = 0; s < wowee::pipeline::WoweeSpellReagent::kMaxReagentSlots; ++s) {
|
||||
if (e.reagentItemId[s] == 0) continue;
|
||||
if (!slots.empty()) slots += ", ";
|
||||
slots += std::to_string(e.reagentItemId[s]) + " x " +
|
||||
std::to_string(e.reagentCount[s]);
|
||||
++used;
|
||||
}
|
||||
if (slots.empty()) slots = "(none)";
|
||||
std::printf(" %4u %5u %-12s %d %-35s %s\n",
|
||||
e.reagentSetId, e.spellId,
|
||||
wowee::pipeline::WoweeSpellReagent::reagentKindName(e.reagentKind),
|
||||
used, slots.c_str(), 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 = stripWsprExt(base);
|
||||
if (!wowee::pipeline::WoweeSpellReagentLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"validate-wspr: WSPR not found: %s.wspr\n", base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeSpellReagentLoader::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;
|
||||
std::vector<uint32_t> spellsSeen;
|
||||
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.reagentSetId);
|
||||
if (!e.name.empty()) ctx += " " + e.name;
|
||||
ctx += ")";
|
||||
if (e.reagentSetId == 0)
|
||||
errors.push_back(ctx + ": reagentSetId is 0");
|
||||
if (e.name.empty())
|
||||
errors.push_back(ctx + ": name is empty");
|
||||
if (e.spellId == 0)
|
||||
errors.push_back(ctx +
|
||||
": spellId is 0 — missing WSPL cross-ref");
|
||||
if (e.reagentKind > wowee::pipeline::WoweeSpellReagent::Tradeable) {
|
||||
errors.push_back(ctx + ": reagentKind " +
|
||||
std::to_string(e.reagentKind) + " not in 0..4");
|
||||
}
|
||||
// Per-slot checks: itemId+count must be both set or both clear
|
||||
int usedSlots = 0;
|
||||
for (int s = 0; s < wowee::pipeline::WoweeSpellReagent::kMaxReagentSlots; ++s) {
|
||||
uint32_t it = e.reagentItemId[s];
|
||||
uint32_t cnt = e.reagentCount[s];
|
||||
if (it != 0 && cnt == 0) {
|
||||
warnings.push_back(ctx +
|
||||
": slot " + std::to_string(s) +
|
||||
" has itemId=" + std::to_string(it) +
|
||||
" but count=0 — reagent will not be consumed");
|
||||
} else if (it == 0 && cnt != 0) {
|
||||
warnings.push_back(ctx +
|
||||
": slot " + std::to_string(s) +
|
||||
" has count=" + std::to_string(cnt) +
|
||||
" but itemId=0 — count is unreachable");
|
||||
}
|
||||
if (it != 0) ++usedSlots;
|
||||
}
|
||||
// SoulShard kind should reference item 6265 in slot 0.
|
||||
// Other shard ids are server-custom but the canonical
|
||||
// case is worth flagging.
|
||||
if (e.reagentKind == wowee::pipeline::WoweeSpellReagent::SoulShard &&
|
||||
e.reagentItemId[0] != 6265 && e.reagentItemId[0] != 0) {
|
||||
warnings.push_back(ctx +
|
||||
": SoulShard kind with non-canonical reagent " +
|
||||
"id " + std::to_string(e.reagentItemId[0]) +
|
||||
" in slot 0 (canonical Soul Shard is item 6265)");
|
||||
}
|
||||
// FocusedItem kind: reagent is required to cast but
|
||||
// not consumed. Should still have an itemId set.
|
||||
if (e.reagentKind == wowee::pipeline::WoweeSpellReagent::FocusedItem &&
|
||||
usedSlots == 0) {
|
||||
warnings.push_back(ctx +
|
||||
": FocusedItem kind with no reagent slots set " +
|
||||
"— focused-item gating has nothing to gate");
|
||||
}
|
||||
for (uint32_t prev : idsSeen) {
|
||||
if (prev == e.reagentSetId) {
|
||||
errors.push_back(ctx + ": duplicate reagentSetId");
|
||||
break;
|
||||
}
|
||||
}
|
||||
idsSeen.push_back(e.reagentSetId);
|
||||
// Two reagent sets for the same spell collide —
|
||||
// engine would honor only the first.
|
||||
if (e.spellId != 0) {
|
||||
for (uint32_t prevSpell : spellsSeen) {
|
||||
if (prevSpell == e.spellId) {
|
||||
warnings.push_back(ctx +
|
||||
": duplicate spellId " +
|
||||
std::to_string(e.spellId) +
|
||||
" — only first reagent set will be used");
|
||||
break;
|
||||
}
|
||||
}
|
||||
spellsSeen.push_back(e.spellId);
|
||||
}
|
||||
}
|
||||
bool ok = errors.empty();
|
||||
if (jsonOut) {
|
||||
nlohmann::json j;
|
||||
j["wspr"] = base + ".wspr";
|
||||
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-wspr: %s.wspr\n", base.c_str());
|
||||
if (ok && warnings.empty()) {
|
||||
std::printf(" OK — %zu reagent sets, all reagentSetIds unique, all spell ids set\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 handleSpellReagentsCatalog(int& i, int argc, char** argv,
|
||||
int& outRc) {
|
||||
if (std::strcmp(argv[i], "--gen-spr") == 0 && i + 1 < argc) {
|
||||
outRc = handleGenMage(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--gen-spr-warlock") == 0 && i + 1 < argc) {
|
||||
outRc = handleGenWarlock(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--gen-spr-rez") == 0 && i + 1 < argc) {
|
||||
outRc = handleGenRez(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--info-wspr") == 0 && i + 1 < argc) {
|
||||
outRc = handleInfo(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--validate-wspr") == 0 && i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace cli
|
||||
} // namespace editor
|
||||
} // namespace wowee
|
||||
Loading…
Add table
Add a link
Reference in a new issue