RynthSuite/Plugins/ub-Rythai/RynthCore.Plugin.UbRythai/UbRythaiPortalGems.cs
BlankenshipG 7797901d69 feat: port SK test branch (2026.10.18.24) onto sk
Squash of test/hotbuild-2026-10-16 as merged onto aelrynth main 2026.10.17.1, matching the
2026.10.18.24 test installer. The test branch wins where both changed the same lines; sk-only
changes kept; duplicate features cut to the test branch's copy. RynthAi HandWrittenVersion stays
0.5.0-legacy-ui on sk.

Highlights: RynthOracle 0.6.0 (Legendary, Markers, Dynamic Stamps and Temple guardians merged into
the Quests list, RynthNav Go to), RynthILT 0.2.20 (ub-IT auto-chunk rules, rating level,
RynthILT.Data v3), RynthAi ub-IT /ub and VT/MT meta compatibility and the loot attribute checklist,
RynthNav destination alternatives. Changelog/2026-10-18-sk-port-test-branch-2026.10.18.24.md.
2026-10-18 16:22:40 -04:00

69 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using RynthCore.PluginSdk;
namespace RynthCore.Plugin.UbRythai;
/// <summary>
/// UB-ILT MiniRemote portal gem list + inventory lookup (name match) for RynthCore hosts.
/// </summary>
internal static class UbRythaiPortalGems
{
/// <summary>Same canonical names as UB-ILT MiniRemote / Enlightenment recall gem list.</summary>
public static readonly string[] CanonicalGemNames =
{
"Enlightened Facility Hub Portal Gem",
"Facility Hub Portal Gem",
"Infinite Town Network Portal Gem",
"Lifestone Recall Portal Gem",
"Frozen Valley Everlasting Portal Gem",
};
/// <summary>Attempts to find an inventory object id whose name matches <paramref name="gemName"/>.</summary>
public static bool TryFindInventoryObjectIdByName(RynthCoreHost host, uint playerId, string gemName, out uint objectId)
{
objectId = 0;
if (playerId == 0 || string.IsNullOrWhiteSpace(gemName))
return false;
if (!host.HasGetContainerContents || !host.HasGetNumContainedItems || !host.HasGetObjectName)
return false;
var visited = new HashSet<uint>();
var queue = new Queue<(uint containerId, int depth)>();
queue.Enqueue((playerId, 0));
uint[] buf = new uint[512];
while (queue.Count > 0)
{
(uint containerId, int depth) = queue.Dequeue();
if (containerId == 0 || !visited.Add(containerId))
continue;
if (depth > 6)
continue;
int n = host.GetContainerContents(containerId, buf);
for (int i = 0; i < n; i++)
{
uint id = buf[i];
if (id == 0)
continue;
if (host.TryGetObjectName(id, out string? name) && !string.IsNullOrWhiteSpace(name))
{
if (name.Equals(gemName, StringComparison.OrdinalIgnoreCase))
{
objectId = id;
return true;
}
}
int contained = host.GetNumContainedItems(id);
int subContainers = host.GetNumContainedContainers(id);
if (contained > 0 || subContainers > 0)
queue.Enqueue((id, depth + 1));
}
}
return false;
}
}