-- 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:1237 · businessList _port["businessList"] = function() do return _rt.choose(_rt.andThen((_rt.typeof(_data["BUSINESSES"]) ~= "undefined"), function() return _rt.isArray(_data["BUSINESSES"]) end), function() return _data["BUSINESSES"] end, function() return _rt.array({}) end) end end -- H5 engine.js:1240 · businessById _port["businessById"] = function(id) do return _rt.orElse(_rt.call(_port["businessList"](), "find", function(b) return (_rt.get(b, "id") == id) end), function() return nil end) end end -- H5 engine.js:1241 · businessPower _port["businessPower"] = function(s, b) do return _rt.choose(b, function() return _rt.orElse(_rt.get(_rt.orElse(_rt.get(s, "businessRequirements"), function() return {} end), _rt.get(b, "id")), function() return _rt.get(b, "power") end) end, function() return 0 end) end end -- H5 engine.js:1242 · businessForRoute _port["businessForRoute"] = function(routeId) do return _rt.orElse(_rt.orElse(_rt.call(_port["businessList"](), "find", function(b) return (_rt.get(b, "route") == routeId) end), function() return _rt.get(_port["businessList"](), 0) end), function() return nil end) end end -- H5 engine.js:1243 · progressionPrestige _port["progressionPrestige"] = function(s) do return _rt.choose(_rt.andThen(s, function() return (_rt.get(s, "prestigeTotal") ~= nil) end), function() return _rt.get(s, "prestigeTotal") end, function() return _rt.orElse(_rt.andThen(s, function() return _rt.get(s, "prestige") end), function() return 0 end) end) end end -- H5 engine.js:1247 · milestoneList _port["milestoneList"] = function() do return _rt.choose(_rt.andThen((_rt.typeof(_data["UNLOCKS"]) ~= "undefined"), function() return _rt.isArray(_data["UNLOCKS"]) end), function() return _data["UNLOCKS"] end, function() return _rt.array({}) end) end end -- H5 engine.js:1250 · milestoneCrossed _port["milestoneCrossed"] = function(before, after) do return _rt.call(_port["milestoneList"](), "filter", function(m) return _rt.andThen(_rt.compare(">", _rt.get(m, "p"), before), function() return _rt.compare("<=", _rt.get(m, "p"), after) end) end) end end -- H5 engine.js:1253 · nextMilestone _port["nextMilestone"] = function(p) do return _rt.orElse(_rt.call(_port["milestoneList"](), "find", function(m) return _rt.compare(">", _rt.get(m, "p"), p) end), function() return nil end) end end _port["CATCHUP_FREE"] = 5 _port["CATCHUP_STEP"] = 0.05 _port["CATCHUP_CAP"] = 1 _port["CATCHUP_FROM"] = 2000 -- H5 engine.js:1264 · catchUpStreak _port["catchUpStreak"] = function(s) do return _rt.math["max"](0, _rt.orElse(_rt.andThen(_rt.andThen(s, function() return _rt.get(s, "catchup") end), function() return _rt.get(_rt.get(s, "catchup"), "streak") end), function() return 0 end)) end end -- H5 engine.js:1265 · catchUpMul _port["catchUpMul"] = function(s) if _rt.truth(_rt.compare("<", _port["progressionPrestige"](s), _port["CATCHUP_FROM"])) then do return 1 end end do return _rt.add(1, _rt.math["min"](_port["CATCHUP_CAP"], (_port["CATCHUP_STEP"] * _rt.math["max"](0, (_port["catchUpStreak"](s) - _port["CATCHUP_FREE"]))))) end end -- H5 engine.js:1269 · setCatchUpStreak _port["setCatchUpStreak"] = function(s, n) _rt.set(s, "catchup", {["streak"] = _rt.math["max"](0, _rt.bit("|", n, 0))}); end _port["P2X_MS"] = ((30 * 60) * 1000) -- H5 engine.js:1273 · prestige2xLeft _port["prestige2xLeft"] = function(s) do return _rt.math["max"](0, (_rt.orElse(_rt.andThen(_rt.andThen(s, function() return _rt.get(s, "buff") end), function() return _rt.get(_rt.get(s, "buff"), "p2x") end), function() return 0 end) - _rt.now())) end end -- H5 engine.js:1276 · prestige2xActive _port["prestige2xActive"] = function(s) do return _rt.compare(">", _port["prestige2xLeft"](s), 0) end end -- H5 engine.js:1277 · grantPrestige2x _port["grantPrestige2x"] = function(s) _rt.set(s, "buff", _rt.orElse(_rt.get(s, "buff"), function() return {} end)); _rt.set(_rt.get(s, "buff"), "p2x", _rt.add(_rt.now(), _port["P2X_MS"])); do return _port["P2X_MS"] end end -- H5 engine.js:1282 · businessUnlocked _port["businessUnlocked"] = function(s, b) if _rt.truth((not _rt.truth(b))) then do return false end end if _rt.truth(_rt.compare("<", _port["progressionPrestige"](s), _rt.get(b, "prestige"))) then do return false end end if _rt.truth(_rt.andThen((_rt.get(b, "route") == "cross"), function() return (not _rt.truth(_port["unlocked"](s, "cross"))) end)) then do return false end end do return true end end -- H5 engine.js:1288 · bestBusiness _port["bestBusiness"] = function(s) local list = _rt.call(_port["businessList"](), "filter", function(b) return _port["businessUnlocked"](s, b) end); do return _rt.orElse(_rt.orElse(_rt.get(list, (_rt.get(list, "length") - 1)), function() return _rt.get(_port["businessList"](), 0) end), function() return nil end) end end -- H5 engine.js:1292 · runBusiness _port["runBusiness"] = function(run) if _rt.truth((not _rt.truth(run))) then do return nil end end local b = _rt.choose(_rt.get(run, "bizId"), function() return _port["businessById"](_rt.get(run, "bizId")) end, function() return _port["businessForRoute"](_rt.get(run, "routeId")) end); do return _rt.orElse(b, function() return _port["businessForRoute"](_rt.get(run, "routeId")) end) end end -- H5 engine.js:1298 · businessBaseSilver _port["businessBaseSilver"] = function(b) do return _rt.choose(b, function() return _rt.math["round"]((_rt.get(b, "value") * _rt.get(b, "coef"))) end, function() return 0 end) end end _port["SHOP_DEPOSIT_TRIPS"] = 15 -- H5 engine.js:1304 · bizTier _port["bizTier"] = function(b) local i = _rt.call(_port["businessList"](), "findIndex", function(x) return (_rt.get(x, "id") == _rt.andThen(b, function() return _rt.get(b, "id") end)) end); do return _rt.choose(_rt.compare("<", i, 0), function() return 1 end, function() return _rt.add(i, 1) end) end end -- H5 engine.js:1308 · openedTier _port["openedTier"] = function(s) do return _rt.math["max"](1, _rt.orElse(_rt.andThen(s, function() return _rt.get(s, "openTier") end), function() return 1 end)) end end -- H5 engine.js:1309 · depositFor _port["depositFor"] = function(b) local i = _port["bizTier"](b); if _rt.truth(_rt.compare("<=", i, 1)) then do return 0 end end local prev = _rt.get(_port["businessList"](), (i - 2)); do return _rt.math["round"]((_port["businessBaseSilver"](prev) * _port["SHOP_DEPOSIT_TRIPS"])) end end -- H5 engine.js:1315 · shopOpened _port["shopOpened"] = function(s, b) do return _rt.compare("<=", _port["bizTier"](b), _port["openedTier"](s)) end end -- H5 engine.js:1316 · shopOpening _port["shopOpening"] = function(s, b) if _rt.truth((not _rt.truth(b))) then do return {["ok"] = false, ["msg"] = "生意不存在"} end end local tier = _port["bizTier"](b); if _rt.truth(_rt.compare("<=", tier, _port["openedTier"](s))) then do return {["ok"] = false, ["msg"] = "该业务已开通"} end end if _rt.truth(_rt.compare(">", tier, _rt.add(_port["openedTier"](s), 1))) then do return {["ok"] = false, ["msg"] = _rt.add(_rt.add("请先开通", _rt.get(_rt.get(_port["businessList"](), (tier - 2)), "name")), "业务")} end end if _rt.truth((not _rt.truth(_port["businessUnlocked"](s, b)))) then do return {["ok"] = false, ["msg"] = _rt.add(_rt.add("累计声望还差 ", _port["fmtNum"](_rt.math["max"](0, (_rt.get(b, "prestige") - _port["progressionPrestige"](s))))), " 点")} end end local dep = _port["depositFor"](b); if _rt.truth(_rt.compare("<", _rt.get(s, "silver"), dep)) then do return {["ok"] = false, ["msg"] = _rt.add(_rt.add("开通费用还差 ", _port["fmtNum"]((dep - _rt.get(s, "silver")))), " 两")} end end do return {["ok"] = true, ["tier"] = tier, ["dep"] = dep} end end -- H5 engine.js:1326 · openShop _port["openShop"] = function(s, bizId) local check = _port["shopOpening"](s, _port["businessById"](bizId)); if _rt.truth((not _rt.truth(_rt.get(check, "ok")))) then do return check end end local tier, dep tier = _rt.get(check, "tier") dep = _rt.get(check, "dep") _rt.update(s, "silver", "-", dep); _rt.set(s, "openTier", tier); _rt.set(_rt.default(s, "businessRequirements", function() return {} end), bizId, _rt.get(_port["businessById"](bizId), "power")); _port["track"](s, "shop", tier); do return {["ok"] = true, ["msg"] = _rt.add(_rt.add(_rt.add(_rt.add("已开通", _rt.get(_port["businessById"](bizId), "name")), "业务 · 花费 "), _port["fmtNum"](dep)), " 两"), ["tier"] = tier} end end -- H5 engine.js:1338 · branchCount _port["branchCount"] = function(s) do return _rt.math["max"](1, _rt.orElse(_rt.andThen(s, function() return _rt.get(s, "branches") end), function() return 1 end)) end end -- H5 engine.js:1339 · chainCost _port["chainCost"] = function(s) local cfg = _port["chainCfg"](); local n = _rt.add(_port["branchCount"](s), 1); if _rt.truth(_rt.compare(">", n, _rt.get(cfg, "maxBranches"))) then do return nil end end do return _rt.math["round"](((_rt.get(cfg, "costBase") * _port["costScale"](s)) * _rt.math["pow"](_rt.get(cfg, "costGrowth"), (n - 2)))) end end -- H5 engine.js:1345 · chainPrestigeGate _port["chainPrestigeGate"] = function(n) local cfg = _port["chainCfg"](); if _rt.truth(_rt.compare("<=", n, 1)) then do return 0 end end do return (_rt.math["round"](((_rt.get(cfg, "prestigeBase") * _rt.math["pow"](_rt.get(cfg, "prestigeGrowth"), (n - 2))) / 100)) * 100) end end -- H5 engine.js:1350 · chainMul _port["chainMul"] = function(s) local cfg = _port["chainCfg"](); local n = _port["branchCount"](s); do return _rt.add(1, (_rt.get(cfg, "synergyPer") * (n - 1))) end end -- H5 engine.js:1355 · chainCanExpand _port["chainCanExpand"] = function(s) local cfg = _port["chainCfg"](); local n = _rt.add(_port["branchCount"](s), 1); if _rt.truth(_rt.compare(">", n, _rt.get(cfg, "maxBranches"))) then do return {["ok"] = false, ["msg"] = "已达上限 · 十家连锁"} end end local needEsc = (_rt.get(cfg, "escortsPer") * n); if _rt.truth(_rt.compare("<", _rt.get(_rt.get(s, "escorts"), "length"), needEsc)) then do return {["ok"] = false, ["msg"] = _rt.add(_rt.add(_rt.add(_rt.add("需拥有 ", needEsc), " 名镖师(当前 "), _rt.get(_rt.get(s, "escorts"), "length")), " 名)")} end end local gate = _port["chainPrestigeGate"](n); if _rt.truth(_rt.compare("<", _port["progressionPrestige"](s), gate)) then do return {["ok"] = false, ["msg"] = _rt.add("需累计声望 ", _port["fmtNum"](gate))} end end do return {["ok"] = true} end end -- H5 engine.js:1365 · openBranch _port["openBranch"] = function(s) local chk = _port["chainCanExpand"](s); if _rt.truth((not _rt.truth(_rt.get(chk, "ok")))) then do return chk end end local cost = _port["chainCost"](s); 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); _rt.set(s, "branches", _rt.add(_port["branchCount"](s), 1)); _port["track"](s, "branch", _rt.get(s, "branches")); do return {["ok"] = true, ["msg"] = _rt.add(_rt.add(_rt.add("第 ", _rt.get(s, "branches")), " 家镖局开张 · 连锁镖银 ×"), _rt.call(_port["chainMul"](s), "toFixed", 2)), ["branches"] = _rt.get(s, "branches")} end end -- H5 engine.js:1375 · fmtNum _port["fmtNum"] = function(n) do return _rt.call(_rt.math["round"](n), "toLocaleString", "zh-CN") end end -- H5 engine.js:1378 · monopolyDegree _port["monopolyDegree"] = function(s, id) do return _rt.math["max"](0, _rt.math["min"](_rt.get(_port["monopolyCfg"](), "maxDegree"), _rt.orElse(_rt.get(_rt.orElse(_rt.andThen(s, function() return _rt.get(s, "monopoly") end), function() return {} end), id), function() return 0 end))) end end -- H5 engine.js:1379 · monopolyList _port["monopolyList"] = function(s) local cfg = _port["monopolyCfg"](); local prog = _port["progressionPrestige"](s); local share = _rt.choose((_rt.get(cfg, "shareRate") ~= nil), function() return _rt.get(cfg, "shareRate") end, function() return 0.15 end); do return _rt.call(_port["monopolyRoutes"](), "map", function(r) local biz = _port["businessById"](_rt.get(r, "biz")); local base = _port["businessBaseSilver"](biz); local degree = _port["monopolyDegree"](s, _rt.get(r, "id")); local open = _rt.compare(">=", prog, _rt.get(r, "gate")); local route = _rt.choose(biz, function() return _rt.call(_data["ROUTES"], "find", function(x) return (_rt.get(x, "id") == _rt.get(biz, "route")) end) end, function() return nil end); local dur = _rt.choose(route, function() return _port["durationSec"](s, route, _rt.array({}), _port["businessPower"](s, biz)) end, function() return 1 end); local onlineHourly = _rt.choose(route, function() return ((base * (3600 / _rt.math["max"](2, dur))) * _port["chainMul"](s)) end, function() return 0 end); local hourly = _rt.math["round"](((onlineHourly * share) * (degree / 100))); local cost = _rt.math["round"](((base * _rt.get(cfg, "costK")) * _rt.add(1, (degree / 100)))); do return {["id"] = _rt.get(r, "id"), ["name"] = _rt.get(r, "name"), ["region"] = _rt.get(r, "region"), ["biz"] = _rt.get(r, "biz"), ["bizName"] = _rt.choose(biz, function() return _rt.get(biz, "name") end, function() return "" end), ["desc"] = _rt.get(r, "desc"), ["gate"] = _rt.get(r, "gate"), ["open"] = open, ["degree"] = degree, ["max"] = _rt.compare(">=", degree, _rt.get(cfg, "maxDegree")), ["hourly"] = hourly, ["cost"] = cost, ["onlineHourly"] = _rt.math["round"](onlineHourly), ["flow"] = _rt.math["round"](((onlineHourly * share) * 24))} end end) end end -- H5 engine.js:1399 · investMonopoly _port["investMonopoly"] = function(s, id) local cfg = _port["monopolyCfg"](); local row = _rt.call(_port["monopolyList"](s), "find", function(m) return (_rt.get(m, "id") == id) end); if _rt.truth((not _rt.truth(row))) then do return {["ok"] = false, ["msg"] = "商路不存在"} end end if _rt.truth((not _rt.truth(_rt.get(row, "open")))) then do return {["ok"] = false, ["msg"] = _rt.add(_rt.add("累计声望 ", _port["fmtNum"](_rt.get(row, "gate"))), " 开通该商路")} end end if _rt.truth(_rt.get(row, "max")) then do return {["ok"] = false, ["msg"] = "该商路控制度已达 100%"} end end if _rt.truth(_rt.compare("<", _rt.get(s, "silver"), _rt.get(row, "cost"))) then do return {["ok"] = false, ["msg"] = _rt.add(_rt.add("银两不足,需 ", _port["fmtNum"](_rt.get(row, "cost"))), " 两")} end end _rt.update(s, "silver", "-", _rt.get(row, "cost")); if _rt.truth((not _rt.truth(_rt.get(s, "monopoly")))) then _rt.set(s, "monopoly", {}); end _rt.set(_rt.get(s, "monopoly"), id, _rt.math["min"](_rt.get(cfg, "maxDegree"), _rt.add(_rt.get(row, "degree"), _rt.get(cfg, "step")))); _port["track"](s, "monopoly", _rt.get(_rt.get(s, "monopoly"), id)); do return {["ok"] = true, ["msg"] = _rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.get(row, "name"), " 商路控制度 → "), _rt.get(_rt.get(s, "monopoly"), id)), "% · 每小时收入 "), _port["fmtNum"](_rt.get(_rt.call(_port["monopolyList"](s), "find", function(m) return (_rt.get(m, "id") == id) end), "hourly"))), " 两/时"), ["degree"] = _rt.get(_rt.get(s, "monopoly"), id)} end end -- H5 engine.js:1412 · monopolyHourly _port["monopolyHourly"] = function(s) do return _rt.call(_port["monopolyList"](s), "reduce", function(a, m) return _rt.add(a, _rt.get(m, "hourly")) end, 0) end end end