-- Generated from the frozen legacy-h5 rules by migration/port-engine.cjs. -- Edit the migration source or an explicit native adapter; regenerate and run parity tests. ---@param _port table ---@param _data table ---@param _rt table return function(_port, _data, _rt) -- H5 engine.js:1885 · recruitCost _port["recruitCost"] = function(e) local costs = _rt.choose((_rt.typeof(_data["RECRUIT_COST"]) ~= "undefined"), function() return _data["RECRUIT_COST"] end, function() return _rt.array({18, 45, 110, 270, 730, 1800}) end); do return _rt.orElse(_rt.get(costs, _rt.get(e, "q")), function() return _rt.get(costs, (_rt.get(costs, "length") - 1)) end) end end -- H5 engine.js:1890 · recruit _port["recruit"] = function(s, idx) local e = _rt.get(_rt.get(s, "recruits"), idx); if _rt.truth((not _rt.truth(e))) then do return {["ok"] = false, ["msg"] = "该招募人选已变更,请重新选择"} end end local cost = _port["recruitCost"](e); if _rt.truth(_rt.compare("<", _rt.get(s, "silver"), cost)) then do return {["ok"] = false, ["msg"] = _rt.add(_rt.add("银两不足,需 ", _port["fmtNum"](cost)), " 两")} end end _rt.update(s, "silver", "-", cost); local dup = _rt.call(_rt.get(s, "escorts"), "find", function(x) return (_rt.get(x, "name") == _rt.get(e, "name")) end); if _rt.truth(dup) then _rt.set(dup, "frag", _rt.add(_rt.orElse(_rt.get(dup, "frag"), function() return 0 end), 5)); _rt.call(_rt.get(s, "recruits"), "splice", idx, 1); do return {["ok"] = true, ["msg"] = _rt.add(_rt.get(e, "name"), "已在麾下,转化为 5 枚同名碎片"), ["cost"] = cost, ["dup"] = true} end end local hired = _rt.assign({}, e, {["id"] = _rt.call(_rt.call(_rt.math["random"](), "toString", 36), "slice", 2, 9), ["equip"] = _rt.orElse(_rt.get(e, "equip"), function() return {["weapon"] = 0, ["mount"] = 0, ["armor"] = 0, ["compass"] = 0} end), ["train"] = _rt.orElse(_rt.get(e, "train"), function() return {["force"] = 0, ["agility"] = 0, ["insight"] = 0, ["courage"] = 0} end), ["reforge"] = _rt.orElse(_rt.get(e, "reforge"), function() return {["weapon"] = 0, ["mount"] = 0, ["armor"] = 0, ["compass"] = 0} end), ["reforgePity"] = _rt.orElse(_rt.get(e, "reforgePity"), function() return {["weapon"] = 0, ["mount"] = 0, ["armor"] = 0, ["compass"] = 0} end), ["frag"] = _rt.orElse(_rt.get(e, "frag"), function() return 0 end)}); _rt.call(_rt.get(s, "escorts"), "push", hired); if _rt.truth((not _rt.truth(_rt.call(_rt.get(_rt.get(s, "codex"), "escorts"), "includes", _rt.get(e, "name"))))) then _rt.call(_rt.get(_rt.get(s, "codex"), "escorts"), "push", _rt.get(e, "name")); end if _rt.truth((not _rt.truth(_rt.call(_rt.get(_rt.get(s, "codex"), "roster"), "includes", _rt.get(e, "name"))))) then _rt.call(_rt.get(_rt.get(s, "codex"), "roster"), "push", _rt.get(e, "name")); end _rt.call(_rt.get(s, "recruits"), "splice", idx, 1); do return {["ok"] = true, ["msg"] = _rt.add(_rt.add("招募 ", _rt.get(e, "name")), " 成功"), ["cost"] = cost, ["escortId"] = _rt.get(hired, "id")} end end -- H5 engine.js:1917 · refreshRecruits _port["refreshRecruits"] = function(s) _rt.set(s, "recruits", _port["genRecruits"](s)); end -- H5 engine.js:1922 · leaderboard _port["leaderboard"] = function(s, metric) local key = _rt.orElse(metric, function() return "prestige" end); local mine = _rt.choose((key == "silver"), function() return _rt.get(s, "silver") end, function() return _rt.choose((key == "runs"), function() return _rt.get(_rt.get(s, "stats"), "runs") end, function() return _rt.choose((key == "events"), function() return _rt.get(_rt.get(_rt.get(s, "codex"), "events"), "length") end, function() return _rt.choose((key == "cities"), function() return _rt.get(_rt.get(_rt.get(s, "codex"), "cities"), "length") end, function() return _rt.get(s, "prestige") end) end) end) end); local scale = _rt.orElse(_rt.get({["silver"] = 1, ["prestige"] = 1, ["runs"] = 0.35, ["events"] = 0.5, ["cities"] = 0.8}, key), function() return 1 end); local rows = _rt.call(_port["RIVALS"], "map", function(r) return {["name"] = _rt.get(r, "name"), ["score"] = _rt.choose((key == "silver"), function() return _rt.math["round"]((_rt.get(r, "base") * 0.7)) end, function() return _rt.choose((key == "runs"), function() return _rt.math["round"]((_rt.get(r, "base") * 0.045)) end, function() return _rt.choose((key == "events"), function() return _rt.math["round"]((_rt.get(r, "base") * 0.035)) end, function() return _rt.choose((key == "cities"), function() return _rt.math["round"]((_rt.get(r, "base") * 0.006)) end, function() return _rt.get(r, "base") end) end) end) end)} end); _rt.call(rows, "push", {["name"] = "你 · 本镖局", ["score"] = mine, ["me"] = true}); _rt.call(rows, "sort", function(a, b) return (_rt.get(b, "score") - _rt.get(a, "score")) end); do return {["metric"] = key, ["rows"] = rows, ["rank"] = _rt.add(_rt.call(rows, "findIndex", function(r) return _rt.get(r, "me") end), 1), ["total"] = _rt.get(rows, "length")} end end -- H5 engine.js:1941 · track _port["track"] = function(s, type, value) if _rt.truth((not _rt.truth(_rt.get(s, "telemetry")))) then _rt.set(s, "telemetry", _rt.array({})); end _rt.call(_rt.get(s, "telemetry"), "push", {["ts"] = _rt.now(), ["type"] = type, ["v"] = _rt.orElse(value, function() return 0 end)}); if _rt.truth(_rt.compare(">", _rt.get(_rt.get(s, "telemetry"), "length"), 300)) then _rt.call(_rt.get(s, "telemetry"), "splice", 0, (_rt.get(_rt.get(s, "telemetry"), "length") - 300)); end end -- H5 engine.js:1946 · telemetrySummary _port["telemetrySummary"] = function(s) local t = _rt.orElse(_rt.get(s, "telemetry"), function() return _rt.array({}) end); local byType = {}; _rt.call(t, "forEach", function(x) _rt.set(byType, _rt.get(x, "type"), _rt.add(_rt.orElse(_rt.get(byType, _rt.get(x, "type")), function() return 0 end), 1)); end); local days = _rt.get(_rt.setOf(_rt.call(t, "map", function(x) return _rt.call(_rt.call(_rt.date(_rt.get(x, "ts")), "toISOString"), "slice", 0, 10) end)), "size"); do return {["total"] = _rt.get(t, "length"), ["days"] = days, ["byType"] = byType} end end end