starrail-manager
Version:
The StarRail Manager is a Node.js wrapper for the MiHoMo API and StarRail Data used in Honkai: StarRail.\ **This is not an official Honkai: StarRail project.**
54 lines • 3.29 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculateScore = calculateScore;
const config_1 = require("../config");
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
function calculateScore(json, weightData) {
var _a;
const defaultWeight = readJson(config_1.config.scorePath + "score.json");
const none_path = path_1.default.resolve(__dirname, "../assets/score/none.json");
const weight_none = JSON.parse(fs_1.default.readFileSync(none_path, "utf-8"));
const max_path = path_1.default.resolve(__dirname, "../assets/score/max_value.json");
const maxVal = JSON.parse(fs_1.default.readFileSync(max_path, "utf-8"));
let weight = defaultWeight;
if (typeof weightData === "number") {
const selfData = readJson(config_1.config.customWightPath);
const arr = selfData[json.id];
if (!arr || arr.length < weightData) {
throw new Error(`${json.name} の重要度データが見つかりません。`);
}
weight = arr[weightData - 1];
}
if (typeof weightData === "string") {
const selfData = readJson(config_1.config.customWightPath);
const candidates = selfData[json.id];
weight = (_a = candidates.find((item) => item.name === weightData)) !== null && _a !== void 0 ? _a : defaultWeight;
}
let totalScore = 0;
json.relics = json.relics.map((relic) => {
var _a, _b, _c, _d, _e, _f, _g;
const mainType = relic.main_affix.type;
const part = relic.part;
const main_weight = (_g = (_d = (_c = (_b = (_a = weight === null || weight === void 0 ? void 0 : weight[json.id]) === null || _a === void 0 ? void 0 : _a.main) === null || _b === void 0 ? void 0 : _b[part]) === null || _c === void 0 ? void 0 : _c[mainType]) !== null && _d !== void 0 ? _d : (_f = (_e = weight_none.main) === null || _e === void 0 ? void 0 : _e[part]) === null || _f === void 0 ? void 0 : _f[mainType]) !== null && _g !== void 0 ? _g : 0;
const mainScore = ((relic.level + 1) / 16) * main_weight * 100;
const subScore = relic.sub_affix.reduce((sum, affix) => {
var _a, _b, _c, _d, _e;
const val = typeof affix.val === "number" ? affix.val : parseFloat(affix.val);
const sub_weight = (_e = (_c = (_b = (_a = weight === null || weight === void 0 ? void 0 : weight[json.id]) === null || _a === void 0 ? void 0 : _a.weight) === null || _b === void 0 ? void 0 : _b[affix.type]) !== null && _c !== void 0 ? _c : (_d = weight_none.weight) === null || _d === void 0 ? void 0 : _d[affix.type]) !== null && _e !== void 0 ? _e : 0;
return sum + (val / maxVal[affix.type]) * sub_weight * 100;
}, 0);
const relicScore = mainScore * 0.5 + subScore * 0.5;
totalScore += relicScore;
return Object.assign(Object.assign({}, relic), { score: relicScore.toFixed(1) });
});
json.total_score = Number(totalScore.toFixed(1));
return json;
}
function readJson(path) {
return JSON.parse(fs_1.default.readFileSync(path, "utf-8"));
}
//# sourceMappingURL=scorer.js.map