pub trait ShopProvider {
type Item: Copy + Eq + Hash + Debug;
type ShopId: Copy + Eq + Hash + Debug;
// Required methods
fn shop_inventory(&self, shop_id: &Self::ShopId) -> Vec<(Self::Item, u32)>;
fn shop_name(&self, shop_id: &Self::ShopId) -> &str;
// Provided methods
fn buy_price(&self, item: &Self::Item) -> u32 { ... }
fn sell_price(&self, item: &Self::Item) -> u32 { ... }
fn can_sell(&self, item: &Self::Item) -> bool { ... }
fn discount_rate(&self, _shop_id: &Self::ShopId) -> f32 { ... }
fn sell_rate(&self, _shop_id: &Self::ShopId) -> f32 { ... }
fn has_limited_stock(&self, _item: &Self::Item) -> bool { ... }
fn max_stock(&self, _item: &Self::Item) -> u32 { ... }
fn restocks(&self, _shop_id: &Self::ShopId) -> bool { ... }
fn restock_interval(&self, _shop_id: &Self::ShopId) -> u32 { ... }
}Expand description
Provider trait for shop / mart data.
Shops in a JRPG may sell items at prices that differ from the item’s base price. This trait lets the engine query a shop’s inventory and its display name.
§Associated types
Item— The item identifier (must match theItemProvider::Itemtype).ShopId— The shop identifier (typically an enum of shop locations).
Required Associated Types§
Required Methods§
Sourcefn shop_inventory(&self, shop_id: &Self::ShopId) -> Vec<(Self::Item, u32)>
fn shop_inventory(&self, shop_id: &Self::ShopId) -> Vec<(Self::Item, u32)>
Returns the shop’s inventory as (item, price) pairs.
The price in each pair is the price this specific shop charges,
which may differ from the base ItemProvider::item_price.
Provided Methods§
Sourcefn buy_price(&self, item: &Self::Item) -> u32
fn buy_price(&self, item: &Self::Item) -> u32
Price the player pays to buy one unit of item.
Defaults to 0; games override with their list price. Used by the
buy driver.
Sourcefn sell_price(&self, item: &Self::Item) -> u32
fn sell_price(&self, item: &Self::Item) -> u32
Sourcefn can_sell(&self, item: &Self::Item) -> bool
fn can_sell(&self, item: &Self::Item) -> bool
Whether the shop will buy item from the player.
Defaults to true; games return false for key items and anything
else that cannot be sold. Used by the sell
driver.
Sourcefn discount_rate(&self, _shop_id: &Self::ShopId) -> f32
fn discount_rate(&self, _shop_id: &Self::ShopId) -> f32
Discount multiplier applied when buying from this shop.
1.0 = full price, 0.8 = 20 % off, 1.2 = premium surcharge.
Used by the buy driver.
Sourcefn sell_rate(&self, _shop_id: &Self::ShopId) -> f32
fn sell_rate(&self, _shop_id: &Self::ShopId) -> f32
Per-shop sell-back multiplier applied on top of
sell_price.
Defaults to 1.0 (pass-through). The Gen-1 half-price rule is already
encoded in the sell_price default (buy_price / 2), so a non-unit
default here would compose to quarter price. Override per shop for
special vendors that pay more or less than the game-wide sell price.
Sourcefn has_limited_stock(&self, _item: &Self::Item) -> bool
fn has_limited_stock(&self, _item: &Self::Item) -> bool
Whether item has limited stock in this shop.
Defaults to false — unlimited stock by default.
Sourcefn max_stock(&self, _item: &Self::Item) -> u32
fn max_stock(&self, _item: &Self::Item) -> u32
Maximum stock count for item when [has_limited_stock] is true.
Defaults to 0; meaningful only when has_limited_stock returns
true.
Sourcefn restocks(&self, _shop_id: &Self::ShopId) -> bool
fn restocks(&self, _shop_id: &Self::ShopId) -> bool
Whether this shop periodically restocks sold‑out items.
Defaults to false.
Sourcefn restock_interval(&self, _shop_id: &Self::ShopId) -> u32
fn restock_interval(&self, _shop_id: &Self::ShopId) -> u32
How many game‑ticks / steps / frames between restock cycles.
Defaults to 0; meaningful only when [restocks] returns true.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".