调整 OutGameDropPool 表定义 + 添加部分组件定义
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using GeometryTD.CustomUtility;
|
||||
using GeometryTD.Definition;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace GeometryTD.DataTable
|
||||
@@ -14,12 +16,11 @@ namespace GeometryTD.DataTable
|
||||
public override int Id => m_Id;
|
||||
|
||||
public LevelThemeType LevelThemeType { get; private set; }
|
||||
public RarityType Rarity { get; private set; }
|
||||
public string ItemType { get; private set; }
|
||||
public int ItemId { get; private set; }
|
||||
public int Weight { get; private set; }
|
||||
public int MinPhase { get; private set; }
|
||||
public int MaxPhase { get; private set; }
|
||||
public int[] Weights { get; private set; }
|
||||
public int[] MinPhase { get; private set; }
|
||||
public int[] MaxPhase { get; private set; }
|
||||
|
||||
public override bool ParseDataRow(string dataRowString, object userData)
|
||||
{
|
||||
@@ -34,31 +35,110 @@ namespace GeometryTD.DataTable
|
||||
m_Id = int.Parse(columnStrings[index++]);
|
||||
index++;
|
||||
LevelThemeType = EnumUtility<LevelThemeType>.Get(columnStrings[index++]);
|
||||
Rarity = EnumUtility<RarityType>.Get(columnStrings[index++]);
|
||||
ItemType = columnStrings[index++];
|
||||
ItemId = ParseIntOrDefault(columnStrings[index++], 0);
|
||||
Weight = ParseIntOrDefault(columnStrings[index++], 1);
|
||||
MinPhase = ParseIntOrDefault(columnStrings[index++], 1);
|
||||
MaxPhase = ParseIntOrDefault(columnStrings[index++], int.MaxValue);
|
||||
|
||||
if (Weight <= 0)
|
||||
{
|
||||
Weight = 1;
|
||||
}
|
||||
|
||||
if (MinPhase <= 0)
|
||||
{
|
||||
MinPhase = 1;
|
||||
}
|
||||
|
||||
if (MaxPhase < MinPhase)
|
||||
{
|
||||
MaxPhase = MinPhase;
|
||||
}
|
||||
Weights = ParseWeights(columnStrings[index++]);
|
||||
MinPhase = ParsePhases(columnStrings[index++], 1);
|
||||
MaxPhase = ParsePhases(columnStrings[index++], int.MaxValue);
|
||||
NormalizePhaseRanges();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int GetWeight(RarityType rarity)
|
||||
{
|
||||
int index = Mathf.Clamp((int)rarity - 1, 0, RarityCount - 1);
|
||||
return Weights[index];
|
||||
}
|
||||
|
||||
public int GetMinPhase(RarityType rarity)
|
||||
{
|
||||
int index = Mathf.Clamp((int)rarity - 1, 0, RarityCount - 1);
|
||||
return MinPhase[index];
|
||||
}
|
||||
|
||||
public int GetMaxPhase(RarityType rarity)
|
||||
{
|
||||
int index = Mathf.Clamp((int)rarity - 1, 0, RarityCount - 1);
|
||||
return MaxPhase[index];
|
||||
}
|
||||
|
||||
private static int[] ParseWeights(string raw)
|
||||
{
|
||||
if (!raw.StartsWith('[') || !raw.EndsWith(']'))
|
||||
{
|
||||
throw new ArgumentException("Weights must be enclosed in square brackets.");
|
||||
}
|
||||
|
||||
if (raw.Length == 2)
|
||||
{
|
||||
return new int[RarityCount];
|
||||
}
|
||||
|
||||
string[] raws = raw.Substring(1, raw.Length - 2).Split(",");
|
||||
if (raws.Length != RarityCount)
|
||||
{
|
||||
throw new ArgumentException($"Weights must contain exactly {RarityCount} values.");
|
||||
}
|
||||
|
||||
int[] weights = new int[RarityCount];
|
||||
for (int i = 0; i < raws.Length; i++)
|
||||
{
|
||||
weights[i] = Mathf.Max(0, int.Parse(raws[i]));
|
||||
}
|
||||
|
||||
return weights;
|
||||
}
|
||||
|
||||
private static int[] ParsePhases(string raw, int fallbackValue)
|
||||
{
|
||||
if (!raw.StartsWith('[') || !raw.EndsWith(']'))
|
||||
{
|
||||
throw new ArgumentException("Phase ranges must be enclosed in square brackets.");
|
||||
}
|
||||
|
||||
if (raw.Length == 2)
|
||||
{
|
||||
int[] fallbackValues = new int[RarityCount];
|
||||
for (int i = 0; i < fallbackValues.Length; i++)
|
||||
{
|
||||
fallbackValues[i] = fallbackValue;
|
||||
}
|
||||
|
||||
return fallbackValues;
|
||||
}
|
||||
|
||||
string[] raws = raw.Substring(1, raw.Length - 2).Split(",");
|
||||
if (raws.Length != RarityCount)
|
||||
{
|
||||
throw new ArgumentException($"Phase ranges must contain exactly {RarityCount} values.");
|
||||
}
|
||||
|
||||
int[] phases = new int[RarityCount];
|
||||
for (int i = 0; i < raws.Length; i++)
|
||||
{
|
||||
phases[i] = int.Parse(raws[i]);
|
||||
}
|
||||
|
||||
return phases;
|
||||
}
|
||||
|
||||
private void NormalizePhaseRanges()
|
||||
{
|
||||
for (int i = 0; i < RarityCount; i++)
|
||||
{
|
||||
if (MinPhase[i] <= 0)
|
||||
{
|
||||
MinPhase[i] = 1;
|
||||
}
|
||||
|
||||
if (MaxPhase[i] < MinPhase[i])
|
||||
{
|
||||
MaxPhase[i] = MinPhase[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int ParseIntOrDefault(string raw, int fallbackValue)
|
||||
{
|
||||
if (int.TryParse(raw, out int parsed))
|
||||
@@ -68,5 +148,7 @@ namespace GeometryTD.DataTable
|
||||
|
||||
return fallbackValue;
|
||||
}
|
||||
|
||||
private const int RarityCount = (int)RarityType.Red;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user