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
@@ -10510,6 +10510,7 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
const ui::TransferMarketState m = modern::project_transfer_market(g_, revision);
|
||||
std::string feedback;
|
||||
bool bid_pending = false;
|
||||
const auto saved_poach = poach_;
|
||||
try {
|
||||
if (action == "list") {
|
||||
const std::string id = ui_text(*payload, "playerId");
|
||||
@@ -10599,11 +10600,121 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"transfer"}, feedback);
|
||||
std::get<cli::Json::Object>(answer.value)["outcome"] = "offer_rejected";
|
||||
}
|
||||
} else if (action == "poach" || action == "poachOffer" || action == "poachCancel") {
|
||||
// Poaching, in two steps as the original has it:
|
||||
// {action: "poach", playerId}: the checks, the club's answer and the special list row
|
||||
// (start_poach). The attempt counts from here. Where an offer can be made the offer
|
||||
// editor stays open and the answer carries what is asked under "poach".
|
||||
// {action: "poachOffer", fee, monthlySalary, years 1-4}: the offer on the open editor,
|
||||
// decided at once; a low offer keeps the editor open.
|
||||
// {action: "poachCancel"}: the editor is closed without an offer.
|
||||
const auto quote_of = [&](const ui::OutgoingTransferEditorState& e) {
|
||||
return cli::Json::Object{{"playerId", modern::ui_player_id(g_, e.player)}, {"name", ui::original_to_utf8(e.panel.player_name)},
|
||||
{"sellerId", e.seller >= 0 && e.seller < league_clubs() ? cli::Json(modern::ui_team_id(g_, e.seller)) : cli::Json(nullptr)},
|
||||
{"askingFee", modern::ui_money(int64_t(e.panel.asking_fee))}, {"askingMonthlySalary", modern::ui_money(int64_t(e.panel.asking_monthly_salary))},
|
||||
{"fee", modern::ui_money(int64_t(e.fee))}, {"monthlySalary", modern::ui_money(int64_t(e.monthly_salary))},
|
||||
// the bounds the editor accepts for the two sums
|
||||
{"feeRange", cli::Json::Object{{"min", modern::ui_money(int64_t(e.money_calculators[0].minimum))}, {"max", modern::ui_money(int64_t(e.money_calculators[0].maximum))}}},
|
||||
{"salaryRange", cli::Json::Object{{"min", modern::ui_money(int64_t(e.money_calculators[1].minimum))}, {"max", modern::ui_money(int64_t(e.money_calculators[1].maximum))}}},
|
||||
{"years", int(e.duration_years)}, {"attemptsLeft", modern::poach_attempts_left(g_, manager)}};
|
||||
};
|
||||
if (action == "poach") {
|
||||
if (transfer_offer_editor_ || poach_) return refuse("poach_open", "Ein Abwerbeversuch ist noch offen.");
|
||||
const std::string id = ui_text(*payload, "playerId");
|
||||
int slot = -1;
|
||||
for (int t = 0; t < league_clubs() && slot < 0; ++t) {
|
||||
if (t == team) continue;
|
||||
const SquadRange other = squad_range(t);
|
||||
for (size_t i = 0; i < other.count; ++i) {
|
||||
const int p = g_.squad_slots[other.first + i] & 0x0fff;
|
||||
if (p != 0x0fff && modern::ui_player_id(g_, p) == id) { slot = int(other.first + i); break; }
|
||||
}
|
||||
}
|
||||
if (slot < 0) return refuse("unknown_player", "Dieser Spieler spielt bei keinem anderen Verein der Ligen.");
|
||||
const auto opened = open_poach(manager, slot, revision, error);
|
||||
if (!opened) { restore(); poach_ = saved_poach; return refuse("transfer_refused", error); }
|
||||
std::string text;
|
||||
for (const auto& line : opened->start.messages) text += (text.empty() ? "" : " ") + ui::original_to_utf8(line);
|
||||
if (opened->editor) {
|
||||
revision = previous + 1;
|
||||
transfer_offer_revision_ = revision;
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"transfer"}, text.empty() ? "Der Verein nennt seine Forderung." : text);
|
||||
auto& out = std::get<cli::Json::Object>(answer.value);
|
||||
out["outcome"] = "poach_open";
|
||||
out["poach"] = quote_of(opened->editor->editor);
|
||||
} else {
|
||||
revision = opened->start.status == PoachStatus::invalid ? previous : previous + 1;
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"transfer"}, text.empty() ? "Abwerben ist hier nicht möglich." : text);
|
||||
auto& out = std::get<cli::Json::Object>(answer.value);
|
||||
out["outcome"] = "poach_refused";
|
||||
out["attemptsLeft"] = modern::poach_attempts_left(g_, manager);
|
||||
}
|
||||
} else {
|
||||
if (!transfer_offer_editor_ || !poach_) return refuse("no_poach", "Es ist kein Abwerbeversuch offen.");
|
||||
transfer_offer_revision_ = revision; // other commands may have counted on since the editor opened
|
||||
ui::OutgoingTransferEditorState e = transfer_offer_projection(g_, *transfer_offer_editor_, revision,
|
||||
g_.memory.u8(::bmh::layout::TextGradientDisabled) == 0);
|
||||
const auto send = [&](ui::OutgoingTransferRequestKind k, ui::OutgoingTransferField field, uint32_t value)
|
||||
-> std::optional<TransferOfferEditorDispatch> {
|
||||
ui::OutgoingTransferRequest r;
|
||||
r.kind = k;
|
||||
r.identity = {e.manager_slot, e.runtime_club, e.revision, e.list_entry, e.source_slot, e.player, e.seller, e.bid_slot};
|
||||
r.field = field, r.value = value, r.quote_loan = e.quote_loan;
|
||||
r.fee = e.fee, r.monthly_salary = e.monthly_salary, r.duration_years = e.duration_years, r.bonuses = e.bonuses;
|
||||
r.quoted_fee = e.panel.quoted_fee, r.quoted_monthly_salary = e.panel.quoted_monthly_salary, r.quoted_years = e.panel.quoted_years;
|
||||
auto d = dispatch_transfer_offer(r, hooks, revision, error);
|
||||
if (d) e = d->editor;
|
||||
return d;
|
||||
};
|
||||
if (action == "poachCancel") {
|
||||
if (!send(ui::OutgoingTransferRequestKind::cancel, ui::OutgoingTransferField::fee, e.fee)) { restore(); poach_ = saved_poach; return refuse("transfer_refused", error); }
|
||||
feedback = "Der Abwerbeversuch ist beendet.";
|
||||
} else {
|
||||
const auto money_of = [&](const char* key) -> int64_t {
|
||||
const cli::Json* v = ui_field(*payload, key);
|
||||
try {
|
||||
if (!v || ui_text(*v, "currency") != "EUR") return -1;
|
||||
const auto text = ui_text(*v, "minor"); size_t end = 0; const auto amount = std::stoll(text, &end);
|
||||
return end == text.size() && amount >= 0 && amount % 100 == 0 && amount / 100 <= std::numeric_limits<int32_t>::max() / 12 * 12 ? amount : -1;
|
||||
} catch (const std::exception&) { return -1; }
|
||||
};
|
||||
const int64_t fee = money_of("fee"), salary = money_of("monthlySalary");
|
||||
const cli::Json* years = ui_field(*payload, "years");
|
||||
if (fee < 0 || salary < 0 || salary / 100 > std::numeric_limits<int32_t>::max() / 12 || !years || !years->integer() || *years->integer() < 1 || *years->integer() > 4)
|
||||
return refuse("invalid_payload", "fee, monthlySalary (Money, ganze Euro) und years 1-4 nötig.");
|
||||
bool ok = true;
|
||||
if (ok && e.fee != uint32_t(fee / 100)) { e.fee = uint32_t(fee / 100); ok = bool(send(ui::OutgoingTransferRequestKind::quote_change, ui::OutgoingTransferField::fee, e.fee)); }
|
||||
if (ok && e.monthly_salary != uint32_t(salary / 100)) {
|
||||
e.monthly_salary = uint32_t(salary / 100);
|
||||
ok = bool(send(ui::OutgoingTransferRequestKind::quote_change, ui::OutgoingTransferField::monthly_salary, e.monthly_salary));
|
||||
}
|
||||
if (ok && e.duration_years != uint8_t(*years->integer())) {
|
||||
e.duration_years = uint8_t(*years->integer());
|
||||
ok = bool(send(ui::OutgoingTransferRequestKind::quote_change, ui::OutgoingTransferField::duration_years, e.duration_years));
|
||||
}
|
||||
std::optional<TransferOfferEditorDispatch> sent;
|
||||
if (ok) sent = send(ui::OutgoingTransferRequestKind::submit, ui::OutgoingTransferField::fee, e.fee);
|
||||
if (!sent) { restore(); poach_ = saved_poach; return refuse("transfer_refused", error); }
|
||||
const TransferActionStatus status = sent->action.status;
|
||||
feedback = status == TransferActionStatus::accepted ? "Angenommen: Der Spieler wechselt zu Ihrem Verein."
|
||||
: status == TransferActionStatus::offer_too_low ? "Das Angebot ist zu niedrig."
|
||||
: status == TransferActionStatus::pending ? "Das Angebot ist abgegeben."
|
||||
: notices.empty() ? "Das Angebot wurde abgelehnt." : "";
|
||||
for (const auto& n : notices) feedback += " " + n;
|
||||
revision = previous + 1;
|
||||
if (!e.closed) transfer_offer_revision_ = revision; // the editor waits for a better offer
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"transfer", "squad", "desktop"}, feedback);
|
||||
auto& out = std::get<cli::Json::Object>(answer.value);
|
||||
out["outcome"] = status == TransferActionStatus::accepted ? "poach_accepted" : !e.closed ? "poach_open" : status == TransferActionStatus::pending ? "offer_pending" : "poach_rejected";
|
||||
if (!e.closed) out["poach"] = quote_of(e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return refuse("invalid_payload", "action ist list oder bid.");
|
||||
return refuse("invalid_payload", "action ist list, bid, poach, poachOffer oder poachCancel.");
|
||||
}
|
||||
} catch (const std::exception& ex) {
|
||||
restore();
|
||||
poach_ = saved_poach;
|
||||
if (question) return refuse("decision_pending", "Ein menschlicher Verkäufer müsste gefragt werden (noch nicht unterstützt).");
|
||||
return refuse("transfer_refused", ex.what());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user