Merge rynth/main (2026.10.8.1) into sk/features-on-rynth-main
Resolves the conflicts that kept PR #2 from merging. Where rynth/main already ships the same feature, its version wins: the shared read-only RynthInstallPaths, /ra iteminfo (PR #2's Mag-Tools item info window is dropped), pet essence refill trust, object filing, spell metadata and the Monster Editor's Category / MatchExpression. See Changelog/2026-10-08-merge-rynth-main-into-pr2.md. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
commit
2e54796b15
160 changed files with 15447 additions and 2566 deletions
|
|
@ -43,6 +43,12 @@ public class WorldObjectCache
|
|||
private readonly HashSet<int> _landscape = new(); // has physics position
|
||||
private readonly HashSet<int> _inventory = new(); // no physics position
|
||||
private readonly Dictionary<int, float> _healthRatios = new(); // last known health ratio per object (0-1)
|
||||
// Ids whose ratio is an estimate from our own damage lines (a ring, wall or chain spell's other
|
||||
// targets: the server sends health only for the selected target). A real health update replaces
|
||||
// the estimate and takes the id out of this set.
|
||||
private readonly HashSet<int> _estimatedHealth = new();
|
||||
/// <summary>The lowest an estimate goes: 0 means dead to every reader, and only the server says that.</summary>
|
||||
internal const float EstimatedHealthFloor = 0.01f;
|
||||
|
||||
// OnCreateObject IDs pending classification
|
||||
private readonly Queue<uint> _pending = new();
|
||||
|
|
@ -199,6 +205,7 @@ public class WorldObjectCache
|
|||
_creatures.Remove(sid);
|
||||
_landscape.Remove(sid);
|
||||
_healthRatios.Remove(sid);
|
||||
_estimatedHealth.Remove(sid);
|
||||
_classifyRetry.Remove(id);
|
||||
_slowRetry.Remove(id);
|
||||
_reclassifySkipState.Remove(id);
|
||||
|
|
@ -234,6 +241,37 @@ public class WorldObjectCache
|
|||
return _healthRatios.TryGetValue(id, out float v) ? v : -1f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lowers a creature's health by our own hit when the server sends it no health of its own: the
|
||||
/// other targets of a ring, wall or chain spell (ACE pushes health only for the selected target).
|
||||
/// <paramref name="fraction"/> is damage / max health, or 0 when the max is unknown, which only
|
||||
/// marks the creature as hurt (0.99). Never goes to 0 (dead is the server's call: the kill
|
||||
/// notice, a health update or the corpse) and never raises a known value. A real health update
|
||||
/// overwrites the estimate.
|
||||
/// </summary>
|
||||
public void ApplyDamageEstimate(int id, double fraction)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
if (_playerId != 0 && unchecked((uint)id) == _playerId) return;
|
||||
float cur = _healthRatios.TryGetValue(id, out float v) ? v : 1f;
|
||||
if (cur <= 0f) return;
|
||||
float next = fraction > 0
|
||||
? (float)Math.Max(EstimatedHealthFloor, cur - fraction)
|
||||
: Math.Min(cur, 0.99f);
|
||||
if (next >= cur && _healthRatios.ContainsKey(id)) return;
|
||||
_healthRatios[id] = next;
|
||||
_estimatedHealth.Add(id);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>True when <paramref name="id"/>'s health ratio is our estimate rather than the server's.</summary>
|
||||
public bool IsHealthEstimated(int id)
|
||||
{
|
||||
lock (_gate)
|
||||
return _estimatedHealth.Contains(id);
|
||||
}
|
||||
|
||||
public void OnUpdateHealth(uint id, float healthRatio)
|
||||
{
|
||||
lock (_gate)
|
||||
|
|
@ -243,6 +281,7 @@ public class WorldObjectCache
|
|||
|
||||
int sid = (int)id;
|
||||
_healthRatios[sid] = Math.Clamp(healthRatio, 0f, 1f);
|
||||
_estimatedHealth.Remove(sid); // the server's number replaces any estimate
|
||||
|
||||
if (!_creatures.Add(sid))
|
||||
return; // creature already known — ratio updated above, nothing more to do
|
||||
|
|
@ -601,13 +640,16 @@ public class WorldObjectCache
|
|||
return;
|
||||
}
|
||||
|
||||
// Non-creature with a known type: classify it by its ItemType flags and place it
|
||||
// by ownership. Only weapons/armor/casters/containers were accepted here before,
|
||||
// so keys, gems, spell components, food and misc fell through to Unknown
|
||||
// landscape (never inventory) and ReclassifyUnknownDynamics re-probed them
|
||||
// every 2 s forever.
|
||||
// Non-creature with a position and a known item type: equipped gear, a ground
|
||||
// drop, a chest. It gets the class its type gives and is filed by who has it
|
||||
// (FileTypedObject). Only weapons, armor, casters and containers were taken
|
||||
// here before, all into the inventory: keys, gems, comps, food and the like
|
||||
// stayed Unknown landscape and were re-probed every 2 s for good, and other
|
||||
// players' wielded gear and ground-dropped weapons counted as ours
|
||||
// (2026-10-05). A static object that isn't a chest or a lifestone returns
|
||||
// false and stays Unknown scenery below, hazard check included.
|
||||
AcObjectClass typedCls = ClassifyItem(uid, typeFlags);
|
||||
if (typedCls != AcObjectClass.Unknown && PlaceTypedObject(uid, id, name, typedCls, typeFlags))
|
||||
if (typedCls != AcObjectClass.Unknown && FileTypedObject(uid, id, name, typedCls, typeFlags))
|
||||
return;
|
||||
}
|
||||
else if (uid >= 0x80000000u)
|
||||
|
|
@ -657,83 +699,77 @@ public class WorldObjectCache
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Places a positioned, non-creature object whose ItemType resolved to a real class.
|
||||
/// Must be called under <see cref="_gate"/>.
|
||||
/// <list type="bullet">
|
||||
/// <item>Portals / lifestones → landscape with their real class.</item>
|
||||
/// <item>Dynamic objects owned by the player (wielded, in the main pack, or in a side pack) → inventory.</item>
|
||||
/// <item>Other dynamic objects (ground drops, corpse / chest contents) → landscape with the item class.</item>
|
||||
/// <item>Ownership unreadable → gear-like types go to inventory, the rest to landscape.</item>
|
||||
/// <item>Static non-fixture, non-container objects (doors, signs) → returns false; the caller keeps them Unknown scenery.</item>
|
||||
/// </list>
|
||||
/// Returns true when the object was placed and recorded in <see cref="_byId"/>.
|
||||
/// </summary>
|
||||
private bool PlaceTypedObject(uint uid, int id, string name, AcObjectClass cls, uint typeFlags)
|
||||
{
|
||||
bool isFixture = cls is AcObjectClass.Portal or AcObjectClass.Lifestone;
|
||||
bool isDynamic = uid >= 0x80000000u;
|
||||
private const uint ItemTypeGear = ItemTypeMeleeWeapon | ItemTypeMissileWeapon | ItemTypeCaster | ItemTypeArmor | ItemTypeContainer;
|
||||
|
||||
bool toInventory;
|
||||
if (isFixture)
|
||||
private enum Holder { Unknown, Player, OtherWielder, OtherContainer, Nobody }
|
||||
|
||||
/// <summary>
|
||||
/// Who has the object: the player (wielded, in the main pack, or in a side pack), another
|
||||
/// wielder (other players' and NPCs' gear), another container (a corpse, a chest), or
|
||||
/// nobody (it lies on the ground). Unknown when the player isn't known yet or the engine
|
||||
/// can't read the object's ownership. Caller holds _gate.
|
||||
/// </summary>
|
||||
private Holder WhoHas(int id)
|
||||
{
|
||||
if (_playerId == 0 || !TryGetOwnership(id, out int containerId, out int wielderId, out _))
|
||||
return Holder.Unknown;
|
||||
uint container = unchecked((uint)containerId), wielder = unchecked((uint)wielderId);
|
||||
if (wielder == _playerId || container == _playerId) return Holder.Player;
|
||||
if (wielder != 0) return Holder.OtherWielder;
|
||||
if (container == 0) return Holder.Nobody;
|
||||
// Side packs sit in the main pack (AC has no deeper nesting).
|
||||
return TryGetOwnership(containerId, out int outer, out _, out _) && unchecked((uint)outer) == _playerId
|
||||
? Holder.Player : Holder.OtherContainer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Files a positioned non-creature whose item type gave it a real class. Caller holds _gate.
|
||||
/// <list type="bullet">
|
||||
/// <item>A lifestone: landscape.</item>
|
||||
/// <item>Another static object: a chest goes on the landscape; anything else returns false
|
||||
/// and the caller keeps it Unknown scenery (doors, signs, static hotspots).</item>
|
||||
/// <item>A dynamic object the player has: inventory. One another player or an NPC wields:
|
||||
/// neither list (known by id only), so it is not ours, not a ground item on the radar and
|
||||
/// not something a meta can pick up. In another container or loose on the ground: landscape.</item>
|
||||
/// <item>Ownership unreadable: gear goes to the inventory as before, the rest to the landscape.</item>
|
||||
/// </list>
|
||||
/// A non-gear object that lands on the landscape gets the hazard check it had as Unknown
|
||||
/// (a hotspot spawned with a dynamic id and a Misc type is still a hazard).
|
||||
/// </summary>
|
||||
private bool FileTypedObject(uint uid, int id, string name, AcObjectClass cls, uint typeFlags)
|
||||
{
|
||||
bool gear = (typeFlags & ItemTypeGear) != 0;
|
||||
bool toInventory, toLandscape;
|
||||
if (cls == AcObjectClass.Lifestone)
|
||||
{
|
||||
toInventory = false;
|
||||
toLandscape = true;
|
||||
}
|
||||
else if (!isDynamic)
|
||||
else if (uid < 0x80000000u)
|
||||
{
|
||||
// Chests are static containers; other static objects stay Unknown scenery.
|
||||
if ((typeFlags & ItemTypeContainer) == 0)
|
||||
return false;
|
||||
if ((typeFlags & ItemTypeContainer) == 0) return false;
|
||||
toInventory = false;
|
||||
toLandscape = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool owned = IsOwnedByPlayer(id, out bool ownershipKnown);
|
||||
toInventory = ownershipKnown
|
||||
? owned
|
||||
: (typeFlags & (ItemTypeMeleeWeapon | ItemTypeMissileWeapon | ItemTypeCaster | ItemTypeArmor | ItemTypeContainer)) != 0;
|
||||
Holder holder = WhoHas(id);
|
||||
toInventory = holder == Holder.Player || (holder == Holder.Unknown && gear);
|
||||
toLandscape = !toInventory && holder != Holder.OtherWielder;
|
||||
}
|
||||
|
||||
_classifyRetry.Remove(uid);
|
||||
_reclassifySkipState.Remove(uid);
|
||||
if (toInventory)
|
||||
{
|
||||
if (_inventory.Add(id)) _inventoryDirty = true;
|
||||
_landscape.Remove(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_inventory.Remove(id)) _inventoryDirty = true;
|
||||
_landscape.Add(id);
|
||||
}
|
||||
if (toInventory) { if (_inventory.Add(id)) _inventoryDirty = true; }
|
||||
else if (_inventory.Remove(id)) _inventoryDirty = true;
|
||||
if (toLandscape) _landscape.Add(id);
|
||||
else _landscape.Remove(id);
|
||||
_byId[id] = Make(id, name, cls);
|
||||
TraceClassify(uid, name.Length > 0, true, true, typeFlags, toInventory ? $"typed->{cls}(inv)" : $"typed->{cls}(land)");
|
||||
if (toLandscape && !gear)
|
||||
MaybeRegisterHazard(uid, name);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// True when the object is wielded by the player, sits in the player's main pack, or sits in
|
||||
/// a side pack whose container is the player. <paramref name="known"/> is false when the
|
||||
/// player id isn't set yet or the ownership read failed.
|
||||
/// </summary>
|
||||
private bool IsOwnedByPlayer(int id, out bool known)
|
||||
{
|
||||
known = false;
|
||||
if (_playerId == 0 || !TryGetOwnership(id, out int containerId, out int wielderId, out _))
|
||||
return false;
|
||||
|
||||
known = true;
|
||||
uint container = unchecked((uint)containerId);
|
||||
uint wielder = unchecked((uint)wielderId);
|
||||
if (wielder == _playerId || container == _playerId)
|
||||
return true;
|
||||
|
||||
// One level of nesting covers side packs (AC doesn't allow packs inside packs).
|
||||
return container != 0
|
||||
&& TryGetOwnership(containerId, out int outer, out _, out _)
|
||||
&& unchecked((uint)outer) == _playerId;
|
||||
}
|
||||
|
||||
// PublicWeenieDesc._bitfield BF_CORPSE (ObjectDescriptionFlag.Corpse).
|
||||
private const uint BfCorpse = 0x2000;
|
||||
|
||||
|
|
@ -799,7 +835,7 @@ public class WorldObjectCache
|
|||
List<int>? toPromote = null;
|
||||
List<int>? toCorpse = null;
|
||||
List<(int id, string name, AcObjectClass cls)>? statics = null;
|
||||
List<(int Id, uint Flags)>? toType = null; // Unknowns whose ItemType is now a real item class
|
||||
List<(int Id, uint Flags)>? typed = null; // Unknowns whose item type now gives a class
|
||||
foreach (int id in _landscape)
|
||||
{
|
||||
uint uid = unchecked((uint)id);
|
||||
|
|
@ -829,7 +865,11 @@ public class WorldObjectCache
|
|||
// Bounded to Monster/Unknown so we don't name-query every ground
|
||||
// item each pass; IsCorpseName is specific ("X corpse"/"Corpse of X")
|
||||
// so a live mob cannot be misread as a corpse.
|
||||
if ((wo.ObjectClass == AcObjectClass.Monster || wo.ObjectClass == AcObjectClass.Unknown)
|
||||
// Container too: a corpse typed before its name or flag was readable is filed as a
|
||||
// landscape Container by FileTypedObject (it used to go to the inventory, which the
|
||||
// inventory pass below re-checks).
|
||||
if ((wo.ObjectClass == AcObjectClass.Monster || wo.ObjectClass == AcObjectClass.Unknown
|
||||
|| wo.ObjectClass == AcObjectClass.Container)
|
||||
&& ((_host.TryGetObjectName(uid, out string maybeCorpse) && IsCorpseName(maybeCorpse))
|
||||
|| HasCorpseFlag(uid)))
|
||||
{
|
||||
|
|
@ -854,11 +894,11 @@ public class WorldObjectCache
|
|||
isCreature = true;
|
||||
if (!isCreature)
|
||||
{
|
||||
// Type known now (or arrived late): place it as a real item instead of
|
||||
// re-probing it every pass. Applied after the loop: placing mutates _landscape.
|
||||
// Its type arrived after it was classified: file it as the item it is instead
|
||||
// of probing it again every pass. Done after the loop (filing edits _landscape).
|
||||
if (gotType && typeFlags != 0 && ClassifyByItemType(typeFlags) != AcObjectClass.Unknown)
|
||||
{
|
||||
(toType ??= new()).Add((id, typeFlags));
|
||||
(typed ??= new()).Add((id, typeFlags));
|
||||
continue;
|
||||
}
|
||||
DiagLogReclassifySkip(uid, wo.Name);
|
||||
|
|
@ -914,27 +954,27 @@ public class WorldObjectCache
|
|||
_host.Log($"[RynthAi] ReclassifyUnknownDynamics: rescued {toCorpse.Count} stale corpse(s) → Corpse");
|
||||
}
|
||||
|
||||
if (toType != null)
|
||||
if (typed != null)
|
||||
{
|
||||
int placed = 0, toInv = 0;
|
||||
foreach (var (id, flags) in toType)
|
||||
int filed = 0, intoInventory = 0;
|
||||
foreach (var (id, flags) in typed)
|
||||
{
|
||||
if (!_byId.TryGetValue(id, out var wo)) continue;
|
||||
uint uid = unchecked((uint)id);
|
||||
// An Unknown result would be re-queued every pass, so leave it to the skip diag.
|
||||
AcObjectClass cls = ClassifyItem(uid, flags);
|
||||
if (cls == AcObjectClass.Unknown || !PlaceTypedObject(uid, id, wo.Name ?? string.Empty, cls, flags)) continue;
|
||||
placed++;
|
||||
if (_inventory.Contains(id)) toInv++;
|
||||
if (cls == AcObjectClass.Unknown || !FileTypedObject(uid, id, wo.Name ?? string.Empty, cls, flags)) continue;
|
||||
filed++;
|
||||
if (_inventory.Contains(id)) intoInventory++;
|
||||
}
|
||||
_host.Log($"[RynthAi] ReclassifyUnknownDynamics: typed {placed} Unknown object(s) as items ({toInv} into inventory)");
|
||||
if (filed > 0)
|
||||
_host.Log($"[RynthAi] ReclassifyUnknownDynamics: typed {filed} Unknown object(s) as items ({intoInventory} into the inventory)");
|
||||
}
|
||||
|
||||
// DIAG: heartbeat — Unknown landscape candidates checked but nothing promoted
|
||||
// this pass. Confirms ReclassifyUnknownDynamics is running and engine signals
|
||||
// keep failing for the stuck uids (vs. them never reaching _landscape at all).
|
||||
if (toPromote == null
|
||||
&& toType == null
|
||||
&& typed == null
|
||||
&& _reclassifySkipState.Count > 0
|
||||
&& _reclassifyDiagSummaryCount < MaxReclassifyDiagSummaries)
|
||||
{
|
||||
|
|
@ -1096,10 +1136,64 @@ public class WorldObjectCache
|
|||
uint uid = unchecked((uint)id);
|
||||
if (stype == DecalTypeKey)
|
||||
return _host.HasGetObjectWcid && _host.TryGetObjectWcid(uid, out uint wcid) ? unchecked((int)wcid) : defaultValue;
|
||||
if ((stype & 0xFFFFFF00u) == DecalTypeKey)
|
||||
return GetDecalLongKey(uid, stype, defaultValue);
|
||||
if (!_host.HasGetObjectIntProperty) return defaultValue;
|
||||
return _host.TryGetObjectIntProperty(uid, stype, out int v) ? v : defaultValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decal's other synthetic LongValueKeys (0x0D000001-0x0D00002A, Decal.Adapter's numbering),
|
||||
/// read as the game property each one is. VTank profiles use them: LootSnobV4 has 336 rules on
|
||||
/// MaxDamage and 109 on Coverage. They were read as STypeInt ids, which no object has, so
|
||||
/// they were always 0 and those rules never matched (until 2026-10-07). Icons are the
|
||||
/// portal.dat index without its 0x06000000 base, as Decal gives them. Keys with no property
|
||||
/// here (landblock, monarch, physics flags, spell counts) answer the default.
|
||||
/// </summary>
|
||||
private int GetDecalLongKey(uint uid, uint key, int defaultValue)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case 0x0D000001: return DecalIcon(uid, 8, defaultValue); // Icon
|
||||
case 0x0D000008: { uint s = GetDataIdProperty(unchecked((int)uid), 28); return s != 0 ? unchecked((int)s) : defaultValue; } // AssociatedSpell
|
||||
case 0x0D000029: return DecalIcon(uid, 50, defaultValue); // IconOverlay
|
||||
case 0x0D00002A: return DecalIcon(uid, 52, defaultValue); // IconUnderlay
|
||||
}
|
||||
uint stype = DecalIntStype(key);
|
||||
if (stype == 0 || !_host.HasGetObjectIntProperty) return defaultValue;
|
||||
return _host.TryGetObjectIntProperty(uid, stype, out int v) ? v : defaultValue;
|
||||
}
|
||||
|
||||
/// <summary>The STypeInt a Decal synthetic long key is, or 0 (not an int property).</summary>
|
||||
public static uint DecalIntStype(uint key) => key switch
|
||||
{
|
||||
0x0D000004 => 6, // ItemSlots -> ItemsCapacity
|
||||
0x0D000005 => 7, // PackSlots -> ContainersCapacity
|
||||
0x0D000006 => 12, // StackCount -> StackSize
|
||||
0x0D000007 => 11, // StackMax -> MaxStackSize
|
||||
0x0D00000B => 10, // WieldingSlot -> CurrentWieldedLocation
|
||||
0x0D00000D => 4, // Coverage -> ClothingPriority
|
||||
0x0D00000E => 9, // EquipableSlots -> ValidLocations
|
||||
0x0D00000F => 51, // EquipType -> CombatUse
|
||||
0x0D000010 => 18, // IconOutline -> UiEffects
|
||||
0x0D000011 => 50, // MissileType -> AmmoType
|
||||
0x0D000012 => 16, // UsageMask -> ItemUseable
|
||||
0x0D000014 => 152, // HookMask -> HookItemType
|
||||
0x0D000015 => 151, // HookType
|
||||
0x0D00001A => 1, // Category -> ItemType
|
||||
0x0D00001F => 49, // WeapSpeed -> WeaponTime
|
||||
0x0D000020 => 48, // EquipSkill -> WeaponSkill
|
||||
0x0D000021 => 45, // DamageType
|
||||
0x0D000022 => 44, // MaxDamage -> Damage (the appraisal's weapon profile)
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
private int DecalIcon(uint uid, uint did, int defaultValue)
|
||||
{
|
||||
uint v = GetDataIdProperty(unchecked((int)uid), did);
|
||||
return v != 0 ? unchecked((int)(v & 0x00FFFFFFu)) : defaultValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read an STypeDID property (e.g. a scroll's Spell 28 from its CreateObject header).
|
||||
/// 0 if the API is unavailable or the property is not set.
|
||||
|
|
@ -1753,6 +1847,24 @@ public class WorldObjectCache
|
|||
get { lock (_gate) return _hazardVersion; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A dungeon cell the character took hotspot damage in ("You suffer 32 damage from acid!"):
|
||||
/// registered and persisted like a sighted hazard, so the patrol reroutes around it now and
|
||||
/// on every later visit. Outdoor cells (a 24 m land cell) are never registered. True when new.
|
||||
/// </summary>
|
||||
public bool RegisterDamageHazardCell(uint cellId, string source)
|
||||
{
|
||||
if (cellId == 0 || (cellId & 0xFFFF) < 0x0100) return false;
|
||||
lock (_gate)
|
||||
{
|
||||
if (!_hazardCells.Add(cellId)) return false;
|
||||
_hazardVersion++;
|
||||
}
|
||||
DungeonHazardStore.Append(cellId >> 16, cellId);
|
||||
_host.Log($"[Hazard] took {source} damage in cell 0x{cellId:X8} (persisted)");
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsHazardCell(uint cellId)
|
||||
{
|
||||
lock (_gate)
|
||||
|
|
|
|||
Loading…
Reference in a new issue