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:
MichaelandClaude Fable 5.2 committed 2026-11-16 15:26:03 +01:00
1 parent a2790751a6
commit 7424b09738
8 files changed
+282 -3

No files matched your search

+108
View File
@@ -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";