33 lines
1.1 KiB
C#
33 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
namespace GeometryTD.Definition
|
|
{
|
|
public static class InventoryRarityRuleService
|
|
{
|
|
public static RarityType NormalizeComponentRarity(RarityType rarity)
|
|
{
|
|
if (rarity < RarityType.White || rarity > RarityType.Red)
|
|
{
|
|
return RarityType.White;
|
|
}
|
|
|
|
return rarity;
|
|
}
|
|
|
|
public static RarityType ResolveTowerRarity(
|
|
RarityType muzzleRarity,
|
|
RarityType bearingRarity,
|
|
RarityType baseRarity)
|
|
{
|
|
int normalizedMuzzle = (int)NormalizeComponentRarity(muzzleRarity);
|
|
int normalizedBearing = (int)NormalizeComponentRarity(bearingRarity);
|
|
int normalizedBase = (int)NormalizeComponentRarity(baseRarity);
|
|
|
|
float average = (normalizedMuzzle + normalizedBearing + normalizedBase) / 3f;
|
|
int floored = Mathf.FloorToInt(average);
|
|
int clamped = Mathf.Clamp(floored, (int)RarityType.White, (int)RarityType.Red);
|
|
return (RarityType)clamped;
|
|
}
|
|
}
|
|
}
|