VendorInventoryComponent ​
Inherits: RefCounted
Stock-based vendor inventory that manages item availability and creates instances on-demand No longer inherits from InventoryComponent - uses pure stock tracking instead
Variables ​
VendorDefinition | vendor_definition | |
Dictionary | current_stock | {} |
float | last_restock_time | 0.0 |
Dictionary | item_restock_times | {} |
Array[Dictionary] | transaction_history | [] |
Dictionary | vendor_currency_reserves | {} |
ChronoManager | chrono_manager |
Methods ​
void | initialize_vendor_inventory( definition: VendorDefinition ) |
int | get_stock_quantity( item_id: int ) |
bool | is_item_in_stock( item_id: int ) |
void | set_stock_quantity( item_id: int, quantity: int ) |
bool | reduce_stock( item_id: int, quantity: int ) |
void | increase_stock( item_id: int, quantity: int ) |
Array[Dictionary] | get_available_items() |
Array[Dictionary] | get_all_stocked_items() |
int | get_currency_amount( currency_id: int ) |
void | set_currency_amount( currency_id: int, amount: int ) |
bool | can_afford( currency_id: int, cost: int ) |
bool | remove_currency( currency_id: int, amount: int ) |
void | add_currency( currency_id: int, amount: int ) |
bool | has_unlimited_currency( currency_id: int ) |
ItemInstance | create_item_for_purchase( item_id: int, quantity: int ) |
bool | check_and_restock() |
void | perform_restock() |
float | get_time_until_restock() |
Dictionary | sell_item_to_player( item_id: int, quantity: int, player: Entity ) |
Dictionary | buy_item_from_player( item_instance: ItemInstance, quantity: int, player: Entity ) |
int | get_item_price( item_id: int ) |
String | get_item_display_price( item_id: int ) |
String | get_buyback_price( item_instance: ItemInstance ) |
int | calculate_sell_price( item_instance: ItemInstance ) |
int | get_repair_cost( item: ItemInstance ) |
int | get_repair_cost_all( player: Entity ) |
Dictionary | repair_equipment( player: Entity, item: ItemInstance = null ) |
Dictionary | get_vendor_summary() |
Dictionary | get_save_data() |
void | load_save_data( data: Dictionary ) |
bool | is_valid_setup() |
Signals ​
vendor_restocked() ​
Emitted when vendor restocks items
item_sold_to_player( item_definition: ItemDefinition, quantity: int, total_cost: int, currency_id: int ) ​
Emitted when player buys an item from vendor
item_bought_from_player( item_instance: ItemInstance, quantity: int, total_payment: int, currency_id: int ) ​
Emitted when player sells an item to vendor
item_out_of_stock( item_definition: ItemDefinition ) ​
Emitted when item goes out of stock
stock_changed( item_id: int, new_quantity: int, old_quantity: int ) ​
Emitted when stock levels change
currency_changed( currency_id: int, new_amount: int ) ​
Emitted when vendor's currency reserves change
Constants ​
intUNLIMITED_STOCK =-1- Constant for unlimited stock
Variable descriptions ​
VendorDefinition vendor_definition ​
Reference to the vendor definition (blueprint)
Dictionary current_stock = ​
Current stock quantities by item_id: Dictionary[int, int] (-1 = unlimited)
float last_restock_time = 0.0 ​
Last restock time (hours on the clock of the vendor: restock_time_source of its definition)
Dictionary item_restock_times = ​
The last time each item was due for a restock (item id -> game hours): every item waits its own interval
Array[Dictionary] transaction_history = [] ​
Player transaction history (for reputation/relationship building)
Dictionary vendor_currency_reserves = ​
Vendor's current currency reserves for buying items from players (-1 = unlimited)
ChronoManager chrono_manager ​
The combat system manager
Method descriptions ​
void initialize_vendor_inventory( definition: VendorDefinition ) ​
Initialize vendor inventory from definition
int get_stock_quantity( item_id: int ) ​
Get current stock quantity for an item
bool is_item_in_stock( item_id: int ) ​
Check if item is in stock
void set_stock_quantity( item_id: int, quantity: int ) ​
Set stock quantity for an item (with signals)
bool reduce_stock( item_id: int, quantity: int ) ​
Reduce stock quantity (for sales)
void increase_stock( item_id: int, quantity: int ) ​
Increase stock quantity (for restocking)
Array[Dictionary] get_available_items() ​
Get all available item definitions (items with stock > 0 or unlimited)
Array[Dictionary] get_all_stocked_items() ​
Get all stocked items (including out of stock for display)
int get_currency_amount( currency_id: int ) ​
Get current amount of a currency
void set_currency_amount( currency_id: int, amount: int ) ​
Set currency amount (with signal)
bool can_afford( currency_id: int, cost: int ) ​
Check if vendor can afford a cost
bool remove_currency( currency_id: int, amount: int ) ​
Remove currency (returns false if insufficient)
void add_currency( currency_id: int, amount: int ) ​
Add currency
bool has_unlimited_currency( currency_id: int ) ​
Check if vendor has unlimited currency
ItemInstance create_item_for_purchase( item_id: int, quantity: int ) ​
Create an item instance for purchase (only called when actually buying)
bool check_and_restock() ​
No description yet.
void perform_restock() ​
Manually trigger restocking of everything that can restock
float get_time_until_restock() ​
Get time until the next restock (game hours; -1 when nothing restocks)
Dictionary sell_item_to_player( item_id: int, quantity: int, player: Entity ) ​
Player buys item from vendor: all or nothing (the stock, the price and the room for everything are checked first)
Dictionary buy_item_from_player( item_instance: ItemInstance, quantity: int, player: Entity ) ​
Player sells item to vendor (a key item cannot be sold)
int get_item_price( item_id: int ) ​
Get the selling price for an item (what player pays to vendor)
String get_item_display_price( item_id: int ) ​
Get display price for an item with currency formatting
String get_buyback_price( item_instance: ItemInstance ) ​
Get buy-back price for an item instance (what vendor will pay player)
int calculate_sell_price( item_instance: ItemInstance ) ​
Calculate what vendor will pay player for an item (numerical value)
int get_repair_cost( item: ItemInstance ) ​
A short description of the vendor (for debugging and the UI) What this vendor charges to repair a piece of equipment, in its preferred currency (0 = nothing to repair)
int get_repair_cost_all( player: Entity ) ​
What this vendor charges to repair everything the player wears
Dictionary repair_equipment( player: Entity, item: ItemInstance = null ) ​
Repairs one worn piece (or every damaged piece when item is null) of the player and takes the price from the purse of the player, all or nothing. Gives {"success": bool, "message": String, "cost": int}
Dictionary get_vendor_summary() ​
No description yet.
Dictionary get_save_data() ​
The stock of the vendor for a save.
void load_save_data( data: Dictionary ) ​
Restores the stock of the vendor from a save.
bool is_valid_setup() ​
Validate vendor setup