Modern UI contract: bank read and bank.commit
The bank read lists account, fixed deposit, credit line, investments, the 12 stocks with their price history and the offered funds as Money. bank.commit moves money to or from the fixed deposit and buys or sells shares and fund units through the desk's own checks. Credits follow; the stock tip draws a random number and will be a quote.request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
43ae1ab510
commit
a1590a34ef
3 files changed
+84
-1
No files matched your search
@@ -31,6 +31,7 @@ Revision kommt vom Aufrufer (Konsole bzw. AppController), der Read ändert nicht
|
||||
| `lineup` | die Kaderzeilen in Reihenfolge (die ersten elf spielen) mit Rolle, die Plätze der Startelf auf der Taktiktafel (`depth` 0–19, `lane` 0–8; das JSON hat keine Kommazahlen), `manual` (Aufstellung von Hand) |
|
||||
| `tactics` | die acht Einstellungen (`tactic:0` Grundausrichtung bis `tactic:7` Einsatz) mit Wert und Maximum aus der EXE; die Bedeutung der Diagramm-Einstellungen 1–3, 5, 6 ist nicht belegt, daher neutrale Namen |
|
||||
| `training` | Bälle je Spielertyp und Trainingsbereich (1–3) mit den Grenzen, je Spieler Intensität und Schwerpunkt, ob das Training eingerichtet ist, Automatik-Bits |
|
||||
| `bank` | Konto, Festgeld, Kreditrahmen, Anlagen (alles `Money`), die 12 Aktien (Kurs, Vorkurs, Bestand, bezahlt, Höchstkauf, 30 Kurse Verlauf) und die angebotenen Fonds; Kredite noch `unavailable` (folgen), der Aktientipp zieht Zufall und kommt als `quote.request` |
|
||||
|
||||
Fehler: `unknown_read`, `manager_not_active`, `no_active_manager`, `unknown_team`.
|
||||
|
||||
@@ -45,6 +46,7 @@ Fehler: `unknown_read`, `manager_not_active`, `no_active_manager`, `unknown_team
|
||||
| Command | payload | Wirkung |
|
||||
|---|---|---|
|
||||
| `camp.book` | `campId`, optional `focus {condition, technique, play}` (0–15; Erholung folgt) | setzt die Schwerpunkte und bucht das Lager wie der Schreibtisch; Fehler `unknown_camp`, `invalid_focus`, `booked_this_week`, `visit_limit`, `insufficient_funds` |
|
||||
| `bank.commit` | `action` `deposit`/`withdraw` mit `amount` (`Money`, ganze Euro) oder `buy`/`sell` mit `assetId` (`stock:<n>`, `fund:<n>`) und `count` | wie die Bank am Schreibtisch; Fehler `invalid_amount`, `amount_unavailable`, `invalid_share_count`, `insufficient_funds`, `investment_limit`, `invalid_fund_count` u. a. |
|
||||
| `lineup.commit` | `order`: Spieler-IDs in der gewünschten Reihenfolge | öffnet die Aufstellung wie am Schreibtisch und tauscht die Zeilen; Fehler `unknown_player`, `lineup_refused` (z. B. Verletzte, Ausländerregel) |
|
||||
| `tactics.commit` | `values`: die acht Werte | jede geänderte Einstellung über die Prüfung der Taktiktafel (eine gesetzte Grundausrichtung beendet die Steuerung durch den Assistenten); Fehler `invalid_tactic` |
|
||||
| `training.commit` | optional `types` (4), `areas` (9), `players [{playerId, intensity}]` | richtet das Training bei Bedarf ein, setzt erst die Senkungen, dann die Erhöhungen (jeder Zwischenstand bleibt in den Grenzen); Fehler `training_unavailable`, `unknown_player` und die Gründe der Engine |
|
||||
|
||||
@@ -8765,7 +8765,7 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
|
||||
const std::string kind = ui_text(request, "kind"), request_id = ui_text(request, "requestId");
|
||||
const int manager = context.manager;
|
||||
if (manager < 0 || size_t(manager) >= g_.manager_teams.size() ||
|
||||
(kind != "lineup" && kind != "tactics" && kind != "training"))
|
||||
(kind != "lineup" && kind != "tactics" && kind != "training" && kind != "bank"))
|
||||
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);
|
||||
@@ -8795,6 +8795,36 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
|
||||
{"rows", std::move(rows)}, {"positions", std::move(positions)}, {"depthMax", 19}, {"laneMax", 8},
|
||||
{"manual", g_.manager_options.size() > size_t(manager) * 5 && g_.manager_options[size_t(manager) * 5] == 0}});
|
||||
}
|
||||
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
|
||||
ui::BankState b;
|
||||
try { b = ui::bank_from_game(g_, exe_, revision); } catch (const std::exception&) {
|
||||
return modern::ui_error(request_id, "bank_unavailable", "Die Bank ist hier nicht verfügbar.", revision, false);
|
||||
}
|
||||
A stocks, funds;
|
||||
for (size_t i = 0; i < b.stocks.size(); ++i) {
|
||||
const auto& s = b.stocks[i];
|
||||
A history;
|
||||
for (uint16_t h : s.history) history.push_back(modern::ui_money(h));
|
||||
stocks.push_back(O{{"id", "stock:" + std::to_string(i)}, {"name", b.finance_stock_labels[i]},
|
||||
{"price", modern::ui_money(s.price)}, {"previousPrice", modern::ui_money(s.previous_price)},
|
||||
{"owned", int(s.owned)}, {"paid", modern::ui_money(s.paid)}, {"maxToBuy", s.max_to_buy},
|
||||
{"history", std::move(history)}});
|
||||
}
|
||||
for (size_t i = 0; i < b.funds.size(); ++i) {
|
||||
const auto& f = b.funds[i];
|
||||
if (f.price == 0) continue; // a fund the game does not offer
|
||||
funds.push_back(O{{"id", "fund:" + std::to_string(i)}, {"name", f.name}, {"price", modern::ui_money(f.price)},
|
||||
{"owned", int(f.owned)}, {"paid", modern::ui_money(f.paid)}, {"maxToBuy", f.max_to_buy}});
|
||||
}
|
||||
return modern::ui_snapshot(g_, context, request_id,
|
||||
O{{"kind", "bank"}, {"teamId", modern::ui_team_id(g_, team)},
|
||||
{"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{}}}}});
|
||||
}
|
||||
if (kind == "tactics") {
|
||||
// the eight settings (record +0xd2..+0xd9) with the executable's maxima; the meaning of
|
||||
// settings 1-3, 5 and 6 (diagrams on the original board) is not proven, hence neutral labels
|
||||
@@ -9015,6 +9045,35 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
if (!ok) { restore(); return refuse(error.empty() ? "invalid_training" : error, "Training nicht übernommen: " + error); }
|
||||
if (revision != previous) revision = previous + 1;
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"training"}, "Training übernommen.");
|
||||
} else if (kind == "bank.commit") {
|
||||
// payload {action: deposit|withdraw, amount: Money} or {action: buy|sell, assetId: stock:<n>|fund:<n>, count}
|
||||
const std::string action = ui_text(*payload, "action");
|
||||
ui::BankRequest r;
|
||||
r.manager_slot = manager, r.runtime_club = g_.manager_teams[size_t(manager)], r.revision = revision;
|
||||
if (action == "deposit" || action == "withdraw") {
|
||||
const cli::Json* amount = ui_field(*payload, "amount");
|
||||
const std::string minor = amount ? ui_text(*amount, "minor") : std::string{};
|
||||
int64_t cents = 0;
|
||||
try { cents = minor.empty() ? 0 : std::stoll(minor); } catch (const std::exception&) { cents = 0; }
|
||||
if (cents <= 0 || cents % 100 != 0 || cents / 100 > INT32_MAX)
|
||||
return refuse("invalid_amount", "amount ist ein positiver Betrag in ganzen Euro (Money).");
|
||||
r.kind = ui::BankRequestKind::move_to_deposit;
|
||||
r.amount = int32_t(cents / 100) * (action == "deposit" ? 1 : -1);
|
||||
} else if (action == "buy" || action == "sell") {
|
||||
const std::string asset = ui_text(*payload, "assetId");
|
||||
const cli::Json* count = ui_field(*payload, "count");
|
||||
const bool stock = asset.starts_with("stock:"), fund = asset.starts_with("fund:");
|
||||
if ((!stock && !fund) || !count || !count->integer()) return refuse("invalid_payload", "assetId und count nötig.");
|
||||
try { r.asset_index = std::stoi(asset.substr(stock ? 6 : 5)); } catch (const std::exception&) { return refuse("unknown_asset", asset); }
|
||||
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 {
|
||||
return refuse("invalid_payload", "action ist deposit, withdraw, buy oder sell.");
|
||||
}
|
||||
if (!dispatch_bank(r, revision, error)) { restore(); return refuse(error, "Bankauftrag abgelehnt: " + error); }
|
||||
revision = previous + 1;
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"bank", "desktop"}, "Bankauftrag ausgeführt.");
|
||||
} else if (kind == "lineup.commit") {
|
||||
// payload {order: [player ids]}: the squad in this order (the first eleven start); the
|
||||
// board opens as on the desk (the human line-up path), then rows are swapped into place
|
||||
|
||||
@@ -213,6 +213,28 @@ int main(int argc, char** argv) {
|
||||
"messageType")) == "error" && modern::save_stream(session.state()) == kept && rev == before_training + 1,
|
||||
"training over the limit refused without change");
|
||||
}
|
||||
// bank: read, fixed deposit, a share, a refused withdrawal
|
||||
{
|
||||
const J bank = session.ui_read(O{{"kind", "bank"}}, rev);
|
||||
const J& accounts = at(at(bank, "data"), "accounts");
|
||||
const auto* stocks = at(at(bank, "data"), "stocks").array();
|
||||
check(s(at(bank, "messageType")) == "snapshot" && stocks && stocks->size() == 12, "bank read");
|
||||
const std::string deposit_before = s(at(at(accounts, "deposit"), "minor"));
|
||||
const uint64_t before_bank = rev;
|
||||
const J done = session.ui_command(cmd("request:b1", "bank.commit",
|
||||
O{{"action", "deposit"}, {"amount", O{{"minor", "10000000"}, {"currency", "EUR"}, {"minorUnits", 2}}}}), rev);
|
||||
const J after = session.ui_read(O{{"kind", "bank"}}, rev);
|
||||
check(s(at(done, "messageType")) == "command_result" && rev == before_bank + 1 &&
|
||||
std::stoll(s(at(at(at(at(after, "data"), "accounts"), "deposit"), "minor"))) ==
|
||||
std::stoll(deposit_before) + 10000000, "100000 euros to the fixed deposit");
|
||||
const J share = session.ui_command(cmd("request:b2", "bank.commit", O{{"action", "buy"}, {"assetId", "stock:0"}, {"count", 1}}), rev);
|
||||
check(s(at(share, "messageType")) == "command_result" && rev == before_bank + 2, "one share bought");
|
||||
const auto kept = modern::save_stream(session.state());
|
||||
const J refused = session.ui_command(cmd("request:b3", "bank.commit",
|
||||
O{{"action", "withdraw"}, {"amount", O{{"minor", "99999999900"}, {"currency", "EUR"}, {"minorUnits", 2}}}}), rev);
|
||||
check(s(at(refused, "messageType")) == "error" && modern::save_stream(session.state()) == kept && rev == before_bank + 2,
|
||||
"withdrawal above the deposit refused without change");
|
||||
}
|
||||
} catch (const std::exception& ex) {
|
||||
std::fprintf(stderr, "FAIL: %s\n", ex.what());
|
||||
return 1;
|
||||
|
||||
Reference in new issue
Block a user