Initial commit: Theriapolis baseline at port/godot branch point
Captures the pre-Godot-port state of the codebase. This is the rollback anchor for the Godot port (M0 of theriapolis-rpg-implementation-plan-godot-port.md). All Phase 0 through Phase 6.5 work is included; Phase 7 is in flight. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using Theriapolis.Core.Data;
|
||||
using Theriapolis.Core.Items;
|
||||
using Theriapolis.Core.Util;
|
||||
|
||||
namespace Theriapolis.Core.Loot;
|
||||
|
||||
/// <summary>
|
||||
/// Phase 7 M2 — container-level deterministic loot rolls. Wraps
|
||||
/// <see cref="LootRoller"/> with a per-container <see cref="SeededRng"/>
|
||||
/// derived from the dungeon's layout seed and the container's slot index,
|
||||
/// so the same <c>(worldSeed, poiId, slotIdx)</c> always rolls the same
|
||||
/// items.
|
||||
///
|
||||
/// Per Phase 7 plan §4.4 / §5.5:
|
||||
/// <c>lootContainerSeed = dungeonLayoutSeed ^ C.RNG_DUNGEON_LOOT ^ slotIdx</c>
|
||||
///
|
||||
/// The <see cref="LootRoller"/> path is the encounter-drop pipeline (uses
|
||||
/// the encounter's RNG); this path is for static dungeon containers and
|
||||
/// does not advance any encounter-time stream.
|
||||
/// </summary>
|
||||
public static class LootGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Roll a single container's contents.
|
||||
/// </summary>
|
||||
/// <param name="tableId">Loot-table id (e.g. <c>loot_dungeon_imperium_t2</c>).</param>
|
||||
/// <param name="containerSeed">
|
||||
/// Per-container seed. Caller is expected to derive this as
|
||||
/// <c>worldSeed ^ C.RNG_DUNGEON_LAYOUT ^ poiId ^ C.RNG_DUNGEON_LOOT ^ slotIdx</c>.
|
||||
/// </param>
|
||||
/// <param name="tables">Loot-table dictionary from <see cref="ContentResolver.LootTables"/>.</param>
|
||||
/// <param name="items">Item dictionary from <see cref="ContentResolver.Items"/>.</param>
|
||||
/// <returns>An array of <see cref="ItemInstance"/> ready to drop into an inventory.</returns>
|
||||
public static ItemInstance[] RollContainer(
|
||||
string tableId,
|
||||
ulong containerSeed,
|
||||
IReadOnlyDictionary<string, LootTableDef> tables,
|
||||
IReadOnlyDictionary<string, ItemDef> items)
|
||||
{
|
||||
var rng = new SeededRng(containerSeed);
|
||||
var drops = LootRoller.Roll(tableId, tables, items, rng);
|
||||
var result = new ItemInstance[drops.Count];
|
||||
for (int i = 0; i < drops.Count; i++)
|
||||
result[i] = new ItemInstance(drops[i].Def, drops[i].Qty);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convenience overload that resolves the per-container seed from the
|
||||
/// dungeon layout seed + slot index per the Phase 7 dice contract.
|
||||
/// </summary>
|
||||
public static ItemInstance[] RollContainer(
|
||||
string tableId,
|
||||
ulong dungeonLayoutSeed,
|
||||
int slotIdx,
|
||||
IReadOnlyDictionary<string, LootTableDef> tables,
|
||||
IReadOnlyDictionary<string, ItemDef> items)
|
||||
{
|
||||
ulong containerSeed = dungeonLayoutSeed ^ C.RNG_DUNGEON_LOOT ^ (ulong)slotIdx;
|
||||
return RollContainer(tableId, containerSeed, tables, items);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using Theriapolis.Core.Data;
|
||||
using Theriapolis.Core.Util;
|
||||
|
||||
namespace Theriapolis.Core.Loot;
|
||||
|
||||
/// <summary>
|
||||
/// Pure deterministic loot roller. Given a table id and an RNG (typically
|
||||
/// the encounter's <see cref="Rules.Combat.Encounter.RollDie"/>), produces
|
||||
/// the list of (itemDef, qty) tuples to drop.
|
||||
///
|
||||
/// Determinism: dice come from the encounter RNG so save+load round-trips
|
||||
/// produce identical drops — important for the autosave_combat retry slot.
|
||||
/// </summary>
|
||||
public static class LootRoller
|
||||
{
|
||||
public sealed record DropResult(ItemDef Def, int Qty);
|
||||
|
||||
/// <summary>
|
||||
/// Roll <paramref name="tableId"/> against the supplied RNG. Returns an
|
||||
/// empty list when the table id is empty/unknown.
|
||||
/// </summary>
|
||||
public static List<DropResult> Roll(
|
||||
string tableId,
|
||||
IReadOnlyDictionary<string, LootTableDef> tables,
|
||||
IReadOnlyDictionary<string, ItemDef> items,
|
||||
SeededRng rng)
|
||||
{
|
||||
var results = new List<DropResult>();
|
||||
if (string.IsNullOrEmpty(tableId) || !tables.TryGetValue(tableId, out var table))
|
||||
return results;
|
||||
|
||||
foreach (var drop in table.Drops)
|
||||
{
|
||||
// Independent chance roll per drop.
|
||||
if (rng.NextFloat() > drop.Chance) continue;
|
||||
if (!items.TryGetValue(drop.ItemId, out var def)) continue;
|
||||
|
||||
int qty;
|
||||
if (drop.QtyMax <= drop.QtyMin) qty = System.Math.Max(1, drop.QtyMin);
|
||||
else qty = rng.NextInt(drop.QtyMin, drop.QtyMax + 1);
|
||||
|
||||
results.Add(new DropResult(def, qty));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user