using System; using System.Collections.Generic; using Cielonos.Core.Interaction; using Cielonos.MainGame.Characters; using Cielonos.MainGame.Inventory; using Cielonos.MainGame.Inventory.Collections; using Cielonos.MainGame.Items; using Cielonos.MainGame.UI; using UnityEngine; namespace Cielonos.MainGame.Interactions { /// /// 物流中心(商店)场景交互对象。 /// 玩家靠近按交互键后呼出 LogisticCenterUIPage,显示可购买的随机装备。 /// 商店可反复打开(不像机械台单次使用),商品在首次进入时生成,买完即消失。 /// 货币通过消耗背包中的 RareMaterial 消耗品来支付。 /// public class LogisticsCenter : InteractableObjectBase { private const int OFFER_COUNT = 5; private List currentOffers; private bool isInitialized; protected override void InitializeChoices() { choices.Add(new InteractionChoice("Open Logistic Center", OpenShop)); } /// /// 由 RunManager 或场景加载逻辑调用,预先生成本次商店的商品列表和价格。 /// 若未调用此方法,交互时会自动从 Resources/Items 中生成。 /// /// 本局 Run 的随机数生成器。= currentOffers.Count) return; ShopOffer offer = currentOffers[index]; // 获取玩家背包中的 RareMaterial PlayerInventorySubcontroller inventorySc = MainGameManager.Player.inventorySc; RareMaterial rareMaterial = MainGameManager.Player.inventorySc.GetRareMaterial(); if (rareMaterial == null || rareMaterial.stackAmount < offer.price) { Debug.Log("[LogisticCenter] RareMaterial 不足,无法购买。"); return; } // 扣除 RareMaterial rareMaterial.Use(offer.price); int remaining = rareMaterial != null ? rareMaterial.stackAmount : 0; // 将物品加入背包 inventorySc.backpackSm.ObtainItem(offer.prefab); // 从商品列表中移除已购买的商品 currentOffers.RemoveAt(index); Debug.Log($"[LogisticCenter] 玩家购买了 '{offer.prefab.name}',花费 {offer.price} RareMaterial,剩余 {remaining}。"); } /// /// 从 Resources/Items 中筛选可售卖的装备并生成 ShopOffer(含随机价格)。 /// 商店出售所有类型装备(MainWeapon、Support、Passive),但排除 None 稀有度。 /// private static List RollShopOffers(System.Random rng) { ItemFilter filter = ItemFilter.ByRarity(ItemRarity.None).Not(); List rolledItems = ItemPoolHelper.Roll( OFFER_COUNT, rng, filter, "MainWeapon", "SupportEquipment", "PassiveEquipment" ); List offers = new List(rolledItems.Count); foreach (GameObject prefab in rolledItems) { ItemBase item = prefab.GetComponent(); if (item == null || item.contentData == null) continue; int price = MainGameManager.Config.RollPrice(item.contentData.itemRarity, rng); offers.Add(new ShopOffer(prefab, price)); } return offers; } } /// /// 商店中的单个商品条目:包含物品预制体引用和售价。 /// [Serializable] public class ShopOffer { public GameObject prefab; public int price; public ShopOffer(GameObject prefab, int price) { this.prefab = prefab; this.price = price; } } }