-- 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:1655 · creditPrestige _port["creditPrestige"] = function(s, amount) local before = _rt.orElse(_rt.get(s, "prestigeTotal"), function() return 0 end); _rt.set(s, "prestige", _rt.add(_rt.orElse(_rt.get(s, "prestige"), function() return 0 end), amount)); _rt.set(s, "prestigeTotal", _rt.add(before, amount)); local hit = _port["milestoneCrossed"](before, _rt.get(s, "prestigeTotal")); local gift = 0; if _rt.truth(_rt.get(hit, "length")) then _rt.call(hit, "forEach", function(m) (function() gift = _rt.add(gift, _rt.orElse(_rt.get(m, "gift"), function() return 0 end)); return gift end)(); end); if _rt.truth(gift) then _rt.update(s, "gift", "+", gift); end _port["setCatchUpStreak"](s, 0); end do return {["gift"] = gift, ["milestones"] = _rt.call(hit, "map", function(m) return {["p"] = _rt.get(m, "p"), ["title"] = _rt.get(m, "title"), ["text"] = _rt.get(m, "text"), ["gift"] = _rt.orElse(_rt.get(m, "gift"), function() return 0 end)} end)} end end -- H5 engine.js:1669 · legCount _port["legCount"] = function(run) do return _rt.orElse(_rt.andThen(run, function() return _rt.get(run, "legs") end), function() return 1 end) end end -- H5 engine.js:1671 · legName _port["legName"] = function(run, idx) local stops = _rt.get(_port["LEG_STOPS"], _rt.get(run, "routeId")); do return _rt.orElse(_rt.andThen(stops, function() return _rt.get(stops, idx) end), function() return _rt.add(_rt.add("第", _rt.add(idx, 1)), "驿") end) end end -- H5 engine.js:1677 · arriveLeg _port["arriveLeg"] = function(s, run, idx) if _rt.truth((not _rt.truth(_rt.get(run, "paid")))) then _rt.set(run, "paid", {["silver"] = 0, ["prestige"] = 0}); end local full = _port["settle"](s, run); local silver = _rt.math["round"]((_rt.get(full, "silver") * _rt.orElse(_rt.get(_port["LEG_S_SHARE"], idx), function() return 0 end))); local prestige = _rt.math["round"]((_rt.get(full, "prestige") * _rt.orElse(_rt.get(_port["LEG_P_SHARE"], idx), function() return 0 end))); _rt.update(_rt.get(run, "paid"), "silver", "+", silver); _rt.update(_rt.get(run, "paid"), "prestige", "+", prestige); _rt.set(run, "legIdx", _rt.add(idx, 1)); _rt.update(s, "silver", "+", silver); _rt.update(_rt.get(s, "stats"), "silverEarned", "+", silver); local cr = _port["creditPrestige"](s, prestige); if _rt.truth(_rt.get(cr, "gift")) then _rt.set(run, "giftLegs", _rt.add(_rt.orElse(_rt.get(run, "giftLegs"), function() return 0 end), _rt.get(cr, "gift"))); end local stop = _port["legName"](run, idx); _rt.set(s, "news", _rt.call(_rt.call(_rt.array({_rt.add(_rt.add(_rt.add(_rt.add(_rt.add(_rt.add("镖队抵", stop), ",入账 "), _port["fmtNum"](silver)), " 两 · "), prestige), " 声望")}), "concat", _rt.get(s, "news")), "slice", 0, 30)); do return {["type"] = "leg", ["runId"] = _rt.get(run, "id"), ["idx"] = _rt.add(idx, 1), ["legs"] = _port["legCount"](run), ["stop"] = stop, ["silver"] = silver, ["prestige"] = prestige, ["milestones"] = _rt.get(cr, "milestones"), ["gift"] = _rt.get(cr, "gift")} end end -- H5 engine.js:1698 · settleFinal _port["settleFinal"] = function(s, run) local full = _port["settle"](s, run); local paid = _rt.orElse(_rt.get(run, "paid"), function() return {["silver"] = 0, ["prestige"] = 0} end); local ps = _rt.orElse(_rt.get(paid, "silver"), function() return 0 end); local pp = _rt.orElse(_rt.get(paid, "prestige"), function() return 0 end); local clamped = _rt.orElse(_rt.compare("<", _rt.get(full, "silver"), ps), function() return _rt.compare("<", _rt.get(full, "prestige"), pp) end); do return _rt.assign({}, full, {["fullSilver"] = _rt.math["max"](_rt.get(full, "silver"), ps), ["fullPrestige"] = _rt.math["max"](_rt.get(full, "prestige"), pp), ["silver"] = _rt.math["max"](0, (_rt.get(full, "silver") - ps)), ["prestige"] = _rt.math["max"](0, (_rt.get(full, "prestige") - pp)), ["paidSilver"] = ps, ["paidPrestige"] = pp, ["clamped"] = clamped, ["giftLegs"] = _rt.orElse(_rt.get(run, "giftLegs"), function() return 0 end), ["legs"] = _port["legCount"](run), ["legIdx"] = _rt.orElse(_rt.get(run, "legIdx"), function() return 0 end)}) end end -- H5 engine.js:1723 · quoteOf _port["quoteOf"] = function(s, ids) local rb = _port["reforgeBonus"](s, ids); local baseS = (_rt.add(_rt.add(1, _port["rankBonus"](_port["rankIndex"](_port["progressionPrestige"](s)))), (0.04 * (_rt.get(_rt.get(s, "facilities"), "zhangfang") - 1))) * _rt.choose(_port["bountyActive"](s), function() return _rt.add(1, _rt.get(_port["BOUNTY"], "mul")) end, function() return 1 end)); local baseP = _rt.add(1, (0.05 * _rt.math["max"](0, (_rt.get(_rt.get(s, "facilities"), "biaoqi") - 1)))); do return {["silverBonus"] = (baseS * _rt.add(1, _rt.get(rb, "silver"))), ["prestigeBonus"] = (baseP * _rt.add(1, _rt.get(rb, "prestige"))), ["baseSilver"] = baseS, ["basePrestigeMul"] = baseP, ["rfSilver"] = _rt.add(1, _rt.get(rb, "silver")), ["rfPrestige"] = _rt.add(1, _rt.get(rb, "prestige")), ["rfTime"] = _rt.add(1, _rt.get(rb, "time")), ["rfSlots"] = _port["reforgeSlots"](s, ids), ["chain"] = _port["chainMul"](s), ["chainP"] = _rt.add(1, (0.12 * (_port["branchCount"](s) - 1))), ["catchUp"] = _port["catchUpMul"](s)} end end -- H5 engine.js:1744 · settle _port["settle"] = function(s, run) local route = _rt.orElse(_rt.call(_data["ROUTES"], "find", function(r) return (_rt.get(r, "id") == _rt.get(run, "routeId")) end), function() return _rt.get(_data["ROUTES"], 0) end); local biz = _port["runBusiness"](run); local coef = _rt.choose(biz, function() return _rt.get(biz, "coef") end, function() return _rt.get(route, "coef") end); local powerWithEvent = _port["effectivePower"](run); local P = _rt.math["min"](2, _rt.math["pow"]((powerWithEvent / _rt.get(run, "need")), 0.35)); local F = _rt.add(1, (_rt.get(run, "insight") * _port["SILVER_PER_INSIGHT"])); local E = _rt.get(_rt.get(run, "effects"), "silver"); local rankIdx = _port["rankIndex"](_port["progressionPrestige"](s)); local q = _rt.orElse(_rt.get(run, "quote"), function() return nil end); local rb = _port["reforgeBonus"](s, _rt.get(run, "escortIds")); local baseBonus = _rt.choose(q, function() return _rt.choose((_rt.get(q, "baseSilver") ~= nil), function() return _rt.get(q, "baseSilver") end, function() return _rt.get(q, "silverBonus") end) end, function() return (_rt.add(_rt.add(1, _port["rankBonus"](rankIdx)), (0.04 * (_rt.get(_rt.get(s, "facilities"), "zhangfang") - 1))) * _rt.choose(_port["bountyActive"](s), function() return _rt.add(1, _rt.get(_port["BOUNTY"], "mul")) end, function() return 1 end)) end); local rfSilver = _rt.choose(q, function() return _rt.choose((_rt.get(q, "rfSilver") ~= nil), function() return _rt.get(q, "rfSilver") end, function() return 1 end) end, function() return _rt.add(1, _rt.get(rb, "silver")) end); local rfPrestige = _rt.choose(q, function() return _rt.choose((_rt.get(q, "rfPrestige") ~= nil), function() return _rt.get(q, "rfPrestige") end, function() return 1 end) end, function() return _rt.add(1, _rt.get(rb, "prestige")) end); local rfTime = _rt.choose(q, function() return _rt.choose((_rt.get(q, "rfTime") ~= nil), function() return _rt.get(q, "rfTime") end, function() return 1 end) end, function() return _rt.add(1, _rt.get(rb, "time")) end); local prestigeBaseMul = _rt.choose(q, function() return _rt.choose((_rt.get(q, "basePrestigeMul") ~= nil), function() return _rt.get(q, "basePrestigeMul") end, function() return (_rt.get(q, "prestigeBonus") / _rt.math["max"](1e-9, rfPrestige)) end) end, function() return _rt.add(1, (0.05 * _rt.math["max"](0, (_rt.get(_rt.get(s, "facilities"), "biaoqi") - 1)))) end); local rfSlots = _rt.choose(_rt.andThen(q, function() return _rt.get(q, "rfSlots") end), function() return _rt.get(q, "rfSlots") end, function() return _port["reforgeSlots"](s, _rt.get(run, "escortIds")) end); local silverBonus = _rt.choose(q, function() return _rt.get(q, "silverBonus") end, function() return (baseBonus * rfSilver) end); local prestigeBonus = _rt.choose(q, function() return _rt.get(q, "prestigeBonus") end, function() return (prestigeBaseMul * rfPrestige) end); local basePrestige = _rt.choose(_rt.andThen(biz, function() return _rt.get(biz, "gain") end), function() return _rt.get(biz, "gain") end, function() return _rt.get(route, "prestige") end); local chain = _rt.choose(q, function() return _rt.get(q, "chain") end, function() return _port["chainMul"](s) end); local chainP = _rt.choose(q, function() return _rt.get(q, "chainP") end, function() return _rt.add(1, (0.12 * (_port["branchCount"](s) - 1))) end); local catchUp = _rt.choose(q, function() return _rt.get(q, "catchUp") end, function() return _port["catchUpMul"](s) end); local p2x = _rt.choose(_port["prestige2xActive"](s), function() return 2 end, function() return 1 end); local silver = _rt.math["max"](1, _rt.math["round"](((((((_rt.get(run, "value") * coef) * P) * F) * E) * silverBonus) * chain))); local prestige = _rt.math["max"](1, _rt.math["round"](_rt.add(((((basePrestige * prestigeBonus) * chainP) * catchUp) * p2x), _rt.orElse(_rt.get(_rt.get(run, "effects"), "prestige"), function() return 0 end)))); local decisions = _port["cityDecisionReport"](run); if _rt.truth(decisions) then (function() silver = _rt.get(decisions, "silver"); return silver end)(); (function() prestige = _rt.get(_rt.get(run, "journeyDecision"), "basePrestige"); return prestige end)(); end do return {["routeName"] = _rt.get(route, "name"), ["bizName"] = _rt.choose(_rt.get(run, "cityGoalId"), function() return _rt.get(run, "bizName") end, function() return _rt.choose(biz, function() return _rt.get(biz, "name") end, function() return _rt.get(route, "name") end) end), ["bizId"] = _rt.choose(biz, function() return _rt.get(biz, "id") end, function() return "" end), ["value"] = _rt.get(run, "value"), ["coef"] = coef, ["P"] = P, ["F"] = F, ["E"] = E, ["chain"] = chain, ["chainP"] = chainP, ["catchUp"] = catchUp, ["p2x"] = p2x, ["silverBonus"] = silverBonus, ["prestigeBonus"] = prestigeBonus, ["baseBonus"] = baseBonus, ["prestigeBaseMul"] = prestigeBaseMul, ["basePrestigeAmt"] = basePrestige, ["rfSilver"] = rfSilver, ["rfPrestige"] = rfPrestige, ["rfTime"] = rfTime, ["rfSlots"] = rfSlots, ["silver"] = silver, ["prestige"] = prestige, ["decisions"] = decisions, ["power"] = powerWithEvent, ["need"] = _rt.get(run, "need"), ["quoted"] = (not _rt.truth((not _rt.truth(q)))), ["failed"] = _rt.get(run, "battleFailed")} end end -- H5 engine.js:1795 · tick _port["tick"] = function(s, dt) local event = nil; local legs = _rt.array({}); for _, run in ipairs(_rt.get(s, "runs")) do do if _rt.truth(_rt.orElse(_rt.get(run, "done"), function() return _rt.get(run, "paused") end)) then goto _continue25 end _rt.update(run, "elapsed", "+", dt); if _rt.truth(_rt.andThen(_rt.compare("<", _rt.get(run, "eventIdx"), _rt.get(_rt.get(run, "eventAt"), "length")), function() return _rt.compare(">=", _rt.get(run, "elapsed"), _rt.get(_rt.get(run, "eventAt"), _rt.get(run, "eventIdx"))) end)) then if _rt.truth(_rt.get(run, "journeyDecision")) then _rt.set(run, "elapsed", _rt.get(_rt.get(run, "eventAt"), _rt.get(run, "eventIdx"))); end _rt.increment(run, "eventIdx", 1, false); (function() event = {["type"] = "event", ["runId"] = _rt.get(run, "id"), ["event"] = _port["fireEvent"](s, run)}; return event end)(); break end local total = (_rt.get(run, "duration") * _rt.get(_rt.get(run, "effects"), "time")); local legN = _port["legCount"](run); while _rt.truth(_rt.andThen(_rt.compare("<", _rt.get(run, "legIdx"), (legN - 1)), function() return _rt.compare(">=", _rt.get(run, "elapsed"), ((total * _rt.add(_rt.get(run, "legIdx"), 1)) / legN)) end)) do do _rt.call(legs, "push", _port["arriveLeg"](s, run, _rt.get(run, "legIdx"))); end ::_continue26:: end if _rt.truth(_rt.compare(">=", _rt.get(run, "elapsed"), total)) then _rt.set(run, "done", true); _rt.set(run, "settleDetail", _port["settleFinal"](s, run)); end end ::_continue25:: end if _rt.truth(event) then do return _rt.choose(_rt.get(legs, "length"), function() return _rt.assign({["legs"] = legs}, event) end, function() return event end) end end if _rt.truth(_rt.get(legs, "length")) then do return {["type"] = "leg", ["legs"] = legs} end end if _rt.truth(_rt.call(_rt.get(s, "runs"), "some", function(r) return _rt.get(r, "done") end)) then do return {["type"] = "done"} end end do return nil end end -- H5 engine.js:1824 · commitAll _port["commitAll"] = function(s, double) local done = _rt.call(_rt.get(s, "runs"), "filter", function(r) return _rt.get(r, "done") end); if _rt.truth((not _rt.truth(_rt.get(done, "length")))) then do return nil end end local totalSilver = 0; local totalPrestige = 0; local totalGift = 0; local gains = _rt.array({}); local left = _rt.array({}); local milestones = _rt.array({}); local cityUnlocks = _rt.array({}); _rt.call(done, "forEach", function(run) local d = _rt.orElse(_rt.get(run, "settleDetail"), function() return _port["settleFinal"](s, run) end); local cityUnlock = _port["creditCityRun"](s, run); if _rt.truth(cityUnlock) then _rt.call(cityUnlocks, "push", cityUnlock); end if _rt.truth(_rt.andThen(_rt.andThen(_rt.get(run, "endCity"), function() return (not _rt.truth(_rt.andThen(_rt.get(run, "cityGoalId"), function() return _rt.get(run, "battleFailed") end))) end), function() return (not _rt.truth(_rt.call(_rt.get(_rt.get(s, "codex"), "cities"), "includes", _rt.get(run, "endCity")))) end)) then _rt.call(_rt.get(_rt.get(s, "codex"), "cities"), "push", _rt.get(run, "endCity")); end local paidBack = _rt.choose(double, function() return _rt.orElse(_rt.get(d, "paidSilver"), function() return 0 end) end, function() return 0 end); local sv = _rt.add(_rt.math["round"]((_rt.get(d, "silver") * _rt.choose(double, function() return 2 end, function() return 1 end))), paidBack); _rt.update(s, "silver", "+", sv); local cr = _port["creditPrestige"](s, _rt.get(d, "prestige")); if _rt.truth(_rt.get(cr, "gift")) then (function() totalGift = _rt.add(totalGift, _rt.get(cr, "gift")); return totalGift end)(); end local legGift = _rt.orElse(_rt.orElse(_rt.get(d, "giftLegs"), function() return _rt.get(run, "giftLegs") end), function() return 0 end); if _rt.truth(legGift) then (function() totalGift = _rt.add(totalGift, legGift); return totalGift end)(); end if _rt.truth(_rt.get(_rt.get(cr, "milestones"), "length")) then _rt.call(_rt.get(cr, "milestones"), "forEach", function(m) return _rt.call(milestones, "push", m) end); else _port["setCatchUpStreak"](s, _rt.add(_port["catchUpStreak"](s), 1)); end (function() totalSilver = _rt.add(totalSilver, sv); return totalSilver end)(); (function() totalPrestige = _rt.add(totalPrestige, _rt.get(d, "prestige")); return totalPrestige end)(); local bizIndex = _rt.call(_port["businessList"](), "indexOf", _port["runBusiness"](run)); local gift = _rt.add(_rt.add(2, _rt.choose((_rt.get(run, "routeId") == "cross"), function() return 5 end, function() return _rt.choose((_rt.get(run, "routeId") == "far"), function() return 3 end, function() return 0 end) end)), _rt.math["max"](0, (bizIndex - 3))); _rt.update(s, "gift", "+", gift); (function() totalGift = _rt.add(totalGift, gift); return totalGift end)(); local tripPrestige = _rt.choose((_rt.get(d, "fullPrestige") ~= nil), function() return _rt.get(d, "fullPrestige") end, function() return _rt.get(d, "prestige") end); _rt.call(_rt.get(run, "escortIds"), "forEach", function(id) local e = _rt.call(_rt.get(s, "escorts"), "find", function(x) return (_rt.get(x, "id") == id) end); if _rt.truth((not _rt.truth(e))) then do return nil end end _rt.set(_rt.get(e, "at"), "loyalty", _rt.math["max"](0, (_rt.get(_rt.get(e, "at"), "loyalty") - 1))); local up = _port["addExp"](s, e, _rt.add(_rt.math["round"](_rt.add(20, _rt.orElse(_rt.get(_rt.get(run, "effects"), "exp"), function() return 0 end))), (tripPrestige / 2))); if _rt.truth(up) then _rt.call(gains, "push", _rt.add(_rt.add(_rt.add(_rt.get(e, "name"), "升至 "), _rt.get(e, "level")), " 级")); end local fragGain = _rt.orElse(_rt.get({["near"] = 1, ["city"] = 2, ["far"] = 3, ["cross"] = 5}, _rt.get(run, "routeId")), function() return 1 end); _rt.set(e, "frag", _rt.add(_rt.orElse(_rt.get(e, "frag"), function() return 0 end), fragGain)); if _rt.truth(_rt.andThen(_rt.compare("<", _rt.get(_rt.get(e, "at"), "loyalty"), 30), function() return _rt.compare(">", _rt.get(_rt.get(s, "escorts"), "length"), 1) end)) then local chance = _rt.math["min"](1, _rt.add(_port["LEAVE_BASE"], ((30 - _rt.get(_rt.get(e, "at"), "loyalty")) * _port["LEAVE_STEP"]))); if _rt.truth(_rt.compare("<", _rt.math["random"](), chance)) then _rt.set(s, "escorts", _rt.call(_rt.get(s, "escorts"), "filter", function(x) return (_rt.get(x, "id") ~= id) end)); _rt.increment(_rt.get(s, "stats"), "left", 1, false); _rt.call(left, "push", _rt.add(_rt.get(e, "name"), "因忠诚过低离队")); end end end); end); _rt.set(s, "runs", _rt.call(_rt.get(s, "runs"), "filter", function(r) return (not _rt.truth(_rt.get(r, "done"))) end)); _rt.update(_rt.get(s, "stats"), "runs", "+", _rt.get(done, "length")); _rt.update(_rt.get(s, "stats"), "silverEarned", "+", totalSilver); _port["track"](s, "settle", totalSilver); if _rt.truth(_rt.get(left, "length")) then _rt.set(s, "news", _rt.call(_rt.call(left, "concat", _rt.get(s, "news")), "slice", 0, 30)); end if _rt.truth(_rt.get(milestones, "length")) then local names = _rt.call(_rt.call(milestones, "map", function(m) return _rt.get(m, "title") end), "join", "、"); _rt.set(s, "news", _rt.call(_rt.call(_rt.array({_rt.add(_rt.add(_rt.add(_rt.add("声望至 ", _port["fmtNum"](_rt.get(_rt.get(milestones, (_rt.get(milestones, "length") - 1)), "p"))), " · "), names), " 达成")}), "concat", _rt.get(s, "news")), "slice", 0, 30)); end do return {["silver"] = totalSilver, ["prestige"] = totalPrestige, ["gift"] = totalGift, ["gains"] = gains, ["left"] = left, ["milestones"] = milestones, ["cityUnlocks"] = cityUnlocks, ["runs"] = _rt.get(done, "length"), ["double"] = (not _rt.truth((not _rt.truth(double))))} end end end