增加收获属性逻辑,优化掉落物表现效果
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
using NUnit.Framework;
|
||||
using SepCore.Battle;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Event;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VampireLike.Tests.Gameplay.EditMode
|
||||
{
|
||||
[TestFixture]
|
||||
public class HarvestingEconomyTests
|
||||
{
|
||||
[Test]
|
||||
public void HarvestInterestRate_IsFivePercent()
|
||||
{
|
||||
Assert.AreEqual(0.05f, HarvestSettlementUtility.HarvestCompoundRate, 1e-5f);
|
||||
Assert.AreEqual("HarvestInterest", HarvestSettlementUtility.HarvestModifierSource);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WaveHarvestSettlementEventArgs_CreateAndClear_MaintainsValues()
|
||||
{
|
||||
var args = WaveHarvestSettlementEventArgs.Create(10, 1, 11);
|
||||
Assert.AreEqual(10, args.HarvestIncome);
|
||||
Assert.AreEqual(1, args.HarvestGrowth);
|
||||
Assert.AreEqual(11, args.CurrentHarvest);
|
||||
|
||||
args.Clear();
|
||||
Assert.AreEqual(0, args.HarvestIncome);
|
||||
Assert.AreEqual(0, args.HarvestGrowth);
|
||||
Assert.AreEqual(0, args.CurrentHarvest);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HarvestCompoundGrowth_SmallInitialValue_RoundsUpToOne()
|
||||
{
|
||||
// 当收获为 1 时,1 * 0.05 = 0.05,Mathf.CeilToInt 向上取整应为 1
|
||||
int initialHarvest = 1;
|
||||
int growth = Mathf.CeilToInt(initialHarvest * HarvestCompoundRate);
|
||||
Assert.AreEqual(1, growth);
|
||||
|
||||
// 当收获为 10 时,10 * 0.05 = 0.5,Mathf.CeilToInt 向上取整应为 1
|
||||
int growth10 = Mathf.CeilToInt(10 * HarvestCompoundRate);
|
||||
Assert.AreEqual(1, growth10);
|
||||
|
||||
// 当收获为 21 时,21 * 0.05 = 1.05,Mathf.CeilToInt 向上取整应为 2
|
||||
int growth21 = Mathf.CeilToInt(21 * HarvestCompoundRate);
|
||||
Assert.AreEqual(2, growth21);
|
||||
|
||||
// 当收获为 50 时,50 * 0.05 = 2.5,Mathf.CeilToInt 向上取整应为 3
|
||||
int growth50 = Mathf.CeilToInt(50 * HarvestCompoundRate);
|
||||
Assert.AreEqual(3, growth50);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HarvestCompoundGrowth_SimulateMultiWaveProgression_InAttributePipeline()
|
||||
{
|
||||
var pipeline = new AttributePipeline();
|
||||
pipeline.SetBaseValue(StatType.Harvesting, 10f);
|
||||
|
||||
int totalIncome = 0;
|
||||
// 模拟连续 5 波的收获结算
|
||||
for (int wave = 1; wave <= 5; wave++)
|
||||
{
|
||||
int currentHarvest = Mathf.FloorToInt(pipeline.GetValue(StatType.Harvesting));
|
||||
totalIncome += currentHarvest;
|
||||
|
||||
int growth = Mathf.CeilToInt(currentHarvest * HarvestCompoundRate);
|
||||
pipeline.AddModifier(
|
||||
StatType.Harvesting,
|
||||
new StatModifier(growth, ModifierType.Flat, HarvestSettlementUtility.HarvestModifierSource));
|
||||
}
|
||||
|
||||
// Wave 1: Harvest=10, Income=10, Growth=1 -> Next Harvest=11
|
||||
// Wave 2: Harvest=11, Income=11, Growth=1 -> Next Harvest=12
|
||||
// Wave 3: Harvest=12, Income=12, Growth=1 -> Next Harvest=13
|
||||
// Wave 4: Harvest=13, Income=13, Growth=1 -> Next Harvest=14
|
||||
// Wave 5: Harvest=14, Income=14, Growth=1 -> Next Harvest=15
|
||||
// Total Income = 10 + 11 + 12 + 13 + 14 = 60
|
||||
Assert.AreEqual(60, totalIncome);
|
||||
Assert.AreEqual(15f, pipeline.GetValue(StatType.Harvesting), 1e-4f);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HarvestCompoundGrowth_HighInitial_AcceleratesExponentially()
|
||||
{
|
||||
var pipeline = new AttributePipeline();
|
||||
pipeline.SetBaseValue(StatType.Harvesting, 40f);
|
||||
|
||||
// Wave 1: 40 -> growth = ceil(40 * 0.05 = 2.0) = 2 -> 42
|
||||
int harvestW1 = Mathf.FloorToInt(pipeline.GetValue(StatType.Harvesting));
|
||||
int g1 = Mathf.CeilToInt(harvestW1 * HarvestCompoundRate);
|
||||
Assert.AreEqual(2, g1);
|
||||
pipeline.AddModifier(StatType.Harvesting, new StatModifier(g1, ModifierType.Flat));
|
||||
Assert.AreEqual(42f, pipeline.GetValue(StatType.Harvesting), 1e-4f);
|
||||
|
||||
// Wave 2: 42 -> growth = ceil(42 * 0.05 = 2.1) = 3 -> 45
|
||||
int harvestW2 = Mathf.FloorToInt(pipeline.GetValue(StatType.Harvesting));
|
||||
int g2 = Mathf.CeilToInt(harvestW2 * HarvestCompoundRate);
|
||||
Assert.AreEqual(3, g2);
|
||||
pipeline.AddModifier(StatType.Harvesting, new StatModifier(g2, ModifierType.Flat));
|
||||
Assert.AreEqual(45f, pipeline.GetValue(StatType.Harvesting), 1e-4f);
|
||||
}
|
||||
|
||||
private const float HarvestCompoundRate = HarvestSettlementUtility.HarvestCompoundRate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6a278e1490834900afaef82f39139288
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,147 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3294c9f757948d8b1a930824cc98a35
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user