refactor(jewel): emit AOS attributes via AosAttributes.GetProperties

This commit is contained in:
Kamron Batman 2026-06-22 08:13:20 -07:00
parent fc756406ba
commit b47dc7d391
3 changed files with 81 additions and 119 deletions

View file

@ -0,0 +1,36 @@
using Server.Items;
using Xunit;
namespace UOContent.Tests;
[Collection("Sequential UOContent Tests")]
public class BaseJewelPropertiesTests
{
[Fact]
public void Jewel_AttributeLineSet_Preserved()
{
var ring = new GoldRing();
try
{
ring.Attributes.DefendChance = 5;
ring.Attributes.BonusStr = 10;
ring.Attributes.Luck = 100;
ring.Attributes.NightSight = 1;
ring.Attributes.SpellChanneling = 1;
ring.Attributes.IncreasedKarmaLoss = 3;
var map = ItemOplTestHelper.DecodeAttributeLines(ring);
Assert.Equal("5", map[1060408]); // DefendChance
Assert.Equal("10", map[1060485]); // BonusStr
Assert.Equal("100", map[1060436]); // Luck (raw; jewel has no luck bonus)
Assert.Equal("", map[1060441]); // NightSight
Assert.Equal("", map[1060482]); // SpellChanneling
Assert.Equal("3", map[1075210]); // IncreasedKarmaLoss (Core.ML EJ)
}
finally
{
ring.Delete();
}
}
}

View file

@ -0,0 +1,44 @@
using System;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.Text;
using Server;
namespace UOContent.Tests;
public static class ItemOplTestHelper
{
// Builds the item's OPL and returns attribute/property cliloc lines (>= 1060000),
// ignoring base-item lines (name, weight, etc.) so tests isolate the attribute surface.
public static Dictionary<int, string> DecodeAttributeLines(Item item)
{
var opl = new ObjectPropertyList(item);
item.GetProperties(opl);
opl.Terminate();
var buffer = opl.Buffer;
var map = new Dictionary<int, string>();
var pos = 15;
while (true)
{
var cliloc = BinaryPrimitives.ReadInt32BigEndian(buffer.AsSpan(pos));
pos += 4;
if (cliloc == 0)
{
break;
}
var byteLen = BinaryPrimitives.ReadUInt16BigEndian(buffer.AsSpan(pos));
pos += 2;
var arg = Encoding.Unicode.GetString(buffer, pos, byteLen);
pos += byteLen;
if (cliloc is >= 1060000 and < 1080000)
{
map[cliloc] = arg;
}
}
return map;
}
}