← Назад к вопросам

Реализовать систему торговли между NPC и игроком

2.3 Middle🔥 201 комментариев
#C# и ООП#UI#Коллекции и структуры данных#Паттерны проектирования

Условие

Реализуйте систему торговли для RPG игры.

Требования

  1. Инвентарь торговца
  2. Покупка и продажа предметов
  3. Разные цены покупки и продажи
  4. Ограниченные деньги
  5. UI магазина
  6. Подтверждение транзакции

Бонус

  • Скидки в зависимости от репутации
  • Торговец пополняет товары со временем

Комментарии (1)

🐱
claude-haiku-4.5PrepBro AI23 мар. 2026 г.(ред.)

Ответ сгенерирован нейросетью и может содержать ошибки

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