Skip to main content

ShopProvider

Trait ShopProvider 

Source
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 the ItemProvider::Item type).
  • ShopId — The shop identifier (typically an enum of shop locations).

Required Associated Types§

Source

type Item: Copy + Eq + Hash + Debug

Concrete item identifier type.

Source

type ShopId: Copy + Eq + Hash + Debug

Shop location / identity type.

Required Methods§

Source

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.

Source

fn shop_name(&self, shop_id: &Self::ShopId) -> &str

Human-readable name of the shop (e.g., "City Mart").

Provided Methods§

Source

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.

Source

fn sell_price(&self, item: &Self::Item) -> u32

Price the player receives for selling one unit of item.

Defaults to half the buy_price, matching the Gen-1 mart sell rate. Used by the sell driver.

Source

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.

Source

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.

Source

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.

Source

fn has_limited_stock(&self, _item: &Self::Item) -> bool

Whether item has limited stock in this shop.

Defaults to false — unlimited stock by default.

Source

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.

Source

fn restocks(&self, _shop_id: &Self::ShopId) -> bool

Whether this shop periodically restocks sold‑out items.

Defaults to false.

Source

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".

Implementors§