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
|
|
@ -87,27 +87,28 @@ public enum AcIntProperty
|
|||
|
||||
/// <summary>
|
||||
/// Loot-relevant float item properties. Values match Chorizite STypeFloat sequential enum
|
||||
/// (UNDEF=0, HEARTBEAT_INTERVAL=1, …). Cast to int when calling item.Values(key, 0.0).
|
||||
/// (UNDEF=0, HEARTBEAT_INTERVAL=1, …) and ACE's PropertyFloat. Cast to int when calling item.Values(key, 0.0).
|
||||
/// AttackBonus, DamageMod, ManaConvMod and SlayerDamageBonus were one low until 2026-10-05.
|
||||
/// </summary>
|
||||
public enum AcFloatProperty
|
||||
{
|
||||
AcidProtMod = 18, // ARMOR_MOD_VS_ACID
|
||||
AttackBonus = 61, // WEAPON_OFFENSE — attack bonus %
|
||||
AttackBonus = 62, // WEAPON_OFFENSE — attack bonus %
|
||||
BluntProtMod = 15, // ARMOR_MOD_VS_BLUDGEON
|
||||
ColdProtMod = 16, // ARMOR_MOD_VS_COLD
|
||||
DamageMod = 62, // DAMAGE_MOD — damage bonus %
|
||||
DamageMod = 63, // DAMAGE_MOD — damage bonus %
|
||||
DamageVariance = 22, // DAMAGE_VARIANCE
|
||||
DefenseBonus = 29, // WEAPON_DEFENSE — melee defense bonus %
|
||||
ElectricProtMod = 19, // ARMOR_MOD_VS_ELECTRIC
|
||||
ElementalDamageMod = 152, // ELEMENTAL_DAMAGE_MOD
|
||||
FireProtMod = 17, // ARMOR_MOD_VS_FIRE
|
||||
MagicDefBonus = 150, // WEAPON_MAGIC_DEFENSE
|
||||
ManaConvMod = 143, // MANA_CONVERSION_MOD
|
||||
ManaConvMod = 144, // MANA_CONVERSION_MOD
|
||||
MissileDefBonus = 149, // WEAPON_MISSILE_DEFENSE
|
||||
NetherProtMod = 165, // ARMOR_MOD_VS_NETHER
|
||||
PierceProtMod = 14, // ARMOR_MOD_VS_PIERCE
|
||||
SlashProtMod = 13, // ARMOR_MOD_VS_SLASH
|
||||
SlayerDamageBonus = 137, // SLAYER_DAMAGE_BONUS
|
||||
SlayerDamageBonus = 138, // SLAYER_DAMAGE_BONUS
|
||||
}
|
||||
|
||||
/// <summary>AC material types. Integer values match the live acclient.exe property table.</summary>
|
||||
|
|
|
|||
|
|
@ -133,6 +133,11 @@ public sealed class LootEditItemRequest
|
|||
public string RuleName { get; set; } = string.Empty;
|
||||
/// <summary>True: the profile open in the Loot Editor; false: the one RynthAi loots with.</summary>
|
||||
public bool ToOpenProfile { get; set; }
|
||||
/// <summary>
|
||||
/// Also require the item's T11 attributes (LootItemRuleOptions.IncludeT11). Added
|
||||
/// 2026-10-07; an older engine never sends it, so it reads false.
|
||||
/// </summary>
|
||||
public bool IncludeT11 { get; set; }
|
||||
/// <summary>Echoed in the draft so the popup knows the answer is to its latest ask.</summary>
|
||||
public int Seq { get; set; }
|
||||
}
|
||||
|
|
@ -156,6 +161,10 @@ public sealed class LootEditItemDraft
|
|||
public string Format { get; set; } = string.Empty;
|
||||
/// <summary>What was built (the defaults filled in).</summary>
|
||||
public int Match { get; set; }
|
||||
/// <summary>The rule was asked to include the item's T11 attributes (added 2026-10-07).</summary>
|
||||
public bool IncludeT11 { get; set; }
|
||||
/// <summary>The item is T11 gear, so "Include T11 attributes" has something to add (added 2026-10-07).</summary>
|
||||
public bool IsT11 { get; set; }
|
||||
public int Action { get; set; }
|
||||
public int KeepCount { get; set; }
|
||||
public string RuleName { get; set; } = string.Empty;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using RynthCore.Loot.T11;
|
||||
using RynthCore.Loot.VTank;
|
||||
|
||||
namespace RynthCore.Loot.Editing;
|
||||
|
|
@ -26,6 +27,11 @@ public sealed class LootItemFacts
|
|||
public Dictionary<int, double> Doubles { get; set; } = new();
|
||||
/// <summary>The item's spell names (empty when none or not identified).</summary>
|
||||
public List<string> Spells { get; set; } = new();
|
||||
/// <summary>
|
||||
/// The item's T11 reading (ACECustom tier 11+ text), or null when it wasn't asked for.
|
||||
/// <see cref="T11ItemInfo.None"/> for an item that isn't T11 gear.
|
||||
/// </summary>
|
||||
public T11ItemInfo? T11 { get; set; }
|
||||
|
||||
public bool Stackable => MaxStackSize > 1 || StackSize > 1;
|
||||
|
||||
|
|
@ -53,6 +59,11 @@ public sealed class LootItemRuleOptions
|
|||
public int? KeepCount { get; set; }
|
||||
/// <summary>Null or blank: "Keep Copper Pea" and the like.</summary>
|
||||
public string? RuleName { get; set; }
|
||||
/// <summary>
|
||||
/// Also require the item's T11 attributes (tier, grade, damage %, each modifier, slot
|
||||
/// special, Cast on Strike), each at least as good as this item's. Works with any match.
|
||||
/// </summary>
|
||||
public bool IncludeT11 { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>A built rule, ready to preview and insert.</summary>
|
||||
|
|
@ -155,6 +166,7 @@ public static class LootItemRules
|
|||
};
|
||||
bool hasClass = f.ObjectClass != (int)AcObjectClass.Unknown;
|
||||
LootItemMatch match = o.Match;
|
||||
bool likeBare = false;
|
||||
if (match == LootItemMatch.NameAndClass && !hasClass)
|
||||
{
|
||||
match = LootItemMatch.Name;
|
||||
|
|
@ -177,13 +189,15 @@ public static class LootItemRules
|
|||
return null;
|
||||
}
|
||||
rule.Conditions.Add(Cond(VTankNodeTypes.ObjectClass, Num(f.ObjectClass)));
|
||||
int extra = AddLikeConditions(rule, f, notes);
|
||||
if (extra == 0)
|
||||
notes.Add($"Nothing but the class to go on: this rule matches every {ClassName(f.ObjectClass)}."
|
||||
+ (f.Ints.Count == 0 ? " (Assess the item first for its material, workmanship and stats.)" : string.Empty));
|
||||
likeBare = AddLikeConditions(rule, f, notes) == 0;
|
||||
break;
|
||||
}
|
||||
|
||||
int t11Added = o.IncludeT11 ? AddT11Conditions(rule, f, notes) : 0;
|
||||
if (likeBare && t11Added == 0)
|
||||
notes.Add($"Nothing but the class to go on: this rule matches every {ClassName(f.ObjectClass)}."
|
||||
+ (f.Ints.Count == 0 ? " (Assess the item first for its material, workmanship and stats.)" : string.Empty));
|
||||
|
||||
string defaultName = DefaultRuleName(name.Length > 0 ? name : ClassName(f.ObjectClass), action, keep, match);
|
||||
string ruleName = OneLine(o.RuleName).Trim();
|
||||
rule.Name = ruleName.Length > 0 ? ruleName : defaultName;
|
||||
|
|
@ -248,6 +262,59 @@ public static class LootItemRules
|
|||
return rule.Conditions.Count - n;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The T11 conditions, on RynthAi's virtual T11 keys: Is T11, then tier, grade, damage %,
|
||||
/// every catalogued modifier, slot special and Cast on Strike count, each at least this
|
||||
/// item's. Left out on purpose: Can Wield (the character, not the item), Zone Locked
|
||||
/// (where it was appraised), the wield gates (they follow from the tier) and the modifier
|
||||
/// count / rating total / roll % (they follow from the per-modifier values).
|
||||
/// How many it added.
|
||||
/// </summary>
|
||||
private static int AddT11Conditions(VTankLootRule rule, LootItemFacts f, List<string> notes)
|
||||
{
|
||||
T11ItemInfo? t = f.T11;
|
||||
if (t == null || !t.IsT11)
|
||||
{
|
||||
notes.Add("Not a T11 item, so there are no T11 attributes to add.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int n = rule.Conditions.Count;
|
||||
void Equal(int key, int v) => rule.Conditions.Add(Cond(VTankNodeTypes.LongValKeyE, Num(v), Num(key)));
|
||||
void AtLeast(int key, int v) { if (v > 0) rule.Conditions.Add(Cond(VTankNodeTypes.LongValKeyGE, Num(v), Num(key))); }
|
||||
|
||||
Equal(T11Keys.IsT11, 1);
|
||||
if (!t.HasText)
|
||||
{
|
||||
notes.Add("The item hasn't been identified, so only \"Is T11\" could be added. Assess it and preview again for its tier, grade and modifiers.");
|
||||
return rule.Conditions.Count - n;
|
||||
}
|
||||
|
||||
AtLeast(T11Keys.EstimatedTier, t.EstimatedTier);
|
||||
AtLeast(T11Keys.WeaponGrade, t.GradeRank);
|
||||
AtLeast(T11Keys.DamagePercent, t.DamagePercent);
|
||||
|
||||
bool valuelessSpecial = false;
|
||||
var unknown = new List<string>();
|
||||
foreach (T11Modifier m in t.Modifiers)
|
||||
{
|
||||
if (T11Catalog.ModifierByKey(m.Key) == null)
|
||||
{
|
||||
unknown.Add(m.Name);
|
||||
continue;
|
||||
}
|
||||
// A modifier's key reads 0 when it is absent, so a value-less one can't be required by value.
|
||||
if (m.Value > 0) AtLeast(T11Keys.ForModifier(m.Key), m.Value);
|
||||
else if (m.IsSlotSpecial) valuelessSpecial = true;
|
||||
}
|
||||
if (valuelessSpecial) Equal(T11Keys.HasSlotSpecial, 1);
|
||||
AtLeast(T11Keys.CastOnStrikeCount, t.Procs.Count);
|
||||
|
||||
if (unknown.Count > 0)
|
||||
notes.Add("Left out (RynthAi has no loot key for these modifiers yet): " + string.Join(", ", unknown) + ".");
|
||||
return rule.Conditions.Count - n;
|
||||
}
|
||||
|
||||
private static VTankLootCondition Cond(int type, params string[] lines) => new(type, "0", lines);
|
||||
|
||||
private static string Num(int v) => v.ToString(CultureInfo.InvariantCulture);
|
||||
|
|
|
|||
|
|
@ -38,27 +38,55 @@ public static class LootRuleText
|
|||
|
||||
// ── Key tables (the common ones; unknown ids show as "key N") ──────────
|
||||
|
||||
public static readonly (int Id, string Name)[] LongKeys =
|
||||
{
|
||||
(5, "EncumbVal"), (9, "Locations"), (19, "Value"), (25, "Level"), (28, "ArmorLevel"), (44, "Damage"), (45, "DamageType"),
|
||||
(48, "WeaponSkill"), (54, "MaxDamage"),
|
||||
(87, "MaxStructure"), (88, "Structure"), (105, "ItemWorkmanship"), (107, "ItemMaxMana"),
|
||||
(131, "MaterialType"), (158, "WieldRequirements"), (159, "WieldSkilltype"), (160, "WieldDifficulty"),
|
||||
(218, "EquippedSlots"), (353, "ImbuedEffect"), (370, "DamageRating"), (371, "DamageResistRating"),
|
||||
(372, "CritRating"), (373, "CritResistRating"), (374, "CritDamageRating"),
|
||||
(375, "CritDamageResistRating"), (376, "HealBoostRating"), (379, "VitalityRating"),
|
||||
(0x0D000000, "Type (WCID)"), // Decal's synthetic key: the weenie class id
|
||||
};
|
||||
/// <summary>Retail / Decal long keys, then RynthAi's virtual T11 keys (T11Keys; RynthAi-only).</summary>
|
||||
public static readonly (int Id, string Name)[] LongKeys = BuildLongKeys();
|
||||
|
||||
private static (int Id, string Name)[] BuildLongKeys()
|
||||
{
|
||||
var keys = new List<(int, string)>
|
||||
{
|
||||
(5, "EncumbVal"), (9, "Locations"), (19, "Value"), (25, "Level"), (28, "ArmorLevel"), (44, "Damage (max)"), (45, "DamageType"),
|
||||
(48, "WeaponSkill"), (54, "WeaponEncumbrance"), // 54 was labelled MaxDamage until 2026-10-07; max damage is 44
|
||||
(87, "MaxStructure"), (88, "Structure"), (105, "ItemWorkmanship"), (107, "ItemMaxMana"),
|
||||
(131, "MaterialType"), (158, "WieldRequirements"), (159, "WieldSkilltype"), (160, "WieldDifficulty"),
|
||||
(218, "EquippedSlots"), (353, "ImbuedEffect"), (370, "DamageRating"), (371, "DamageResistRating"),
|
||||
(372, "CritRating"), (373, "CritResistRating"), (374, "CritDamageRating"),
|
||||
(375, "CritDamageResistRating"), (376, "HealBoostRating"), (377, "NetherResistRating"), (379, "VitalityRating"),
|
||||
(0x0D000000, "Type (WCID)"), // Decal's synthetic key: the weenie class id
|
||||
// Decal's other synthetic keys (Decal.Adapter LongValueKey), as VTank's editor names them;
|
||||
// RynthAi reads each as the game property it is (WorldObjectCache.GetDecalLongKey).
|
||||
(0x0D000001, "Icon"), (0x0D000004, "ItemSlots"), (0x0D000005, "PackSlots"),
|
||||
(0x0D000006, "StackCount"), (0x0D000007, "StackMax"), (0x0D000008, "AssociatedSpell"),
|
||||
(0x0D00000B, "WieldingSlot"), (0x0D00000D, "Coverage"), (0x0D00000E, "EquipableSlots"),
|
||||
(0x0D00000F, "EquipType"), (0x0D000010, "IconOutline"), (0x0D000011, "MissileType"),
|
||||
(0x0D000012, "UsageMask"), (0x0D000014, "HookMask"), (0x0D000015, "HookType"),
|
||||
(0x0D00001A, "Category"), (0x0D00001F, "WeapSpeed"), (0x0D000020, "EquipSkill"),
|
||||
(0x0D000021, "DamageType (Decal)"), (0x0D000022, "MaxDamage"),
|
||||
(0x0D000029, "IconOverlay"), (0x0D00002A, "IconUnderlay"),
|
||||
};
|
||||
keys.AddRange(T11.T11Keys.Names());
|
||||
return keys.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// STypeFloat ids (ACE's PropertyFloat), then the 0x0A0000xx keys VTank's own editor writes
|
||||
/// for the appraisal's weapon profile (uTank2 LootPlugins.DoubleValueKey). 5, 29, 62, 63 and
|
||||
/// 167 were labelled ApproachDistance, WeaponLength, WeaponDefense, WeaponOffense and ManaRate
|
||||
/// until 2026-10-05.
|
||||
/// </summary>
|
||||
public static readonly (int Id, string Name)[] DoubleKeys =
|
||||
{
|
||||
(5, "ApproachDistance"), (22, "DamageVariance"), (29, "WeaponLength"), (62, "WeaponDefense"),
|
||||
(63, "WeaponOffense"), (152, "ElementalDamageVsMonsters"), (167, "ManaRate"),
|
||||
(5, "ManaRate"), (22, "DamageVariance"), (29, "WeaponDefense"), (62, "WeaponOffense"),
|
||||
(63, "DamageMod"), (144, "ManaConversionMod"), (149, "WeaponMissileDefense"),
|
||||
(150, "WeaponMagicDefense"), (152, "ElementalDamageVsMonsters"), (167, "CooldownDuration"),
|
||||
(0x0A000009, "SalvageWorkmanship"), (0x0A00000B, "Variance"),
|
||||
(0x0A00000C, "AttackBonus"), (0x0A00000E, "DamageBonus"),
|
||||
};
|
||||
|
||||
/// <summary>String keys. Use (14) and LongDesc (16) hold the T11 "Modifiers:" / "Property Details:" text.</summary>
|
||||
public static readonly (int Id, string Name)[] StringKeys =
|
||||
{
|
||||
(1, "Name"), (5, "Inscription"), (7, "Title"),
|
||||
(1, "Name"), (5, "Inscription"), (7, "Title"), (14, "Use"), (16, "LongDesc"),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -85,12 +113,15 @@ public static class LootRuleText
|
|||
|
||||
// ── Value tables (what a long key's number means) ──────────────────────
|
||||
|
||||
/// <summary>WieldRequirements (158): what WieldDifficulty is checked against (ACE's WieldRequirement enum).</summary>
|
||||
/// <summary>
|
||||
/// WieldRequirements (158): what WieldDifficulty is checked against (ACE's WieldRequirement
|
||||
/// enum). 13 is ACECustom's Int64Stat, the T11 item-aug gate (RynthAi restores it on T11 items).
|
||||
/// </summary>
|
||||
public static readonly (int Id, string Name)[] WieldRequirements =
|
||||
{
|
||||
(0, "Invalid"), (1, "Skill"), (2, "Base Skill"), (3, "Attribute"), (4, "Base Attribute"),
|
||||
(5, "Vital"), (6, "Base Vital"), (7, "Level"), (8, "Training"), (9, "Int Property"),
|
||||
(10, "Bool Property"), (11, "Creature Type"), (12, "Heritage"),
|
||||
(10, "Bool Property"), (11, "Creature Type"), (12, "Heritage"), (13, "Int64 Property"),
|
||||
};
|
||||
|
||||
/// <summary>MaterialType (131): ACE's MaterialType enum, in id order (grouped cloth, gems, hides, metals, stone, wood).</summary>
|
||||
|
|
@ -129,19 +160,20 @@ public static class LootRuleText
|
|||
/// </summary>
|
||||
public static (int Id, string Name)[]? ValueTableFor(int longKey) => longKey switch
|
||||
{
|
||||
45 => DamageTypes,
|
||||
48 => Skills,
|
||||
45 or 0x0D000021 => DamageTypes,
|
||||
48 or 0x0D000020 => Skills,
|
||||
131 => Materials,
|
||||
158 => WieldRequirements,
|
||||
159 => Skills,
|
||||
T11.T11Keys.WeaponGrade => T11.T11Catalog.Grades,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
/// <summary>True when the long key's value is a set of flags (a named value is one flag or a common pair).</summary>
|
||||
public static bool ValueTableIsFlags(int longKey) => longKey == 45;
|
||||
public static bool ValueTableIsFlags(int longKey) => longKey is 45 or 0x0D000021;
|
||||
|
||||
/// <summary>The long keys that have a value table, for the vocabulary.</summary>
|
||||
public static readonly int[] KeysWithValueTables = { 45, 48, 131, 158, 159 };
|
||||
public static readonly int[] KeysWithValueTables = { 45, 48, 131, 158, 159, 0x0D000020, 0x0D000021, T11.T11Keys.WeaponGrade };
|
||||
|
||||
/// <summary>
|
||||
/// True for the conditions whose value is picked by name when the key has a
|
||||
|
|
|
|||
197
Shared/RynthCore.LootSdk/T11/T11Catalog.cs
Normal file
197
Shared/RynthCore.LootSdk/T11/T11Catalog.cs
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RynthCore.Loot.T11;
|
||||
|
||||
/// <summary>
|
||||
/// The player counter a T11 wield gate is checked against. On the server these are
|
||||
/// PropertyInt64 values (WieldRequirement.Int64Stat); the client never receives the
|
||||
/// gate as properties, only as a "Wield requires: N <counter>" description line.
|
||||
/// </summary>
|
||||
public enum T11Counter
|
||||
{
|
||||
/// <summary>LumAugItemCount (PropertyInt64 9008). The server checks the raw count, without Triune Weave.</summary>
|
||||
ItemAugmentations = 9008,
|
||||
/// <summary>TriuneWeaveCount (PropertyInt64 50000), the T16+ armor gate.</summary>
|
||||
TriuneWeave = 50000,
|
||||
/// <summary>BattlemagesWrathCharmCount (PropertyInt64 50001).</summary>
|
||||
BattlemagesWrath = 50001,
|
||||
/// <summary>NetherVeilCharmCount (PropertyInt64 50002).</summary>
|
||||
NetherVeil = 50002,
|
||||
/// <summary>CrashingSteelCharmCount (PropertyInt64 50003).</summary>
|
||||
CrashingSteel = 50003,
|
||||
/// <summary>TrueShotCharmCount (PropertyInt64 50004).</summary>
|
||||
TrueShot = 50004,
|
||||
}
|
||||
|
||||
/// <summary>One Zone Control modifier the server can stamp on T11 gear.</summary>
|
||||
/// <param name="Key">The server's catalog key (ZoneModifiers.Catalog).</param>
|
||||
/// <param name="Name">The name printed at the start of the appraisal line.</param>
|
||||
/// <param name="RatingKey">The retail Gear* rating property the modifier sets, or 0.</param>
|
||||
/// <param name="SlotSpecial">True for the one-per-slot specials, whose line has no roll band.</param>
|
||||
public sealed record T11ModifierDef(int Key, string Name, int RatingKey, bool SlotSpecial);
|
||||
|
||||
/// <summary>
|
||||
/// Static T11 tables mirrored from ACECustom: weapon sub-grades, the Zone Control
|
||||
/// modifier catalog, the wield-gate counter names and the tier-from-gate estimate.
|
||||
/// Pure data, shared by the RynthAi evaluator, the loot editor and the tests.
|
||||
/// </summary>
|
||||
public static class T11Catalog
|
||||
{
|
||||
/// <summary>The name prefix the server gives every tier 11+ drop (ApplyT11NamePrefix).</summary>
|
||||
public const string NamePrefix = "T11 - ";
|
||||
|
||||
/// <summary>Retail rating keys counted by the TotalRatings condition (VTank's set).</summary>
|
||||
public static readonly int[] TotalRatingKeys = { 370, 371, 372, 373, 374, 375, 376, 379 };
|
||||
|
||||
/// <summary>
|
||||
/// Weapon sub-grades best to worst with their rank (S = 16 ... F- = 1, 0 = no grade).
|
||||
/// Order and labels follow WeaponScalingManager.SubGradeBands.
|
||||
/// </summary>
|
||||
public static readonly (int Id, string Name)[] Grades =
|
||||
{
|
||||
(16, "S"), (15, "A+"), (14, "A"), (13, "A-"), (12, "B+"), (11, "B"), (10, "B-"),
|
||||
(9, "C+"), (8, "C"), (7, "C-"), (6, "D+"), (5, "D"), (4, "D-"), (3, "F+"), (2, "F"), (1, "F-"),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// ZoneModifiers.Catalog (ACECustom). Rating keys: 370 Damage, 371 Damage Resist, 372 Crit,
|
||||
/// 373 Crit Resist, 374 Crit Damage, 375 Crit Damage Resist, 376 Healing Boost,
|
||||
/// 377 Nether Resist, 379 Max Health.
|
||||
/// </summary>
|
||||
public static readonly T11ModifierDef[] Modifiers =
|
||||
{
|
||||
new(19, "Max Health", 379, false),
|
||||
new(25, "Armor Level", 0, false),
|
||||
new(28, "Damage Rating", 370, false),
|
||||
new(29, "Crit Damage Rating", 374, false),
|
||||
new(31, "Healing Boost", 376, false),
|
||||
new(32, "Spell Duration", 0, false),
|
||||
new(33, "Crit Chance", 372, false),
|
||||
new(41, "Fortify Vitals", 0, true),
|
||||
new(42, "Battle Mending", 0, true),
|
||||
new(43, "All Attributes", 0, false),
|
||||
new(44, "Pct HP Damage", 0, true),
|
||||
new(45, "Cheat Death", 0, true),
|
||||
new(46, "Regeneration", 0, true),
|
||||
new(47, "Max Health Pct", 0, false),
|
||||
new(48, "Life on Hit", 0, false),
|
||||
new(49, "Reinforced", 0, false),
|
||||
new(50, "Damage Resist", 371, false),
|
||||
new(51, "Crit Damage Resist", 375, false),
|
||||
new(52, "Crit Resist", 373, false),
|
||||
new(53, "Nether Resist", 377, false),
|
||||
};
|
||||
|
||||
// Longest names first, so "Max Health Pct" is tried before "Max Health".
|
||||
private static readonly T11ModifierDef[] ModifiersByNameLength = SortByNameLength(Modifiers);
|
||||
|
||||
private static T11ModifierDef[] SortByNameLength(T11ModifierDef[] defs)
|
||||
{
|
||||
var copy = (T11ModifierDef[])defs.Clone();
|
||||
Array.Sort(copy, (a, b) => b.Name.Length.CompareTo(a.Name.Length));
|
||||
return copy;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The catalog entry whose name starts <paramref name="text"/> as a whole word
|
||||
/// ("Max Health Pct +2%" is Max Health Pct, not Max Health), or null.
|
||||
/// </summary>
|
||||
public static T11ModifierDef? MatchModifier(string text)
|
||||
{
|
||||
foreach (var def in ModifiersByNameLength)
|
||||
{
|
||||
if (!text.StartsWith(def.Name, StringComparison.OrdinalIgnoreCase)) continue;
|
||||
if (text.Length == def.Name.Length || text[def.Name.Length] == ' ') return def;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>The catalog entry for a server key, or null.</summary>
|
||||
public static T11ModifierDef? ModifierByKey(int key)
|
||||
{
|
||||
foreach (var def in Modifiers)
|
||||
if (def.Key == key) return def;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>Rank of a sub-grade label ("B+" = 12), or 0 when it isn't one.</summary>
|
||||
public static int GradeRank(string? label)
|
||||
{
|
||||
if (string.IsNullOrEmpty(label)) return 0;
|
||||
foreach (var (id, name) in Grades)
|
||||
if (string.Equals(name, label, StringComparison.OrdinalIgnoreCase)) return id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>The words a "Wield requires:" line uses for each counter.</summary>
|
||||
public static readonly (T11Counter Counter, string Name)[] CounterNames =
|
||||
{
|
||||
(T11Counter.ItemAugmentations, "Item Augmentations"),
|
||||
(T11Counter.TriuneWeave, "Triune Weave"),
|
||||
(T11Counter.BattlemagesWrath, "Battlemage's Wrath"),
|
||||
(T11Counter.NetherVeil, "Nether Veil"),
|
||||
(T11Counter.CrashingSteel, "Crashing Steel"),
|
||||
(T11Counter.TrueShot, "True Shot"),
|
||||
};
|
||||
|
||||
/// <summary>The counter named by a "Wield requires:" line, or null.</summary>
|
||||
public static T11Counter? CounterByName(string name)
|
||||
{
|
||||
foreach (var (counter, n) in CounterNames)
|
||||
if (string.Equals(n, name.Trim(), StringComparison.OrdinalIgnoreCase)) return counter;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>Display name of a counter.</summary>
|
||||
public static string CounterName(T11Counter counter)
|
||||
{
|
||||
foreach (var (c, n) in CounterNames)
|
||||
if (c == counter) return n;
|
||||
return counter.ToString();
|
||||
}
|
||||
|
||||
/// <summary>Highest loot tier on the server's default weapon-scaling ladder (T11-T25).</summary>
|
||||
public const int MaxTier = 25;
|
||||
|
||||
/// <summary>
|
||||
/// Triune Weave required per tier above 15 on the default ladder: 500 at T16 up to 5,000
|
||||
/// at T25. Weapons and armor carry the same Triune gate; weapons add a family-charm gate
|
||||
/// of the same size, which isn't needed for the estimate.
|
||||
/// </summary>
|
||||
public const int TriunePerTier = 500;
|
||||
|
||||
/// <summary>
|
||||
/// The loot tier implied by an item-augmentation wield gate, using the server's default
|
||||
/// weapon-scaling table: T11 = 2,000, T12 = 2,500, then +500 per tier, capped at 4,000.
|
||||
/// Without a Triune Weave gate the cap makes T15 and above read as 15 (see the
|
||||
/// three-argument overload). Returns 11 for a T11-named item with no gate read yet, and 0
|
||||
/// for anything else. The server owner can retune the table, so this is an estimate.
|
||||
/// </summary>
|
||||
public static int EstimateTier(int itemAugGate, bool isT11)
|
||||
{
|
||||
if (itemAugGate <= 0) return isT11 ? 11 : 0;
|
||||
if (itemAugGate < 2500) return 11;
|
||||
return Math.Min(15, 12 + (itemAugGate - 2500) / 500);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The loot tier implied by both T11 wield gates. The item-aug gate stops rising at T15,
|
||||
/// so from T16 the Triune Weave gate (<see cref="TriunePerTier"/> x (tier - 15)) carries
|
||||
/// the tier: 500 = T16 ... 5,000 = T25. Any Triune gate means T16 or higher (the server
|
||||
/// only stamps it from T16) and the result is capped at <see cref="MaxTier"/>. Without a
|
||||
/// Triune gate this is <see cref="EstimateTier(int, bool)"/>.
|
||||
/// </summary>
|
||||
public static int EstimateTier(int itemAugGate, int triuneGate, bool isT11)
|
||||
{
|
||||
if (triuneGate > 0) return Math.Clamp(15 + triuneGate / TriunePerTier, 16, MaxTier);
|
||||
return EstimateTier(itemAugGate, isT11);
|
||||
}
|
||||
|
||||
/// <summary>Modifier keys with a rating, for callers that map Gear* keys back to modifiers.</summary>
|
||||
public static IEnumerable<T11ModifierDef> RatingModifiers()
|
||||
{
|
||||
foreach (var def in Modifiers)
|
||||
if (def.RatingKey != 0) yield return def;
|
||||
}
|
||||
}
|
||||
348
Shared/RynthCore.LootSdk/T11/T11ItemInfo.cs
Normal file
348
Shared/RynthCore.LootSdk/T11/T11ItemInfo.cs
Normal file
|
|
@ -0,0 +1,348 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace RynthCore.Loot.T11;
|
||||
|
||||
/// <summary>One "Wield requires: N <counter>" gate.</summary>
|
||||
public readonly record struct T11WieldGate(T11Counter Counter, int Amount);
|
||||
|
||||
/// <summary>One line of the appraisal's "Modifiers:" section.</summary>
|
||||
public sealed class T11Modifier
|
||||
{
|
||||
/// <summary>Catalog key (T11Catalog.Modifiers), or 0 for a name the catalog doesn't know.</summary>
|
||||
public int Key { get; init; }
|
||||
/// <summary>The modifier name as printed.</summary>
|
||||
public string Name { get; init; } = string.Empty;
|
||||
/// <summary>The rolled value (the first number after the name; 0 for value-less specials).</summary>
|
||||
public int Value { get; init; }
|
||||
/// <summary>Low end of the "[min-max]" roll band, or null when the line has none.</summary>
|
||||
public int? Min { get; init; }
|
||||
/// <summary>High end of the "[min-max]" roll band, or null when the line has none.</summary>
|
||||
public int? Max { get; init; }
|
||||
/// <summary>Where the value landed in its band, 0-100, or -1 without a usable band.</summary>
|
||||
public int RollPercent { get; init; } = -1;
|
||||
/// <summary>The retail Gear* rating key the modifier sets, or 0.</summary>
|
||||
public int RatingKey { get; init; }
|
||||
/// <summary>True for a one-per-slot special (Fortify Vitals, Battle Mending, ...).</summary>
|
||||
public bool IsSlotSpecial { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What the client can learn about a T11 (tier 11+) ACECustom drop. The server keeps the
|
||||
/// T11 properties (weapon quality, loot tier, the Zone Control record, the item-aug wield
|
||||
/// gate) out of the appraisal and prints them as description text instead, so this is
|
||||
/// parsed from the name, LongDesc (key 16) and Use (key 14). See ACECustom AppraiseInfo
|
||||
/// (BuildProperties, BuildWeapon, PromoteZoneModifierLines) for the formats.
|
||||
/// </summary>
|
||||
public sealed class T11ItemInfo
|
||||
{
|
||||
/// <summary>A non-T11 item: every field at its default.</summary>
|
||||
public static readonly T11ItemInfo None = new();
|
||||
|
||||
/// <summary>True when the item is T11 gear (name prefix, or T11-only text in its description).</summary>
|
||||
public bool IsT11 { get; private set; }
|
||||
/// <summary>True when the name starts with "T11 - ".</summary>
|
||||
public bool HasNamePrefix { get; private set; }
|
||||
/// <summary>Weapon sub-grade label ("B+"), or null.</summary>
|
||||
public string? Grade { get; private set; }
|
||||
/// <summary>Sub-grade rank, S = 16 ... F- = 1, 0 = no grade.</summary>
|
||||
public int GradeRank { get; private set; }
|
||||
/// <summary>"N% of max damage" from the grade line, or -1.</summary>
|
||||
public int DamagePercent { get; private set; } = -1;
|
||||
/// <summary>Every wield gate, at most one per counter.</summary>
|
||||
public IReadOnlyList<T11WieldGate> WieldGates => _gates;
|
||||
/// <summary>The Zone Control modifier lines, in appraisal order.</summary>
|
||||
public IReadOnlyList<T11Modifier> Modifiers => _modifiers;
|
||||
/// <summary>"Cast on Strike" lines: spell name and proc chance percent.</summary>
|
||||
public IReadOnlyList<(string Name, double ChancePercent)> Procs => _procs;
|
||||
/// <summary>True when the appraisal said "Zone Locked (Power Reduced)" (depends on where the examiner stood).</summary>
|
||||
public bool ZoneLocked { get; private set; }
|
||||
/// <summary>True when the item had appraisal text (false for a T11 name seen before its ID).</summary>
|
||||
public bool HasText { get; private set; }
|
||||
|
||||
private readonly List<T11WieldGate> _gates = new();
|
||||
private readonly List<T11Modifier> _modifiers = new();
|
||||
private readonly List<(string, double)> _procs = new();
|
||||
|
||||
/// <summary>The item-augmentation gate, or 0 when there is none.</summary>
|
||||
public int WieldItemAugs => GateAmount(T11Counter.ItemAugmentations);
|
||||
|
||||
/// <summary>The amount required of <paramref name="counter"/>, or 0 when it isn't gated.</summary>
|
||||
public int GateAmount(T11Counter counter)
|
||||
{
|
||||
foreach (var g in _gates)
|
||||
if (g.Counter == counter) return g.Amount;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The estimated loot tier (11-25), or 0 for non-T11 items. T16 and up come from the
|
||||
/// Triune Weave gate; an item without one reads at most 15.
|
||||
/// </summary>
|
||||
public int EstimatedTier => T11Catalog.EstimateTier(WieldItemAugs, GateAmount(T11Counter.TriuneWeave), IsT11);
|
||||
|
||||
/// <summary>Sum of modifier values that land on the TotalRatings keys.</summary>
|
||||
public int ModifierRatingTotal
|
||||
{
|
||||
get
|
||||
{
|
||||
int total = 0;
|
||||
foreach (var m in _modifiers)
|
||||
if (Array.IndexOf(T11Catalog.TotalRatingKeys, m.RatingKey) >= 0) total += m.Value;
|
||||
return total;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Sum of modifier values that set <paramref name="ratingKey"/>, or 0.</summary>
|
||||
public int RatingFromModifiers(int ratingKey)
|
||||
{
|
||||
int total = 0;
|
||||
foreach (var m in _modifiers)
|
||||
if (m.RatingKey == ratingKey) total += m.Value;
|
||||
return total;
|
||||
}
|
||||
|
||||
/// <summary>The value of the modifier with catalog key <paramref name="key"/>, or 0 when absent.</summary>
|
||||
public int ModifierValue(int key)
|
||||
{
|
||||
foreach (var m in _modifiers)
|
||||
if (m.Key == key) return m.Value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>Average roll position (0-100) of the banded modifiers, or 0 without any.</summary>
|
||||
public int AverageRollPercent
|
||||
{
|
||||
get
|
||||
{
|
||||
int sum = 0, n = 0;
|
||||
foreach (var m in _modifiers)
|
||||
if (m.RollPercent >= 0) { sum += m.RollPercent; n++; }
|
||||
return n == 0 ? 0 : (int)Math.Round(sum / (double)n, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Best roll position (0-100) of the banded modifiers, or 0 without any.</summary>
|
||||
public int BestRollPercent
|
||||
{
|
||||
get
|
||||
{
|
||||
int best = 0;
|
||||
foreach (var m in _modifiers)
|
||||
if (m.RollPercent > best) best = m.RollPercent;
|
||||
return best;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>True when any modifier is a slot special.</summary>
|
||||
public bool HasSlotSpecial
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (var m in _modifiers)
|
||||
if (m.IsSlotSpecial) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Parsing ─────────────────────────────────────────────────────────────
|
||||
|
||||
private const RegexOptions Opt = RegexOptions.CultureInvariant | RegexOptions.IgnoreCase;
|
||||
|
||||
// "- Weapon Grade: B+ (86% of max damage)" / "- Weapon Grade: S"
|
||||
private static readonly Regex GradeLine = new(
|
||||
@"^-?\s*Weapon Grade:\s*(?<g>S|[A-DF][+-]?)(?=\s|\(|$)(?:\s*\((?<pct>\d+)% of max damage\))?", Opt);
|
||||
|
||||
// "- Wield requires: 2,000 Item Augmentations" (weapons) / "Wield requires: 2,000 Item Augmentations" (armor).
|
||||
// ACE prints N0, so the group separator follows the server's culture: keep digits only.
|
||||
private static readonly Regex WieldLine = new(
|
||||
@"^-?\s*Wield requires:\s*(?<n>\d[\d,.\s']*?)\s+(?<what>[A-Za-z' ]+?)\s*$", Opt);
|
||||
|
||||
// "- Cast on Strike: Force Arc (13% proc chance)"
|
||||
private static readonly Regex ProcLine = new(
|
||||
@"^-\s*Cast on Strike:\s*(?<name>.+?)\s*\((?<pct>\d+(?:\.\d+)?)% proc chance\)\s*$", Opt);
|
||||
|
||||
// A modifier's value: the first signed whole number after the name.
|
||||
private static readonly Regex FirstNumber = new(@"[+-]?\d+", RegexOptions.CultureInvariant);
|
||||
|
||||
// The roll band at the end of a modifier line: "[14-69]".
|
||||
private static readonly Regex Band = new(@"\[(?<min>\d+)\s*-\s*(?<max>\d+)\]\s*$", RegexOptions.CultureInvariant);
|
||||
|
||||
// An uncatalogued modifier from a newer server: "Some Name +12 [5-20]" or "Modifier 60 +3 [1-5]".
|
||||
private static readonly Regex GenericModifier = new(@"^(?<name>.+?)\s+(?<val>[+-]?\d+)", RegexOptions.CultureInvariant);
|
||||
// Checked before GenericModifier, whose lazy name would stop at "Modifier" and read the key as the value.
|
||||
private static readonly Regex UnknownKeyName = new(@"^(?<name>Modifier (?<key>\d+))(?=\s|$)", RegexOptions.CultureInvariant);
|
||||
|
||||
private const string ModifiersHeader = "Modifiers:";
|
||||
private const string ZoneLockedText = "Zone Locked (Power Reduced)";
|
||||
|
||||
/// <summary>
|
||||
/// Parses an item. <paramref name="name"/>, <paramref name="longDesc"/> and
|
||||
/// <paramref name="use"/> may be null or empty (an item not yet appraised has no text;
|
||||
/// the name prefix alone still marks it T11). Never throws.
|
||||
/// </summary>
|
||||
public static T11ItemInfo Parse(string? name, string? longDesc, string? use)
|
||||
{
|
||||
bool prefix = !string.IsNullOrEmpty(name) && name.StartsWith(T11Catalog.NamePrefix, StringComparison.Ordinal);
|
||||
if (!prefix && string.IsNullOrEmpty(longDesc) && string.IsNullOrEmpty(use)) return None;
|
||||
|
||||
var info = new T11ItemInfo
|
||||
{
|
||||
HasNamePrefix = prefix,
|
||||
HasText = !string.IsNullOrEmpty(longDesc) || !string.IsNullOrEmpty(use),
|
||||
};
|
||||
try
|
||||
{
|
||||
info.ParseText(longDesc);
|
||||
info.ParseText(use);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Malformed text never breaks loot evaluation; whatever parsed so far stands.
|
||||
}
|
||||
|
||||
// Grade, gates and banded modifiers only appear on T11 gear; Cast on Strike and the
|
||||
// zone-lock line alone do not mark an item.
|
||||
info.IsT11 = prefix || info.GradeRank > 0 || info._gates.Count > 0 || info._modifiers.Count > 0;
|
||||
return info.IsT11 ? info : None;
|
||||
}
|
||||
|
||||
private void ParseText(string? text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text)) return;
|
||||
string[] lines = text.Replace("\r\n", "\n").Split('\n');
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
string line = lines[i].Trim();
|
||||
if (line.Length == 0) continue;
|
||||
|
||||
if (line.Contains(ZoneLockedText, StringComparison.OrdinalIgnoreCase)) { ZoneLocked = true; continue; }
|
||||
|
||||
if (string.Equals(line, ModifiersHeader, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
i = ParseModifierBlock(lines, i + 1) - 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
Match m = GradeLine.Match(line);
|
||||
if (m.Success && GradeRank == 0)
|
||||
{
|
||||
Grade = m.Groups["g"].Value.ToUpperInvariant();
|
||||
GradeRank = T11Catalog.GradeRank(Grade);
|
||||
if (m.Groups["pct"].Success && int.TryParse(m.Groups["pct"].Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out int pct))
|
||||
DamagePercent = pct;
|
||||
continue;
|
||||
}
|
||||
|
||||
m = WieldLine.Match(line);
|
||||
if (m.Success && T11Catalog.CounterByName(m.Groups["what"].Value) is T11Counter counter)
|
||||
{
|
||||
int amount = DigitsOnly(m.Groups["n"].Value);
|
||||
if (amount > 0) AddGate(counter, amount);
|
||||
continue;
|
||||
}
|
||||
|
||||
m = ProcLine.Match(line);
|
||||
if (m.Success && double.TryParse(m.Groups["pct"].Value, NumberStyles.Float, CultureInfo.InvariantCulture, out double chance))
|
||||
_procs.Add((m.Groups["name"].Value, chance));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Reads "- ..." lines after a "Modifiers:" header; returns the index of the first line not consumed.</summary>
|
||||
private int ParseModifierBlock(string[] lines, int start)
|
||||
{
|
||||
int i = start;
|
||||
for (; i < lines.Length; i++)
|
||||
{
|
||||
string line = lines[i].Trim();
|
||||
if (line.Length == 0 || !line.StartsWith("-", StringComparison.Ordinal)) break;
|
||||
string body = line.Substring(1).Trim();
|
||||
if (body.Length == 0) continue;
|
||||
if (body.Contains(ZoneLockedText, StringComparison.OrdinalIgnoreCase)) { ZoneLocked = true; continue; }
|
||||
_modifiers.Add(ParseModifier(body));
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
private static T11Modifier ParseModifier(string body)
|
||||
{
|
||||
T11ModifierDef? def = T11Catalog.MatchModifier(body);
|
||||
string name;
|
||||
string rest;
|
||||
int key = 0;
|
||||
if (def != null)
|
||||
{
|
||||
name = def.Name;
|
||||
key = def.Key;
|
||||
rest = body.Substring(def.Name.Length);
|
||||
}
|
||||
else if (UnknownKeyName.Match(body) is { Success: true } k
|
||||
&& int.TryParse(k.Groups["key"].Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out int parsedKey))
|
||||
{
|
||||
key = parsedKey;
|
||||
name = k.Groups["name"].Value;
|
||||
rest = body.Substring(name.Length);
|
||||
def = T11Catalog.ModifierByKey(parsedKey);
|
||||
if (def != null) name = def.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
Match g = GenericModifier.Match(body);
|
||||
name = g.Success ? g.Groups["name"].Value.Trim() : body;
|
||||
rest = g.Success ? body.Substring(g.Groups["name"].Length) : string.Empty;
|
||||
}
|
||||
|
||||
int value = 0;
|
||||
Match num = FirstNumber.Match(rest);
|
||||
if (num.Success) int.TryParse(num.Value, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out value);
|
||||
|
||||
int? min = null, max = null;
|
||||
int roll = -1;
|
||||
Match band = Band.Match(rest);
|
||||
if (band.Success
|
||||
&& int.TryParse(band.Groups["min"].Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out int lo)
|
||||
&& int.TryParse(band.Groups["max"].Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out int hi))
|
||||
{
|
||||
min = lo;
|
||||
max = hi;
|
||||
if (hi > lo) roll = Math.Clamp((int)Math.Round((value - lo) * 100.0 / (hi - lo), MidpointRounding.AwayFromZero), 0, 100);
|
||||
}
|
||||
|
||||
return new T11Modifier
|
||||
{
|
||||
Key = key,
|
||||
Name = name,
|
||||
Value = value,
|
||||
Min = min,
|
||||
Max = max,
|
||||
RollPercent = roll,
|
||||
RatingKey = def?.RatingKey ?? 0,
|
||||
IsSlotSpecial = def?.SlotSpecial ?? false,
|
||||
};
|
||||
}
|
||||
|
||||
private void AddGate(T11Counter counter, int amount)
|
||||
{
|
||||
for (int i = 0; i < _gates.Count; i++)
|
||||
{
|
||||
if (_gates[i].Counter != counter) continue;
|
||||
if (amount > _gates[i].Amount) _gates[i] = new T11WieldGate(counter, amount);
|
||||
return;
|
||||
}
|
||||
_gates.Add(new T11WieldGate(counter, amount));
|
||||
}
|
||||
|
||||
private static int DigitsOnly(string s)
|
||||
{
|
||||
long v = 0;
|
||||
foreach (char c in s)
|
||||
{
|
||||
if (c < '0' || c > '9') continue;
|
||||
v = v * 10 + (c - '0');
|
||||
if (v > int.MaxValue) return int.MaxValue;
|
||||
}
|
||||
return (int)v;
|
||||
}
|
||||
}
|
||||
161
Shared/RynthCore.LootSdk/T11/T11Keys.cs
Normal file
161
Shared/RynthCore.LootSdk/T11/T11Keys.cs
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace RynthCore.Loot.T11;
|
||||
|
||||
/// <summary>
|
||||
/// Virtual long-value keys for T11 loot rules. A loot rule uses them like any long key
|
||||
/// (LongValKeyGE / LE / E / NE), so VTank-format profiles need no new node types. RynthAi
|
||||
/// answers them from <see cref="T11ItemInfo"/>; other loot engines (VTank, Mag) don't know
|
||||
/// them and read them as 0.
|
||||
/// </summary>
|
||||
public static class T11Keys
|
||||
{
|
||||
/// <summary>
|
||||
/// First id of the reserved block ("RY" in the high bytes). Far above retail STypeInt ids,
|
||||
/// ACECustom's custom ids (9000-50999) and Decal's 0x0D000000 WCID key.
|
||||
/// </summary>
|
||||
public const int Base = 0x52590000;
|
||||
|
||||
/// <summary>1 when the item is T11 gear, else 0.</summary>
|
||||
public const int IsT11 = Base + 1;
|
||||
/// <summary>Estimated loot tier from the wield gates (11-25; T16+ from the Triune Weave gate), 0 for non-T11.</summary>
|
||||
public const int EstimatedTier = Base + 2;
|
||||
/// <summary>Weapon sub-grade rank: S = 16, A+ = 15 ... F- = 1, 0 = no grade.</summary>
|
||||
public const int WeaponGrade = Base + 3;
|
||||
/// <summary>The weapon's damage as a percent of a perfect roll, 0 when not shown.</summary>
|
||||
public const int DamagePercent = Base + 4;
|
||||
/// <summary>Item augmentations required to wield, 0 for none.</summary>
|
||||
public const int WieldItemAugs = Base + 5;
|
||||
/// <summary>1 = this character meets every wield gate, 0 = it doesn't, -1 = a needed counter is unknown.</summary>
|
||||
public const int CanWield = Base + 6;
|
||||
/// <summary>Number of Zone Control modifier lines.</summary>
|
||||
public const int ModifierCount = Base + 7;
|
||||
/// <summary>Sum of modifier values that count toward TotalRatings.</summary>
|
||||
public const int ModifierRatingTotal = Base + 8;
|
||||
/// <summary>Average roll position of the banded modifiers, 0-100.</summary>
|
||||
public const int AverageRollPercent = Base + 9;
|
||||
/// <summary>Best roll position of the banded modifiers, 0-100.</summary>
|
||||
public const int BestRollPercent = Base + 10;
|
||||
/// <summary>1 when the item has a slot special (Fortify Vitals, Battle Mending, ...).</summary>
|
||||
public const int HasSlotSpecial = Base + 11;
|
||||
/// <summary>Number of "Cast on Strike" procs.</summary>
|
||||
public const int CastOnStrikeCount = Base + 12;
|
||||
/// <summary>1 when the appraisal said "Zone Locked (Power Reduced)". Depends on where you stood when it was appraised.</summary>
|
||||
public const int ZoneLocked = Base + 13;
|
||||
/// <summary>Triune Weave required to wield (T16+ armor), 0 for none.</summary>
|
||||
public const int WieldTriuneWeave = Base + 14;
|
||||
|
||||
/// <summary>
|
||||
/// Base of the per-modifier keys: <c>ModifierBase + catalog key</c> is that modifier's value
|
||||
/// on the item, 0 when absent (ModifierBase + 28 = Damage Rating).
|
||||
/// </summary>
|
||||
public const int ModifierBase = Base + 0x100;
|
||||
|
||||
/// <summary>One past the last id in the block.</summary>
|
||||
public const int End = Base + 0x200;
|
||||
|
||||
/// <summary>True for any id in the T11 block.</summary>
|
||||
public static bool IsVirtual(int key) => key > Base && key < End;
|
||||
|
||||
/// <summary>The per-modifier key for a catalog key.</summary>
|
||||
public static int ForModifier(int catalogKey) => ModifierBase + catalogKey;
|
||||
|
||||
/// <summary>Editor names for every T11 key, summary keys first.</summary>
|
||||
public static IEnumerable<(int Id, string Name)> Names()
|
||||
{
|
||||
yield return (IsT11, "T11: Is T11");
|
||||
yield return (EstimatedTier, "T11: Tier (est.)");
|
||||
yield return (WeaponGrade, "T11: Weapon Grade");
|
||||
yield return (DamagePercent, "T11: Damage % of Max");
|
||||
yield return (WieldItemAugs, "T11: Wield Item Augs");
|
||||
yield return (WieldTriuneWeave, "T11: Wield Triune Weave");
|
||||
yield return (CanWield, "T11: Can Wield");
|
||||
yield return (ModifierCount, "T11: Modifier Count");
|
||||
yield return (ModifierRatingTotal, "T11: Modifier Ratings");
|
||||
yield return (AverageRollPercent, "T11: Avg Roll %");
|
||||
yield return (BestRollPercent, "T11: Best Roll %");
|
||||
yield return (HasSlotSpecial, "T11: Has Slot Special");
|
||||
yield return (CastOnStrikeCount, "T11: Cast on Strike Count");
|
||||
yield return (ZoneLocked, "T11: Zone Locked");
|
||||
foreach (var def in T11Catalog.Modifiers)
|
||||
yield return (ForModifier(def.Key), "T11 Mod: " + def.Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The value of T11 key <paramref name="key"/> for <paramref name="item"/>. CanWield needs
|
||||
/// <paramref name="player"/>; without it CanWield reads -1 (unknown) for gated items.
|
||||
/// Returns false for an id outside the block or an unused id in it.
|
||||
/// </summary>
|
||||
public static bool TryGetValue(T11ItemInfo item, int key, T11PlayerAugs? player, out int value)
|
||||
{
|
||||
value = 0;
|
||||
if (!IsVirtual(key)) return false;
|
||||
if (key >= ModifierBase)
|
||||
{
|
||||
int catalogKey = key - ModifierBase;
|
||||
if (T11Catalog.ModifierByKey(catalogKey) == null) return false;
|
||||
value = item.ModifierValue(catalogKey);
|
||||
return true;
|
||||
}
|
||||
switch (key)
|
||||
{
|
||||
case IsT11: value = item.IsT11 ? 1 : 0; return true;
|
||||
case EstimatedTier: value = item.EstimatedTier; return true;
|
||||
case WeaponGrade: value = item.GradeRank; return true;
|
||||
case DamagePercent: value = item.DamagePercent < 0 ? 0 : item.DamagePercent; return true;
|
||||
case WieldItemAugs: value = item.WieldItemAugs; return true;
|
||||
case WieldTriuneWeave: value = item.GateAmount(T11Counter.TriuneWeave); return true;
|
||||
case CanWield:
|
||||
// Before its ID a T11 item's gates are unknown, so it can't count as wieldable yet.
|
||||
if (item.WieldGates.Count == 0) value = item.IsT11 && !item.HasText ? -1 : 1;
|
||||
else value = player?.CanWield(item) ?? -1;
|
||||
return true;
|
||||
case ModifierCount: value = item.Modifiers.Count; return true;
|
||||
case ModifierRatingTotal: value = item.ModifierRatingTotal; return true;
|
||||
case AverageRollPercent: value = item.AverageRollPercent; return true;
|
||||
case BestRollPercent: value = item.BestRollPercent; return true;
|
||||
case HasSlotSpecial: value = item.HasSlotSpecial ? 1 : 0; return true;
|
||||
case CastOnStrikeCount: value = item.Procs.Count; return true;
|
||||
case ZoneLocked: value = item.ZoneLocked ? 1 : 0; return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The value the server stripped from a T11 item's appraisal, for the retail keys loot rules
|
||||
/// already use: wield requirement slot 1 (158 = 13 Int64 Property, 159 = 9008, 160 = the
|
||||
/// item-aug gate) and the Gear* ratings a modifier line carries (370-379). Only call this
|
||||
/// when the live property is absent. Returns false when the item supplies no value.
|
||||
/// </summary>
|
||||
public static bool TryGetStrippedValue(T11ItemInfo item, int key, out int value)
|
||||
{
|
||||
value = 0;
|
||||
if (!item.IsT11) return false;
|
||||
switch (key)
|
||||
{
|
||||
case 158:
|
||||
if (item.WieldItemAugs <= 0) return false;
|
||||
value = WieldRequirementInt64Stat;
|
||||
return true;
|
||||
case 159:
|
||||
if (item.WieldItemAugs <= 0) return false;
|
||||
value = (int)T11Counter.ItemAugmentations;
|
||||
return true;
|
||||
case 160:
|
||||
if (item.WieldItemAugs <= 0) return false;
|
||||
value = item.WieldItemAugs;
|
||||
return true;
|
||||
}
|
||||
if (key < 370 || key > 379) return false;
|
||||
int fromMods = item.RatingFromModifiers(key);
|
||||
if (fromMods == 0) return false;
|
||||
value = fromMods;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>ACECustom's WieldRequirement.Int64Stat (the value after HeritageType = 12).</summary>
|
||||
public const int WieldRequirementInt64Stat = 13;
|
||||
|
||||
/// <summary>True for the retail keys <see cref="TryGetStrippedValue"/> can answer.</summary>
|
||||
public static bool IsStrippedKey(int key) => key is 158 or 159 or 160 || (key >= 370 && key <= 379);
|
||||
}
|
||||
138
Shared/RynthCore.LootSdk/T11/T11PlayerAugs.cs
Normal file
138
Shared/RynthCore.LootSdk/T11/T11PlayerAugs.cs
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace RynthCore.Loot.T11;
|
||||
|
||||
/// <summary>
|
||||
/// The player counters T11 wield gates are checked against. ACECustom doesn't send these at
|
||||
/// login (they aren't [SendOnLogin]), so they come from the "/aug" reply, or from a manual
|
||||
/// item-aug override. Thread-safe: chat writes it, loot evaluation reads it.
|
||||
/// </summary>
|
||||
public sealed class T11PlayerAugs
|
||||
{
|
||||
private readonly object _gate = new();
|
||||
private readonly Dictionary<T11Counter, long> _counts = new();
|
||||
private long? _itemAugOverride;
|
||||
|
||||
/// <summary>When the counters were last updated from "/aug" (UTC), or null.</summary>
|
||||
public DateTime? UpdatedUtc { get; private set; }
|
||||
|
||||
/// <summary>The manual item-aug count that replaces the "/aug" value, or null for automatic.</summary>
|
||||
public long? ItemAugOverride
|
||||
{
|
||||
get { lock (_gate) return _itemAugOverride; }
|
||||
set { lock (_gate) _itemAugOverride = value is < 0 ? null : value; }
|
||||
}
|
||||
|
||||
/// <summary>Records one counter read from "/aug".</summary>
|
||||
public void Set(T11Counter counter, long value)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
_counts[counter] = Math.Max(0, value);
|
||||
UpdatedUtc = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The player's count for <paramref name="counter"/>, or null when unknown. Item
|
||||
/// augmentations honour the manual override.
|
||||
/// </summary>
|
||||
public long? Get(T11Counter counter)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
if (counter == T11Counter.ItemAugmentations && _itemAugOverride.HasValue) return _itemAugOverride;
|
||||
return _counts.TryGetValue(counter, out long v) ? v : null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Forgets the "/aug" counts (logout). The manual override is kept.</summary>
|
||||
public void Clear()
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
_counts.Clear();
|
||||
UpdatedUtc = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the player meets every wield gate of <paramref name="item"/>: 1 = yes (or the
|
||||
/// item has no gate), 0 = a gate is not met, -1 = a needed counter is unknown. Mirrors the
|
||||
/// server's check (Player_Inventory, WieldRequirement.Int64Stat): raw counter >= amount.
|
||||
/// </summary>
|
||||
public int CanWield(T11ItemInfo item)
|
||||
{
|
||||
bool unknown = false;
|
||||
foreach (var gate in item.WieldGates)
|
||||
{
|
||||
long? have = Get(gate.Counter);
|
||||
if (have == null) { unknown = true; continue; }
|
||||
if (have.Value < gate.Amount) return 0;
|
||||
}
|
||||
return unknown ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads ACECustom's "/aug" reply into <see cref="T11PlayerAugs"/>. The reply is one chat line
|
||||
/// per counter ("Item:1,234", "Triune Weave: 5 (adds ...)"), so a bare "Item:" line is only
|
||||
/// trusted shortly after the "Advanced Augmentation Levels:" header.
|
||||
/// </summary>
|
||||
public sealed class T11AugReportParser
|
||||
{
|
||||
/// <summary>How long after the header (or the last accepted line) reply lines are trusted.</summary>
|
||||
public const long WindowMs = 5000;
|
||||
|
||||
private const RegexOptions Opt = RegexOptions.CultureInvariant | RegexOptions.IgnoreCase;
|
||||
private static readonly Regex Header = new(@"^Advanced Augmentation Levels:\s*$", Opt);
|
||||
private static readonly Regex Line = new(@"^(?<what>[A-Za-z' ]+?)\s*:\s*(?<n>\d[\d,.\s']*)", Opt);
|
||||
|
||||
private long _openUntil = long.MinValue;
|
||||
|
||||
/// <summary>
|
||||
/// Feeds one chat line. Returns true when it updated a counter. <paramref name="nowMs"/>
|
||||
/// is any monotonic millisecond clock.
|
||||
/// </summary>
|
||||
public bool Feed(string? text, long nowMs, T11PlayerAugs into)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text)) return false;
|
||||
string line = text.Trim();
|
||||
if (Header.IsMatch(line))
|
||||
{
|
||||
_openUntil = nowMs + WindowMs;
|
||||
return false;
|
||||
}
|
||||
if (nowMs > _openUntil) return false;
|
||||
|
||||
Match m = Line.Match(line);
|
||||
if (!m.Success) return false;
|
||||
T11Counter? counter = CounterFor(m.Groups["what"].Value.Trim());
|
||||
if (counter == null) return false;
|
||||
|
||||
long value = 0;
|
||||
foreach (char c in m.Groups["n"].Value)
|
||||
{
|
||||
if (c < '0' || c > '9') { if (c == ' ' || c == ',' || c == '.' || c == '\'') continue; break; }
|
||||
value = value * 10 + (c - '0');
|
||||
}
|
||||
into.Set(counter.Value, value);
|
||||
_openUntil = nowMs + WindowMs;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>The counter a "/aug" line label stands for, or null for the ones T11 gates don't use.</summary>
|
||||
private static T11Counter? CounterFor(string label) => label.ToLowerInvariant() switch
|
||||
{
|
||||
"item" => T11Counter.ItemAugmentations,
|
||||
"triune weave" => T11Counter.TriuneWeave,
|
||||
"battlemage's wrath charm" => T11Counter.BattlemagesWrath,
|
||||
"nether veil charm" => T11Counter.NetherVeil,
|
||||
"crashing steel charm" => T11Counter.CrashingSteel,
|
||||
"true shot charm" => T11Counter.TrueShot,
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
|
@ -1,128 +0,0 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace RynthCore.Install;
|
||||
|
||||
/// <summary>
|
||||
/// Resolves where RynthCore and RynthSuite are installed. The installer lets the user pick
|
||||
/// both folders and records them under <c>Software\Rynth</c> (HKCU for a per-user install,
|
||||
/// HKLM for an all-users install), so nothing may assume <c>C:\Games\...</c> any more.
|
||||
/// <para>
|
||||
/// Resolution order per folder: environment override (<c>RYNTHCORE_DIR</c> /
|
||||
/// <c>RYNTHSUITE_DIR</c>, for dev setups) → HKCU → HKLM (32-bit view, where the 32-bit
|
||||
/// installer writes) → the historical default under <c>C:\Games</c>. Results are cached
|
||||
/// for the life of the process.
|
||||
/// </para>
|
||||
/// Linked into the RynthAi plugin and the Loot / Monster editors. RynthCore keeps an identical copy in
|
||||
/// <c>src/RynthCore.App/RynthInstallPaths.cs</c> (engine, launcher, injector) — change both together.
|
||||
/// Registry access is a direct RegGetValueW P/Invoke so it works under NativeAOT and trimming
|
||||
/// without pulling in Microsoft.Win32.Registry.
|
||||
/// </summary>
|
||||
internal static class RynthInstallPaths
|
||||
{
|
||||
/// <summary>Default RynthCore folder (pre-2026.10.4.2 installs always used this).</summary>
|
||||
public const string DefaultCoreDir = @"C:\Games\RynthCore";
|
||||
|
||||
/// <summary>Default RynthSuite folder (pre-2026.10.4.2 installs always used this).</summary>
|
||||
public const string DefaultSuiteDir = @"C:\Games\RynthSuite";
|
||||
|
||||
/// <summary>Registry key (under HKCU or HKLM) written by the installer.</summary>
|
||||
public const string RegistryKey = @"Software\Rynth";
|
||||
|
||||
private static string? _coreDir;
|
||||
private static string? _suiteDir;
|
||||
|
||||
/// <summary>RynthCore install folder (launcher, <c>Runtime\</c>, <c>Logs\</c>, <c>Tools\</c>).</summary>
|
||||
public static string CoreDir => _coreDir ??= Resolve("RYNTHCORE_DIR", "CoreDir", DefaultCoreDir);
|
||||
|
||||
/// <summary>RynthSuite folder (plugins and their data, e.g. <c>RynthAi\</c>).</summary>
|
||||
public static string SuiteDir => _suiteDir ??= Resolve("RYNTHSUITE_DIR", "SuiteDir", DefaultSuiteDir);
|
||||
|
||||
/// <summary>Unified RynthCore log folder (<c><CoreDir>\Logs</c>).</summary>
|
||||
public static string CoreLogsDir => Path.Combine(CoreDir, "Logs");
|
||||
|
||||
/// <summary>RynthAi plugin home and data root (<c><SuiteDir>\RynthAi</c>).</summary>
|
||||
public static string RynthAiDir => Path.Combine(SuiteDir, "RynthAi");
|
||||
|
||||
/// <summary>Reads a string value from <c>Software\Rynth</c> (HKCU first, then HKLM 32-bit view); null when absent.</summary>
|
||||
public static string? ReadSetting(string valueName)
|
||||
=> ReadRegistryString(HKEY_CURRENT_USER, valueName, 0)
|
||||
?? ReadRegistryString(HKEY_LOCAL_MACHINE, valueName, RRF_SUBKEY_WOW6432KEY);
|
||||
|
||||
/// <summary>Deletes a value from HKCU <c>Software\Rynth</c> (used for one-shot installer hand-offs). Best effort.</summary>
|
||||
public static void DeleteUserSetting(string valueName)
|
||||
{
|
||||
try { RegDeleteKeyValueW(HKEY_CURRENT_USER, RegistryKey, valueName); } catch { }
|
||||
}
|
||||
|
||||
private static string Resolve(string envVar, string valueName, string fallback)
|
||||
{
|
||||
string? fromEnv = null;
|
||||
try { fromEnv = Environment.GetEnvironmentVariable(envVar); } catch { }
|
||||
|
||||
foreach (string? candidate in new[] { fromEnv, ReadSetting(valueName) })
|
||||
{
|
||||
string? normalized = Normalize(candidate);
|
||||
if (normalized != null) return normalized;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/// <summary>Accepts only absolute paths; trims whitespace, quotes and trailing separators.</summary>
|
||||
private static string? Normalize(string? path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path)) return null;
|
||||
string p = path.Trim().Trim('"').TrimEnd('\\', '/');
|
||||
if (p.Length == 2 && p[1] == ':') p += "\\"; // keep "D:" as the drive root "D:\"
|
||||
try
|
||||
{
|
||||
if (!Path.IsPathFullyQualified(p)) return null;
|
||||
string full = Path.GetFullPath(p);
|
||||
return full.Length > 3 ? full.TrimEnd('\\') : full; // "D:\" stays a root
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Win32 registry (advapi32) ───────────────────────────────────────────
|
||||
|
||||
private static readonly IntPtr HKEY_CURRENT_USER = new(unchecked((int)0x80000001));
|
||||
private static readonly IntPtr HKEY_LOCAL_MACHINE = new(unchecked((int)0x80000002));
|
||||
private const uint RRF_RT_REG_SZ = 0x00000002;
|
||||
private const uint RRF_RT_REG_EXPAND_SZ = 0x00000004;
|
||||
private const uint RRF_SUBKEY_WOW6432KEY = 0x00020000;
|
||||
private const int ERROR_SUCCESS = 0;
|
||||
|
||||
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
|
||||
private static extern int RegGetValueW(IntPtr hkey, string lpSubKey, string lpValue, uint dwFlags,
|
||||
IntPtr pdwType, char[]? pvData, ref uint pcbData);
|
||||
|
||||
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
|
||||
private static extern int RegDeleteKeyValueW(IntPtr hkey, string lpSubKey, string lpValueName);
|
||||
|
||||
private static string? ReadRegistryString(IntPtr root, string valueName, uint viewFlags)
|
||||
{
|
||||
try
|
||||
{
|
||||
uint flags = RRF_RT_REG_SZ | RRF_RT_REG_EXPAND_SZ | viewFlags;
|
||||
uint bytes = 0;
|
||||
if (RegGetValueW(root, RegistryKey, valueName, flags, IntPtr.Zero, null, ref bytes) != ERROR_SUCCESS || bytes < 2)
|
||||
return null;
|
||||
|
||||
var buffer = new char[(bytes + 1) / 2];
|
||||
if (RegGetValueW(root, RegistryKey, valueName, flags, IntPtr.Zero, buffer, ref bytes) != ERROR_SUCCESS)
|
||||
return null;
|
||||
|
||||
int len = Array.IndexOf(buffer, '\0');
|
||||
return new string(buffer, 0, len >= 0 ? len : buffer.Length);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Missing advapi32 entry point or access denied — fall back to the defaults.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue