S7-01 + S7-02

This commit is contained in:
2026-03-12 10:46:11 +08:00
parent d34af661b9
commit 185ea43323
20 changed files with 468 additions and 112 deletions
@@ -10,9 +10,7 @@ namespace GeometryTD.Definition
public static TagType[] ResolveComponentTags(
IReadOnlyList<TagType> possibleTags,
RarityType rarity,
InventoryTagSourceType sourceType,
long itemInstanceId,
int configId,
InventoryTagRandomContext randomContext,
IReadOnlyDictionary<TagType, TagGenerationRule> rulesByTag = null,
IReadOnlyDictionary<RarityType, RarityTagBudgetRule> rarityTagBudgetRulesByRarity = null)
{
@@ -23,7 +21,7 @@ namespace GeometryTD.Definition
return Array.Empty<TagType>();
}
Random random = new Random(BuildStableSeed(rarity, sourceType, itemInstanceId, configId));
Random random = new Random(BuildStableSeed(rarity, randomContext));
int tagBudget = ResolveRarityTagBudget(rarity, random, rarityTagBudgetRulesByRarity);
if (tagBudget <= 0)
{
@@ -43,6 +41,23 @@ namespace GeometryTD.Definition
return result;
}
public static TagType[] ResolveComponentTags(
IReadOnlyList<TagType> possibleTags,
RarityType rarity,
InventoryTagSourceType sourceType,
long itemInstanceId,
int configId,
IReadOnlyDictionary<TagType, TagGenerationRule> rulesByTag = null,
IReadOnlyDictionary<RarityType, RarityTagBudgetRule> rarityTagBudgetRulesByRarity = null)
{
return ResolveComponentTags(
possibleTags,
rarity,
new InventoryTagRandomContext(0, sourceType, itemInstanceId, configId),
rulesByTag,
rarityTagBudgetRulesByRarity);
}
public static TagType[] GetEligibleTags(
IReadOnlyList<TagType> possibleTags,
RarityType rarity,
@@ -170,20 +185,17 @@ namespace GeometryTD.Definition
return pool.Count - 1;
}
private static int BuildStableSeed(
RarityType rarity,
InventoryTagSourceType sourceType,
long itemInstanceId,
int configId)
private static int BuildStableSeed(RarityType rarity, InventoryTagRandomContext randomContext)
{
unchecked
{
int seed = 17;
seed = seed * 31 + randomContext.RunSeed;
seed = seed * 31 + (int)InventoryRarityRuleService.NormalizeComponentRarity(rarity);
seed = seed * 31 + (int)sourceType;
seed = seed * 31 + configId;
seed = seed * 31 + (int)itemInstanceId;
seed = seed * 31 + (int)(itemInstanceId >> 32);
seed = seed * 31 + (int)randomContext.SourceType;
seed = seed * 31 + randomContext.ConfigId;
seed = seed * 31 + (int)randomContext.ItemInstanceId;
seed = seed * 31 + (int)(randomContext.ItemInstanceId >> 32);
return seed;
}
}
@@ -0,0 +1,63 @@
using System;
namespace GeometryTD.Definition
{
[Serializable]
public readonly struct InventoryTagRandomContext
{
public InventoryTagRandomContext(int runSeed, InventoryTagSourceType sourceType, long itemInstanceId, int configId)
{
RunSeed = runSeed;
SourceType = sourceType;
ItemInstanceId = itemInstanceId;
ConfigId = configId;
}
public int RunSeed { get; }
public InventoryTagSourceType SourceType { get; }
public long ItemInstanceId { get; }
public int ConfigId { get; }
public static InventoryTagRandomContext CreateSeed(int runSeed, long itemInstanceId, int configId)
{
return new InventoryTagRandomContext(runSeed, InventoryTagSourceType.Seed, itemInstanceId, configId);
}
public static InventoryTagRandomContext CreateShop(int runSeed, int nodeSequenceIndex, int goodsIndex, int configId)
{
return new InventoryTagRandomContext(
runSeed,
InventoryTagSourceType.Shop,
ComposeLocalItemInstanceId(nodeSequenceIndex, goodsIndex),
configId);
}
public static InventoryTagRandomContext CreateDrop(int runSeed, int nodeSequenceIndex, int dropOrdinal, int configId)
{
return new InventoryTagRandomContext(
runSeed,
InventoryTagSourceType.Drop,
ComposeLocalItemInstanceId(nodeSequenceIndex, dropOrdinal),
configId);
}
public static InventoryTagRandomContext CreateReward(int runSeed, int nodeSequenceIndex, int rewardOrdinal, int configId)
{
return new InventoryTagRandomContext(
runSeed,
InventoryTagSourceType.Reward,
ComposeLocalItemInstanceId(nodeSequenceIndex, rewardOrdinal),
configId);
}
public static long ComposeLocalItemInstanceId(int nodeSequenceIndex, int localOrdinal)
{
long normalizedSequence = Math.Max(0, nodeSequenceIndex) + 1L;
long normalizedOrdinal = Math.Max(0, localOrdinal) + 1L;
return (normalizedSequence << 32) | (uint)normalizedOrdinal;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8d4f8e95f2f94e4ca876ff4c871f5b41
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -22,11 +22,7 @@ namespace GeometryTD.Definition
public static void LoadFromRows(IEnumerable<DRTagConfig> rows)
{
ResetToDefaults();
foreach (DRTagConfig row in rows)
{
ApplyRow(row);
}
ReloadFromRows(rows, null);
}
public static bool TryGetDefinition(TagType tagType, out TagDefinition definition)
@@ -47,6 +43,27 @@ namespace GeometryTD.Definition
}
}
public static void ReloadFromRows(IEnumerable<DRTagConfig> tagConfigRows, IEnumerable<DRTag> tagRows)
{
ResetToDefaults();
if (tagConfigRows != null)
{
foreach (DRTagConfig row in tagConfigRows)
{
ApplyRow(row);
}
}
if (tagRows != null)
{
foreach (DRTag row in tagRows)
{
ApplyTagRow(row);
}
}
}
private static Dictionary<TagType, TagDefinition> CreateDefaultDefinitions()
{
return new Dictionary<TagType, TagDefinition>