第一批重构,主要是物理迁移脚本和部分命名空间的调整
- 结构上迁移文件,将脚本分成 Base/Runtime/Presentation/Procedure/Editor 五大文件夹 - 调整 DataTable 和 Definition 下脚本的命名空间 - 依据 UI-5层架构设计规范 拆分原先的 UI 到 Runtime 和 Presentation 下
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
using SepCore.DataTable;
|
||||
using SepCore.Definition;
|
||||
using GameFramework.DataTable;
|
||||
using UnityEngine;
|
||||
|
||||
namespace CustomUtility
|
||||
{
|
||||
public static class RarityUtility
|
||||
{
|
||||
public static ItemRarity SelectRarityForLevel(IDataTable<DRLevelRarity> table, int level)
|
||||
{
|
||||
DRLevelRarity row = GetLevelRarityRow(table, level);
|
||||
if (row == null)
|
||||
{
|
||||
return ItemRarity.White;
|
||||
}
|
||||
|
||||
int white = Mathf.Max(0, row.WhiteWeight);
|
||||
int green = Mathf.Max(0, row.GreenWeight);
|
||||
int blue = Mathf.Max(0, row.BlueWeight);
|
||||
int purple = Mathf.Max(0, row.PurpleWeight);
|
||||
int red = Mathf.Max(0, row.RedWeight);
|
||||
|
||||
int total = white + green + blue + purple + red;
|
||||
if (total <= 0)
|
||||
{
|
||||
return ItemRarity.White;
|
||||
}
|
||||
|
||||
int roll = Random.Range(1, total + 1);
|
||||
if (roll <= white) return ItemRarity.White;
|
||||
roll -= white;
|
||||
if (roll <= green) return ItemRarity.Green;
|
||||
roll -= green;
|
||||
if (roll <= blue) return ItemRarity.Blue;
|
||||
roll -= blue;
|
||||
if (roll <= purple) return ItemRarity.Purple;
|
||||
return ItemRarity.Red;
|
||||
}
|
||||
|
||||
private static DRLevelRarity GetLevelRarityRow(IDataTable<DRLevelRarity> table, int level)
|
||||
{
|
||||
if (table == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
DRLevelRarity[] rows = table.GetAllDataRows();
|
||||
if (rows == null || rows.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int safeLevel = Mathf.Max(1, level);
|
||||
DRLevelRarity below = null;
|
||||
DRLevelRarity above = null;
|
||||
|
||||
foreach (DRLevelRarity row in rows)
|
||||
{
|
||||
if (row == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (safeLevel >= row.LevelMin && safeLevel <= row.LevelMax)
|
||||
{
|
||||
return row;
|
||||
}
|
||||
|
||||
if (safeLevel < row.LevelMin)
|
||||
{
|
||||
if (above == null || row.LevelMin < above.LevelMin)
|
||||
{
|
||||
above = row;
|
||||
}
|
||||
}
|
||||
else if (safeLevel > row.LevelMax)
|
||||
{
|
||||
if (below == null || row.LevelMax > below.LevelMax)
|
||||
{
|
||||
below = row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return above ?? below;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user