Реализовать систему торговли между NPC и игроком
Условие
Реализуйте систему торговли для RPG игры.
Требования
- Инвентарь торговца
- Покупка и продажа предметов
- Разные цены покупки и продажи
- Ограниченные деньги
- UI магазина
- Подтверждение транзакции
Бонус
- Скидки в зависимости от репутации
- Торговец пополняет товары со временем
Комментарии (1)
Ответ сгенерирован нейросетью и может содержать ошибки
# Trading System for RPG
Merchant System
Complete trading system with merchant inventory, buy/sell mechanics, dynamic pricing, and reputation system.
Core Components
MerchantInventory - Manages merchant stock with separate buy and sell prices. Supports limited money pool and automatic restocking.
MerchantManager - Handles buy/sell transactions with price calculations, reputation tracking, and discount application.
TradeItem - Data structure with item reference, quantity, buy price, and sell price.
ShopUI - User interface for browsing items, selecting quantities, and confirming transactions.
Features
- Merchant inventory with independent buy/sell prices
- Limited merchant money pool (prevents exploitation)
- Reputation system with dynamic discounts (±5%)
- Auto-restocking every 60 seconds
- Transaction confirmation dialog
- Full buy/sell support from both directions
Bonuses Implemented
- Reputation-based discounts: good reputation = lower prices (up to 5% discount)
- Merchant stock replenishment with time-based intervals
- Friendship tracking per merchant with persistent reputation
Architecture
Event-driven system with loose coupling between components. Price calculations apply reputation modifier. Money management prevents merchant bankruptcy.