Modern UI contract: scheduling, friendlies and rescheduling
The scheduling read lists the own league matches that can be moved with their target dates and the moved ones; the friendly read quotes a friendly against a club with its free dates. friendly.book books it (the payer accepts the cost, a human opponent consents), fixture.reschedule moves a league match or takes a move back. All without random draws. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f2c895ffb0
commit
06445c24ef
4 files changed
+187
-35
No files matched your search
@@ -10094,6 +10094,75 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"transfer", "squad", "desktop"}, feedback);
|
||||
if (bid_pending) std::get<cli::Json::Object>(answer.value)["outcome"] = "offer_pending";
|
||||
}
|
||||
} else if (kind == "friendly.book" || kind == "fixture.reschedule") {
|
||||
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 das nicht.");
|
||||
// a date of this season as its season day (0..365)
|
||||
const auto day_of = [&](const std::string& iso) -> int {
|
||||
for (int day = 0; day <= 365; ++day) {
|
||||
const AlmanacDate d = almanac_date(g_.season_start + uint32_t(day), g_.display_start_year);
|
||||
char text[16];
|
||||
std::snprintf(text, sizeof text, "%04d-%02d-%02d", d.year, d.month, d.day);
|
||||
if (iso == text) return day;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
const auto flag = [&](const char* key) {
|
||||
const cli::Json* v = ui_field(*payload, key);
|
||||
return v && std::holds_alternative<bool>(v->value) && std::get<bool>(v->value);
|
||||
};
|
||||
if (kind == "friendly.book") {
|
||||
// {opponentId, home?, date, acceptCost, opponentConsent?}: the quote of the friendly read
|
||||
// on a free date; the payer accepts the cost, a human opponent's manager consents
|
||||
const std::string opponent_id = ui_text(*payload, "opponentId");
|
||||
int opponent = -1;
|
||||
for (int t = 0; t < int(g_.world_club_id.size()); ++t) if (g_.world_club_id[size_t(t)] == opponent_id) opponent = t;
|
||||
if (opponent < 0 && opponent_id.starts_with("team:")) try { opponent = std::stoi(opponent_id.substr(5)); } catch (const std::exception&) {}
|
||||
const int day = day_of(ui_text(*payload, "date"));
|
||||
if (opponent < 0 || day < 0) return refuse("invalid_payload", "opponentId und date (dieser Saison) nötig.");
|
||||
const cli::Json* home = ui_field(*payload, "home");
|
||||
FriendlyBookingRequest r;
|
||||
r.quote = modern::quote_friendly_match(g_, manager, opponent, !home || !std::holds_alternative<bool>(home->value) || std::get<bool>(home->value));
|
||||
if (r.quote.status != FriendlyQuoteStatus::quoted) return refuse("friendly_unavailable", "Gegen diesen Verein ist kein Freundschaftsspiel möglich.");
|
||||
r.season_day = uint16_t(day);
|
||||
r.accept_opponent = r.quote.opponent_manager < 0 || flag("opponentConsent");
|
||||
r.consenting_manager = r.quote.opponent_manager;
|
||||
r.accept_cost = flag("acceptCost");
|
||||
r.approving_manager = r.quote.payer_manager;
|
||||
const FriendlyBookingResult result = modern::book_friendly_match(g_, r);
|
||||
if (result.status != FriendlyBookingStatus::booked) {
|
||||
static constexpr const char* kStatus[11] = {"booked", "declined", "opponent_declined", "insufficient_funds", "invalid_manager",
|
||||
"invalid_opponent", "invalid_date", "date_unavailable", "plan_full", "stale_quote", "invalid_request"};
|
||||
restore();
|
||||
return refuse(kStatus[size_t(result.status)], "Das Freundschaftsspiel kam nicht zustande.");
|
||||
}
|
||||
revision = previous + 1;
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"scheduling", "calendar", "desktop", "bank"},
|
||||
"Freundschaftsspiel vereinbart.");
|
||||
} else {
|
||||
// {matchId: "move:...", date}: a league match to another day; {action: "undo", date}: a move taken back
|
||||
if (ui_text(*payload, "action") == "undo") {
|
||||
const int day = day_of(ui_text(*payload, "date"));
|
||||
if (day < 0 || !modern::undo_reschedule(g_, manager, day)) { restore(); return refuse("no_moved_match", "An diesem Tag gibt es keine verlegte Partie."); }
|
||||
} else {
|
||||
int day = -1, league = -1, round = -1, match = -1;
|
||||
if (std::sscanf(ui_text(*payload, "matchId").c_str(), "move:%d-%d-%d-%d", &day, &league, &round, &match) != 4)
|
||||
return refuse("invalid_payload", "matchId (move:...) und date nötig.");
|
||||
LeagueMatchRef ref;
|
||||
for (const auto& r : modern::reschedulable_matches(g_, manager))
|
||||
if (r.day == day && r.league == league && r.round == round && r.match == match) ref = r;
|
||||
const int target = day_of(ui_text(*payload, "date"));
|
||||
if (ref.day < 0 || target < 0) return refuse("unknown_match", "Diese Partie kann nicht verlegt werden.");
|
||||
const RescheduleStatus st = modern::reschedule_league_match(g_, manager, ref, target);
|
||||
if (st != RescheduleStatus::moved) {
|
||||
static constexpr const char* kStatus[7] = {"moved", "invalid_manager", "invalid_match", "invalid_day", "no_free_slot", "day_full", "team_clash"};
|
||||
restore();
|
||||
return refuse(kStatus[size_t(st)], "Die Partie lässt sich nicht auf diesen Tag verlegen.");
|
||||
}
|
||||
}
|
||||
revision = previous + 1;
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"scheduling", "calendar", "desktop"}, "Spielplan geändert.");
|
||||
}
|
||||
} else if (kind == "environment.commit") {
|
||||
// payload {itemId: "environment:<item>", level 0-6}: a monthly budget of the surroundings
|
||||
// (no immediate booking, no random draw); the original's notice comes back as feedback
|
||||
|
||||
Reference in new issue
Block a user