-- 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:659 · hourlyPrestige _port["hourlyPrestige"] = function(s) local b = _port["bestBusiness"](s); if _rt.truth((not _rt.truth(b))) then do return 60 end end local route = _rt.orElse(_rt.call(_data["ROUTES"], "find", function(r) return (_rt.get(r, "id") == _rt.get(b, "route")) end), function() return _rt.get(_data["ROUTES"], 0) end); local sec = _rt.math["max"](60, _port["durationSec"](s, route, nil, _port["businessPower"](s, b))); local bonus = _rt.add(1, (0.05 * _rt.math["max"](0, (_rt.orElse(_rt.andThen(_rt.get(s, "facilities"), function() return _rt.get(_rt.get(s, "facilities"), "biaoqi") end), function() return 1 end) - 1)))); local chainP = _rt.add(1, (0.12 * (_port["branchCount"](s) - 1))); local perRun = ((_rt.math["max"](1, _rt.orElse(_rt.get(b, "gain"), function() return 8 end)) * bonus) * chainP); do return _rt.math["max"](1, _rt.math["round"](((perRun * (3600 / sec)) * _port["parallelLimit"](s)))) end end -- H5 engine.js:669 · bountyCost _port["bountyCost"] = function(s) local h = _port["hourlyPrestige"](s); do return _rt.choose(_rt.andThen(_rt.isFinite(h), function() return _rt.compare(">", h, 0) end), function() return _rt.math["max"](10, _rt.math["round"](h)) end, function() return 60 end) end end -- H5 engine.js:673 · bountyLeft _port["bountyLeft"] = function(s) local t = _rt.andThen(_rt.get(s, "buff"), function() return _rt.get(_rt.get(s, "buff"), "bounty") end); do return _rt.choose(t, function() return _rt.math["max"](0, (t - _rt.now())) end, function() return 0 end) end end -- H5 engine.js:674 · bountyActive _port["bountyActive"] = function(s) do return _rt.compare(">", _port["bountyLeft"](s), 0) end end -- H5 engine.js:675 · buyBounty _port["buyBounty"] = function(s) local cost = _port["bountyCost"](s); if _rt.truth(_rt.compare("<", _rt.orElse(_rt.get(s, "prestige"), function() return 0 end), cost)) then do return {["ok"] = false, ["msg"] = _rt.add(_rt.add("可用声望不足,招揽生意需 ", _port["fmtNum"](cost)), " 点")} end end _rt.update(s, "prestige", "-", cost); _rt.set(s, "buff", _rt.orElse(_rt.get(s, "buff"), function() return {} end)); _rt.set(_rt.get(s, "buff"), "bounty", _rt.add(_rt.now(), _rt.get(_port["BOUNTY"], "ms"))); _port["track"](s, "bounty", cost); do return {["ok"] = true, ["msg"] = "招揽生意已生效 · 从现在起 1 小时内新接的镖单,镖银 +15%", ["cost"] = cost} end end _port["REFORGE_KEYS"] = _rt.array({"weapon", "mount", "armor", "compass"}) _port["REFORGE"] = {["levels"] = _rt.array({"凡", "良", "精", "珍", "绝"}), ["base"] = 30, ["grow"] = 1.32, ["pity"] = 6, ["slots"] = {["weapon"] = {["part"] = "兵器", ["name"] = "锋", ["stat"] = "silver", ["per"] = 0.016}, ["mount"] = {["part"] = "坐骑", ["name"] = "捷", ["stat"] = "time", ["per"] = (-0.008)}, ["armor"] = {["part"] = "护甲", ["name"] = "威", ["stat"] = "prestige", ["per"] = 0.012}, ["compass"] = {["part"] = "罗盘", ["name"] = "识", ["stat"] = "silver", ["per"] = 0.008}}} _rt.set(_port["REFORGE"], "max", _rt.get(_rt.get(_port["REFORGE"], "levels"), "length")); -- H5 engine.js:706 · reforgeLevel _port["reforgeLevel"] = function(e, slot) local v = _rt.andThen(_rt.andThen(e, function() return _rt.get(e, "reforge") end), function() return _rt.get(_rt.get(e, "reforge"), slot) end); do return _rt.choose(_rt.isFinite(v), function() return _rt.math["max"](0, _rt.math["min"](_rt.get(_port["REFORGE"], "max"), v)) end, function() return 0 end) end end -- H5 engine.js:711 · reforgeCost _port["reforgeCost"] = function(e, slot) local lv = _port["reforgeLevel"](e, slot); if _rt.truth(_rt.compare(">=", lv, _rt.get(_port["REFORGE"], "max"))) then do return nil end end do return _rt.math["round"]((_rt.get(_port["REFORGE"], "base") * _rt.math["pow"](_rt.get(_port["REFORGE"], "grow"), lv))) end end -- H5 engine.js:717 · reforgeSlotCost _port["reforgeSlotCost"] = function() local sum = 0; do local lv = 0; while _rt.truth(_rt.compare("<", lv, _rt.get(_port["REFORGE"], "max"))) do do (function() sum = _rt.add(sum, ((_rt.get(_port["REFORGE"], "max") / (_rt.get(_port["REFORGE"], "max") - lv)) * _rt.math["round"]((_rt.get(_port["REFORGE"], "base") * _rt.math["pow"](_rt.get(_port["REFORGE"], "grow"), lv))))); return sum end)(); end ::_continue7:: (function() local _before = lv; lv = lv + (1); return _before end)() end end do return _rt.math["round"](sum) end end -- H5 engine.js:725 · reforgeOf _port["reforgeOf"] = function(e) local out = {["silver"] = 0, ["prestige"] = 0, ["time"] = 0}; for _, slot in ipairs(_port["REFORGE_KEYS"]) do do local lv = _port["reforgeLevel"](e, slot); if _rt.truth((not _rt.truth(lv))) then goto _continue8 end _rt.update(out, _rt.get(_rt.get(_rt.get(_port["REFORGE"], "slots"), slot), "stat"), "+", (_rt.get(_rt.get(_rt.get(_port["REFORGE"], "slots"), slot), "per") * lv)); end ::_continue8:: end do return out end end -- H5 engine.js:738 · reforgeBonus _port["reforgeBonus"] = function(s, ids) local out = {["silver"] = 0, ["prestige"] = 0, ["time"] = 0}; local list = _rt.choose(_rt.andThen(ids, function() return _rt.get(ids, "length") end), function() return _rt.call(_rt.call(ids, "map", function(id) return _rt.call(_rt.get(s, "escorts"), "find", function(x) return (_rt.get(x, "id") == id) end) end), "filter", _rt.truth) end, function() return _rt.array({}) end); if _rt.truth((not _rt.truth(_rt.get(list, "length")))) then do return out end end _rt.call(list, "forEach", function(e) local b = _port["reforgeOf"](e); _rt.update(out, "silver", "+", _rt.get(b, "silver")); _rt.update(out, "prestige", "+", _rt.get(b, "prestige")); _rt.update(out, "time", "+", _rt.get(b, "time")); end); _rt.update(out, "silver", "/", _rt.get(list, "length")); _rt.update(out, "prestige", "/", _rt.get(list, "length")); _rt.update(out, "time", "/", _rt.get(list, "length")); do return out end end -- H5 engine.js:749 · reforgeSlots _port["reforgeSlots"] = function(s, ids) local list = _rt.choose(_rt.andThen(ids, function() return _rt.get(ids, "length") end), function() return _rt.call(_rt.call(ids, "map", function(id) return _rt.call(_rt.get(s, "escorts"), "find", function(x) return (_rt.get(x, "id") == id) end) end), "filter", _rt.truth) end, function() return _rt.array({}) end); do return _rt.call(_port["REFORGE_KEYS"], "map", function(slot) local cfg = _rt.get(_rt.get(_port["REFORGE"], "slots"), slot); local lvs = _rt.call(list, "map", function(e) return _port["reforgeLevel"](e, slot) end); local lv = _rt.choose(_rt.get(lvs, "length"), function() return (_rt.call(lvs, "reduce", function(a, b) return _rt.add(a, b) end, 0) / _rt.get(lvs, "length")) end, function() return 0 end); local same = _rt.andThen(_rt.compare(">", _rt.get(lvs, "length"), 0), function() return _rt.call(lvs, "every", function(x) return (x == _rt.get(lvs, 0)) end) end); do return {["slot"] = slot, ["name"] = _rt.get(cfg, "name"), ["part"] = _rt.get(cfg, "part"), ["stat"] = _rt.get(cfg, "stat"), ["level"] = lv, ["per"] = _rt.get(cfg, "per"), ["bonus"] = (_rt.get(cfg, "per") * lv), ["grade"] = _rt.choose(_rt.compare("<=", lv, 0), function() return "尚未洗练" end, function() return _rt.choose(same, function() return _rt.get(_rt.get(_port["REFORGE"], "levels"), (_rt.math["round"](lv) - 1)) end, function() return _rt.add(_rt.call(lv, "toFixed", 1), "档") end) end)} end end) end end -- H5 engine.js:763 · reforge _port["reforge"] = function(s, escId, slot, times) local e = _rt.call(_rt.get(s, "escorts"), "find", function(x) return (_rt.get(x, "id") == escId) end); if _rt.truth((not _rt.truth(e))) then do return {["ok"] = false, ["msg"] = "该镖师已不在名册,请返回查看"} end end if _rt.truth(_rt.compare("<", _rt.call(_port["REFORGE_KEYS"], "indexOf", slot), 0)) then do return {["ok"] = false, ["msg"] = "该部位不可洗练"} end end local top = (_rt.get(_data["QUALITY"], "length") - 1); if _rt.truth(_rt.compare("<", _rt.orElse(_rt.get(e, "q"), function() return 0 end), top)) then do return {["ok"] = false, ["msg"] = _rt.add(_rt.add("需达到最高品阶(", _rt.get(_rt.get(_data["QUALITY"], top), "key")), ")后才能洗练")} end end if _rt.truth((not _rt.truth(_rt.get(e, "reforge")))) then _rt.set(e, "reforge", {["weapon"] = 0, ["mount"] = 0, ["armor"] = 0, ["compass"] = 0}); end if _rt.truth((not _rt.truth(_rt.get(e, "reforgePity")))) then _rt.set(e, "reforgePity", {["weapon"] = 0, ["mount"] = 0, ["armor"] = 0, ["compass"] = 0}); end local n = _rt.math["max"](1, _rt.math["min"](10, _rt.math["floor"](_rt.orElse(_rt.number(times), function() return 1 end)))); local rolls = 0; local spent = 0; local ups = 0; local last = _port["reforgeLevel"](e, slot); do local i = 0; while _rt.truth(_rt.compare("<", i, n)) do do local cost = _port["reforgeCost"](e, slot); if _rt.truth((cost == nil)) then break end if _rt.truth(_rt.compare("<", _rt.orElse(_rt.get(e, "frag"), function() return 0 end), cost)) then break end _rt.update(e, "frag", "-", cost); (function() spent = _rt.add(spent, cost); return spent end)(); (function() local _before = rolls; rolls = rolls + (1); return _before end)(); local lv = _port["reforgeLevel"](e, slot); local forced = _rt.compare(">=", _rt.orElse(_rt.get(_rt.get(e, "reforgePity"), slot), function() return 0 end), _rt.get(_port["REFORGE"], "pity")); local roll = _rt.math["floor"]((_rt.math["random"]() * _rt.get(_port["REFORGE"], "max"))); local up = _rt.orElse(forced, function() return _rt.compare(">", _rt.add(roll, 1), lv) end); local next = _rt.choose(up, function() return _rt.math["min"](_rt.get(_port["REFORGE"], "max"), _rt.add(lv, 1)) end, function() return lv end); if _rt.truth(_rt.compare(">", next, lv)) then _rt.set(_rt.get(e, "reforge"), slot, next); _rt.set(_rt.get(e, "reforgePity"), slot, 0); (function() local _before = ups; ups = ups + (1); return _before end)(); else _rt.set(_rt.get(e, "reforgePity"), slot, _rt.add(_rt.orElse(_rt.get(_rt.get(e, "reforgePity"), slot), function() return 0 end), 1)); end (function() last = next; return last end)(); end ::_continue9:: (function() local _before = i; i = i + (1); return _before end)() end end if _rt.truth((not _rt.truth(rolls))) then local cost = _port["reforgeCost"](e, slot); if _rt.truth((cost == nil)) then do return {["ok"] = false, ["msg"] = _rt.add(_rt.add("该部位已至「", _rt.get(_rt.get(_port["REFORGE"], "levels"), (_rt.get(_port["REFORGE"], "max") - 1))), "」,已达最高档")} end end do return {["ok"] = false, ["msg"] = _rt.add(_rt.add("同名碎片不足,本次需 ", _port["fmtNum"](cost)), " 枚")} end end _port["track"](s, "reforge", spent); local cfg = _rt.get(_rt.get(_port["REFORGE"], "slots"), slot); local grade = _rt.choose(last, function() return _rt.add(_rt.add("「", _rt.get(_rt.get(_port["REFORGE"], "levels"), (last - 1))), "」") end, function() return "尚未洗练" end); local tail = _rt.choose(ups, function() return _rt.add(_rt.add(_rt.add("升 ", ups), " 档,现为"), grade) end, function() return _rt.add(_rt.add(_rt.add(_rt.add("未升档,已连续 ", _rt.get(_rt.get(e, "reforgePity"), slot)), " 次未提升(满 "), _rt.get(_port["REFORGE"], "pity")), " 次后下一次必提升)") end); do return {["ok"] = true, ["msg"] = _rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.get(e, "name"), " · "), _rt.get(cfg, "part")), _rt.get(cfg, "name")), " 洗练 "), rolls), " 次(耗 "), spent), " 枚碎片),"), tail), ["rolls"] = rolls, ["spent"] = spent, ["ups"] = ups, ["level"] = last} end end -- H5 engine.js:804 · reforgeInfo _port["reforgeInfo"] = function(e) do return _rt.call(_port["REFORGE_KEYS"], "map", function(slot) local cfg = _rt.get(_rt.get(_port["REFORGE"], "slots"), slot); local lv = _port["reforgeLevel"](e, slot); do return {["slot"] = slot, ["part"] = _rt.get(cfg, "part"), ["name"] = _rt.get(cfg, "name"), ["stat"] = _rt.get(cfg, "stat"), ["per"] = _rt.get(cfg, "per"), ["level"] = lv, ["grade"] = _rt.choose(lv, function() return _rt.get(_rt.get(_port["REFORGE"], "levels"), (lv - 1)) end, function() return "尚未洗练" end), ["cost"] = _port["reforgeCost"](e, slot), ["pity"] = _rt.orElse(_rt.andThen(_rt.get(e, "reforgePity"), function() return _rt.get(_rt.get(e, "reforgePity"), slot) end), function() return 0 end), ["bonus"] = (_rt.get(cfg, "per") * lv), ["maxBonus"] = (_rt.get(cfg, "per") * _rt.get(_port["REFORGE"], "max")), ["unlocked"] = _rt.compare(">=", _rt.orElse(_rt.get(e, "q"), function() return 0 end), (_rt.get(_data["QUALITY"], "length") - 1))} end end) end end end