155 lines
4.7 KiB
C#
155 lines
4.7 KiB
C#
using System;
|
|
using GeometryTD.CustomUtility;
|
|
using GeometryTD.Definition;
|
|
using UnityEngine;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace GeometryTD.DataTable
|
|
{
|
|
/// <summary>
|
|
/// 局外道具掉落池配置表。
|
|
/// </summary>
|
|
public class DROutGameDropPool : DataRowBase
|
|
{
|
|
private int m_Id = 0;
|
|
|
|
public override int Id => m_Id;
|
|
|
|
public LevelThemeType LevelThemeType { get; private set; }
|
|
public string ItemType { get; private set; }
|
|
public int ItemId { 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)
|
|
{
|
|
string[] columnStrings = dataRowString.Split(DataTableExtension.DataSplitSeparators);
|
|
for (int i = 0; i < columnStrings.Length; i++)
|
|
{
|
|
columnStrings[i] = columnStrings[i].Trim(DataTableExtension.DataTrimSeparators);
|
|
}
|
|
|
|
int index = 0;
|
|
index++;
|
|
m_Id = int.Parse(columnStrings[index++]);
|
|
index++;
|
|
LevelThemeType = EnumUtility<LevelThemeType>.Get(columnStrings[index++]);
|
|
ItemType = columnStrings[index++];
|
|
ItemId = ParseIntOrDefault(columnStrings[index++], 0);
|
|
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))
|
|
{
|
|
return parsed;
|
|
}
|
|
|
|
return fallbackValue;
|
|
}
|
|
|
|
private const int RarityCount = (int)RarityType.Red;
|
|
}
|
|
}
|