feat(rynthai): enhance T11 item support and logging
- Added new command `/ra t11` for T11 loot management, including wield counters and aug overrides. - Improved logging for item info requests and decisions, providing clearer insights into item handling. - Updated item info processing to accommodate T11-specific attributes and conditions. - Enhanced settings to allow for T11 item augmentation overrides. - Adjusted various components to ensure compatibility with T11 features, including loot rules and item descriptions. This update aims to streamline the integration of T11 mechanics into the RynthAi plugin, enhancing user experience and functionality.
This commit is contained in:
parent
7bcc954ecc
commit
2f38fd6baf
25 changed files with 1993 additions and 39 deletions
|
|
@ -38,17 +38,25 @@ public static class LootRuleText
|
|||
|
||||
// ── Key tables (the common ones; unknown ids show as "key N") ──────────
|
||||
|
||||
public static readonly (int Id, string Name)[] LongKeys =
|
||||
/// <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()
|
||||
{
|
||||
(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
|
||||
};
|
||||
var keys = new List<(int, string)>
|
||||
{
|
||||
(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"), (377, "NetherResistRating"), (379, "VitalityRating"),
|
||||
(0x0D000000, "Type (WCID)"), // Decal's synthetic key: the weenie class id
|
||||
};
|
||||
keys.AddRange(T11.T11Keys.Names());
|
||||
return keys.ToArray();
|
||||
}
|
||||
|
||||
public static readonly (int Id, string Name)[] DoubleKeys =
|
||||
{
|
||||
|
|
@ -56,9 +64,10 @@ public static class LootRuleText
|
|||
(63, "WeaponOffense"), (152, "ElementalDamageVsMonsters"), (167, "ManaRate"),
|
||||
};
|
||||
|
||||
/// <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 +94,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>
|
||||
|
|
@ -134,6 +146,7 @@ public static class LootRuleText
|
|||
131 => Materials,
|
||||
158 => WieldRequirements,
|
||||
159 => Skills,
|
||||
T11.T11Keys.WeaponGrade => T11.T11Catalog.Grades,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
|
|
@ -141,7 +154,7 @@ public static class LootRuleText
|
|||
public static bool ValueTableIsFlags(int longKey) => longKey == 45;
|
||||
|
||||
/// <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, 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,
|
||||
};
|
||||
}
|
||||
Loading…
Reference in a new issue