using NUnit.Framework; using SepCore.CustomUtility; using SepCore.Definition; using SepCore.Event; using SepCore.UI; using UnityEngine; namespace VampireLike.Tests.Gameplay.EditMode { [TestFixture] public class ShopEconomyAndLockTests { [Test] public void RerollPrice_Progression_CalculatesAccurately() { // 公式: BaseCost(1) + (CurrentWave * 1) + (RollTimes * 2) // 第 1 波:初始刷新 1 + 1 + 0 = 2 Assert.AreEqual(2, ShopUseCase.CalculateRefreshPrice(1, 0)); // 第 1 波第 1 次刷新后: 1 + 1 + 2 = 4 Assert.AreEqual(4, ShopUseCase.CalculateRefreshPrice(1, 1)); // 第 1 波第 2 次刷新后: 1 + 1 + 4 = 6 Assert.AreEqual(6, ShopUseCase.CalculateRefreshPrice(1, 2)); // 第 1 波第 3 次刷新后: 1 + 1 + 6 = 8 Assert.AreEqual(8, ShopUseCase.CalculateRefreshPrice(1, 3)); // 第 2 波:初始刷新 1 + 2 + 0 = 3 Assert.AreEqual(3, ShopUseCase.CalculateRefreshPrice(2, 0)); // 第 2 波第 1 次刷新后: 1 + 2 + 2 = 5 Assert.AreEqual(5, ShopUseCase.CalculateRefreshPrice(2, 1)); // 第 5 波第 3 次刷新后: 1 + 5 + 6 = 12 Assert.AreEqual(12, ShopUseCase.CalculateRefreshPrice(5, 3)); // 边界防守:负波次与负刷新次数 Assert.AreEqual(2, ShopUseCase.CalculateRefreshPrice(0, -1)); } [Test] public void SlotLock_ToggleLock_FlipsState() { var selection = new ShopGoodsSelection { GoodsType = GoodsType.Weapon, RefId = 1001, Price = 50, IsLocked = false }; // 初始未锁定 Assert.IsFalse(selection.IsLocked); // 锁定 selection.IsLocked = !selection.IsLocked; Assert.IsTrue(selection.IsLocked); // 解锁 selection.IsLocked = !selection.IsLocked; Assert.IsFalse(selection.IsLocked); } [Test] public void GoodsItemContext_ConstructsWithIsLocked_FromRawData() { var propBuf = new Luban.ByteBuf(); propBuf.WriteInt(101); propBuf.WriteString("TestProp"); propBuf.WriteInt((int)Rarity.Purple); propBuf.WriteInt(120); propBuf.WriteSize(0); propBuf.WriteString("test_icon"); var propConfig = new PropConfig(propBuf); var rawData = new GoodsItemRawData { Price = 120, Rarity = Rarity.Purple, ItemType = ItemType.Prop, DataRow = propConfig, IsLocked = true }; var context = new GoodsItemContext(rawData); Assert.IsTrue(context.IsLocked); Assert.AreEqual(120, context.Price); Assert.AreEqual(Rarity.Purple, context.Rarity); Assert.AreEqual("TestProp", context.Name); var defaultContext = new GoodsItemContext(); Assert.IsFalse(defaultContext.IsLocked); } [Test] public void Luck_IncreasesHighRarityProportion() { // 构造测试用 LevelDropConfig: White: 75, Blue: 20, Purple: 5, Red: 0 var buf = new Luban.ByteBuf(); buf.WriteInt(1001); buf.WriteFloat(75f); // White buf.WriteFloat(20f); // Blue buf.WriteFloat(5f); // Purple buf.WriteFloat(0f); // Red var dropConfig = new LevelDropConfig(buf); int samples = 10000; int highTierCountLuck0 = 0; int highTierCountLuck50 = 0; // 1. 无幸运 (Luck = 0) for (int i = 0; i < samples; i++) { Rarity rarity = RarityUtility.SelectRarity(dropConfig, 0f); if (rarity != Rarity.White) { highTierCountLuck0++; } } // 2. 高幸运 (Luck = 50) for (int i = 0; i < samples; i++) { Rarity rarity = RarityUtility.SelectRarity(dropConfig, 50f); if (rarity != Rarity.White) { highTierCountLuck50++; } } // Luck = 0 时,理论高阶占比 25% (2500 左右) // Luck = 50 时,非白装权重 * 1.75 = 43.75,总权重 118.75,理论高阶占比 ~36.8% (3680 左右) Assert.Greater(highTierCountLuck50, highTierCountLuck0); Assert.Greater(highTierCountLuck50, 3200); Assert.Less(highTierCountLuck0, 2900); } [Test] public void ShopGoodsLockEventArgs_CreateAndClear_MaintainsValues() { var args = ShopGoodsLockEventArgs.Create(2); Assert.AreEqual(2, args.GoodsIndex); Assert.AreEqual(ShopGoodsLockEventArgs.EventId, args.Id); args.Clear(); Assert.AreEqual(-1, args.GoodsIndex); } } }