refactor(fifa17): one authoritative discard implementation + corpus matrix
The pricing DECISION (which rating to trust, when to decline) lived in the host
while the TABLE lived in the adapter, so FIFA semantics were split across two
crates and no single function could be pointed at as authoritative.
Move the decision into the adapter as `discard::value_for_definition(subtype,
rareflag, catalog_rating, core_rating) -> Option<i64>` and have the host call it.
Its three tests move with it. There is now exactly one table implementation, one
decision point (`ItemIdentityResolver::discard_value`), and one deliberately
retained rollback ladder (`legacy_discard_value`).
Add `examples/discard_matrix.rs`, which audits an entire FIFA17 corpus using the
SHIPPED implementation rather than reimplementing the formula, so the matrix
cannot drift from what the server pays. Over the current 1717-definition corpus:
declined -> legacy : 6 (badge, ball, kit x2, misc, stadium -- no catalog rating)
priced zero : 0
negative : 0
implausible : 0
rating boundaries : OK (1/2/3 at <65 / 65..74 / >=75)
Also re-verified both numeric cores against the LIVE client rather than trusting
the earlier notes:
level 0x180141e8a cmp al,0x4b -> 3 ; cmp al,0x41 ; sbb/add 2 -> 2 else 1
value 0x180141119 imul rating*price ; /100 via 0x51eb851f ; imul 0x64 ; sub ;
cmp remainder,0x32 ; jl/inc == round-half-up
`(rating*price + 50)/100` is identical to that for non-negative inputs.
Adapter 247 lib, host 120 lib, fmt and clippy clean.
This commit is contained in:
@@ -50,9 +50,7 @@ use std::net::{TcpListener, TcpStream};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::{Instant, SystemTime, UNIX_EPOCH};
|
||||
|
||||
use openfut_adapter_fifa17::fut::catalog::{
|
||||
Fifa17CardCatalog, Fifa17CardIdentity, Fifa17WireItemIdPolicy,
|
||||
};
|
||||
use openfut_adapter_fifa17::fut::catalog::{Fifa17CardCatalog, Fifa17WireItemIdPolicy};
|
||||
use openfut_adapter_fifa17::fut::club_response::{
|
||||
shape_club_response_with_kits, ActiveKitAssignments, CoreOwnedItem, Fifa17ConsumableIdentity,
|
||||
Fifa17Identity, Fifa17KitIdentity, Fifa17StaffIdentity, ItemIdentityResolver,
|
||||
@@ -1839,7 +1837,12 @@ impl ItemIdentityResolver for Fifa17IdentityResolver {
|
||||
fn discard_value(&self, item: &CoreOwnedItem) -> i64 {
|
||||
if discard_table_enabled() {
|
||||
if let Some(ident) = self.catalog.lookup(&item.card_id) {
|
||||
if let Some(price) = table_discard_value(&ident, item.rating) {
|
||||
if let Some(price) = discard::value_for_definition(
|
||||
ident.subtype,
|
||||
ident.rareflag,
|
||||
ident.rating,
|
||||
item.rating,
|
||||
) {
|
||||
return price;
|
||||
}
|
||||
}
|
||||
@@ -4872,33 +4875,6 @@ fn discard_table_enabled() -> bool {
|
||||
*ENABLED.get_or_init(|| std::env::var("OPENFUT_FIFA17_DISCARD_TABLE").as_deref() == Ok("1"))
|
||||
}
|
||||
|
||||
/// The client's own discard price for a catalogued definition, or `None` when an
|
||||
/// input the client uses is not in hand — the caller then keeps the legacy
|
||||
/// ladder rather than inventing a price or paying 0.
|
||||
///
|
||||
/// `None` cases, all "not known" rather than "worthless":
|
||||
/// * the `cardsubtypeid` decodes to cardtype 0, which has no table row at all;
|
||||
/// * a NON-PLAYER with no catalog rating. Core models every non-player's
|
||||
/// `overall` as 0, and rating 0 prices at 0 coins, so trusting it would pay
|
||||
/// nothing for a real card. Staff are exactly this case today: their rating is
|
||||
/// the `value` column of `managercards`/`*coachcards`/`physiocards`, which the
|
||||
/// import does not yet carry.
|
||||
///
|
||||
/// A PLAYER with no catalog rating legitimately falls back to Core's rating,
|
||||
/// which is authoritative for cardtype 1 (the client does not re-rate players).
|
||||
fn table_discard_value(ident: &Fifa17CardIdentity, core_rating: u8) -> Option<i64> {
|
||||
let cardtype = discard::cardtype_for_subtype(ident.subtype);
|
||||
if cardtype == 0 {
|
||||
return None;
|
||||
}
|
||||
let rating = match ident.rating {
|
||||
Some(r) => r,
|
||||
None if cardtype == 1 => core_rating,
|
||||
None => return None,
|
||||
};
|
||||
Some(discard::discard_value(cardtype, rating, ident.rareflag))
|
||||
}
|
||||
|
||||
/// A JSON response with an explicit status.
|
||||
fn json_status(status: u16, v: &Value) -> WireResponse {
|
||||
let body = serde_json::to_vec(v).unwrap_or_default();
|
||||
@@ -5130,70 +5106,6 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::async_bridge::AsyncBridge;
|
||||
|
||||
/// A catalog identity carrying only the fields discard pricing reads.
|
||||
fn priced_def(subtype: i64, rareflag: i64, rating: Option<u8>) -> Fifa17CardIdentity {
|
||||
Fifa17CardIdentity {
|
||||
asset_id: 1,
|
||||
version: 0,
|
||||
resource_id: 1,
|
||||
rareflag,
|
||||
kind: ContentKind::Player,
|
||||
subtype,
|
||||
card_asset_id: 1,
|
||||
team_id: 0,
|
||||
nation: 0,
|
||||
league_id: 0,
|
||||
rating,
|
||||
amount: None,
|
||||
contract: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// A player is priced from Core's rating and the catalog's `rareflag`, on
|
||||
/// the client's own table — so a special and a common of the SAME rating
|
||||
/// price differently. The legacy ladder pays 1500 for every one of these.
|
||||
#[test]
|
||||
fn a_players_price_follows_its_rareflag_not_just_its_rating() {
|
||||
// rare 3 (TOTW) at level 3 -> price 12200; 90 * 12200 / 100.
|
||||
assert_eq!(
|
||||
table_discard_value(&priced_def(0, 3, None), 90),
|
||||
Some(10_980)
|
||||
);
|
||||
// Same rating, rare 0 (gold common) -> price 400; 4 * rating.
|
||||
assert_eq!(table_discard_value(&priced_def(0, 0, None), 90), Some(360));
|
||||
// Same rating, rare 1 (gold rare) -> 8 * rating.
|
||||
assert_eq!(table_discard_value(&priced_def(0, 1, None), 90), Some(720));
|
||||
}
|
||||
|
||||
/// A consumable's rating is EA's authored one from the catalog, never Core's
|
||||
/// 0 — and cardtype 6 is a class the client does NOT re-rate, so the server's
|
||||
/// values are authoritative.
|
||||
#[test]
|
||||
fn a_consumable_prices_from_its_catalog_rating() {
|
||||
// subtype 201 -> cardtype 6, rating 60 -> level 1, rare 0 -> price 5.
|
||||
assert_eq!(
|
||||
table_discard_value(&priced_def(201, 0, Some(60)), 0),
|
||||
Some(3)
|
||||
);
|
||||
assert!(!discard::client_rerates(discard::cardtype_for_subtype(201)));
|
||||
}
|
||||
|
||||
/// The two "not known" cases MUST decline to price rather than pay 0.
|
||||
#[test]
|
||||
fn an_unknown_input_declines_instead_of_paying_zero() {
|
||||
// Staff: cardtype 10, no catalog rating (it lives in `gkcoachcards.value`,
|
||||
// which the import does not carry). Core's rating is 0, which would
|
||||
// price the card at 0 coins.
|
||||
assert_eq!(discard::cardtype_for_subtype(6), 10);
|
||||
assert_eq!(table_discard_value(&priced_def(6, 0, None), 0), None);
|
||||
// A subtype with no table row at all.
|
||||
assert_eq!(table_discard_value(&priced_def(600, 0, Some(80)), 80), None);
|
||||
// But once the rating IS known, staff price normally.
|
||||
assert_eq!(
|
||||
table_discard_value(&priced_def(6, 0, Some(66)), 0),
|
||||
Some(36)
|
||||
);
|
||||
}
|
||||
/// A configurable in-memory economy double: real balance/entitlements, or a
|
||||
/// forced error to prove fail-closed behavior.
|
||||
struct FakeEconomy {
|
||||
|
||||
Reference in New Issue
Block a user