Modern UI contract: bank credits
The credit read previews the loan dialog (bank or another human lender) with per-field bounds, fees and refund; bank.commit action credit books the same edits. The bank read now points to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
06445c24ef
commit
74c1504e3a
3 files changed
+97
-5
No files matched your search
@@ -8901,7 +8901,7 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
|
||||
const int manager = context.manager;
|
||||
if (manager < 0 || size_t(manager) >= g_.manager_teams.size() ||
|
||||
(kind != "lineup" && kind != "tactics" && kind != "training" && kind != "bank" && kind != "contracts" &&
|
||||
kind != "advertising" && kind != "stadium" && kind != "transfer" && kind != "postmatch"))
|
||||
kind != "advertising" && kind != "stadium" && kind != "transfer" && kind != "postmatch" && kind != "credit"))
|
||||
return modern::ui_read(g_, context, request);
|
||||
if (const std::string wanted = ui_text(request, "managerId"); !wanted.empty() && wanted != modern::ui_manager_id(g_, manager))
|
||||
return modern::ui_error(request_id, "manager_not_active", "Dieser Manager sitzt nicht am Schreibtisch.", revision, false);
|
||||
@@ -9132,6 +9132,44 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
|
||||
return modern::ui_snapshot(g_, context, request_id,
|
||||
O{{"kind", "contracts"}, {"teamId", modern::ui_team_id(g_, team)}, {"players", std::move(players)}, {"quote", std::move(quote)}});
|
||||
}
|
||||
if (kind == "credit") {
|
||||
// the credit dialog (bank or another human manager as lender): the saved loan, the draft after
|
||||
// the request's edits [{field, value}] with labels, bounds per field, fees and refund. Pure:
|
||||
// the edits only preview what bank.commit {action: credit} would book.
|
||||
int counterparty = 0;
|
||||
if (const std::string lender = ui_text(request, "lenderId"); !lender.empty() && lender != "bank") {
|
||||
for (int m = 0; m < int(g_.manager_teams.size()); ++m)
|
||||
if (m != manager && modern::ui_manager_id(g_, m) == lender) counterparty = m + 1;
|
||||
if (counterparty == 0) return modern::ui_error(request_id, "unknown_lender", "Unbekannter Kreditgeber.", revision, false);
|
||||
}
|
||||
const BankCreditContext credit = modern::bank_credit_context(g_, exe_, manager, counterparty);
|
||||
if (!credit.available) return modern::ui_error(request_id, "credit_unavailable", "Kein Kredit möglich.", revision, false);
|
||||
BankCreditDraft draft = modern::bank_credit_draft(credit);
|
||||
if (const cli::Json* edits = ui_field(request, "edits"); edits && edits->array())
|
||||
for (const auto& e : *edits->array()) {
|
||||
const cli::Json* f = ui_field(e, "field");
|
||||
const cli::Json* v = ui_field(e, "value");
|
||||
if (!f || !f->integer() || !v || !v->integer() || !modern::edit_bank_credit(credit, draft, int(*f->integer()), uint32_t(*v->integer())))
|
||||
return modern::ui_error(request_id, "invalid_credit_edit", "Diese Änderung ist nicht möglich.", revision, false);
|
||||
}
|
||||
ui::BankState b;
|
||||
try { b = ui::bank_from_game(g_, exe_, revision); } catch (const std::exception&) {}
|
||||
A fields, saved;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
const BankCreditBounds bounds = modern::bank_credit_bounds(credit, draft, i);
|
||||
fields.push_back(O{{"field", i}, {"label", b.credit_labels[size_t(i)]}, {"value", int64_t(draft.values[size_t(i)])},
|
||||
{"editable", bounds.available},
|
||||
{"min", bounds.available ? cli::Json(int64_t(bounds.minimum)) : cli::Json(nullptr)},
|
||||
{"max", bounds.available ? cli::Json(int64_t(bounds.maximum)) : cli::Json(nullptr)}});
|
||||
}
|
||||
// the saved loan record: principal, total, monthly payment, term, elapsed months, payments made
|
||||
for (uint32_t v : credit.saved) saved.push_back(int64_t(v));
|
||||
return modern::ui_snapshot(g_, context, request_id,
|
||||
O{{"kind", "credit"}, {"lenderId", counterparty == 0 ? cli::Json("bank") : cli::Json(modern::ui_manager_id(g_, counterparty - 1))},
|
||||
{"saved", std::move(saved)}, {"fields", std::move(fields)}, {"fees", modern::ui_money(draft.fees)},
|
||||
{"refund", modern::ui_money(draft.refund)}, {"principalPaid", modern::ui_money(draft.principal_paid)},
|
||||
{"note", "Werte der Felder in ganzen Euro bzw. Monaten wie im Original-Dialog"}});
|
||||
}
|
||||
if (kind == "bank") {
|
||||
// account, fixed deposit, credit line, the 12 stocks and 6 funds (prices in whole euros,
|
||||
// converted to Money); the stock tip draws a random number and is no read
|
||||
@@ -9160,7 +9198,7 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
|
||||
{"accounts", O{{"cash", modern::ui_money(b.balance)}, {"deposit", modern::ui_money(b.deposit)},
|
||||
{"creditLine", modern::ui_money(b.credit_line)}, {"investments", modern::ui_money(b.investment_balance)}}},
|
||||
{"stocks", std::move(stocks)}, {"funds", std::move(funds)},
|
||||
{"credit", O{{"status", "unavailable"}, {"reasonCode", "not_yet_in_contract"}, {"missingFields", A{}}}}});
|
||||
{"credit", O{{"status", "available"}, {"read", "credit"}, {"command", "bank.commit"}}}});
|
||||
}
|
||||
if (kind == "tactics") {
|
||||
// the eight settings (record +0xd2..+0xd9) with the executable's maxima; the meaning of
|
||||
@@ -10270,8 +10308,31 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
r.count = int(*count->integer());
|
||||
r.kind = stock ? (action == "buy" ? ui::BankRequestKind::buy_shares : ui::BankRequestKind::sell_shares)
|
||||
: (action == "buy" ? ui::BankRequestKind::buy_fund : ui::BankRequestKind::sell_fund);
|
||||
} else if (action == "credit") {
|
||||
// {lenderId?: "bank" | managerId, edits: [{field, value}], acceptFees}: the draft of the
|
||||
// credit read, replayed against the saved loan and booked (fees as the original asks)
|
||||
int counterparty = 0;
|
||||
if (const std::string lender = ui_text(*payload, "lenderId"); !lender.empty() && lender != "bank") {
|
||||
for (int m = 0; m < int(g_.manager_teams.size()); ++m)
|
||||
if (m != manager && modern::ui_manager_id(g_, m) == lender) counterparty = m + 1;
|
||||
if (counterparty == 0) return refuse("unknown_lender", "Unbekannter Kreditgeber.");
|
||||
}
|
||||
const BankCreditContext credit = modern::bank_credit_context(g_, exe_, manager, counterparty);
|
||||
if (!credit.available) return refuse("credit_unavailable", "Kein Kredit möglich.");
|
||||
r.kind = ui::BankRequestKind::bank_credit;
|
||||
r.expected_credit = credit.saved;
|
||||
r.credit_counterparty = counterparty;
|
||||
const cli::Json* fees = ui_field(*payload, "acceptFees");
|
||||
r.accept_credit_fees = fees && std::holds_alternative<bool>(fees->value) && std::get<bool>(fees->value);
|
||||
if (const cli::Json* edits = ui_field(*payload, "edits"); edits && edits->array())
|
||||
for (const auto& e : *edits->array()) {
|
||||
const cli::Json* f = ui_field(e, "field");
|
||||
const cli::Json* v = ui_field(e, "value");
|
||||
if (!f || !f->integer() || !v || !v->integer()) return refuse("invalid_payload", "edits sind {field, value}.");
|
||||
r.credit_edits.push_back({int(*f->integer()), uint32_t(*v->integer())});
|
||||
}
|
||||
} else {
|
||||
return refuse("invalid_payload", "action ist deposit, withdraw, buy oder sell.");
|
||||
return refuse("invalid_payload", "action ist deposit, withdraw, buy, sell oder credit.");
|
||||
}
|
||||
if (!dispatch_bank(r, revision, error)) { restore(); return refuse(error, "Bankauftrag abgelehnt: " + error); }
|
||||
revision = previous + 1;
|
||||
|
||||
Reference in new issue
Block a user