Loot/LootRarityTable.cs

Static data class for loot rarity. It defines a monetary multiplier per LootRarity and per-level weighted rarity chance maps, and exposes RandomRarityFromLevel which picks a rarity by weight for a given LevelType.

NetworkingFile Access
using System.Collections.Generic;
using Sandbox;

namespace BrickJam;

/// <summary>
/// Static loot rarity data. Ported verbatim from the legacy <c>Loot</c> entity's static maps.
/// </summary>
public static class LootRarityTable
{
	/// <summary>Monetary value multiplier per rarity.</summary>
	public static readonly Dictionary<LootRarity, float> RarityMap = new()
	{
		{ LootRarity.Broken, 0.2f },
		{ LootRarity.Decrepit, 0.4f },
		{ LootRarity.Worn, 0.6f },
		{ LootRarity.Dusty, 0.8f },
		{ LootRarity.Common, 1f },
		{ LootRarity.Nice, 1.3f },
		{ LootRarity.Great, 1.8f },
		{ LootRarity.Excellent, 2.5f },
		{ LootRarity.Flawless, 4f }
	};

	/// <summary>Per-level weighted chances of each rarity rolling.</summary>
	public static readonly Dictionary<LevelType, Dictionary<LootRarity, float>> RarityChances = new()
	{
		{
			LevelType.Mansion, new()
			{
				{ LootRarity.Broken, 1f }, { LootRarity.Decrepit, 1.2f }, { LootRarity.Worn, 1.4f },
				{ LootRarity.Dusty, 1.2f }, { LootRarity.Common, 1f }, { LootRarity.Nice, 0.6f },
				{ LootRarity.Great, 0.3f }, { LootRarity.Excellent, 0.1f }, { LootRarity.Flawless, 0.03f }
			}
		},
		{
			LevelType.Dungeon, new()
			{
				{ LootRarity.Broken, 0.5f }, { LootRarity.Decrepit, 0.7f }, { LootRarity.Worn, 0.9f },
				{ LootRarity.Dusty, 1f }, { LootRarity.Common, 1.2f }, { LootRarity.Nice, 1f },
				{ LootRarity.Great, 0.7f }, { LootRarity.Excellent, 0.3f }, { LootRarity.Flawless, 0.1f }
			}
		},
		{
			LevelType.Bathrooms, new()
			{
				{ LootRarity.Broken, 0.2f }, { LootRarity.Decrepit, 0.3f }, { LootRarity.Worn, 0.4f },
				{ LootRarity.Dusty, 0.6f }, { LootRarity.Common, 0.9f }, { LootRarity.Nice, 1.2f },
				{ LootRarity.Great, 1.6f }, { LootRarity.Excellent, 1.2f }, { LootRarity.Flawless, 0.9f }
			}
		},
	};

	public static LootRarity RandomRarityFromLevel( LevelType level )
	{
		if ( !RarityChances.TryGetValue( level, out var chances ) )
			return LootRarity.Common;

		return WeightedList.RandomKey( chances );
	}
}