Poaching in two steps: the club is asked and names its price, then the offer is made
transfer.submit takes three more actions. poach runs the original's checks and start_poach on a player of another club; where an offer can be made the offer editor stays open and the answer carries what the club asks and the bounds the editor accepts. poachOffer is decided at once, poachCancel closes the editor. The attempt counts from the first step, as in the original. The transfer market's Abwerben opens the clubs of a league, reads the chosen club's squad, asks before the attempt is spent and then shows the club's demand with the offer to be written. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
a2790751a6
commit
7424b09738
8 files changed
+282
-3
No files matched your search
@@ -22,6 +22,7 @@ Json engine_training_command(const Json &bundle, const Json &draft,
|
||||
Json engine_bank_projection(const Json &bundle);
|
||||
Json engine_bank_command(const Json &bundle, const Json &payload, const std::string &request_id);
|
||||
Json engine_order_command(const Json &bundle, const std::string &player, int aspect, int value, const std::string &request_id);
|
||||
Json engine_poach_command(const Json &bundle, const Json &payload, const std::string &request_id);
|
||||
Json engine_set_piece_command(const Json &bundle, const Json &payload, const std::string &request_id);
|
||||
Json engine_credit_projection(const Json &bundle, const Json &read);
|
||||
Json engine_credit_command(const Json &bundle, const Json &read, const Json &edits, const std::string &request_id);
|
||||
|
||||
@@ -213,6 +213,13 @@ void App::engine_poll() {
|
||||
}
|
||||
refresh(); return;
|
||||
}
|
||||
if (result.response.value("messageType", "") == "poach_squad") {
|
||||
// the squad of the club a manager wants to poach from
|
||||
const auto &read = result.response.at("read");
|
||||
if (read.value("messageType", "") == "error" || !read.contains("data")) { engine_notice_ = "Der Kader ist nicht verfügbar."; engine_poach_squad_ = Json(); }
|
||||
else { engine_poach_squad_ = read.at("data"); if (menu_ == "transfer" && transfer_dialog_ == "poach-clubs") { transfer_dialog_ = "poach-roster"; transfer_view_["poach_top"] = 0; focus_after_render_ = "transfer-poach-back"; } }
|
||||
refresh(); return;
|
||||
}
|
||||
if (result.response.value("messageType", "") == "credit_preview") {
|
||||
const auto &read = result.response.at("read");
|
||||
const auto lender = result.response.value("lender", std::string("bank"));
|
||||
|
||||
@@ -190,6 +190,11 @@ Json engine_order_command(const Json &bundle, const std::string &player, int asp
|
||||
require(projection.at("orders").contains(player) && aspect >= 0 && aspect <= 3 && value >= 2 && value <= 40, "Ungültige Anweisung.");
|
||||
return sports_command(bundle, "lineup.setOrder", {{"playerId", player}, {"aspect", aspect}, {"value", value}}, request_id);
|
||||
}
|
||||
Json engine_poach_command(const Json &bundle, const Json &payload, const std::string &request_id) {
|
||||
const auto action = payload.at("action").get<std::string>();
|
||||
require(action == "poach" || action == "poachOffer" || action == "poachCancel", "Ungültiger Abwerbeauftrag.");
|
||||
return sports_command(bundle, "transfer.submit", payload, request_id);
|
||||
}
|
||||
Json engine_set_piece_command(const Json &bundle, const Json &payload, const std::string &request_id) {
|
||||
const auto projection = engine_lineup_projection(bundle);
|
||||
require(projection.at("set_pieces").is_object(), "Schützen sind in diesem Kontext nicht verfügbar.");
|
||||
|
||||
@@ -134,6 +134,10 @@
|
||||
|
||||
Json engine_transfer_context_,engine_transfer_value_,engine_transfer_filters_=engine_transfer_filters();
|
||||
bool engine_transfer_submitting_=false;
|
||||
// poaching: the squad of the club looked at, what the club asks while an attempt is open
|
||||
// (with the offer being written), and whether an answer of the game is awaited
|
||||
Json engine_poach_squad_, engine_poach_quote_;
|
||||
bool engine_poach_waiting_ = false;
|
||||
void engine_transfer_sync();
|
||||
Json transfer_data() const;
|
||||
std::string transfer_money(const Json &) const;
|
||||
|
||||
@@ -36,6 +36,33 @@ void App::engine_transfer_sync() {
|
||||
engine_transfer_projection(engine_data_, engine_transfer_filters_);
|
||||
} catch (const std::exception &) {
|
||||
}
|
||||
if (engine_poach_waiting_) {
|
||||
// the game's answer to a step of poaching
|
||||
engine_poach_waiting_ = false;
|
||||
const bool refused = engine_response_.value("messageType", "") != "command_result";
|
||||
const auto outcome = engine_response_.value("outcome", std::string());
|
||||
if (outcome == "poach_open" && engine_response_.contains("poach")) {
|
||||
const bool again = engine_poach_quote_.is_object();
|
||||
Json quote = engine_response_.at("poach");
|
||||
// the game names him in its short form; the squad just read has his full name
|
||||
try { for (const auto &row : engine_poach_squad_.at("players")) if (row.at("player").at("id") == quote.at("playerId")) quote["name"] = engine_text(row.at("player").at("name")); } catch (const std::exception &) {}
|
||||
// the offer starts at what is asked; a second try keeps what was offered
|
||||
quote["offer_fee"] = again ? engine_poach_quote_.at("offer_fee") : Json(engine_money_minor(quote.at("askingFee")) / 100);
|
||||
quote["offer_salary"] = again ? engine_poach_quote_.at("offer_salary") : Json(engine_money_minor(quote.at("askingMonthlySalary")) / 100);
|
||||
quote["offer_years"] = again ? engine_poach_quote_.at("offer_years") : Json(std::clamp(quote.value("years", 2), 1, 4));
|
||||
quote["note"] = again ? engine_notice_ : std::string();
|
||||
engine_poach_quote_ = quote;
|
||||
transfer_dialog_ = "poach-offer"; focus_after_render_ = "transfer-poach-fee";
|
||||
} else if (refused && engine_poach_quote_.is_object()) {
|
||||
engine_poach_quote_["note"] = engine_notice_; // the attempt is still open
|
||||
transfer_dialog_ = "poach-offer";
|
||||
} else {
|
||||
const bool cancelled = engine_poach_quote_.is_object() && outcome.empty() && !refused;
|
||||
engine_poach_quote_ = Json(); engine_poach_squad_ = Json();
|
||||
if (cancelled) transfer_dialog_.clear();
|
||||
else { transfer_dialog_ = "booked"; transfer_notice_ = engine_notice_; focus_after_render_ = "transfer-close"; }
|
||||
}
|
||||
}
|
||||
if (engine_transfer_submitting_) {
|
||||
engine_transfer_submitting_ = false;
|
||||
transfer_dialog_ = "booked";
|
||||
@@ -82,10 +109,91 @@ bool App::engine_transfer_action(const std::string &action,
|
||||
},
|
||||
true);
|
||||
};
|
||||
const auto poach_send = [this](const Json &payload, const char *label) {
|
||||
if (!engine_fresh_ || engine_busy_) return;
|
||||
try {
|
||||
const auto request = engine_poach_command(engine_data_, payload, editor::new_id("request:ui-"));
|
||||
engine_poach_waiting_ = true;
|
||||
auto link = engine_link_;
|
||||
engine_start(label, [link, request] {
|
||||
const auto reply = link->command(request);
|
||||
return EngineReply{link, link->snapshot(), reply, nullptr};
|
||||
}, true);
|
||||
} catch (const std::exception &e) { message(e.what()); }
|
||||
};
|
||||
if (action == "transfer-close") {
|
||||
// an open attempt is ended in the game as well
|
||||
if (engine_poach_quote_.is_object()) { poach_send({{"action", "poachCancel"}}, "Abwerbeversuch wird beendet …"); return true; }
|
||||
close_transfer();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-poach") {
|
||||
const auto own = engine_data_.at("desktop").at("meta").at("scope").at("teamId").get<std::string>();
|
||||
const auto *c = world_->find("clubs", own);
|
||||
transfer_dialog_ = "poach-clubs";
|
||||
transfer_poach_league_ = c ? c->value("competition", "") : "";
|
||||
transfer_poach_club_.clear(); engine_poach_squad_ = Json(); engine_poach_quote_ = Json();
|
||||
transfer_view_["poach_top"] = 0;
|
||||
transfer_return_focus_ = target ? target->GetId() : "transfer-poach";
|
||||
focus_after_render_ = "transfer-poach-country";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-poach-club" && target) {
|
||||
const auto club = target->GetAttribute<Rml::String>("data-club", "");
|
||||
if (!world_->find("clubs", club)) return true;
|
||||
transfer_poach_club_ = club;
|
||||
auto link = engine_link_;
|
||||
engine_start("Kader wird gelesen …", [link, club] {
|
||||
auto response = link->read({{"kind", "squad"}, {"teamId", club}});
|
||||
return EngineReply{link, link->snapshot(), {{"messageType", "poach_squad"}, {"read", response}}, nullptr};
|
||||
});
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-poach-back") {
|
||||
transfer_dialog_ = "poach-clubs"; engine_poach_squad_ = Json();
|
||||
focus_after_render_ = "transfer-poach-club-" + transfer_poach_club_;
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-poach-player") {
|
||||
if (transfer_dialog_ != "poach-roster" || id.empty()) return true;
|
||||
std::string name = id;
|
||||
try { for (const auto &row : engine_poach_squad_.at("players")) if (row.at("player").at("id") == id) name = engine_text(row.at("player").at("name")); } catch (const std::exception &) {}
|
||||
confirmation("Bei " + name + " anfragen? Schon die Anfrage zählt als einer der fünf Abwerbeversuche dieser Saison, und jeden Spieler kann man nur einmal je Saison fragen.",
|
||||
[this, poach_send, id] { poach_send({{"action", "poach"}, {"playerId", id}}, "Der Verein wird gefragt …"); });
|
||||
popup_accept_ = "Anfragen";
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-poach-amount" && target && engine_poach_quote_.is_object()) {
|
||||
const std::string field = target->GetAttribute<Rml::String>("data-id", "");
|
||||
if (field != "offer_fee" && field != "offer_salary") return true;
|
||||
AmountRequest a;
|
||||
a.title = field == "offer_fee" ? "Ablöse" : "Monatsgehalt"; a.unit = "€"; a.return_focus = target->GetId();
|
||||
a.min = 0; a.max = field == "offer_fee" ? 99999999 : 9999999; a.step = 1; a.review = false;
|
||||
// what the game's editor accepts
|
||||
try {
|
||||
const auto &range = engine_poach_quote_.at(field == "offer_fee" ? "feeRange" : "salaryRange");
|
||||
a.min = engine_money_minor(range.at("min")) / 100; a.max = std::max<int64_t>(a.min, engine_money_minor(range.at("max")) / 100);
|
||||
} catch (const std::exception &) {}
|
||||
a.value = std::clamp<int64_t>(engine_poach_quote_.at(field).get<int64_t>(), a.min, a.max);
|
||||
a.suggestion_step = field == "offer_fee" ? 100000 : 1000;
|
||||
a.accept = [this, field](int64_t value) { if (!engine_poach_quote_.is_object()) return false; engine_poach_quote_[field] = value; refresh(); return true; };
|
||||
open_amount(std::move(a));
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-poach-years" && target && engine_poach_quote_.is_object()) {
|
||||
const int years = target->GetAttribute<int>("data-id", 0);
|
||||
if (years >= 1 && years <= 4) engine_poach_quote_["offer_years"] = years;
|
||||
focus_after_render_ = target->GetId(); refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-poach-submit" && engine_poach_quote_.is_object()) {
|
||||
const auto cash = [](int64_t euros) { return Json{{"currency", "EUR"}, {"minorUnits", 2}, {"minor", std::to_string(euros * 100)}}; };
|
||||
poach_send({{"action", "poachOffer"}, {"fee", cash(engine_poach_quote_.at("offer_fee").get<int64_t>())}, {"monthlySalary", cash(engine_poach_quote_.at("offer_salary").get<int64_t>())},
|
||||
{"years", engine_poach_quote_.at("offer_years")}}, "Das Angebot wird geprüft …");
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-offer-back") {
|
||||
transfer_dialog_ = "offer";
|
||||
focus_after_render_ = "transfer-fee";
|
||||
|
||||
@@ -330,7 +330,7 @@ std::string App::render_transfer() {
|
||||
pg_button("transfer-offer", mine ? "Verleihen" : "Ausleihen", "tm-deal",
|
||||
"id=\"transfer-offer-loan-lend\" data-kind=\"" + std::string(mine ? "lend" : "loan") + "\" " +
|
||||
std::string(chosen.is_object() && (!engine_mode_ || !mine || !on_list) && (!pending || pending_loan) && (!engine_mode_ || mine || chosen.value("loan_allowed", false)) ? "" : "disabled")) +
|
||||
pg_button("transfer-poach", "Abwerben", "tm-deal", "id=\"transfer-poach\" " + std::string(engine_mode_ ? "disabled title=\"Noch nicht angebunden\"" : "")) + "</div></div>";
|
||||
pg_button("transfer-poach", "Abwerben", "tm-deal", "id=\"transfer-poach\"") + "</div></div>";
|
||||
}
|
||||
out += "</div><nav class=\"pg-foot\">" + (complete ? std::string() : toggle("transfer-data", "transfer-data", "Daten A", "Daten B", b)) + toggle("transfer-all", "transfer-all", "Komplett", "Angebote", !complete);
|
||||
if (complete) out += toggle("transfer-data", "transfer-data", "Daten A", "Daten B", b);
|
||||
@@ -463,7 +463,7 @@ std::string App::render_transfer_dialog() {
|
||||
} else if (transfer_dialog_ == "poach-clubs") {
|
||||
width = 900;
|
||||
title = "Spieler abwerben";
|
||||
sub = "Verein wählen, danach einen Spieler aus dessen Beispielkader.";
|
||||
sub = engine_mode_ ? "Verein wählen, danach einen Spieler aus dessen Kader. Fünf Versuche je Saison." : "Verein wählen, danach einen Spieler aus dessen Beispielkader.";
|
||||
const auto leagues = world_->leagues();
|
||||
if (transfer_poach_league_.empty() && !leagues.empty()) transfer_poach_league_ = leagues[0]->at("id").get<std::string>();
|
||||
const auto *league = world_->find("competitions", transfer_poach_league_);
|
||||
@@ -483,6 +483,48 @@ std::string App::render_transfer_dialog() {
|
||||
"id=\"transfer-poach-club-" + esc(club->at("id").get<std::string>()) + "\" data-club=\"" + esc(club->at("id").get<std::string>()) + "\" " + std::string(club->at("id") == actor ? "disabled" : ""));
|
||||
body += "</div>";
|
||||
actions = close();
|
||||
} else if (transfer_dialog_ == "poach-roster" && engine_mode_) {
|
||||
const auto engine_text = [](const Json &v) { return v.is_string() ? v.get<std::string>() : v.is_object() ? v.value("text", std::string()) : std::string("—"); };
|
||||
// the squad of the chosen club as the game states it
|
||||
width = 720;
|
||||
const auto *club = world_->find("clubs", transfer_poach_club_);
|
||||
title = "Abwerben · " + std::string(club ? world_->name(*club) : "—");
|
||||
sub = "Ein Klick auf den Namen fragt beim Verein an.";
|
||||
body = "<div class=\"pg-panel pg-col\" style=\"" + pg_css("gap:0px;padding:6px 12px;") + "\"><div class=\"pg-t\"><div class=\"pg-thead\">" + pg_th("Spieler", 0) + pg_th("Pos.", 70) + pg_th("Alter", 70, "r") + pg_th("Stärke", 80, "r") +
|
||||
"</div><div id=\"transfer-poach-scroll\" data-scope=\"roster-" + esc(transfer_poach_club_) + "\" class=\"pg-tbody\">";
|
||||
if (engine_poach_squad_.is_object() && engine_poach_squad_.contains("players"))
|
||||
for (const auto &r : engine_poach_squad_.at("players")) {
|
||||
const auto &person = r.at("player");
|
||||
const auto id = person.at("id").get<std::string>();
|
||||
Json strength;
|
||||
try { const auto &m = r.at("metrics").at("strength"); if (m.is_object() && m.value("value", Json()).is_number_integer()) strength = m.at("value"); } catch (const std::exception &) {}
|
||||
const auto position = person.contains("positions") && person.at("positions").is_array() && !person.at("positions").empty() ? person.at("positions")[0] : Json();
|
||||
body += "<div class=\"pg-tr\">" + pg_td(btn("transfer-poach-player", "<span>" + esc(engine_text(person.at("name"))) + "</span>", "pg-link", "id=\"transfer-poach-player-" + esc(id) + "\" data-player=\"" + esc(id) + "\""), 0, "", true) +
|
||||
pg_td(pg_pos(transfer_ui_role(position)), 70, "", true) + pg_td(transfer_ui_number(r.value("age", Json())), 70, "r") + pg_td("<strong>" + transfer_ui_number(strength) + "</strong>", 80, "r") + "</div>";
|
||||
}
|
||||
body += "</div></div></div>";
|
||||
actions = button("transfer-poach-back", "Zurück zu Vereinen", "id=\"transfer-poach-back\"") + close();
|
||||
} else if (transfer_dialog_ == "poach-offer" && engine_poach_quote_.is_object()) {
|
||||
// the club has named its price: the offer is written, sent, or the attempt given up
|
||||
width = 600;
|
||||
const auto &q = engine_poach_quote_;
|
||||
const auto *club = q.at("sellerId").is_string() ? world_->find("clubs", q.at("sellerId").get<std::string>()) : nullptr;
|
||||
title = "Abwerben · " + q.value("name", std::string());
|
||||
sub = (club ? world_->name(*club) + " · " : std::string()) + "noch " + std::to_string(q.value("attemptsLeft", 0)) + (q.value("attemptsLeft", 0) == 1 ? " Versuch" : " Versuche") + " in dieser Saison";
|
||||
const auto euros = [](int64_t value) { return money(value * 100, {{"code", "EUR"}, {"minor_units", 2}}); };
|
||||
const auto engine_price = [](const Json &v) { return money(engine_money_minor(v), {{"code", "EUR"}, {"minor_units", 2}}); };
|
||||
body = "<div class=\"pg-panel pg-row\" style=\"" + pg_css("gap:14px;padding:10px 16px;") + "\">" + (club ? "<span style=\"display:block;flex:none;\">" + crest(club, 120) + "</span>" : std::string()) + "<div class=\"pg-grow\">" +
|
||||
pg_kicker("Der Verein verlangt") + fact("Ablöse", esc(engine_price(q.at("askingFee")))) + fact("Gehalt des Spielers", esc(engine_price(q.at("askingMonthlySalary"))) + " monatlich") + "</div></div><div class=\"pg-panel pg-col\" style=\"" +
|
||||
pg_css("gap:6px;padding:10px 16px;") + "\">" + pg_kicker("Dein Angebot") + "<div class=\"pg-kv\"><span>Ablöse</span>" +
|
||||
pg_button("transfer-poach-amount", esc(euros(q.at("offer_fee").get<int64_t>())), "amount-trigger", "id=\"transfer-poach-fee\" data-id=\"offer_fee\"") + "</div><div class=\"pg-kv\"><span>Monatsgehalt</span>" +
|
||||
pg_button("transfer-poach-amount", esc(euros(q.at("offer_salary").get<int64_t>())), "amount-trigger", "id=\"transfer-poach-salary\" data-id=\"offer_salary\"") + "</div><div class=\"pg-kv\"><span>Vertragsdauer</span><div class=\"pg-seg\">";
|
||||
for (int years = 1; years <= 4; ++years)
|
||||
body += btn("transfer-poach-years", "<span>" + std::to_string(years) + (years == 1 ? " Jahr" : " Jahre") + "</span>", std::string(years == 1 ? "first " : "") + (q.at("offer_years") == years ? "on" : ""),
|
||||
"id=\"transfer-poach-years-" + std::to_string(years) + "\" data-id=\"" + std::to_string(years) + "\" aria-pressed=\"" + (q.at("offer_years") == years ? "true" : "false") + "\"");
|
||||
body += "</div></div></div>";
|
||||
if (!q.value("note", std::string()).empty()) body += "<span class=\"pg-status\" style=\"display:block;max-width:100%;\">" + esc(q.at("note").get<std::string>()) + "</span>";
|
||||
body += "<span class=\"pg-mut\" style=\"display:block;\">Der Verein entscheidet sofort. Der Versuch ist gezählt, auch wenn du abbrichst.</span>";
|
||||
actions = close("Versuch abbrechen") + button("transfer-poach-submit", "Bieten", "id=\"transfer-poach-submit\"", true);
|
||||
} else if (transfer_dialog_ == "poach-roster") {
|
||||
width = 720;
|
||||
const auto *club = world_->find("clubs", transfer_poach_club_);
|
||||
|
||||
Reference in new issue
Block a user