mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-11 03:23:51 +00:00
295 lines
11 KiB
C++
295 lines
11 KiB
C++
|
|
#include "cli_spell_procs_catalog.hpp"
|
||
|
|
#include "cli_arg_parse.hpp"
|
||
|
|
#include "cli_box_emitter.hpp"
|
||
|
|
|
||
|
|
#include "pipeline/wowee_spell_procs.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 stripWspsExt(std::string base) {
|
||
|
|
stripExt(base, ".wsps");
|
||
|
|
return base;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool saveOrError(const wowee::pipeline::WoweeSpellProc& c,
|
||
|
|
const std::string& base, const char* cmd) {
|
||
|
|
if (!wowee::pipeline::WoweeSpellProcLoader::save(c, base)) {
|
||
|
|
std::fprintf(stderr, "%s: failed to save %s.wsps\n",
|
||
|
|
cmd, base.c_str());
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
void printGenSummary(const wowee::pipeline::WoweeSpellProc& c,
|
||
|
|
const std::string& base) {
|
||
|
|
std::printf("Wrote %s.wsps\n", base.c_str());
|
||
|
|
std::printf(" catalog : %s\n", c.name.c_str());
|
||
|
|
std::printf(" procs : %zu\n", c.entries.size());
|
||
|
|
}
|
||
|
|
|
||
|
|
int handleGenWeapon(int& i, int argc, char** argv) {
|
||
|
|
std::string base = argv[++i];
|
||
|
|
std::string name = "WeaponProcs";
|
||
|
|
if (parseOptArg(i, argc, argv)) name = argv[++i];
|
||
|
|
base = stripWspsExt(base);
|
||
|
|
auto c = wowee::pipeline::WoweeSpellProcLoader::makeWeapon(name);
|
||
|
|
if (!saveOrError(c, base, "gen-sps")) return 1;
|
||
|
|
printGenSummary(c, base);
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
int handleGenAura(int& i, int argc, char** argv) {
|
||
|
|
std::string base = argv[++i];
|
||
|
|
std::string name = "AuraProcs";
|
||
|
|
if (parseOptArg(i, argc, argv)) name = argv[++i];
|
||
|
|
base = stripWspsExt(base);
|
||
|
|
auto c = wowee::pipeline::WoweeSpellProcLoader::makeAura(name);
|
||
|
|
if (!saveOrError(c, base, "gen-sps-aura")) return 1;
|
||
|
|
printGenSummary(c, base);
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
int handleGenTalent(int& i, int argc, char** argv) {
|
||
|
|
std::string base = argv[++i];
|
||
|
|
std::string name = "TalentProcs";
|
||
|
|
if (parseOptArg(i, argc, argv)) name = argv[++i];
|
||
|
|
base = stripWspsExt(base);
|
||
|
|
auto c = wowee::pipeline::WoweeSpellProcLoader::makeTalent(name);
|
||
|
|
if (!saveOrError(c, base, "gen-sps-talent")) return 1;
|
||
|
|
printGenSummary(c, base);
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
void appendProcFlagNames(uint32_t flags, std::string& out) {
|
||
|
|
using F = wowee::pipeline::WoweeSpellProc;
|
||
|
|
auto add = [&](const char* n) {
|
||
|
|
if (!out.empty()) out += "|";
|
||
|
|
out += n;
|
||
|
|
};
|
||
|
|
if (flags & F::DealtMeleeAutoAttack) add("DealtMeleeAutoAttack");
|
||
|
|
if (flags & F::DealtMeleeSpell) add("DealtMeleeSpell");
|
||
|
|
if (flags & F::TakenMeleeAutoAttack) add("TakenMeleeAutoAttack");
|
||
|
|
if (flags & F::TakenMeleeSpell) add("TakenMeleeSpell");
|
||
|
|
if (flags & F::DealtRangedAutoAttack) add("DealtRangedAutoAttack");
|
||
|
|
if (flags & F::DealtRangedSpell) add("DealtRangedSpell");
|
||
|
|
if (flags & F::DealtSpell) add("DealtSpell");
|
||
|
|
if (flags & F::DealtSpellHeal) add("DealtSpellHeal");
|
||
|
|
if (flags & F::TakenSpell) add("TakenSpell");
|
||
|
|
if (flags & F::OnKill) add("OnKill");
|
||
|
|
if (flags & F::OnDeath) add("OnDeath");
|
||
|
|
if (flags & F::OnCastFinished) add("OnCastFinished");
|
||
|
|
if (flags & F::Critical) add("Critical");
|
||
|
|
if (out.empty()) out = "-";
|
||
|
|
}
|
||
|
|
|
||
|
|
int handleInfo(int& i, int argc, char** argv) {
|
||
|
|
std::string base = argv[++i];
|
||
|
|
bool jsonOut = consumeJsonFlag(i, argc, argv);
|
||
|
|
base = stripWspsExt(base);
|
||
|
|
if (!wowee::pipeline::WoweeSpellProcLoader::exists(base)) {
|
||
|
|
std::fprintf(stderr, "WSPS not found: %s.wsps\n", base.c_str());
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
auto c = wowee::pipeline::WoweeSpellProcLoader::load(base);
|
||
|
|
if (jsonOut) {
|
||
|
|
nlohmann::json j;
|
||
|
|
j["wsps"] = base + ".wsps";
|
||
|
|
j["name"] = c.name;
|
||
|
|
j["count"] = c.entries.size();
|
||
|
|
nlohmann::json arr = nlohmann::json::array();
|
||
|
|
for (const auto& e : c.entries) {
|
||
|
|
std::string flagNames;
|
||
|
|
appendProcFlagNames(e.procFlags, flagNames);
|
||
|
|
arr.push_back({
|
||
|
|
{"procId", e.procId},
|
||
|
|
{"name", e.name},
|
||
|
|
{"description", e.description},
|
||
|
|
{"triggerSpellId", e.triggerSpellId},
|
||
|
|
{"procFromSpellId", e.procFromSpellId},
|
||
|
|
{"procChance", e.procChance},
|
||
|
|
{"procPpm", e.procPpm},
|
||
|
|
{"procFlags", e.procFlags},
|
||
|
|
{"procFlagsLabels", flagNames},
|
||
|
|
{"internalCooldownMs", e.internalCooldownMs},
|
||
|
|
{"charges", e.charges},
|
||
|
|
{"iconColorRGBA", e.iconColorRGBA},
|
||
|
|
});
|
||
|
|
}
|
||
|
|
j["entries"] = arr;
|
||
|
|
std::printf("%s\n", j.dump(2).c_str());
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
std::printf("WSPS: %s.wsps\n", base.c_str());
|
||
|
|
std::printf(" catalog : %s\n", c.name.c_str());
|
||
|
|
std::printf(" procs : %zu\n", c.entries.size());
|
||
|
|
if (c.entries.empty()) return 0;
|
||
|
|
std::printf(" id trigger fromSpell chance%% PPM ICDms chg flags\n");
|
||
|
|
for (const auto& e : c.entries) {
|
||
|
|
std::string flagNames;
|
||
|
|
appendProcFlagNames(e.procFlags, flagNames);
|
||
|
|
std::printf(" %4u %5u %5u %5.1f %5.1f %5u %3u %s\n",
|
||
|
|
e.procId, e.triggerSpellId, e.procFromSpellId,
|
||
|
|
e.procChance * 100.0f, e.procPpm,
|
||
|
|
e.internalCooldownMs, e.charges,
|
||
|
|
flagNames.c_str());
|
||
|
|
std::printf(" %s\n",
|
||
|
|
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 = stripWspsExt(base);
|
||
|
|
if (!wowee::pipeline::WoweeSpellProcLoader::exists(base)) {
|
||
|
|
std::fprintf(stderr,
|
||
|
|
"validate-wsps: WSPS not found: %s.wsps\n", base.c_str());
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
auto c = wowee::pipeline::WoweeSpellProcLoader::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;
|
||
|
|
constexpr uint32_t kKnownFlagMask =
|
||
|
|
wowee::pipeline::WoweeSpellProc::DealtMeleeAutoAttack |
|
||
|
|
wowee::pipeline::WoweeSpellProc::DealtMeleeSpell |
|
||
|
|
wowee::pipeline::WoweeSpellProc::TakenMeleeAutoAttack |
|
||
|
|
wowee::pipeline::WoweeSpellProc::TakenMeleeSpell |
|
||
|
|
wowee::pipeline::WoweeSpellProc::DealtRangedAutoAttack |
|
||
|
|
wowee::pipeline::WoweeSpellProc::DealtRangedSpell |
|
||
|
|
wowee::pipeline::WoweeSpellProc::DealtSpell |
|
||
|
|
wowee::pipeline::WoweeSpellProc::DealtSpellHeal |
|
||
|
|
wowee::pipeline::WoweeSpellProc::TakenSpell |
|
||
|
|
wowee::pipeline::WoweeSpellProc::OnKill |
|
||
|
|
wowee::pipeline::WoweeSpellProc::OnDeath |
|
||
|
|
wowee::pipeline::WoweeSpellProc::OnCastFinished |
|
||
|
|
wowee::pipeline::WoweeSpellProc::Critical;
|
||
|
|
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.procId);
|
||
|
|
if (!e.name.empty()) ctx += " " + e.name;
|
||
|
|
ctx += ")";
|
||
|
|
if (e.procId == 0)
|
||
|
|
errors.push_back(ctx + ": procId is 0");
|
||
|
|
if (e.name.empty())
|
||
|
|
errors.push_back(ctx + ": name is empty");
|
||
|
|
if (e.triggerSpellId == 0)
|
||
|
|
errors.push_back(ctx +
|
||
|
|
": triggerSpellId is 0 — proc will fire nothing");
|
||
|
|
if (e.procFlags == 0)
|
||
|
|
errors.push_back(ctx +
|
||
|
|
": procFlags is 0 — proc will never trigger "
|
||
|
|
"(no qualifying event configured)");
|
||
|
|
if (e.procFlags & ~kKnownFlagMask) {
|
||
|
|
warnings.push_back(ctx +
|
||
|
|
": procFlags has bits outside known mask " +
|
||
|
|
"(0x" + std::to_string(e.procFlags & ~kKnownFlagMask) +
|
||
|
|
") — engine will ignore unknown flags");
|
||
|
|
}
|
||
|
|
if (e.procChance < 0.0f || e.procChance > 1.0f) {
|
||
|
|
warnings.push_back(ctx +
|
||
|
|
": procChance " + std::to_string(e.procChance) +
|
||
|
|
" is outside [0..1]; engine clamps but author "
|
||
|
|
"should double-check");
|
||
|
|
}
|
||
|
|
if (e.procPpm < 0.0f) {
|
||
|
|
errors.push_back(ctx +
|
||
|
|
": procPpm < 0 — invalid procs-per-minute rate");
|
||
|
|
}
|
||
|
|
// Both procChance and procPpm set is contradictory —
|
||
|
|
// engine prefers procPpm when non-zero so procChance
|
||
|
|
// is ignored.
|
||
|
|
if (e.procChance > 0.0f && e.procPpm > 0.0f) {
|
||
|
|
warnings.push_back(ctx +
|
||
|
|
": both procChance (" + std::to_string(e.procChance) +
|
||
|
|
") and procPpm (" + std::to_string(e.procPpm) +
|
||
|
|
") set — engine uses procPpm and ignores "
|
||
|
|
"procChance");
|
||
|
|
}
|
||
|
|
// No chance configured at all = proc never fires.
|
||
|
|
if (e.procChance == 0.0f && e.procPpm == 0.0f) {
|
||
|
|
warnings.push_back(ctx +
|
||
|
|
": both procChance=0 and procPpm=0 — proc " +
|
||
|
|
"will never trigger");
|
||
|
|
}
|
||
|
|
for (uint32_t prev : idsSeen) {
|
||
|
|
if (prev == e.procId) {
|
||
|
|
errors.push_back(ctx + ": duplicate procId");
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
idsSeen.push_back(e.procId);
|
||
|
|
}
|
||
|
|
bool ok = errors.empty();
|
||
|
|
if (jsonOut) {
|
||
|
|
nlohmann::json j;
|
||
|
|
j["wsps"] = base + ".wsps";
|
||
|
|
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-wsps: %s.wsps\n", base.c_str());
|
||
|
|
if (ok && warnings.empty()) {
|
||
|
|
std::printf(" OK — %zu procs, all procIds 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 handleSpellProcsCatalog(int& i, int argc, char** argv,
|
||
|
|
int& outRc) {
|
||
|
|
if (std::strcmp(argv[i], "--gen-sps") == 0 && i + 1 < argc) {
|
||
|
|
outRc = handleGenWeapon(i, argc, argv); return true;
|
||
|
|
}
|
||
|
|
if (std::strcmp(argv[i], "--gen-sps-aura") == 0 && i + 1 < argc) {
|
||
|
|
outRc = handleGenAura(i, argc, argv); return true;
|
||
|
|
}
|
||
|
|
if (std::strcmp(argv[i], "--gen-sps-talent") == 0 && i + 1 < argc) {
|
||
|
|
outRc = handleGenTalent(i, argc, argv); return true;
|
||
|
|
}
|
||
|
|
if (std::strcmp(argv[i], "--info-wsps") == 0 && i + 1 < argc) {
|
||
|
|
outRc = handleInfo(i, argc, argv); return true;
|
||
|
|
}
|
||
|
|
if (std::strcmp(argv[i], "--validate-wsps") == 0 && i + 1 < argc) {
|
||
|
|
outRc = handleValidate(i, argc, argv); return true;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace cli
|
||
|
|
} // namespace editor
|
||
|
|
} // namespace wowee
|