This commit is contained in:
2026-04-25 23:37:10 +02:00
commit 19d6bd934a
476 changed files with 9198 additions and 0 deletions
@@ -0,0 +1,9 @@
namespace RPGCoreCommon.DropTable
{
public enum ChanceTypeEnum
{
All,
ByWeight,
ByPercent
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7c0aa7d4711440a697970eb700168030
timeCreated: 1760523882
@@ -0,0 +1,9 @@
using UnityEngine;
namespace RPGCoreCommon.DropTable
{
public class DropTableComponent : MonoBehaviour
{
[SerializeReference] private DropTableSO dropTableGroup;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dc0580faa40e4f62bc65a675c74c4c96
timeCreated: 1760523736
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using RPGCoreCommon.Helpers;
using UnityEngine;
using Object = UnityEngine.Object;
namespace RPGCoreCommon.DropTable
{
[Serializable]
internal class DropTableGroup
{
// Rules for randomizing
[SerializeField] internal ChanceTypeEnum chanceType = ChanceTypeEnum.ByPercent;
// SubGroups and/or items of this group
[SerializeField] internal List<DropTableGroupRow> rows = new();
internal void Get(ref Dictionary<Object, int> result)
{
if (!rows.Any())
{
Debug.LogWarning($"Empty <b>{nameof(DropTableGroup)}</b>!");
return;
}
foreach (var row in GetRows())
{
if (row.item)
{
result.TryAdd(row.item, 0);
result[row.item] += row.count;
}
else if (row.subGroupRef)
{
for (var i = 0; i < row.count; i++)
row.subGroupRef.group.Get(ref result);
}
else if (row.subGroupInline != null)
{
for (var i = 0; i < row.count; i++)
row.subGroupInline.Get(ref result);
}
}
}
internal List<DropTableGroupRow> GetRows()
{
return chanceType switch
{
ChanceTypeEnum.All => rows,
ChanceTypeEnum.ByWeight => RandomHelper.RandomElementsByWeight(rows, row => row.chance, 1),
ChanceTypeEnum.ByPercent => rows.Where(row => RandomHelper.Chance(row.chance/100)).ToList(),
_ => throw new ArgumentOutOfRangeException()
};
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e24e6877320d4170b09ca966a136951a
timeCreated: 1760709210
@@ -0,0 +1,14 @@
using UnityEngine;
namespace RPGCoreCommon.DropTable
{
[System.Serializable]
public class DropTableGroupRow
{
[SerializeField] internal float chance;
[SerializeField] internal int count = 1;
[SerializeReference] internal DropTableGroup subGroupInline;
[SerializeReference] internal DropTableSO subGroupRef;
[SerializeReference] internal Object item;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3597a5bce3db4068885d19da0a9e4a2a
timeCreated: 1760694296
@@ -0,0 +1,19 @@
using System.Collections.Generic;
using UnityEngine;
namespace RPGCoreCommon.DropTable
{
[System.Serializable]
[CreateAssetMenu(menuName = "RPG Core/Drop Table")]
public class DropTableSO : ScriptableObject
{
[SerializeField] internal DropTableGroup group;
public Dictionary<Object, int> Get()
{
var result = new Dictionary<Object, int>();
group.Get(ref result);
return result;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c1984d6153504b90a4dd21a18d5f034a
timeCreated: 1760522473
@@ -0,0 +1,8 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("RPGCoreCommon.DropTable.Editor")]
namespace RPGCoreCommon.DropTable
{
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2efd7efdd7b349f1a73c5a2a4997e9d3
timeCreated: 1760693427
@@ -0,0 +1,16 @@
{
"name": "RPGCoreCommon.DropTable",
"rootNamespace": "RPGCoreCommon.DropTable",
"references": [
"RPGCoreCommon.Helpers"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8788c3c029994136b7e8bbbff4b283f5
timeCreated: 1760521419