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:
@@ -247,6 +247,44 @@ pub fn discard_value(cardtype: u8, rating: u8, rare: i64) -> i64 {
|
||||
(i64::from(rating) * price + 50) / 100
|
||||
}
|
||||
|
||||
/// THE authoritative FIFA 17 discard price for one owned definition, or `None`
|
||||
/// when an input the client itself uses is not in hand.
|
||||
///
|
||||
/// This is the single entry point every caller must use — the wire shaper and
|
||||
/// the quick-sell payout both reach it through
|
||||
/// [`super::item::ItemIdentityResolver::discard_value`], so the number displayed
|
||||
/// and the number credited cannot diverge.
|
||||
///
|
||||
/// `None` means "not known", never "worthless", and the caller falls back to the
|
||||
/// legacy ladder rather than paying 0:
|
||||
///
|
||||
/// * `cardtype == 0` — the subtype decodes to 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.
|
||||
///
|
||||
/// A PLAYER with no catalog rating legitimately uses Core's rating: cardtype 1
|
||||
/// is not re-rated by the client, so Core is authoritative there. For the
|
||||
/// cardtypes that ARE re-rated ([`client_rerates`]) the catalog rating is the
|
||||
/// client's own value and must be present, or we cannot match its display.
|
||||
pub fn value_for_definition(
|
||||
subtype: i64,
|
||||
rareflag: i64,
|
||||
catalog_rating: Option<u8>,
|
||||
core_rating: u8,
|
||||
) -> Option<i64> {
|
||||
let cardtype = cardtype_for_subtype(subtype);
|
||||
if cardtype == 0 {
|
||||
return None;
|
||||
}
|
||||
let rating = match catalog_rating {
|
||||
Some(r) => r,
|
||||
None if cardtype == 1 => core_rating,
|
||||
None => return None,
|
||||
};
|
||||
Some(discard_value(cardtype, rating, rareflag))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -343,6 +381,42 @@ mod tests {
|
||||
assert_eq!(discard_value(10, 67, 0), 37);
|
||||
}
|
||||
|
||||
/// A player is priced from Core's rating and the catalog's `rareflag`, so a
|
||||
/// special and a common of the SAME rating price differently. The legacy
|
||||
/// ladder paid 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!(value_for_definition(0, 3, None, 90), Some(10_980));
|
||||
// Same rating, rare 0 (gold common) -> 4 * rating.
|
||||
assert_eq!(value_for_definition(0, 0, None, 90), Some(360));
|
||||
// Same rating, rare 1 (gold rare) -> 8 * rating.
|
||||
assert_eq!(value_for_definition(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 not re-rated, so the server's values are what the
|
||||
/// client itself prices with.
|
||||
#[test]
|
||||
fn a_consumable_prices_from_its_catalog_rating() {
|
||||
// subtype 201 -> cardtype 6, rating 60 -> level 1, rare 0 -> price 5.
|
||||
assert_eq!(value_for_definition(201, 0, Some(60), 0), Some(3));
|
||||
assert!(!client_rerates(cardtype_for_subtype(201)));
|
||||
}
|
||||
|
||||
/// The two "not known" cases MUST decline rather than pay 0.
|
||||
#[test]
|
||||
fn an_unknown_input_declines_instead_of_paying_zero() {
|
||||
// Staff: cardtype 10, no catalog rating. Core's rating is 0, which would
|
||||
// price the card at 0 coins.
|
||||
assert_eq!(cardtype_for_subtype(6), 10);
|
||||
assert_eq!(value_for_definition(6, 0, None, 0), None);
|
||||
// A subtype with no table row at all.
|
||||
assert_eq!(value_for_definition(600, 0, Some(80), 80), None);
|
||||
// Once the rating IS known, staff price normally.
|
||||
assert_eq!(value_for_definition(6, 0, Some(66), 0), Some(36));
|
||||
}
|
||||
|
||||
/// The subtype decode must agree with the settled club-item subtypes and the
|
||||
/// staff family selector this crate already carries.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user