Offer only the tactics the match engine reads; suggest a change after an own injury
In a live match the tactics board shows the attitude and the commitment with what they do; the play-pattern items have no effect on a match and are not offered there. When an own starter is injured the match stops and the strongest bench player of his position is offered as the change. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
1732a2477b
commit
bd20960f90
3 files changed
+42
-1
No files matched your search
@@ -128,6 +128,7 @@ Json engine_live_fixture(const Json &recording, const Json &bundle) {
|
||||
const auto &p = *at->second;
|
||||
rows.push_back({{"id", id}, {"name", p.at("player").at("name")}, {"slot", rows.size()},
|
||||
{"strength", metric(p, "strength")}, {"condition", metric(p, "condition")},
|
||||
{"position", p.at("player").value("positions", Json::array()).empty() ? Json() : p.at("player").at("positions").front()},
|
||||
{"caps", nullptr}, {"international_goals", nullptr}});
|
||||
};
|
||||
for (const auto &id : order) add(id);
|
||||
@@ -260,6 +261,7 @@ Json engine_live_roster(const Json &bundle) {
|
||||
const auto &p = *at->second;
|
||||
rows.push_back({{"id", id}, {"name", p.at("player").at("name")}, {"slot", rows.size()},
|
||||
{"strength", metric(p, "strength")}, {"condition", metric(p, "condition")},
|
||||
{"position", p.at("player").value("positions", Json::array()).empty() ? Json() : p.at("player").at("positions").front()},
|
||||
{"caps", nullptr}, {"international_goals", nullptr}});
|
||||
};
|
||||
for (const auto &id : order) add(id);
|
||||
|
||||
@@ -148,7 +148,41 @@ void App::engine_live_poll() {
|
||||
if (standing) {
|
||||
if (accepted || kind != "live.step") {
|
||||
const auto fixture = engine_live_progress(live_.fixture(), state, engine_data_, engine_live_roster_);
|
||||
if (fixture.value("ok", false)) live_.follow(fixture);
|
||||
if (fixture.value("ok", false)) {
|
||||
std::set<std::string> seen;
|
||||
for (const auto &e : live_.fixture().at("frames").back().at("events")) seen.insert(e.at("id").get<std::string>());
|
||||
live_.follow(fixture);
|
||||
// An own starter is injured: the match stops and the nearest change is offered - the
|
||||
// strongest bench player of his position, else the strongest on the bench.
|
||||
try {
|
||||
const auto owner = live_owner();
|
||||
const auto &match = live_match_by_id(live_.fixture().at("matches"), owner.at("match_id"));
|
||||
const std::string own_side = match.at("home").at("id") == owner.at("team").at("id") ? "home" : "away";
|
||||
for (const auto &e : live_.fixture().at("frames").back().at("events")) {
|
||||
if (seen.contains(e.at("id").get<std::string>()) || e.value("kind", std::string()) != "injury" ||
|
||||
e.at("match_id") != match.at("id") || e.at("side") != own_side || !e.at("player").is_object() || !live_dialog_.empty()) continue;
|
||||
const std::string hurt = e.at("player").value("id", std::string());
|
||||
size_t out = engine_live_roster_.size();
|
||||
for (size_t i = 0; i < engine_live_roster_.size() && i < 11; ++i) if (engine_live_roster_[i].at("id") == hurt) out = i;
|
||||
if (out >= 11) continue;
|
||||
int best = -1, best_same = -1;
|
||||
const auto strength = [&](size_t i) { const auto &v = engine_live_roster_[i].at("strength"); return v.is_number_integer() ? v.get<int>() : 0; };
|
||||
for (size_t i = 11; i < engine_live_roster_.size() && i < 16; ++i) {
|
||||
if (best < 0 || strength(i) > strength(size_t(best))) best = int(i);
|
||||
if (engine_live_roster_[i].value("position", Json()) == engine_live_roster_[out].value("position", Json()) &&
|
||||
(best_same < 0 || strength(i) > strength(size_t(best_same)))) best_same = int(i);
|
||||
}
|
||||
const int in = best_same >= 0 ? best_same : best;
|
||||
if (in < 0) continue;
|
||||
live_resume_speed_ = live_.speed(); live_.speed(0);
|
||||
live_dialog_ = "lineup"; live_dialog_draft_ = Json::object();
|
||||
live_out_ = hurt; live_in_ = engine_live_roster_[size_t(in)].at("id").get<std::string>();
|
||||
live_feedback_ = e.at("player").value("name", std::string("Ein Spieler")) + " ist verletzt.";
|
||||
std::fprintf(stderr, "live: substitution offered after an injury: %s for %s%c", live_in_.c_str(), live_out_.c_str(), char(10));
|
||||
focus_after_render_ = "live-dialog-apply";
|
||||
}
|
||||
} catch (const std::exception &) {}
|
||||
}
|
||||
} else {
|
||||
live_.speed(0);
|
||||
live_feedback_ = "Der Spieltag steht: " + response.value("code", std::string("live_step_refused"));
|
||||
|
||||
@@ -112,9 +112,13 @@ std::string App::live_detail(const Json &owner, const Json &frame) {
|
||||
}
|
||||
if (live_tab_ == "tactics" && live_.running() && engine_live_tactics_.size() == 8) {
|
||||
std::string out = "<div class=\"live-context\"><h3>" + live_text("Taktik in diesem Spiel") + "</h3>";
|
||||
// the match engine reads the attitude (item 0) and the commitment (item 7); the play
|
||||
// patterns between them have no effect on a match and are not offered here
|
||||
for (size_t i = 0; i < engine_live_tactics_.size(); ++i)
|
||||
if (i == 0 || i == 7)
|
||||
out += "<div class=\"live-tactic-row\">" + live_text(engine_live_tactics_[i].at("label").get<std::string>()) +
|
||||
live_text(i == 0 && engine_live_assistant_ ? std::string("Assistent passt an") : live_tactic_value(i, engine_live_tactics_[i].at("value").get<int>(), engine_live_tactics_[i].at("max").get<int>())) + "</div>";
|
||||
out += "<p class=\"live-note\">" + live_text("Offensiver heißt mehr eigene Chancen und mehr Chancen für den Gegner. Mehr Einsatz bringt Druck nach vorn, aber auch mehr Karten und Verletzungen.") + "</p>";
|
||||
return out + btn("live-intervene-tactics", "Taktik ändern", "", "id=\"live-tactics-edit\"") + "</div>";
|
||||
}
|
||||
if (live_tab_ == "tactics" && recorded)
|
||||
@@ -177,6 +181,7 @@ std::string App::live_dialog_markup(const Json &owner) {
|
||||
const bool engine_board = live_.running() && engine_live_tactics_.size() == 8;
|
||||
const auto &values = engine_board ? live_dialog_draft_.at("values") : live_dialog_draft_.at("tactics").at("values");
|
||||
for (size_t i = 0; i < names.size(); ++i)
|
||||
if (!engine_board || i == 0 || i == 7)
|
||||
body += "<div class=\"live-tactic-row\">" + live_text(engine_board ? engine_live_tactics_[i].at("label").get<std::string>() : std::string(names[i])) + btn("live-tactic-cycle", engine_board ? live_tactic_value(i, values[i].get<int>(), engine_live_tactics_[i].at("max").get<int>()) : "Wert " + std::to_string(values[i].get<int>()), "", "id=\"live-tactic-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) + "\"") + "</div>";
|
||||
}
|
||||
body += "<div class=\"live-dialog-actions\">" + btn("live-dialog-cancel", "Abbrechen", "", "id=\"live-dialog-cancel\"") +
|
||||
|
||||
Reference in new issue
Block a user