迁移数据表到 Luban,移除 JsonNet、EnumUtility
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using SepCore.Definition;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.CustomUtility
|
||||
{
|
||||
public static class RarityUtility
|
||||
{
|
||||
public static Rarity SelectRarityForLevel(int level)
|
||||
{
|
||||
int configId = level >= 1000 ? level : 1000 + level;
|
||||
LevelDropConfig dropConfig = GameEntry.Luban.Get<LevelDropConfig>(configId);
|
||||
return SelectRarity(dropConfig);
|
||||
}
|
||||
|
||||
public static Rarity SelectRarity(LevelDropConfig dropConfig)
|
||||
{
|
||||
float total = dropConfig.WhiteWeight + dropConfig.GreenWeight + dropConfig.BlueWeight + dropConfig.PurpleWeight + dropConfig.RedWeight;
|
||||
if (total <= 0f)
|
||||
{
|
||||
Log.Error("LevelDropConfig '{0}' has invalid total weight '{1}'.", dropConfig.Id, total);
|
||||
return Rarity.White;
|
||||
}
|
||||
|
||||
float roll = Random.Range(0f, total);
|
||||
if (roll < dropConfig.WhiteWeight) return Rarity.White;
|
||||
roll -= dropConfig.WhiteWeight;
|
||||
if (roll < dropConfig.GreenWeight) return Rarity.Green;
|
||||
roll -= dropConfig.GreenWeight;
|
||||
if (roll < dropConfig.BlueWeight) return Rarity.Blue;
|
||||
roll -= dropConfig.BlueWeight;
|
||||
if (roll < dropConfig.PurpleWeight) return Rarity.Purple;
|
||||
return Rarity.Red;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user