Modern UI contract: advertising read, advertising.accept and budget.commit
The advertising read lists boards, shirt and TV rights with their contract and open offers, the three budgets and the finance preview. advertising.accept takes an offer by id, budget.commit sets a budget, both through the desk's own checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f71f072774
commit
4372e6b78a
3 files changed
+109
-1
No files matched your search
@@ -8823,7 +8823,8 @@ 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 != "bank" && kind != "contracts"))
|
||||
(kind != "lineup" && kind != "tactics" && kind != "training" && kind != "bank" && kind != "contracts" &&
|
||||
kind != "advertising"))
|
||||
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);
|
||||
@@ -8853,6 +8854,45 @@ 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 == "advertising") {
|
||||
// the 14 boards, the shirt and the TV rights with their contract, the open offers per place,
|
||||
// the three budgets and the original's finance preview
|
||||
ui::AdvertisingState a;
|
||||
try { a = ui::advertising_from_game(g_, manager, revision); } catch (const std::exception&) {
|
||||
return modern::ui_error(request_id, "advertising_unavailable", "Die Werbung ist hier nicht verfügbar.", revision, false);
|
||||
}
|
||||
const auto contract = [&](const ui::AdvertisingContract& c, const std::string& id, int display) {
|
||||
A offers;
|
||||
if (display >= 0 && display < 16)
|
||||
for (const auto& o : a.offers[size_t(display)].offers) {
|
||||
if (!o.present) continue;
|
||||
const auto& names = display == 15 ? a.television_sponsor_names : a.board_sponsor_names;
|
||||
offers.push_back(O{{"id", "offer:ad-" + std::to_string(display) + "-" + std::to_string(o.raw_slot)},
|
||||
{"sponsor", o.sponsor_id < names.size() ? cli::Json(names[o.sponsor_id]) : cli::Json(nullptr)},
|
||||
{"monthly", modern::ui_money(o.monthly_amount)}, {"boards", int(o.bundle_units)},
|
||||
{"months", int(o.months)}, {"allowed", o.can_accept}});
|
||||
}
|
||||
return cli::Json(O{{"id", id}, {"active", c.active},
|
||||
{"sponsor", c.active ? cli::Json(c.sponsor_name) : cli::Json(nullptr)},
|
||||
{"monthly", modern::ui_money(c.monthly_amount)}, {"monthsRemaining", int(c.months_remaining)},
|
||||
{"extensionMonths", int(c.extension_months)}, {"option", c.option_marker},
|
||||
{"offers", std::move(offers)}});
|
||||
};
|
||||
A boards;
|
||||
for (size_t i = 0; i < a.boards.size(); ++i) boards.push_back(contract(a.boards[i], "ad:board/" + std::to_string(i), int(i)));
|
||||
A budgets;
|
||||
static constexpr const char* kBudgets[3] = {"budget:merchandise", "budget:press", "budget:fans"};
|
||||
for (size_t i = 0; i < 3; ++i)
|
||||
budgets.push_back(O{{"id", kBudgets[i]}, {"label", a.spending_labels[i]}, {"current", modern::ui_money(a.spending[i].current_amount)},
|
||||
{"maximum", modern::ui_money(a.spending[i].maximum_amount)}, {"deliveryWeeks", int(a.spending[i].delivery_weeks)},
|
||||
{"available", a.spending[i].available}});
|
||||
return modern::ui_snapshot(g_, context, request_id,
|
||||
O{{"kind", "advertising"}, {"teamId", modern::ui_team_id(g_, team)}, {"boards", std::move(boards)},
|
||||
{"shirt", contract(a.shirt, "ad:shirt", 14)}, {"television", contract(a.television, "ad:tv", 15)},
|
||||
{"budgets", std::move(budgets)},
|
||||
{"preview", O{{"income", modern::ui_money(a.finance_preview.income)}, {"expenses", modern::ui_money(a.finance_preview.expenses)},
|
||||
{"balance", modern::ui_money(a.finance_preview.balance)}}}});
|
||||
}
|
||||
if (kind == "contracts") {
|
||||
// per player: remaining months, monthly salary, insurance, the team bonuses; the open quote
|
||||
// (quote.request) with the monthly demand for one to four years
|
||||
@@ -8985,10 +9025,12 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
const int saved_entry_manager = lineup_entry_manager_, saved_entry_club = lineup_entry_club_;
|
||||
const auto saved_quote = contract_quote_;
|
||||
const uint64_t saved_quote_id = next_contract_quote_id_, saved_contract_request = last_contract_request_id_;
|
||||
const uint64_t saved_advertising_request = last_advertising_request_id_;
|
||||
const auto restore = [&] {
|
||||
g_ = saved_state; rand_ = saved_rand; game_ = saved_game; revision = previous;
|
||||
lineup_entry_manager_ = saved_entry_manager, lineup_entry_club_ = saved_entry_club; // the board stays as it was
|
||||
contract_quote_ = saved_quote, next_contract_quote_id_ = saved_quote_id, last_contract_request_id_ = saved_contract_request;
|
||||
last_advertising_request_id_ = saved_advertising_request;
|
||||
};
|
||||
cli::Json answer;
|
||||
std::string error;
|
||||
@@ -9268,6 +9310,43 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
: result.feedback);
|
||||
if (!result.accepted) std::get<cli::Json::Object>(answer.value)["outcome"] = "offer_rejected";
|
||||
}
|
||||
} else if (kind == "advertising.accept" || kind == "budget.commit") {
|
||||
// advertising.accept {offerId: "offer:ad-<display>-<pool slot>"}: an offer of the advertising read;
|
||||
// budget.commit {budgetId: "budget:merchandise|press|fans", amount: Money}
|
||||
const int team = g_.manager_teams[size_t(manager)];
|
||||
if (team < 0 || team >= league_clubs()) return refuse("no_club", "Am Schreibtisch des Bundestrainers gibt es keine Werbung.");
|
||||
const ui::AdvertisingState a = ui::advertising_from_game(g_, manager, revision);
|
||||
ui::AdvertisingRequest r;
|
||||
r.request_id = last_advertising_request_id_ + 1;
|
||||
r.manager_slot = manager, r.runtime_club = team, r.revision = revision;
|
||||
if (kind == "advertising.accept") {
|
||||
const std::string id = ui_text(*payload, "offerId");
|
||||
int display = -1, raw = -1;
|
||||
if (std::sscanf(id.c_str(), "offer:ad-%d-%d", &display, &raw) != 2 || display < 0 || display >= 16)
|
||||
return refuse("unknown_offer", "Unbekanntes Werbeangebot: " + id);
|
||||
const auto& list = a.offers[size_t(display)];
|
||||
const auto offer = std::find_if(list.offers.begin(), list.offers.end(), [&](const auto& o) { return o.present && o.raw_slot == raw; });
|
||||
if (offer == list.offers.end() || !offer->can_accept) return refuse("unknown_offer", "Dieses Werbeangebot gibt es nicht (mehr).");
|
||||
r.kind = ui::AdvertisingActionKind::accept_offer;
|
||||
r.offer.manager = manager, r.offer.display_slot = display, r.offer.contract_slot = list.contract_slot;
|
||||
r.offer.expected_contract = list.contract_bytes, r.offer.raw_slot = raw, r.offer.expected_offer = offer->bytes;
|
||||
} else {
|
||||
const std::string id = ui_text(*payload, "budgetId");
|
||||
const int index = id == "budget:merchandise" ? 0 : id == "budget:press" ? 1 : id == "budget:fans" ? 2 : -1;
|
||||
if (index < 0) return refuse("unknown_budget", "Unbekanntes Budget: " + id);
|
||||
const cli::Json* amount = ui_field(*payload, "amount");
|
||||
int64_t cents = -1;
|
||||
try { cents = amount ? std::stoll(ui_text(*amount, "minor")) : -1; } catch (const std::exception&) { cents = -1; }
|
||||
if (cents < 0 || cents % 100 || cents / 100 > UINT32_MAX) return refuse("invalid_amount", "amount in ganzen Euro (Money).");
|
||||
const auto& view = a.spending[size_t(index)];
|
||||
r.kind = ui::AdvertisingActionKind::set_spending;
|
||||
r.spending.manager = manager, r.spending.target_slot = view.target_slot, r.spending.amount = uint32_t(cents / 100);
|
||||
r.spending.expected_amount = view.current_amount, r.spending.expected_delivery_weeks = view.delivery_weeks;
|
||||
}
|
||||
if (!dispatch_advertising(r, revision, error)) { restore(); return refuse("advertising_refused", error); }
|
||||
revision = previous + 1;
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"advertising", "desktop", "bank"},
|
||||
kind == "advertising.accept" ? "Werbevertrag abgeschlossen." : "Budget gesetzt.");
|
||||
} 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");
|
||||
|
||||
Reference in new issue
Block a user