G1-01 + G1-02

This commit is contained in:
SepComet
2026-03-12 13:20:02 +08:00
parent 1c45205e92
commit 99ed963faa
24 changed files with 424 additions and 32 deletions
@@ -24,6 +24,8 @@ public partial class GameEntry
public static SpriteCacheComponent SpriteCache { get; private set; }
public static InventoryGenerationComponent InventoryGeneration { get; private set; }
private static void InitCustomComponents()
{
BuiltinData = UnityGameFramework.Runtime.GameEntry.GetComponent<BuiltinDataComponent>();
@@ -35,5 +37,6 @@ public partial class GameEntry
ShopNode = UnityGameFramework.Runtime.GameEntry.GetComponent<ShopNodeComponent>();
ResolutionAdapter = UnityGameFramework.Runtime.GameEntry.GetComponent<ResolutionAdapterComponent>();
SpriteCache = UnityGameFramework.Runtime.GameEntry.GetComponent<SpriteCacheComponent>();
InventoryGeneration = UnityGameFramework.Runtime.GameEntry.GetComponent<InventoryGenerationComponent>();
}
}
}
@@ -1,4 +1,5 @@
using GeometryTD.DataTable;
using GeometryTD.Factory;
namespace GeometryTD.CustomComponent
{
@@ -3,6 +3,7 @@ using GameFramework.DataTable;
using GeometryTD.CustomEvent;
using GeometryTD.DataTable;
using GeometryTD.Definition;
using GeometryTD.Factory;
using GeometryTD.Procedure;
using Newtonsoft.Json.Linq;
using GeometryTD.UI;
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3d606503b1c28cf4983b8b44abbf14f7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,218 @@
using System;
using System.Collections.Generic;
using GameFramework.DataTable;
using GeometryTD.CustomUtility;
using GeometryTD.DataTable;
using GeometryTD.Definition;
using GeometryTD.Factory;
using GeometryTD.UI;
using UnityEngine;
using UnityGameFramework.Runtime;
namespace GeometryTD.CustomComponent
{
public sealed class InventoryGenerationComponent : GameFrameworkComponent
{
private long _nextTempInstanceId = 1000000;
private readonly List<DRShopPrice> _shopPriceRows = new();
private IDataTable<DRShopPrice> _shopPriceTable;
private IDataTable<DRMuzzleComp> _muzzleCompTable;
private IDataTable<DRBearingComp> _bearingCompTable;
private IDataTable<DRBaseComp> _baseCompTable;
public List<GoodsItemRawData> BuildShopGoods(int goodsCount, int runSeed = 0, int sequenceIndex = -1)
{
if (goodsCount <= 0)
{
return new List<GoodsItemRawData>();
}
EnsureShopTables();
List<GoodsItemRawData> goodsItems = new(goodsCount);
for (int i = 0; i < goodsCount; i++)
{
goodsItems.Add(BuildShopGoodsItem(i, runSeed, sequenceIndex));
}
return goodsItems;
}
public EnemyDropResult ResolveEnemyDrop(in EnemyDropContext context)
{
throw new NotImplementedException(
"InventoryGenerationComponent.ResolveEnemyDrop() will be implemented in G2.");
}
public IReadOnlyList<TowerCompItemData> BuildRewardCandidates(
int displayPhaseIndex,
LevelThemeType themeType,
int candidateCount)
{
throw new NotImplementedException(
"InventoryGenerationComponent.BuildRewardCandidates() will be implemented in G2.");
}
private void EnsureShopTables()
{
_shopPriceTable ??= GameEntry.DataTable.GetDataTable<DRShopPrice>();
_muzzleCompTable ??= GameEntry.DataTable.GetDataTable<DRMuzzleComp>();
_bearingCompTable ??= GameEntry.DataTable.GetDataTable<DRBearingComp>();
_baseCompTable ??= GameEntry.DataTable.GetDataTable<DRBaseComp>();
if (_shopPriceTable == null || _muzzleCompTable == null || _bearingCompTable == null ||
_baseCompTable == null)
{
throw new InvalidOperationException(
"InventoryGenerationComponent requires ShopPrice, MuzzleComp, BearingComp, and BaseComp data tables.");
}
if (_shopPriceRows.Count > 0)
{
return;
}
DRShopPrice[] rows = _shopPriceTable.GetAllDataRows();
if (rows == null || rows.Length <= 0)
{
throw new InvalidOperationException(
"InventoryGenerationComponent requires at least one shop price row.");
}
foreach (var row in rows)
{
if (row != null)
{
_shopPriceRows.Add(row);
}
}
if (_shopPriceRows.Count <= 0)
{
throw new InvalidOperationException("InventoryGenerationComponent requires non-null shop price rows.");
}
}
private GoodsItemRawData BuildShopGoodsItem(int goodsIndex, int runSeed, int sequenceIndex)
{
TowerCompItemData sourceItem = BuildRandomComponentItem(goodsIndex, runSeed, sequenceIndex);
return new GoodsItemRawData
{
GoodsIndex = goodsIndex,
Title = sourceItem.Name,
TypeText = BuildTypeText(sourceItem.SlotType),
Description = BuildDescription(sourceItem),
Price = ResolveRandomPrice(sourceItem.Rarity),
Tags = sourceItem.Tags != null ? (TagType[])sourceItem.Tags.Clone() : Array.Empty<TagType>(),
IconAreaContext = BuildIconAreaContext(sourceItem),
SourceItem = sourceItem,
IsPurchased = false
};
}
private TowerCompItemData BuildRandomComponentItem(int goodsIndex, int runSeed, int sequenceIndex)
{
int slotRoll = UnityEngine.Random.Range(0, 3);
DRShopPrice priceRow = _shopPriceRows[UnityEngine.Random.Range(0, _shopPriceRows.Count)];
RarityType rarity = InventoryRarityRuleService.NormalizeComponentRarity(
priceRow != null ? priceRow.Rarity : RarityType.White);
return slotRoll switch
{
0 => BuildRandomMuzzleItem(rarity, goodsIndex, runSeed, sequenceIndex),
1 => BuildRandomBearingItem(rarity, goodsIndex, runSeed, sequenceIndex),
_ => BuildRandomBaseItem(rarity, goodsIndex, runSeed, sequenceIndex)
};
}
private MuzzleCompItemData BuildRandomMuzzleItem(RarityType rarity, int goodsIndex, int runSeed,
int sequenceIndex)
{
DRMuzzleComp[] rows = _muzzleCompTable.GetAllDataRows();
DRMuzzleComp config = rows[UnityEngine.Random.Range(0, rows.Length)];
long instanceId = _nextTempInstanceId++;
InventoryTagRandomContext randomContext =
InventoryTagRandomContext.CreateShop(runSeed, sequenceIndex, goodsIndex, config.Id);
return ComponentItemFactory.CreateMuzzle(config, instanceId, rarity, randomContext);
}
private BearingCompItemData BuildRandomBearingItem(RarityType rarity, int goodsIndex, int runSeed,
int sequenceIndex)
{
DRBearingComp[] rows = _bearingCompTable.GetAllDataRows();
DRBearingComp config = rows[UnityEngine.Random.Range(0, rows.Length)];
long instanceId = _nextTempInstanceId++;
InventoryTagRandomContext randomContext =
InventoryTagRandomContext.CreateShop(runSeed, sequenceIndex, goodsIndex, config.Id);
return ComponentItemFactory.CreateBearing(config, instanceId, rarity, randomContext);
}
private BaseCompItemData BuildRandomBaseItem(RarityType rarity, int goodsIndex, int runSeed, int sequenceIndex)
{
DRBaseComp[] rows = _baseCompTable.GetAllDataRows();
DRBaseComp config = rows[UnityEngine.Random.Range(0, rows.Length)];
long instanceId = _nextTempInstanceId++;
InventoryTagRandomContext randomContext =
InventoryTagRandomContext.CreateShop(runSeed, sequenceIndex, goodsIndex, config.Id);
return ComponentItemFactory.CreateBase(config, instanceId, rarity, randomContext);
}
private int ResolveRandomPrice(RarityType rarity)
{
for (int i = 0; i < _shopPriceRows.Count; i++)
{
DRShopPrice row = _shopPriceRows[i];
if (row != null && row.Rarity == rarity)
{
int min = Mathf.Max(0, row.MinPrice);
int max = Mathf.Max(min, row.MaxPrice);
return UnityEngine.Random.Range(min, max + 1);
}
}
return 0;
}
private static IconAreaContext BuildIconAreaContext(TowerCompItemData item)
{
return new IconAreaContext
{
Rarity = item.Rarity,
ComponentSlotType = item.SlotType,
Color = IconColorGenerator.GenerateForComponent(item)
};
}
private static string BuildTypeText(TowerCompSlotType slotType)
{
return slotType switch
{
TowerCompSlotType.Muzzle => "枪口组件",
TowerCompSlotType.Bearing => "轴承组件",
TowerCompSlotType.Base => "底座组件",
_ => "组件"
};
}
private static string BuildDescription(TowerCompItemData item)
{
if (item is MuzzleCompItemData muzzleComp)
{
return ItemDescUtility.BuildMuzzleDesc(muzzleComp);
}
if (item is BearingCompItemData bearingComp)
{
return ItemDescUtility.BuildBearingDesc(bearingComp);
}
if (item is BaseCompItemData baseComp)
{
return ItemDescUtility.BuildBaseDesc(baseComp);
}
return string.Empty;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5a41477f01c335444a26223742e2a9b3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bcacad8280fb40ff88961b131604e5e4
timeCreated: 1773292400
@@ -0,0 +1,82 @@
using System;
using GeometryTD.DataTable;
using GeometryTD.Definition;
namespace GeometryTD.Factory
{
public static class ComponentItemFactory
{
public static MuzzleCompItemData CreateMuzzle(
DRMuzzleComp config,
long instanceId,
RarityType rarity,
InventoryTagRandomContext randomContext)
{
RarityType normalizedRarity = InventoryRarityRuleService.NormalizeComponentRarity(rarity);
return new MuzzleCompItemData
{
InstanceId = instanceId,
ConfigId = config.Id,
Name = config.Name,
Rarity = normalizedRarity,
Endurance = 100f,
Constraint = config.Constraint,
Tags = ComponentTagGenerationService.ResolveComponentTags(
config.PossibleTag,
normalizedRarity,
randomContext),
AttackDamage = config.AttackDamage != null ? (int[])config.AttackDamage.Clone() : Array.Empty<int>(),
DamageRandomRate = config.DamageRandomRate,
AttackMethodType = config.AttackMethodType
};
}
public static BearingCompItemData CreateBearing(
DRBearingComp config,
long instanceId,
RarityType rarity,
InventoryTagRandomContext randomContext)
{
RarityType normalizedRarity = InventoryRarityRuleService.NormalizeComponentRarity(rarity);
return new BearingCompItemData
{
InstanceId = instanceId,
ConfigId = config.Id,
Name = config.Name,
Rarity = normalizedRarity,
Endurance = 100f,
Constraint = config.Constraint,
Tags = ComponentTagGenerationService.ResolveComponentTags(
config.PossibleTag,
normalizedRarity,
randomContext),
RotateSpeed = config.RotateSpeed != null ? (float[])config.RotateSpeed.Clone() : Array.Empty<float>(),
AttackRange = config.AttackRange != null ? (float[])config.AttackRange.Clone() : Array.Empty<float>()
};
}
public static BaseCompItemData CreateBase(
DRBaseComp config,
long instanceId,
RarityType rarity,
InventoryTagRandomContext randomContext)
{
RarityType normalizedRarity = InventoryRarityRuleService.NormalizeComponentRarity(rarity);
return new BaseCompItemData
{
InstanceId = instanceId,
ConfigId = config.Id,
Name = config.Name,
Rarity = normalizedRarity,
Endurance = 100f,
Constraint = config.Constraint,
Tags = ComponentTagGenerationService.ResolveComponentTags(
config.PossibleTag,
normalizedRarity,
randomContext),
AttackSpeed = config.AttackSpeed != null ? (float[])config.AttackSpeed.Clone() : Array.Empty<float>(),
AttackPropertyType = config.AttackPropertyType
};
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bf4dd23294965e945bdda9496e0278e9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,8 +1,9 @@
using GeometryTD.CustomUtility;
using GeometryTD.Definition;
using Newtonsoft.Json.Linq;
using UnityGameFramework.Runtime;
namespace GeometryTD.Definition
namespace GeometryTD.Factory
{
public static class EventEffectFactory
{
@@ -1,8 +1,9 @@
using GeometryTD.CustomUtility;
using GeometryTD.Definition;
using Newtonsoft.Json.Linq;
using UnityGameFramework.Runtime;
namespace GeometryTD.Definition
namespace GeometryTD.Factory
{
public static class EventRequirementFactory
{
@@ -1,6 +1,7 @@
using GeometryTD.CustomComponent;
using GeometryTD.Definition;
namespace GeometryTD.CustomComponent
namespace GeometryTD.Factory
{
internal static class PhaseEndConditionFactory
{
@@ -1,7 +1,8 @@
using System.Collections.Generic;
using GeometryTD.Definition;
using GeometryTD.Procedure;
namespace GeometryTD.Procedure
namespace GeometryTD.Factory
{
public static class RunStateFactory
{
@@ -55,4 +56,4 @@ namespace GeometryTD.Procedure
return seed == 0 ? 1 : seed;
}
}
}
}
@@ -5,6 +5,7 @@ using System;
using GeometryTD.CustomEvent;
using GeometryTD.CustomUtility;
using GeometryTD.Definition;
using GeometryTD.Factory;
using GeometryTD.UI;
using UnityGameFramework.Runtime;
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using GeometryTD.CustomUtility;
using GeometryTD.Definition;
using GeometryTD.Factory;
namespace GeometryTD.Procedure
{