-- 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:465 · trainCap _port["trainCap"] = function(s) do return _rt.add(20, (10 * _rt.orElse(_rt.andThen(_rt.get(s, "facilities"), function() return _rt.get(_rt.get(s, "facilities"), "wuguan") end), function() return 1 end))) end end -- H5 engine.js:469 · unitFreight _port["unitFreight"] = function(s) local b = _port["bestBusiness"](s); local v = _rt.choose(b, function() return _port["businessBaseSilver"](b) end, function() return 0 end); do return _rt.choose(_rt.compare(">", v, 0), function() return v end, function() return 90 end) end end -- H5 engine.js:474 · costScale _port["costScale"] = function(s) do return _rt.math["max"](1, (_port["unitFreight"](s) / 90)) end end -- H5 engine.js:479 · trainCost _port["trainCost"] = function(key, current, s) local base = _rt.orElse(_rt.get({["force"] = 5, ["agility"] = 5, ["insight"] = 5, ["courage"] = 5}, key), function() return 5 end); local k = _rt.choose(s, function() return _port["costScale"](s) end, function() return 1 end); do return _rt.math["round"](((base * k) * _rt.math["pow"](1.08, current))) end end -- H5 engine.js:485 · trainAttr _port["trainAttr"] = function(s, escId, key) 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(_rt.array({"force", "agility", "insight", "courage"}), "indexOf", key), 0)) then do return {["ok"] = false, ["msg"] = "该属性不可训练"} end end local cur = _rt.orElse(_rt.andThen(_rt.get(e, "train"), function() return _rt.get(_rt.get(e, "train"), key) end), function() return 0 end); local cap = _port["trainCap"](s); if _rt.truth(_rt.compare(">=", cur, cap)) then do return {["ok"] = false, ["msg"] = _rt.add(_rt.add(_rt.add(_rt.get(_data["ATTRS"], key), "已达上限 "), cap), ",需升级武馆")} end end local cost = _port["trainCost"](key, cur, 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); if _rt.truth((not _rt.truth(_rt.get(e, "train")))) then _rt.set(e, "train", {["force"] = 0, ["agility"] = 0, ["insight"] = 0, ["courage"] = 0}); end _rt.set(_rt.get(e, "train"), key, _rt.add(cur, 1)); _port["track"](s, "train", cost); do return {["ok"] = true, ["msg"] = _rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.get(e, "name"), "的"), _rt.get(_data["ATTRS"], key)), "训练至 "), _rt.add(cur, 1)), "/"), cap)} end end _port["TRAIN_KEYS"] = _rt.array({"force", "agility", "insight", "courage"}) -- H5 engine.js:506 · trainPlan _port["trainPlan"] = function(s, escId, key) local e = _rt.call(_rt.get(s, "escorts"), "find", function(x) return (_rt.get(x, "id") == escId) end); local cap = _port["trainCap"](s); if _rt.truth((not _rt.truth(e))) then do return {["levels"] = 0, ["cost"] = 0, ["from"] = 0, ["to"] = 0, ["cap"] = cap, ["reached"] = false} end end local from = _rt.orElse(_rt.andThen(_rt.get(e, "train"), function() return _rt.get(_rt.get(e, "train"), key) end), function() return 0 end); local cur = from; local silver = _rt.get(s, "silver"); local cost = 0; local n = 0; while _rt.truth(_rt.andThen(_rt.compare("<", cur, cap), function() return _rt.compare("<", n, 400) end)) do do local c = _port["trainCost"](key, cur, s); if _rt.truth(_rt.compare("<", silver, c)) then break end (function() silver = (silver - c); return silver end)(); (function() cost = _rt.add(cost, c); return cost end)(); (function() local _before = cur; cur = cur + (1); return _before end)(); (function() local _before = n; n = n + (1); return _before end)(); end ::_continue4:: end do return {["levels"] = n, ["cost"] = cost, ["from"] = from, ["to"] = cur, ["cap"] = cap, ["reached"] = _rt.compare(">=", cur, cap)} end end -- H5 engine.js:521 · trainAllPlan _port["trainAllPlan"] = function(s, escId) local e = _rt.call(_rt.get(s, "escorts"), "find", function(x) return (_rt.get(x, "id") == escId) end); local cap = _port["trainCap"](s); local added = {["force"] = 0, ["agility"] = 0, ["insight"] = 0, ["courage"] = 0}; if _rt.truth((not _rt.truth(e))) then do return {["levels"] = 0, ["cost"] = 0, ["added"] = added, ["cap"] = cap, ["reached"] = false} end end local cur = {}; _rt.call(_port["TRAIN_KEYS"], "forEach", function(k) return _rt.set(cur, k, _rt.orElse(_rt.andThen(_rt.get(e, "train"), function() return _rt.get(_rt.get(e, "train"), k) end), function() return 0 end)) end); local silver = _rt.get(s, "silver"); local cost = 0; local levels = 0; do local guard = 0; while _rt.truth(_rt.compare("<", guard, 3000)) do do local pick = nil; for _, k in ipairs(_port["TRAIN_KEYS"]) do do if _rt.truth(_rt.compare(">=", _rt.get(cur, k), cap)) then goto _continue6 end if _rt.truth(_rt.orElse((not _rt.truth(pick)), function() return _rt.compare("<", _rt.get(cur, k), _rt.get(cur, pick)) end)) then (function() pick = k; return pick end)(); end end ::_continue6:: end if _rt.truth((not _rt.truth(pick))) then break end local c = _port["trainCost"](pick, _rt.get(cur, pick), s); if _rt.truth(_rt.compare("<", silver, c)) then break end (function() silver = (silver - c); return silver end)(); (function() cost = _rt.add(cost, c); return cost end)(); _rt.increment(cur, pick, 1, false); _rt.increment(added, pick, 1, false); (function() local _before = levels; levels = levels + (1); return _before end)(); end ::_continue5:: (function() local _before = guard; guard = guard + (1); return _before end)() end end local reached = _rt.call(_port["TRAIN_KEYS"], "every", function(k) return _rt.compare(">=", _rt.get(cur, k), cap) end); do return {["levels"] = levels, ["cost"] = cost, ["added"] = added, ["cap"] = cap, ["reached"] = reached, ["to"] = cur} end end -- H5 engine.js:544 · trainBulk _port["trainBulk"] = function(s, escId, key) 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["TRAIN_KEYS"], "indexOf", key), 0)) then do return {["ok"] = false, ["msg"] = "该属性不可训练"} end end local p = _port["trainPlan"](s, escId, key); if _rt.truth((not _rt.truth(_rt.get(p, "levels")))) then local cap = _port["trainCap"](s); if _rt.truth(_rt.compare(">=", _rt.get(p, "from"), cap)) then do return {["ok"] = false, ["msg"] = _rt.add(_rt.add(_rt.add(_rt.get(_data["ATTRS"], key), "已达上限 "), cap), ",需升级武馆")} end end do return {["ok"] = false, ["msg"] = _rt.add(_rt.add("银两不足,下一级需 ", _port["fmtNum"](_port["trainCost"](key, _rt.get(p, "from"), s))), " 两")} end end _rt.update(s, "silver", "-", _rt.get(p, "cost")); if _rt.truth((not _rt.truth(_rt.get(e, "train")))) then _rt.set(e, "train", {["force"] = 0, ["agility"] = 0, ["insight"] = 0, ["courage"] = 0}); end _rt.set(_rt.get(e, "train"), key, _rt.get(p, "to")); _port["track"](s, "train", _rt.get(p, "cost")); do return {["ok"] = true, ["msg"] = _rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.get(e, "name"), "的"), _rt.get(_data["ATTRS"], key)), " +"), _rt.get(p, "from")), " → +"), _rt.get(p, "to")), "(连练 "), _rt.get(p, "levels")), " 次,花 "), _rt.get(p, "cost")), " 两)")} end end -- H5 engine.js:561 · trainAllBulk _port["trainAllBulk"] = function(s, escId) 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 local p = _port["trainAllPlan"](s, escId); if _rt.truth((not _rt.truth(_rt.get(p, "levels")))) then do return {["ok"] = false, ["msg"] = _rt.choose(_rt.get(p, "reached"), function() return _rt.add("四项训练均已达到上限 ", _rt.get(p, "cap")) end, function() return "银两不足,无法继续训练" end)} end end _rt.update(s, "silver", "-", _rt.get(p, "cost")); if _rt.truth((not _rt.truth(_rt.get(e, "train")))) then _rt.set(e, "train", {["force"] = 0, ["agility"] = 0, ["insight"] = 0, ["courage"] = 0}); end _rt.call(_port["TRAIN_KEYS"], "forEach", function(k) _rt.update(_rt.get(e, "train"), k, "+", _rt.get(_rt.get(p, "added"), k)); end); _port["track"](s, "train", _rt.get(p, "cost")); local detail = _rt.call(_rt.call(_rt.call(_port["TRAIN_KEYS"], "filter", function(k) return _rt.compare(">", _rt.get(_rt.get(p, "added"), k), 0) end), "map", function(k) return _rt.add(_rt.add(_rt.get(_data["ATTRS"], k), " +"), _rt.get(_rt.get(p, "added"), k)) end), "join", "、"); do return {["ok"] = true, ["msg"] = _rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.get(e, "name"), " 四项属性连练 "), _rt.get(p, "levels")), " 次("), detail), "),花 "), _rt.get(p, "cost")), " 两")} end end _port["BRK"] = {["fragBase"] = 3, ["fragGrow"] = 1.55, ["silverMul"] = 2} -- H5 engine.js:584 · breakthroughCost _port["breakthroughCost"] = function(e) local next = _rt.add(_rt.orElse(_rt.get(e, "q"), function() return 0 end), 1); local table = _rt.choose((_rt.typeof(_data["RECRUIT_COST"]) ~= "undefined"), function() return _data["RECRUIT_COST"] end, function() return nil end); local ref = _rt.choose(table, function() return _rt.choose((_rt.get(table, next) ~= nil), function() return _rt.get(table, next) end, function() return _rt.get(table, (_rt.get(table, "length") - 1)) end) end, function() return 0 end); do return {["frag"] = _rt.math["round"]((_rt.get(_port["BRK"], "fragBase") * _rt.math["pow"](_rt.get(_port["BRK"], "fragGrow"), (next - 1)))), ["silver"] = _rt.math["round"]((ref * _rt.get(_port["BRK"], "silverMul")))} end end -- H5 engine.js:595 · breakthrough _port["breakthrough"] = function(s, escId, way) 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.get(e, "q"), (_rt.get(_data["QUALITY"], "length") - 1))) then do return {["ok"] = false, ["msg"] = "已达最高品阶"} end end local next = _rt.add(_rt.get(e, "q"), 1); if _rt.truth(_rt.compare(">", next, _port["maxQuality"](s))) then do return {["ok"] = false, ["msg"] = _rt.add(_rt.add(_rt.add(_rt.add("累计声望达到 ", _port["fmtNum"](_rt.get(_port["qualityGate"](next), "p"))), " 后可突破至"), _rt.get(_rt.get(_data["QUALITY"], next), "key")), "阶")} end end local c = _port["breakthroughCost"](e); if _rt.truth(_rt.compare("<", _rt.orElse(_rt.get(e, "frag"), function() return 0 end), _rt.get(c, "frag"))) then do return {["ok"] = false, ["msg"] = _rt.add(_rt.add(_rt.add(_rt.add("同名碎片不足,需 ", _port["fmtNum"](_rt.get(c, "frag"))), " 枚(现有 "), _port["fmtNum"](_rt.orElse(_rt.get(e, "frag"), function() return 0 end))), ")")} end end if _rt.truth(_rt.compare("<", _rt.orElse(_rt.get(s, "silver"), function() return 0 end), _rt.get(c, "silver"))) then do return {["ok"] = false, ["msg"] = _rt.add(_rt.add("银两不足,突破需 ", _port["fmtNum"](_rt.get(c, "silver"))), " 两")} end end _rt.update(e, "frag", "-", _rt.get(c, "frag")); _rt.update(s, "silver", "-", _rt.get(c, "silver")); _rt.set(e, "q", next); _port["track"](s, "breakthrough", next); 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(_rt.get(_data["QUALITY"], next), "key")), "阶 · 品阶战力倍率 ×"), _rt.call(_rt.get(_rt.get(_data["QUALITY"], next), "mul"), "toFixed", 1)), "(耗 "), _rt.get(c, "frag")), " 碎片 · "), _port["fmtNum"](_rt.get(c, "silver"))), " 两)"), ["frag"] = _rt.get(c, "frag"), ["silver"] = _rt.get(c, "silver")} end end _port["FRAG_EXCHANGE"] = {["silver"] = 90, ["prestige"] = 10, ["pow"] = 0.35} -- H5 engine.js:627 · fragRate _port["fragRate"] = function(s) local k = _rt.choose(s, function() return _port["costScale"](s) end, function() return 1 end); local scale = _rt.math["pow"](k, _rt.get(_port["FRAG_EXCHANGE"], "pow")); do return {["silver"] = _rt.math["max"](1, _rt.math["round"]((_rt.get(_port["FRAG_EXCHANGE"], "silver") * scale))), ["prestige"] = _rt.math["max"](1, _rt.math["round"]((_rt.get(_port["FRAG_EXCHANGE"], "prestige") * scale))), ["scale"] = scale} end end -- H5 engine.js:636 · exchangeFrag _port["exchangeFrag"] = function(s, escId, target, amount) 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.andThen((target ~= "silver"), function() return (target ~= "prestige") end)) then do return {["ok"] = false, ["msg"] = "请选择要兑换的资源"} end end local have = _rt.math["max"](0, _rt.orElse(_rt.get(e, "frag"), function() return 0 end)); local spend = _rt.choose((amount == "all"), function() return have end, function() return _rt.math["floor"](_rt.number(amount)) end); if _rt.truth(_rt.orElse((not _rt.truth(_rt.isFinite(spend))), function() return _rt.compare("<=", spend, 0) end)) then do return {["ok"] = false, ["msg"] = "请输入大于零的有效兑换数量"} end end if _rt.truth(_rt.compare(">", spend, have)) then do return {["ok"] = false, ["msg"] = _rt.add(_rt.add("碎片不足,仅有 ", have), " 枚")} end end local gained = (spend * _rt.get(_port["fragRate"](s), target)); _rt.set(e, "frag", (have - spend)); if _rt.truth((target == "silver")) then _rt.update(s, "silver", "+", gained); else _rt.update(s, "prestige", "+", gained); end _port["track"](s, "exchange", spend); do return {["ok"] = true, ["msg"] = _rt.add(_rt.add(_rt.add(_rt.add("已消耗 ", spend), " 枚碎片,获得 "), gained), _rt.choose((target == "silver"), function() return " 两银子" end, function() return " 点可用声望" end)), ["spent"] = spend, ["gained"] = gained, ["target"] = target} end end _port["BOUNTY"] = {["mul"] = 0.15, ["ms"] = ((60 * 60) * 1000)} end