S4-07 process 2

当前 `Tag.txt -> DRTag -> TagGenerationRuleRegistry` 已形成组件 Tag 生成规则闭环:
- `InventoryTagRuleService` 不再主要依赖内部 `MinRarity` 硬编码,而是统一消费 `DRTag` 提供的 `MinRarity + Weight`
- `ShopFormUseCase`、`EnemyDropResolver`、`InventorySeedUtility` 也已切回这一统一入口。
- 现阶段的职责边界明确为:`Tag.txt` 负责基础字典与生成规则,`TagConfig.txt` 负责触发阶段、描述与效果参数。
This commit is contained in:
SepComet
2026-03-11 11:20:16 +08:00
parent 9de2e50262
commit b1b68ebde5
46 changed files with 615 additions and 452 deletions
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using GeometryTD.CustomUtility;
using GeometryTD.DataTable;
using GeometryTD.Definition;
using NUnit.Framework;
@@ -7,16 +8,16 @@ namespace GeometryTD.Tests.EditMode
{
public sealed class InventoryTagRuleServiceTests
{
private static readonly IReadOnlyDictionary<TagType, RarityType> MinRarityByTag =
new Dictionary<TagType, RarityType>
private static readonly IReadOnlyDictionary<TagType, TagGenerationRuleData> RulesByTag =
new Dictionary<TagType, TagGenerationRuleData>
{
{ TagType.Fire, RarityType.White },
{ TagType.Ice, RarityType.White },
{ TagType.Crit, RarityType.White },
{ TagType.Shatter, RarityType.Green },
{ TagType.Inferno, RarityType.Purple },
{ TagType.AbsoluteZero, RarityType.Purple },
{ TagType.Execution, RarityType.Purple },
{ TagType.Fire, new TagGenerationRuleData { TagType = TagType.Fire, MinRarity = RarityType.White, Weight = 20 } },
{ TagType.Ice, new TagGenerationRuleData { TagType = TagType.Ice, MinRarity = RarityType.White, Weight = 20 } },
{ TagType.Crit, new TagGenerationRuleData { TagType = TagType.Crit, MinRarity = RarityType.White, Weight = 20 } },
{ TagType.Shatter, new TagGenerationRuleData { TagType = TagType.Shatter, MinRarity = RarityType.Green, Weight = 15 } },
{ TagType.Inferno, new TagGenerationRuleData { TagType = TagType.Inferno, MinRarity = RarityType.Purple, Weight = 5 } },
{ TagType.AbsoluteZero, new TagGenerationRuleData { TagType = TagType.AbsoluteZero, MinRarity = RarityType.Purple, Weight = 5 } },
{ TagType.Execution, new TagGenerationRuleData { TagType = TagType.Execution, MinRarity = RarityType.Purple, Weight = 5 } },
};
[Test]
@@ -33,7 +34,7 @@ namespace GeometryTD.Tests.EditMode
(TagType)99
},
RarityType.Green,
MinRarityByTag);
RulesByTag);
Assert.That(result, Is.EqualTo(new[] { TagType.Fire }));
}
@@ -47,7 +48,7 @@ namespace GeometryTD.Tests.EditMode
InventoryTagSourceType.Shop,
12345,
7,
MinRarityByTag);
RulesByTag);
TagType[] second = InventoryTagRuleService.ResolveComponentTags(
new[] { TagType.Fire, TagType.Ice, TagType.Crit, TagType.Shatter },
@@ -55,7 +56,7 @@ namespace GeometryTD.Tests.EditMode
InventoryTagSourceType.Shop,
12345,
7,
MinRarityByTag);
RulesByTag);
Assert.That(second, Is.EqualTo(first));
}
@@ -69,7 +70,7 @@ namespace GeometryTD.Tests.EditMode
InventoryTagSourceType.Drop,
9001,
4,
MinRarityByTag);
RulesByTag);
Assert.That(result.Length, Is.EqualTo(2));
Assert.That(new HashSet<TagType>(result).Count, Is.EqualTo(result.Length));
@@ -84,11 +85,82 @@ namespace GeometryTD.Tests.EditMode
InventoryTagSourceType.Seed,
42,
1,
MinRarityByTag);
RulesByTag);
Assert.That(result, Is.EqualTo(new[] { TagType.Fire }));
}
[Test]
public void ResolveComponentTags_Uses_Weight_Within_EligiblePool()
{
IReadOnlyDictionary<TagType, TagGenerationRuleData> weightedRules =
new Dictionary<TagType, TagGenerationRuleData>
{
{ TagType.Fire, new TagGenerationRuleData { TagType = TagType.Fire, MinRarity = RarityType.White, Weight = 100 } },
{ TagType.Ice, new TagGenerationRuleData { TagType = TagType.Ice, MinRarity = RarityType.White, Weight = 1 } },
{ TagType.Crit, new TagGenerationRuleData { TagType = TagType.Crit, MinRarity = RarityType.White, Weight = 1 } },
};
TagType[] result = InventoryTagRuleService.ResolveComponentTags(
new[] { TagType.Fire, TagType.Ice, TagType.Crit },
RarityType.Green,
InventoryTagSourceType.Shop,
1,
1,
weightedRules);
Assert.That(result, Has.Length.EqualTo(1));
Assert.That(result[0], Is.EqualTo(TagType.Fire));
}
[Test]
public void ResolveComponentTags_Prefers_HighWeight_Tag_In_ExpandedPool()
{
IReadOnlyDictionary<TagType, TagGenerationRuleData> weightedRules =
new Dictionary<TagType, TagGenerationRuleData>
{
{ TagType.Fire, new TagGenerationRuleData { TagType = TagType.Fire, MinRarity = RarityType.White, Weight = 500 } },
{ TagType.Ice, new TagGenerationRuleData { TagType = TagType.Ice, MinRarity = RarityType.White, Weight = 1 } },
{ TagType.Crit, new TagGenerationRuleData { TagType = TagType.Crit, MinRarity = RarityType.White, Weight = 1 } },
{ TagType.Shatter, new TagGenerationRuleData { TagType = TagType.Shatter, MinRarity = RarityType.White, Weight = 1 } },
};
int fireCount = 0;
for (int i = 0; i < 32; i++)
{
TagType[] result = InventoryTagRuleService.ResolveComponentTags(
new[] { TagType.Fire, TagType.Ice, TagType.Crit, TagType.Shatter },
RarityType.Green,
InventoryTagSourceType.Shop,
1000 + i,
1,
weightedRules);
Assert.That(result, Has.Length.EqualTo(1));
if (result[0] == TagType.Fire)
{
fireCount++;
}
}
Assert.That(fireCount, Is.GreaterThanOrEqualTo(28));
}
[Test]
public void TagGenerationRuleRegistry_LoadFromRows_Overrides_MinRarity_And_Weight()
{
DRTag fireRow = new DRTag();
Assert.That(fireRow.ParseDataRow("\t1\t元素\tFire\tGreen\t33", null), Is.True);
TagGenerationRuleRegistry.LoadFromRows(new[] { fireRow });
Assert.That(TagGenerationRuleRegistry.TryGetRule(TagType.Fire, out TagGenerationRuleData rule), Is.True);
Assert.That(rule.MinRarity, Is.EqualTo(RarityType.Green));
Assert.That(rule.Weight, Is.EqualTo(33));
TagGenerationRuleRegistry.ResetToDefaults();
}
[Test]
public void CreateSampleInventory_Generates_SeedTags_Within_Launch_Set_And_Matches_Tower_Stats()
{