RynthSuite as of 2026-11-29 (internal 46bae49): release 2026.11.28.1
This commit is contained in:
parent
25552fa794
commit
598f49c899
131 changed files with 11825 additions and 329 deletions
|
|
@ -0,0 +1,643 @@
|
|||
// ============================================================================
|
||||
// RynthDefective - Appraisal/AppraisalText.cs
|
||||
// What the Appraisal window says about an object (2026-11-28: all the data,
|
||||
// roughly in the retail layout): the retail examine panel's
|
||||
// lines in its order and words where retail has them ("Value:", "Damage:
|
||||
// 25 - 50, Slashing", "Bonus to Melee Defense: +15%.", "Spellcraft: 400.",
|
||||
// "Wield requires Heavy Weapons 400", ...), grouped under small headings, and
|
||||
// every property the engine holds at the end (the "All properties" list).
|
||||
//
|
||||
// Pure: an AppraisalInput (the engine's ObjectProperties dictionaries, the
|
||||
// creature's vitals and attributes, a spell name lookup) in, an AppraisalDoc
|
||||
// out. The tests run it (Tools/RynthDefective.Tests).
|
||||
//
|
||||
// Property ids are ACE's (PropertyInt/Float/String/Bool/DataId); the name
|
||||
// tables are RynthAi's (MagItemInfoTables, PropertyNames, linked in).
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using RynthCore.Plugin.RynthAi.ItemInfo;
|
||||
using RynthCore.Plugin.RynthAi.Meta;
|
||||
|
||||
namespace RynthCore.Plugin.RynthDefective.Appraisal;
|
||||
|
||||
/// <summary>How a line is coloured.</summary>
|
||||
internal enum AppraiseTone { Text, Dim, Good, Bad, Magic, Gold }
|
||||
|
||||
internal readonly record struct AppraiseLine(string Text, AppraiseTone Tone = AppraiseTone.Text);
|
||||
|
||||
internal sealed class AppraiseSection
|
||||
{
|
||||
public AppraiseSection(string title) { Title = title; }
|
||||
public string Title { get; }
|
||||
public List<AppraiseLine> Lines { get; } = new();
|
||||
public void Add(string text, AppraiseTone tone = AppraiseTone.Text) { if (text.Length > 0) Lines.Add(new AppraiseLine(text, tone)); }
|
||||
}
|
||||
|
||||
/// <summary>A bar under the name: a creature's Health / Stamina / Mana, an item's mana. Max 0 = only the ratio is known.</summary>
|
||||
internal readonly record struct AppraiseBar(string Label, uint Current, uint Max, float Ratio, AppraiseBarKind Kind);
|
||||
internal enum AppraiseBarKind { Health, Stamina, Mana }
|
||||
|
||||
/// <summary>One raw property for the "All properties" list.</summary>
|
||||
internal readonly record struct AppraiseRaw(string Kind, uint Key, string Name, string Value);
|
||||
|
||||
internal sealed class AppraisalDoc
|
||||
{
|
||||
public uint Id { get; init; }
|
||||
public string Name { get; init; } = string.Empty;
|
||||
/// <summary>What it is, under the name: "Heavy Weapons (Sword)", "Level 112 Olthoi", "Jewelry".</summary>
|
||||
public string Kind { get; init; } = string.Empty;
|
||||
/// <summary>The short facts beside the picture: Value, Burden, a stack, uses.</summary>
|
||||
public List<(string Label, string Value)> Facts { get; } = new();
|
||||
public List<AppraiseBar> Bars { get; } = new();
|
||||
/// <summary>A creature's six attributes (Strength .. Self), when assessed; empty otherwise.</summary>
|
||||
public List<(string Label, uint Value, bool Buffed, bool Up)> Attributes { get; } = new();
|
||||
public List<AppraiseSection> Sections { get; } = new();
|
||||
public string Description { get; init; } = string.Empty;
|
||||
public List<AppraiseRaw> Raw { get; } = new();
|
||||
public bool Identified { get; init; }
|
||||
public bool IsCreature { get; init; }
|
||||
|
||||
/// <summary>The whole appraisal as text (the window's Copy).</summary>
|
||||
public string ToText()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine(Name);
|
||||
if (Kind.Length > 0) sb.AppendLine(Kind);
|
||||
foreach (var (label, value) in Facts) sb.AppendLine(label + ": " + value);
|
||||
foreach (var b in Bars)
|
||||
sb.AppendLine(b.Max > 0 ? $"{b.Label}: {b.Current:N0} / {b.Max:N0}" : $"{b.Label}: {MathF.Round(b.Ratio * 100f):0}%");
|
||||
foreach (var a in Attributes) sb.AppendLine($"{a.Label}: {a.Value}");
|
||||
foreach (var s in Sections)
|
||||
{
|
||||
sb.AppendLine().AppendLine(s.Title);
|
||||
foreach (var l in s.Lines) sb.AppendLine(" " + l.Text);
|
||||
}
|
||||
if (Description.Length > 0) sb.AppendLine().AppendLine(Description);
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>What the builder reads: the engine's view of the object.</summary>
|
||||
internal sealed class AppraisalInput
|
||||
{
|
||||
public uint Id;
|
||||
public string Name = string.Empty;
|
||||
/// <summary>The ItemType flags (TryGetItemType) when the properties have none.</summary>
|
||||
public uint ItemType;
|
||||
public bool Identified;
|
||||
public bool IsPlayer;
|
||||
public Dictionary<uint, int> Ints = new();
|
||||
public Dictionary<uint, long> Int64s = new();
|
||||
public Dictionary<uint, bool> Bools = new();
|
||||
public Dictionary<uint, double> Floats = new();
|
||||
public Dictionary<uint, string> Strings = new();
|
||||
public Dictionary<uint, uint> DataIds = new();
|
||||
public Dictionary<uint, uint> InstanceIds = new();
|
||||
public List<uint> Spells = new();
|
||||
/// <summary>Health, Stamina, Mana (current, max) from the last assess; null none.</summary>
|
||||
public (uint H, uint HMax, uint S, uint SMax, uint M, uint MMax)? Vitals;
|
||||
/// <summary>The server's last health ratio for it, -1 none.</summary>
|
||||
public float HealthRatio = -1f;
|
||||
/// <summary>Strength, Endurance, Quickness, Coordination, Focus, Self; null not assessed.</summary>
|
||||
public uint[]? Attributes;
|
||||
public uint EnchantBits;
|
||||
public Func<uint, string> SpellName = id => "Spell " + id.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
internal static class AppraisalText
|
||||
{
|
||||
// ── ACE property ids ─────────────────────────────────────────────────────
|
||||
private const uint IItemType = 1, ICreatureType = 2, IClothingPriority = 4, IBurden = 5, IItemsCapacity = 6,
|
||||
IContainersCapacity = 7, IValidLocations = 9, IMaxStack = 11, IStack = 12, IRareId = 17, IValue = 19, ILevel = 25,
|
||||
IArmorLevel = 28, IAllegianceRank = 30, IBonded = 33, IResistMagic = 36, INumDeaths = 43, IDamage = 44,
|
||||
IDamageType = 45, IWeaponSkill = 48, IWeaponTime = 49, IAmmoType = 50, IMinLevel = 86, IMaxLevel = 87,
|
||||
ILockpickMod = 88, IBoostValue = 90, IMaxStructure = 91, IStructure = 92, IWorkmanship = 105, ISpellcraft = 106,
|
||||
ICurMana = 107, IMaxMana = 108, IArcaneLore = 109, IAllegianceRankLimit = 110, IGender = 113, IAttuned = 114,
|
||||
ISkillLevelLimit = 115, IMaterial = 131, IPkStatus = 134, ISlayerType = 166, INumItemsInMaterial = 170,
|
||||
ITinkered = 171, IImbued = 179, IHeritage = 188, IElementalBonus = 204, ISet = 265, IRemainingLifespan = 268,
|
||||
IUnique = 279, ICleaving = 292, IItemMaxLevel = 319, IWeaponType = 353, IUseRequiresLevel = 369;
|
||||
private static readonly uint[] WieldReq = { 158, 270, 273, 276 }, WieldSkill = { 159, 271, 274, 277 }, WieldDiff = { 160, 272, 275, 278 };
|
||||
private static readonly uint[] MoreImbues = { 303, 304, 305, 306 };
|
||||
|
||||
private const uint FManaRate = 5, FDamageVariance = 22, FWeaponDefense = 29, FWeaponOffense = 62, FDamageMod = 63,
|
||||
FHealkitMod = 100, FSlayerBonus = 138, FManaConversion = 144, FMissileDefense = 149, FMagicDefense = 150,
|
||||
FElementalMod = 152, FArmorVsNether = 165;
|
||||
private static readonly (uint Key, string Name)[] ArmorMods =
|
||||
{
|
||||
(13, "Slashing"), (14, "Piercing"), (15, "Bludgeoning"), (16, "Cold"), (17, "Fire"), (18, "Acid"), (19, "Electric"), (FArmorVsNether, "Nether"),
|
||||
};
|
||||
|
||||
private const uint SName = 1, STitle = 2, STemplate = 5, SInscription = 7, SScribe = 8, SFellowship = 10, SMonarch = 11,
|
||||
SUse = 14, SShortDesc = 15, SLongDesc = 16, SCraftsman = 25, SPortalDest = 38, STinker = 39, SImbuer = 40,
|
||||
SDateOfBirth = 43, SAllegiance = 47, SPlating = 52;
|
||||
private const uint BRetained = 91, BIvoryable = 99, BDyable = 100, BUnlimitedUse = 63, BLocked = 3, BInscribable = 22;
|
||||
private const uint DSpell = 28, DSkillLimit = 37, DSpecializedOnly = 41, DProcSpell = 55;
|
||||
|
||||
private const uint TypeMelee = 0x1, TypeArmor = 0x2, TypeClothing = 0x4, TypeJewelry = 0x8, TypeCreature = 0x10,
|
||||
TypeMissile = 0x100, TypeContainer = 0x200, TypeCaster = 0x8000, TypePortal = 0x10000, TypeManaStone = 0x80000;
|
||||
|
||||
private static readonly CultureInfo Inv = CultureInfo.InvariantCulture;
|
||||
|
||||
public static AppraisalDoc Build(AppraisalInput o)
|
||||
{
|
||||
int type = I(o, IItemType, (int)o.ItemType);
|
||||
uint t = unchecked((uint)type);
|
||||
bool creature = (t & TypeCreature) != 0 || o.IsPlayer || o.Attributes != null || o.Vitals != null;
|
||||
string name = S(o, SName, o.Name);
|
||||
if (name.Length == 0) name = $"0x{o.Id:X8}";
|
||||
|
||||
var doc = new AppraisalDoc
|
||||
{
|
||||
Id = o.Id,
|
||||
Name = name,
|
||||
Kind = creature ? CreatureKind(o) : ItemKind(o, t),
|
||||
Description = S(o, SLongDesc, S(o, SShortDesc, "")),
|
||||
Identified = o.Identified,
|
||||
IsCreature = creature,
|
||||
};
|
||||
|
||||
if (creature) CreatureBody(o, doc);
|
||||
else ItemBody(o, t, doc);
|
||||
|
||||
Raw(o, doc);
|
||||
return doc;
|
||||
}
|
||||
|
||||
// ── Creatures and players ─────────────────────────────────────────────────
|
||||
|
||||
private static string CreatureKind(AppraisalInput o)
|
||||
{
|
||||
var parts = new List<string>(3);
|
||||
int level = I(o, ILevel, 0);
|
||||
if (level > 0) parts.Add("Level " + level.ToString(Inv));
|
||||
if (o.IsPlayer)
|
||||
{
|
||||
string heritage = Heritage(I(o, IHeritage, 0));
|
||||
string gender = I(o, IGender, 0) switch { 1 => "Male", 2 => "Female", _ => "" };
|
||||
string who = (heritage + " " + gender).Trim();
|
||||
if (who.Length > 0) parts.Add(who);
|
||||
}
|
||||
else if (MagItemInfoTables.CreatureTypeName(I(o, ICreatureType, 0)) is { } kind) parts.Add(kind);
|
||||
return string.Join(" · ", parts);
|
||||
}
|
||||
|
||||
private static readonly string[] AttributeNames = { "Strength", "Endurance", "Quickness", "Coordination", "Focus", "Self" };
|
||||
|
||||
private static void CreatureBody(AppraisalInput o, AppraisalDoc doc)
|
||||
{
|
||||
if (o.Vitals is { } v && v.HMax > 0)
|
||||
{
|
||||
doc.Bars.Add(new AppraiseBar("Health", v.H, v.HMax, Ratio(v.H, v.HMax, o.HealthRatio), AppraiseBarKind.Health));
|
||||
if (v.SMax > 0) doc.Bars.Add(new AppraiseBar("Stamina", v.S, v.SMax, v.S / (float)v.SMax, AppraiseBarKind.Stamina));
|
||||
if (v.MMax > 0) doc.Bars.Add(new AppraiseBar("Mana", v.M, v.MMax, v.M / (float)v.MMax, AppraiseBarKind.Mana));
|
||||
}
|
||||
else if (o.HealthRatio >= 0f)
|
||||
doc.Bars.Add(new AppraiseBar("Health", 0, 0, o.HealthRatio, AppraiseBarKind.Health));
|
||||
|
||||
if (o.Attributes is { Length: >= 6 } a)
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
bool buffed = (o.EnchantBits & (1u << i)) != 0, up = (o.EnchantBits & (1u << (16 + i))) != 0;
|
||||
doc.Attributes.Add((AttributeNames[i], a[i], buffed, up));
|
||||
}
|
||||
|
||||
var who = new AppraiseSection(o.IsPlayer ? "Character" : "Creature");
|
||||
if (o.IsPlayer)
|
||||
{
|
||||
who.Add(S(o, STitle, "") is { Length: > 0 } title ? "Title: " + title : "");
|
||||
who.Add(S(o, STemplate, "") is { Length: > 0 } tpl ? "Template: " + tpl : "");
|
||||
who.Add(PkStatus(I(o, IPkStatus, 0)));
|
||||
who.Add(S(o, SAllegiance, "") is { Length: > 0 } al ? "Allegiance: " + al : "");
|
||||
who.Add(S(o, SMonarch, "") is { Length: > 0 } mon ? "Monarch: " + mon : "");
|
||||
who.Add(I(o, IAllegianceRank, 0) is > 0 and var rank ? "Rank: " + rank.ToString(Inv) : "");
|
||||
who.Add(S(o, SFellowship, "") is { Length: > 0 } fel ? "Fellowship: " + fel : "");
|
||||
who.Add(I(o, INumDeaths, 0) is > 0 and var deaths ? "Deaths: " + deaths.ToString("N0", Inv) : "", AppraiseTone.Dim);
|
||||
who.Add(S(o, SDateOfBirth, "") is { Length: > 0 } dob ? "Born: " + dob : "", AppraiseTone.Dim);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (MagItemInfoTables.CreatureTypeName(I(o, ICreatureType, 0)) is { } kind) who.Add("Type: " + kind);
|
||||
if (o.Attributes == null && o.Identified)
|
||||
who.Add("Your assess failed: only its health is known.", AppraiseTone.Dim);
|
||||
}
|
||||
if (who.Lines.Count > 0) doc.Sections.Add(who);
|
||||
if (!o.Identified)
|
||||
doc.Sections.Add(Note("Not assessed yet: asked the server."));
|
||||
}
|
||||
|
||||
// ── Items ─────────────────────────────────────────────────────────────────
|
||||
|
||||
private static string ItemKind(AppraisalInput o, uint t)
|
||||
{
|
||||
if ((t & (TypeMelee | TypeMissile | TypeCaster)) != 0)
|
||||
{
|
||||
string skill = Skill(I(o, IWeaponSkill, 0));
|
||||
string mastery = MagItemInfoTables.Masteries.TryGetValue(I(o, IWeaponType, 0), out string? m) ? m : "";
|
||||
if ((t & TypeCaster) != 0) return "Caster" + (mastery.Length > 0 && mastery != "Wand" ? " (" + mastery + ")" : "");
|
||||
if (skill.Length > 0) return mastery.Length > 0 ? $"{skill} ({mastery})" : skill;
|
||||
return (t & TypeMissile) != 0 ? "Missile weapon" : "Melee weapon";
|
||||
}
|
||||
if ((t & TypeArmor) != 0) return (I(o, IValidLocations, 0) & 0x200000) != 0 ? "Shield" : "Armor";
|
||||
if ((t & TypeClothing) != 0) return "Clothing";
|
||||
if ((t & TypeJewelry) != 0) return "Jewelry";
|
||||
if ((t & TypePortal) != 0) return "Portal";
|
||||
if ((t & TypeContainer) != 0) return "Container";
|
||||
if ((t & TypeManaStone) != 0) return "Mana stone";
|
||||
return MagItemInfoTables.Materials.TryGetValue(I(o, IMaterial, 0), out string? mat) && I(o, INumItemsInMaterial, 0) > 0
|
||||
? "Salvage (" + mat + ")" : "";
|
||||
}
|
||||
|
||||
private static void ItemBody(AppraisalInput o, uint t, AppraisalDoc doc)
|
||||
{
|
||||
// The facts beside the picture.
|
||||
if (Has(o, IValue)) doc.Facts.Add(("Value", I(o, IValue, 0).ToString("N0", Inv)));
|
||||
if (Has(o, IBurden)) doc.Facts.Add(("Burden", I(o, IBurden, 0).ToString("N0", Inv)));
|
||||
int stack = I(o, IStack, 0), maxStack = I(o, IMaxStack, 0);
|
||||
if (stack > 1 || maxStack > 1) doc.Facts.Add(("Stack", maxStack > 1 ? $"{stack:N0} / {maxStack:N0}" : stack.ToString("N0", Inv)));
|
||||
int uses = I(o, IStructure, -1), maxUses = I(o, IMaxStructure, 0);
|
||||
if (maxUses > 0 && uses >= 0) doc.Facts.Add(("Uses", $"{uses:N0} / {maxUses:N0}"));
|
||||
else if (B(o, BUnlimitedUse)) doc.Facts.Add(("Uses", "unlimited"));
|
||||
|
||||
int maxMana = I(o, IMaxMana, 0);
|
||||
if (maxMana > 0)
|
||||
{
|
||||
int cur = Math.Clamp(I(o, ICurMana, 0), 0, maxMana);
|
||||
doc.Bars.Add(new AppraiseBar("Mana", (uint)cur, (uint)maxMana, cur / (float)maxMana, AppraiseBarKind.Mana));
|
||||
}
|
||||
|
||||
Combat(o, t, doc);
|
||||
Armor(o, t, doc);
|
||||
Magic(o, doc);
|
||||
Requirements(o, doc);
|
||||
Properties(o, doc);
|
||||
|
||||
if (!o.Identified)
|
||||
doc.Sections.Add(Note("Not appraised yet: asked the server. Only what the client saw is shown."));
|
||||
}
|
||||
|
||||
private static void Combat(AppraisalInput o, uint t, AppraisalDoc doc)
|
||||
{
|
||||
bool melee = (t & TypeMelee) != 0, missile = (t & TypeMissile) != 0, caster = (t & TypeCaster) != 0;
|
||||
bool anyDefense = HasF(o, FWeaponDefense) || HasF(o, FMissileDefense) || HasF(o, FMagicDefense);
|
||||
if (!melee && !missile && !caster && !anyDefense) return;
|
||||
var s = new AppraiseSection(caster ? "Caster" : "Weapon");
|
||||
|
||||
string skill = Skill(I(o, IWeaponSkill, 0));
|
||||
if (skill.Length > 0 && !caster)
|
||||
{
|
||||
string mastery = MagItemInfoTables.Masteries.TryGetValue(I(o, IWeaponType, 0), out string? m) ? " (" + m + ")" : "";
|
||||
s.Add("Skill: " + skill + mastery);
|
||||
}
|
||||
|
||||
string dtype = DamageTypes(I(o, IDamageType, 0));
|
||||
if (melee && Has(o, IDamage))
|
||||
{
|
||||
double max = I(o, IDamage, 0), variance = F(o, FDamageVariance, 0);
|
||||
double min = max * (1 - variance);
|
||||
s.Add($"Damage: {Num(min)} - {Num(max)}{(dtype.Length > 0 ? ", " + dtype : "")}");
|
||||
}
|
||||
if (missile)
|
||||
{
|
||||
if (HasF(o, FDamageMod)) s.Add($"Damage Modifier: {Pct(F(o, FDamageMod, 1) - 1)}.");
|
||||
if (I(o, IElementalBonus, 0) is > 0 and var eb) s.Add($"Elemental Damage Bonus: {eb.ToString(Inv)}{(dtype.Length > 0 ? ", " + dtype : "")}.");
|
||||
string ammo = I(o, IAmmoType, 0) switch { 1 => "arrows", 2 => "quarrels", 4 => "atlatl darts", _ => "" };
|
||||
if (ammo.Length > 0) s.Add($"Uses {ammo} as ammunition.", AppraiseTone.Dim);
|
||||
}
|
||||
if ((melee || missile) && Has(o, IWeaponTime))
|
||||
{
|
||||
int speed = I(o, IWeaponTime, 0);
|
||||
s.Add($"Speed: {SpeedName(speed)} ({speed.ToString(Inv)})");
|
||||
}
|
||||
if (HasF(o, FWeaponOffense) && Math.Abs(F(o, FWeaponOffense, 1) - 1) > 1e-6)
|
||||
s.Add($"Bonus to Attack Skill: {Pct(F(o, FWeaponOffense, 1) - 1)}.", AppraiseTone.Good);
|
||||
if (caster && HasF(o, FManaConversion) && F(o, FManaConversion, 0) > 1e-6)
|
||||
s.Add($"Bonus to Mana Conversion: {Pct(F(o, FManaConversion, 0))}.", AppraiseTone.Good);
|
||||
if (caster && HasF(o, FElementalMod) && F(o, FElementalMod, 1) > 1 + 1e-6)
|
||||
{
|
||||
double b = F(o, FElementalMod, 1) - 1;
|
||||
string element = dtype.Length > 0 ? dtype : "all";
|
||||
s.Add($"Damage bonus for {element} spells: {Pct(b)} vs. Monsters, {Pct(b / 4)} vs. Players.", AppraiseTone.Good);
|
||||
}
|
||||
if (HasF(o, FWeaponDefense) && Math.Abs(F(o, FWeaponDefense, 1) - 1) > 1e-6)
|
||||
s.Add($"Bonus to Melee Defense: {Pct(F(o, FWeaponDefense, 1) - 1)}.", AppraiseTone.Good);
|
||||
if (HasF(o, FMissileDefense) && Math.Abs(F(o, FMissileDefense, 1) - 1) > 1e-6)
|
||||
s.Add($"Bonus to Missile Defense: {Pct(F(o, FMissileDefense, 1) - 1)}.", AppraiseTone.Good);
|
||||
if (HasF(o, FMagicDefense) && Math.Abs(F(o, FMagicDefense, 1) - 1) > 1e-6)
|
||||
s.Add($"Bonus to Magic Defense: {Pct(F(o, FMagicDefense, 1) - 1)}.", AppraiseTone.Good);
|
||||
|
||||
if (MagItemInfoTables.CreatureTypeName(I(o, ISlayerType, 0)) is { } slayer)
|
||||
s.Add($"Slayer: {slayer}{(HasF(o, FSlayerBonus) ? $" (x{F(o, FSlayerBonus, 1).ToString("0.##", Inv)} damage)" : "")}", AppraiseTone.Good);
|
||||
if (I(o, ICleaving, 0) is > 1 and var cleave) s.Add($"Cleaving: hits up to {cleave.ToString(Inv)} enemies.", AppraiseTone.Good);
|
||||
|
||||
string imbues = Imbues(o);
|
||||
if (imbues.Length > 0) s.Add("Imbued: " + imbues, AppraiseTone.Good);
|
||||
|
||||
if (s.Lines.Count > 0) doc.Sections.Add(s);
|
||||
}
|
||||
|
||||
private static void Armor(AppraisalInput o, uint t, AppraisalDoc doc)
|
||||
{
|
||||
if (!Has(o, IArmorLevel) && (t & (TypeArmor | TypeClothing)) == 0) return;
|
||||
var s = new AppraiseSection("Armor");
|
||||
int al = I(o, IArmorLevel, 0);
|
||||
if (Has(o, IArmorLevel)) s.Add("Armor Level: " + al.ToString("N0", Inv));
|
||||
if (al > 0)
|
||||
foreach (var (key, label) in ArmorMods)
|
||||
{
|
||||
if (!HasF(o, key)) continue;
|
||||
double mod = F(o, key, 1);
|
||||
s.Add($"{label}: {ProtectionName(mod)} ({Math.Round(al * mod).ToString("N0", Inv)})", mod >= 1.2 ? AppraiseTone.Good : mod < 0.8 ? AppraiseTone.Bad : AppraiseTone.Text);
|
||||
}
|
||||
string covers = Coverage(I(o, IClothingPriority, 0));
|
||||
if (covers.Length > 0) s.Add("Covers: " + covers, AppraiseTone.Dim);
|
||||
if (s.Lines.Count > 0) doc.Sections.Add(s);
|
||||
}
|
||||
|
||||
private static void Magic(AppraisalInput o, AppraisalDoc doc)
|
||||
{
|
||||
var s = new AppraiseSection("Magic");
|
||||
if (o.Spells.Count > 0)
|
||||
{
|
||||
var names = new List<string>(o.Spells.Count);
|
||||
foreach (uint id in o.Spells) names.Add(o.SpellName(id));
|
||||
s.Add("Spells: " + string.Join(", ", names), AppraiseTone.Magic);
|
||||
}
|
||||
if (o.DataIds.TryGetValue(DSpell, out uint spell) && spell != 0 && !o.Spells.Contains(spell))
|
||||
s.Add("Spell: " + o.SpellName(spell), AppraiseTone.Magic);
|
||||
if (o.DataIds.TryGetValue(DProcSpell, out uint proc) && proc != 0)
|
||||
s.Add("Casts on a hit: " + o.SpellName(proc), AppraiseTone.Magic);
|
||||
int maxMana = I(o, IMaxMana, 0);
|
||||
if (maxMana > 0) s.Add($"Mana: {Math.Clamp(I(o, ICurMana, 0), 0, maxMana):N0} / {maxMana:N0}");
|
||||
double rate = F(o, FManaRate, 0);
|
||||
if (rate < -1e-9)
|
||||
{
|
||||
double seconds = -1 / rate;
|
||||
s.Add($"Mana Cost: 1 point per {Num(seconds)} seconds.", AppraiseTone.Dim);
|
||||
}
|
||||
if (I(o, ISpellcraft, 0) is > 0 and var sc) s.Add($"Spellcraft: {sc.ToString(Inv)}.");
|
||||
if (s.Lines.Count > 0) doc.Sections.Add(s);
|
||||
}
|
||||
|
||||
private static void Requirements(AppraisalInput o, AppraisalDoc doc)
|
||||
{
|
||||
var s = new AppraiseSection("Requirements");
|
||||
for (int i = 0; i < WieldReq.Length; i++)
|
||||
{
|
||||
int req = I(o, WieldReq[i], 0);
|
||||
if (req == 0) continue;
|
||||
int what = I(o, WieldSkill[i], 0), diff = I(o, WieldDiff[i], 0);
|
||||
s.Add(WieldLine(req, what, diff));
|
||||
}
|
||||
if (I(o, IArcaneLore, 0) is > 0 and var lore) s.Add($"Activation requires Arcane Lore: {lore.ToString(Inv)}");
|
||||
if (o.DataIds.TryGetValue(DSkillLimit, out uint sk) && sk != 0)
|
||||
{
|
||||
int level = I(o, ISkillLevelLimit, 0);
|
||||
s.Add($"Activation requires {Skill((int)sk)}{(level > 0 ? ": " + level.ToString(Inv) : "")}");
|
||||
}
|
||||
if (o.DataIds.TryGetValue(DSpecializedOnly, out uint spec) && spec != 0)
|
||||
s.Add($"Activation requires specialized {Skill((int)spec)}");
|
||||
if (I(o, IAllegianceRankLimit, 0) is > 0 and var rank) s.Add($"Activation requires Allegiance Rank: {rank.ToString(Inv)}");
|
||||
if (I(o, IUseRequiresLevel, 0) is > 0 and var ul) s.Add($"Use requires level {ul.ToString(Inv)}");
|
||||
int min = I(o, IMinLevel, 0), max = I(o, IMaxLevel, 0);
|
||||
if (min > 0 && max > 0) s.Add($"Restricted to characters of levels {min.ToString(Inv)} to {max.ToString(Inv)}.");
|
||||
else if (min > 0) s.Add($"Restricted to characters of level {min.ToString(Inv)} or greater.");
|
||||
else if (max > 0) s.Add($"Restricted to characters of level {max.ToString(Inv)} or below.");
|
||||
if (S(o, SPortalDest, "") is { Length: > 0 } dest) s.Add("Destination: " + dest);
|
||||
if (s.Lines.Count > 0) doc.Sections.Add(s);
|
||||
}
|
||||
|
||||
private static void Properties(AppraisalInput o, AppraisalDoc doc)
|
||||
{
|
||||
var s = new AppraiseSection("Properties");
|
||||
int work = I(o, IWorkmanship, 0), items = I(o, INumItemsInMaterial, 0);
|
||||
string material = MagItemInfoTables.Materials.TryGetValue(I(o, IMaterial, 0), out string? mat) ? mat : "";
|
||||
if (work > 0 && items > 0)
|
||||
s.Add($"Workmanship: {(work / (double)items).ToString("0.00", Inv)} (salvaged from {items.ToString(Inv)} item{(items == 1 ? "" : "s")})");
|
||||
else if (work > 0) s.Add($"Workmanship: {WorkmanshipName(work)} ({work.ToString(Inv)})");
|
||||
if (material.Length > 0) s.Add("Material: " + material);
|
||||
if (MagItemInfoTables.EquipmentSets.TryGetValue(I(o, ISet, 0), out string? set)) s.Add("Set: " + set, AppraiseTone.Gold);
|
||||
|
||||
// Ratings (gear): "Damage Rating +3".
|
||||
var ratings = new List<string>();
|
||||
foreach (var (key, label) in Ratings)
|
||||
if (I(o, key, 0) is > 0 and var r) ratings.Add($"{label} +{r.ToString(Inv)}");
|
||||
if (ratings.Count > 0) s.Add("Ratings: " + string.Join(", ", ratings), AppraiseTone.Good);
|
||||
|
||||
if (I(o, IItemMaxLevel, 0) is > 0 and var maxLevel) s.Add($"Item levels: up to {maxLevel.ToString(Inv)}", AppraiseTone.Dim);
|
||||
if (I(o, ITinkered, 0) is > 0 and var tinkered) s.Add($"This item has been tinkered {tinkered.ToString(Inv)} time{(tinkered == 1 ? "" : "s")}.");
|
||||
if (S(o, SImbuer, "") is { Length: > 0 } imbuer) s.Add("Imbued by " + imbuer + ".", AppraiseTone.Dim);
|
||||
if (S(o, STinker, "") is { Length: > 0 } tinker) s.Add("Last tinkered by " + tinker + ".", AppraiseTone.Dim);
|
||||
if (S(o, SCraftsman, "") is { Length: > 0 } maker) s.Add("Created by " + maker + ".", AppraiseTone.Dim);
|
||||
if (S(o, SPlating, "") is { Length: > 0 } plating) s.Add("Plating: " + plating, AppraiseTone.Dim);
|
||||
|
||||
var flags = new List<string>();
|
||||
switch (I(o, IBonded, 0))
|
||||
{
|
||||
case 1: flags.Add("Bonded"); break;
|
||||
case -1: flags.Add("Dropped on death"); break;
|
||||
case -2: flags.Add("Destroyed on death"); break;
|
||||
}
|
||||
if (I(o, IAttuned, 0) == 1) flags.Add("Attuned (can't be given)");
|
||||
if (B(o, BRetained)) flags.Add("Retained");
|
||||
if (I(o, IResistMagic, 0) >= 9999) flags.Add("Unenchantable");
|
||||
if (B(o, BIvoryable)) flags.Add("Ivoryable");
|
||||
if (B(o, BDyable)) flags.Add("Dyeable");
|
||||
if (B(o, BLocked)) flags.Add("Locked");
|
||||
if (B(o, BInscribable)) flags.Add("Inscribable");
|
||||
if (I(o, IUnique, 0) is > 0 and var unique) flags.Add($"Unique (carry {unique.ToString(Inv)})");
|
||||
if (flags.Count > 0) s.Add("Properties: " + string.Join(", ", flags));
|
||||
|
||||
if (I(o, IRareId, 0) is > 0 and var rare) s.Add($"Rare #{rare.ToString(Inv)}", AppraiseTone.Gold);
|
||||
if (I(o, IRemainingLifespan, 0) is > 0 and var life) s.Add("Time left: " + Duration(life), AppraiseTone.Bad);
|
||||
if (I(o, ILockpickMod, 0) is > 0 and var pick) s.Add($"Bonus to Lockpick Skill: +{pick.ToString(Inv)}", AppraiseTone.Good);
|
||||
if (HasF(o, FHealkitMod) && F(o, FHealkitMod, 1) > 1 + 1e-6) s.Add($"Bonus to Healing Skill: {Pct(F(o, FHealkitMod, 1) - 1)}", AppraiseTone.Good);
|
||||
if (I(o, IBoostValue, 0) is var boost && boost != 0) s.Add($"Restores {Math.Abs(boost).ToString("N0", Inv)} points.", AppraiseTone.Good);
|
||||
if (I(o, IItemsCapacity, 0) is > 0 and var cap)
|
||||
s.Add($"Holds {cap.ToString(Inv)} items{(I(o, IContainersCapacity, 0) is > 0 and var packs ? $" and {packs.ToString(Inv)} packs" : "")}.", AppraiseTone.Dim);
|
||||
if (S(o, SInscription, "") is { Length: > 0 } ins)
|
||||
s.Add($"Inscription: \"{ins}\"{(S(o, SScribe, "") is { Length: > 0 } scribe ? " - " + scribe : "")}", AppraiseTone.Dim);
|
||||
if (S(o, SUse, "") is { Length: > 0 } use) s.Add(use, AppraiseTone.Dim);
|
||||
if (s.Lines.Count > 0) doc.Sections.Add(s);
|
||||
}
|
||||
|
||||
private static readonly (uint Key, string Label)[] Ratings =
|
||||
{
|
||||
(370, "Damage"), (371, "Damage Resist"), (372, "Crit"), (373, "Crit Resist"), (374, "Crit Damage"),
|
||||
(375, "Crit Damage Resist"), (376, "Healing Boost"), (377, "Nether Resist"), (378, "Life Resist"),
|
||||
(379, "Max Health"), (383, "PK Damage"), (384, "PK Damage Resist"), (388, "Overpower"), (389, "Overpower Resist"),
|
||||
};
|
||||
|
||||
// ── All properties ────────────────────────────────────────────────────────
|
||||
|
||||
private static void Raw(AppraisalInput o, AppraisalDoc doc)
|
||||
{
|
||||
foreach (var kv in Sorted(o.Ints)) doc.Raw.Add(new("Int", kv.Key, PropertyNames.GetIntName(kv.Key) ?? "?", kv.Value.ToString(Inv)));
|
||||
foreach (var kv in Sorted(o.Int64s)) doc.Raw.Add(new("Int64", kv.Key, PropertyNames.GetInt64Name(kv.Key) ?? "?", kv.Value.ToString(Inv)));
|
||||
foreach (var kv in Sorted(o.Floats)) doc.Raw.Add(new("Float", kv.Key, PropertyNames.GetFloatName(kv.Key) ?? "?", kv.Value.ToString("0.#####", Inv)));
|
||||
foreach (var kv in Sorted(o.Bools)) doc.Raw.Add(new("Bool", kv.Key, PropertyNames.GetBoolName(kv.Key) ?? "?", kv.Value ? "true" : "false"));
|
||||
foreach (var kv in Sorted(o.Strings)) doc.Raw.Add(new("String", kv.Key, PropertyNames.GetStringName(kv.Key) ?? "?", kv.Value));
|
||||
foreach (var kv in Sorted(o.DataIds)) doc.Raw.Add(new("DataId", kv.Key, PropertyNames.GetDataIdName(kv.Key) ?? "?", $"0x{kv.Value:X8}"));
|
||||
foreach (var kv in Sorted(o.InstanceIds)) doc.Raw.Add(new("InstanceId", kv.Key, PropertyNames.GetInstanceIdName(kv.Key) ?? "?", $"0x{kv.Value:X8}"));
|
||||
for (int i = 0; i < o.Spells.Count; i++) doc.Raw.Add(new("Spell", o.Spells[i], o.SpellName(o.Spells[i]), o.Spells[i].ToString(Inv)));
|
||||
}
|
||||
|
||||
private static List<KeyValuePair<uint, T>> Sorted<T>(Dictionary<uint, T> d)
|
||||
{
|
||||
var l = new List<KeyValuePair<uint, T>>(d);
|
||||
l.Sort((a, b) => a.Key.CompareTo(b.Key));
|
||||
return l;
|
||||
}
|
||||
|
||||
// ── Wording ───────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>"Wield requires Heavy Weapons 400", "... Strength 200", "... level 180", "... specialized Sword", "... Aluvian race".</summary>
|
||||
internal static string WieldLine(int req, int what, int diff) => req switch
|
||||
{
|
||||
1 or 2 => $"Wield requires {(req == 2 ? "base " : "")}{Skill(what)} {diff.ToString(Inv)}",
|
||||
3 or 4 => $"Wield requires {(req == 4 ? "base " : "")}{Attribute(what)} {diff.ToString(Inv)}",
|
||||
5 or 6 => $"Wield requires {(req == 6 ? "base " : "")}{Vital(what)} {diff.ToString(Inv)}",
|
||||
7 => $"Wield requires level {diff.ToString(Inv)}",
|
||||
8 => $"Wield requires {(diff >= 3 ? "specialized" : "trained")} {Skill(what)}",
|
||||
11 => $"Wield requires {MagItemInfoTables.CreatureTypeName(diff) ?? "creature " + diff.ToString(Inv)} type",
|
||||
12 => $"Wield requires {Heritage(diff)} race",
|
||||
_ => $"Wield requires {PropertyNames.GetIntName((uint)what) ?? "property " + what.ToString(Inv)} {diff.ToString(Inv)}",
|
||||
};
|
||||
|
||||
private static string Skill(int id) => id > 0 && MagItemInfoTables.Skills.TryGetValue(id, out string? s) ? s : id > 0 ? "skill " + id.ToString(Inv) : "";
|
||||
|
||||
private static string Attribute(int id) => id switch
|
||||
{
|
||||
1 => "Strength", 2 => "Endurance", 3 => "Quickness", 4 => "Coordination", 5 => "Focus", 6 => "Self", _ => "attribute " + id.ToString(Inv),
|
||||
};
|
||||
|
||||
private static string Vital(int id) => id switch
|
||||
{
|
||||
1 or 2 => "Health", 3 or 4 => "Stamina", 5 or 6 => "Mana", _ => "vital " + id.ToString(Inv),
|
||||
};
|
||||
|
||||
private static string Heritage(int id) => id switch
|
||||
{
|
||||
1 => "Aluvian", 2 => "Gharu'ndim", 3 => "Sho", 4 => "Viamontian", 5 => "Umbraen", 6 => "Gear Knight", 7 => "Tumerok",
|
||||
8 => "Lugian", 9 => "Empyrean", 10 => "Penumbraen", 11 => "Undead", 12 => "Olthoi", 13 => "Olthoi", _ => "",
|
||||
};
|
||||
|
||||
private static string PkStatus(int status) => status switch
|
||||
{
|
||||
0x04 => "Player Killer",
|
||||
0x40 => "PK Lite",
|
||||
0x02 or 0x01 => "Non-Player Killer",
|
||||
_ => "",
|
||||
};
|
||||
|
||||
internal static string SpeedName(int speed) => speed switch
|
||||
{
|
||||
< 11 => "Very Fast",
|
||||
< 31 => "Fast",
|
||||
< 50 => "Average",
|
||||
< 80 => "Slow",
|
||||
_ => "Very Slow",
|
||||
};
|
||||
|
||||
internal static string ProtectionName(double mod) => mod switch
|
||||
{
|
||||
< 0.4 => "Poor",
|
||||
< 0.8 => "Below Average",
|
||||
< 1.2 => "Average",
|
||||
< 1.6 => "Above Average",
|
||||
< 2.0 => "Excellent",
|
||||
_ => "Superb",
|
||||
};
|
||||
|
||||
internal static string WorkmanshipName(int w) => w switch
|
||||
{
|
||||
1 => "Poorly crafted", 2 => "Well-crafted", 3 => "Finely crafted", 4 => "Exquisitely crafted", 5 => "Magnificent",
|
||||
6 => "Nearly flawless", 7 => "Flawless", 8 => "Utterly flawless", 9 => "Incomparable", 10 => "Priceless", _ => "",
|
||||
};
|
||||
|
||||
/// <summary>DamageType flags as retail words: "Slashing/Piercing", "Fire".</summary>
|
||||
internal static string DamageTypes(int flags)
|
||||
{
|
||||
if (flags <= 0) return string.Empty;
|
||||
var parts = new List<string>(2);
|
||||
if ((flags & 0x001) != 0) parts.Add("Slashing");
|
||||
if ((flags & 0x002) != 0) parts.Add("Piercing");
|
||||
if ((flags & 0x004) != 0) parts.Add("Bludgeoning");
|
||||
if ((flags & 0x008) != 0) parts.Add("Cold");
|
||||
if ((flags & 0x010) != 0) parts.Add("Fire");
|
||||
if ((flags & 0x020) != 0) parts.Add("Acid");
|
||||
if ((flags & 0x040) != 0) parts.Add("Electric");
|
||||
if ((flags & 0x400) != 0) parts.Add("Nether");
|
||||
return string.Join("/", parts);
|
||||
}
|
||||
|
||||
/// <summary>ClothingPriority (CoverageMask) as body parts, outer layers first: "Chest, Abdomen, Upper Arms".</summary>
|
||||
internal static string Coverage(int mask)
|
||||
{
|
||||
if (mask <= 0) return string.Empty;
|
||||
var parts = new List<string>();
|
||||
void Part(int bits, string name) { if ((mask & bits) != 0 && !parts.Contains(name)) parts.Add(name); }
|
||||
Part(0x4000, "Head");
|
||||
Part(0x0400 | 0x0008, "Chest");
|
||||
Part(0x0800 | 0x0010, "Abdomen");
|
||||
Part(0x1000 | 0x0020, "Upper Arms");
|
||||
Part(0x2000 | 0x0040, "Lower Arms");
|
||||
Part(0x8000, "Hands");
|
||||
Part(0x0100 | 0x0002, "Upper Legs");
|
||||
Part(0x0200 | 0x0004, "Lower Legs");
|
||||
Part(0x10000, "Feet");
|
||||
return string.Join(", ", parts);
|
||||
}
|
||||
|
||||
private static string Imbues(AppraisalInput o)
|
||||
{
|
||||
int bits = I(o, IImbued, 0);
|
||||
foreach (uint k in MoreImbues) bits |= I(o, k, 0);
|
||||
if (bits == 0) return string.Empty;
|
||||
var parts = new List<string>();
|
||||
void Bit(int b, string name) { if ((bits & b) != 0) parts.Add(name); }
|
||||
Bit(0x1, "Critical Strike"); Bit(0x2, "Crippling Blow"); Bit(0x4, "Armor Rending"); Bit(0x8, "Slash Rending");
|
||||
Bit(0x10, "Pierce Rending"); Bit(0x20, "Bludgeon Rending"); Bit(0x40, "Acid Rending"); Bit(0x80, "Cold Rending");
|
||||
Bit(0x100, "Lightning Rending"); Bit(0x200, "Fire Rending"); Bit(0x400, "Melee Defense"); Bit(0x800, "Missile Defense");
|
||||
Bit(0x1000, "Magic Defense"); Bit(0x2000, "Spellbook"); Bit(0x4000, "Nether Rending");
|
||||
return string.Join(", ", parts);
|
||||
}
|
||||
|
||||
private static string Duration(int seconds)
|
||||
{
|
||||
var t = TimeSpan.FromSeconds(seconds);
|
||||
if (t.TotalDays >= 1) return $"{(int)t.TotalDays}d {t.Hours}h";
|
||||
if (t.TotalHours >= 1) return $"{(int)t.TotalHours}h {t.Minutes}m";
|
||||
return $"{t.Minutes}m {t.Seconds}s";
|
||||
}
|
||||
|
||||
private static AppraiseSection Note(string text)
|
||||
{
|
||||
var s = new AppraiseSection("");
|
||||
s.Add(text, AppraiseTone.Dim);
|
||||
return s;
|
||||
}
|
||||
|
||||
private static float Ratio(uint cur, uint max, float serverRatio) =>
|
||||
serverRatio >= 0f ? serverRatio : max > 0 ? Math.Clamp(cur / (float)max, 0f, 1f) : 0f;
|
||||
|
||||
/// <summary>A fraction as retail's signed percent: 0.12 -> "+12%", -0.05 -> "-5%", 0.0375 -> "+3.75%".</summary>
|
||||
internal static string Pct(double fraction)
|
||||
{
|
||||
double p = fraction * 100.0;
|
||||
string s = Math.Abs(p - Math.Round(p)) < 0.005 ? Math.Round(p).ToString("0", Inv) : p.ToString("0.##", Inv);
|
||||
return (p >= 0 ? "+" : "") + s + "%";
|
||||
}
|
||||
|
||||
private static string Num(double v) => Math.Abs(v - Math.Round(v)) < 0.05 ? Math.Round(v).ToString("0", Inv) : v.ToString("0.#", Inv);
|
||||
|
||||
private static bool Has(AppraisalInput o, uint intKey) => o.Ints.ContainsKey(intKey);
|
||||
private static bool HasF(AppraisalInput o, uint floatKey) => o.Floats.ContainsKey(floatKey);
|
||||
private static int I(AppraisalInput o, uint key, int fallback) => o.Ints.TryGetValue(key, out int v) ? v : fallback;
|
||||
private static double F(AppraisalInput o, uint key, double fallback) => o.Floats.TryGetValue(key, out double v) ? v : fallback;
|
||||
private static bool B(AppraisalInput o, uint key) => o.Bools.TryGetValue(key, out bool v) && v;
|
||||
private static string S(AppraisalInput o, uint key, string fallback) => o.Strings.TryGetValue(key, out string? v) && v.Length > 0 ? v : fallback;
|
||||
}
|
||||
|
|
@ -0,0 +1,441 @@
|
|||
// ============================================================================
|
||||
// RynthDefective - Appraisal/AppraisalWindow.cs
|
||||
// The Appraisal window (2026-11-28): it stays when the bot selects another
|
||||
// item and follows only the player's own clicks. Retail's examine panel, roughly: the picture, the name, what
|
||||
// it is and its value and burden, the bars (a creature's health, stamina and
|
||||
// mana; an item's mana), a creature's attributes, then the appraisal's lines
|
||||
// under small headings, the description, and every property the engine holds
|
||||
// ("All properties", folded).
|
||||
//
|
||||
// It shows what YOU picked (RynthDefectivePlugin.Appraisal.cs): a middle-click
|
||||
// on something in the world (your selection doesn't change), or something you
|
||||
// select yourself with a click. The bot's selections never change it.
|
||||
//
|
||||
// the title row drag to move; Ctrl+wheel: bigger or smaller (30-250%);
|
||||
// right-click: the menu (copy, appraise again, select it,
|
||||
// pin, all properties, hide).
|
||||
// the pin pinned: your own clicks don't change it, only a middle-click.
|
||||
// the square pop it out of the game window into its own window (another
|
||||
// screen), or dock it back (2026-11-28); /rdef appraisal popout | dock.
|
||||
// the arrows appraise it again (ask the server).
|
||||
//
|
||||
// AC's render thread; reads the view the tick built (AppraisalView).
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Numerics;
|
||||
using ImGuiNET;
|
||||
using RynthCore.Plugin.Shared;
|
||||
using RynthCore.Plugin.Shared.RynthUi;
|
||||
using RynthCore.PluginSdk;
|
||||
using static RynthCore.Plugin.Shared.RynthUi.RynthUi;
|
||||
|
||||
namespace RynthCore.Plugin.RynthDefective.Appraisal;
|
||||
|
||||
/// <summary>What the window draws (built on the plugin tick).</summary>
|
||||
internal sealed record AppraisalView(bool Ready, AppraisalDoc? Doc, string Source, bool Pinned, bool Gone)
|
||||
{
|
||||
public static readonly AppraisalView NotReady = new(false, null, string.Empty, false, false);
|
||||
}
|
||||
|
||||
internal sealed class AppraisalWindow
|
||||
{
|
||||
public const string Title = "Appraisal";
|
||||
|
||||
private readonly RynthCoreHost _host;
|
||||
private float _k = 1f, _r = 1f;
|
||||
private bool _rawOpen, _popped;
|
||||
private float _bodyContentH;
|
||||
|
||||
/// <summary>The menu's and chips' actions (the plugin runs them on its tick).</summary>
|
||||
public Action? Refresh { get; set; }
|
||||
public Action? TogglePin { get; set; }
|
||||
public Action<uint>? Select { get; set; }
|
||||
|
||||
public AppraisalWindow(RynthCoreHost host) { _host = host; }
|
||||
|
||||
private float Px(float v) => v * _k;
|
||||
private float Fs(ImFontPtr f) => f.FontSize * _r;
|
||||
|
||||
private void Scale()
|
||||
{
|
||||
float fontK = Math.Max(0.5f, Font(RynthUiFont.Ui10).FontSize / 10f);
|
||||
int pct = _host.PanelScale(Title);
|
||||
_k = pct > 0 ? pct / 100f : fontK;
|
||||
_r = _k / fontK;
|
||||
}
|
||||
|
||||
private const float Pad = 7, Icon = 40, Gap = 7, Radius = 4, ChipSize = 16, BarH = 9, MaxBodyH = 430;
|
||||
|
||||
private uint _bg, _key, _inset, _line, _text, _dim, _faint, _accent, _good, _bad, _gold;
|
||||
private static readonly uint HealthColor = Argb(0xFFE0564E), StaminaColor = Argb(0xFFE0B54E), ManaColor = Argb(0xFF4F8DF0),
|
||||
MagicColor = Argb(0xFF9DB8F5), White = Argb(0xFFFFFFFF);
|
||||
private static uint A(uint c, float alpha) => WithAlpha(c, (uint)Math.Clamp(MathF.Round(alpha * 255f), 0f, 255f));
|
||||
|
||||
/// <summary>Draws into the host's window (<paramref name="popped"/>: its own OS window); returns the height it needs (pixels). Render thread.</summary>
|
||||
public float Draw(AppraisalView v, bool popped = false)
|
||||
{
|
||||
_popped = popped;
|
||||
Scale();
|
||||
_bg = Color(RynthUiColor.Background);
|
||||
_key = Color(RynthUiColor.KeyFace);
|
||||
_inset = Color(RynthUiColor.Inset);
|
||||
_line = Color(RynthUiColor.Hairline);
|
||||
_text = Color(RynthUiColor.Text);
|
||||
_dim = Color(RynthUiColor.Muted);
|
||||
_faint = Color(RynthUiColor.Faint);
|
||||
_accent = Color(RynthUiColor.Accent);
|
||||
_good = Color(RynthUiColor.Green);
|
||||
_bad = Color(RynthUiColor.Red);
|
||||
_gold = Color(RynthUiColor.Highlight);
|
||||
|
||||
Vector2 origin = ImGui.GetCursorScreenPos();
|
||||
origin = new Vector2(MathF.Round(origin.X), MathF.Round(origin.Y));
|
||||
float width = MathF.Floor(ImGui.GetContentRegionAvail().X);
|
||||
if (width < 80) return Px(40);
|
||||
ImDrawListPtr dl = ImGui.GetWindowDrawList();
|
||||
AppraisalDoc? doc = v.Ready ? v.Doc : null;
|
||||
|
||||
float pad = Px(Pad), icon = Px(Icon);
|
||||
ImFontPtr nf = Font(RynthUiFont.NarrowBold13), kf = Font(RynthUiFont.Narrow10), sf = Font(RynthUiFont.Narrow9);
|
||||
|
||||
// ── The header: picture, name, what it is, the facts ──
|
||||
float headH = MathF.Ceiling(2 * pad + icon);
|
||||
float barsH = doc == null ? 0 : doc.Bars.Count * (Px(BarH) + Px(4));
|
||||
float attrH = doc == null || doc.Attributes.Count == 0 ? 0 : 2 * (Fs(kf) + Px(3)) + Px(4);
|
||||
float topH = headH + barsH + attrH;
|
||||
float footH = Fs(sf) + Px(6);
|
||||
|
||||
float bodyWant = doc == null ? 0 : _bodyContentH;
|
||||
float bodyH = MathF.Min(bodyWant, Px(MaxBodyH));
|
||||
float total = topH + (bodyH > 0 ? bodyH + Px(2) : 0) + footH;
|
||||
|
||||
Vector2 max = origin + new Vector2(width, total);
|
||||
dl.AddRectFilled(origin, max, A(_bg, 0.95f), Px(Radius));
|
||||
dl.AddRect(origin, max, _line, Px(Radius));
|
||||
|
||||
float chipsW = 3 * Px(ChipSize) + 2 * Px(4);
|
||||
ImGui.SetCursorScreenPos(origin);
|
||||
ImGui.InvisibleButton("##appr_drag", new Vector2(Math.Max(1, width - chipsW - pad), headH));
|
||||
_host.PanelDragWithLastItem();
|
||||
if (ImGui.IsItemClicked(ImGuiMouseButton.Right)) ImGui.OpenPopup(MenuId);
|
||||
SafeImGui.SetItemTooltip(doc == null
|
||||
? "Middle-click anything in the world to appraise it here (your selection doesn't change), or select something yourself.\nThe bot's selections never change this window.\nDrag to move; Ctrl+wheel: bigger or smaller; right-click: the menu."
|
||||
: $"{doc.Name}\nMiddle-click something else to appraise it; {(v.Pinned ? "pinned: your own clicks don't change it" : "your own clicks change it too")}.\nDrag to move; Ctrl+wheel: bigger or smaller; right-click: the menu.");
|
||||
Menu(v);
|
||||
|
||||
Vector2 ip = origin + new Vector2(pad, pad);
|
||||
dl.AddRectFilled(ip, ip + new Vector2(icon, icon), doc == null ? _inset : _key, Px(3));
|
||||
IntPtr tex = doc != null ? _host.GetIconTexture(RynthIconKind.Object, doc.Id) : IntPtr.Zero;
|
||||
if (tex != IntPtr.Zero)
|
||||
dl.AddImageRounded(tex, ip + new Vector2(Px(3), Px(3)), ip + new Vector2(icon - Px(3), icon - Px(3)), Vector2.Zero, Vector2.One, White, Px(2));
|
||||
else if (doc == null)
|
||||
DrawIcon(dl, RynthIcons.MagnifyingGlass, ip, new Vector2(icon, icon), Px(18), _faint);
|
||||
dl.AddRect(ip, ip + new Vector2(icon, icon), _line, Px(3));
|
||||
|
||||
float tx = ip.X + icon + Px(Gap);
|
||||
float right = origin.X + width - pad;
|
||||
|
||||
// The chips: pin, pop out / dock, appraise again.
|
||||
Vector2 chip = new(right - Px(ChipSize), ip.Y);
|
||||
if (Chip("##appr_refresh", RynthIcons.ArrowsClockwise, chip, _faint, doc == null ? "Nothing to appraise yet." : "Appraise it again (ask the server).") && doc != null)
|
||||
Refresh?.Invoke();
|
||||
chip.X -= Px(ChipSize) + Px(4);
|
||||
if (Chip("##appr_popout", popped ? RynthIcons.ArrowSquareIn : RynthIcons.ArrowSquareOut, chip, _faint,
|
||||
popped ? "Dock it back into the game window (/rdef appraisal dock)."
|
||||
: "Pop it out of the game window into its own window: put it on another screen (/rdef appraisal popout)."))
|
||||
_host.SetPanelPopOut(Title, RynthPanelPopOut.Toggle);
|
||||
chip.X -= Px(ChipSize) + Px(4);
|
||||
if (Chip("##appr_pin", RynthIcons.PushPin, chip, v.Pinned ? _accent : _faint,
|
||||
v.Pinned ? "Pinned: only a middle-click changes this window. Click: follow your own clicks too."
|
||||
: "Follows your own clicks and middle-clicks. Click: pin it (only a middle-click changes it).", v.Pinned))
|
||||
TogglePin?.Invoke();
|
||||
float textRight = chip.X - Px(6);
|
||||
|
||||
if (doc == null)
|
||||
{
|
||||
Clip(dl, nf, Fs(nf), new Vector2(tx, ip.Y), _faint, "Appraisal", textRight - tx);
|
||||
Clip(dl, kf, Fs(kf), new Vector2(tx, ip.Y + Fs(nf) + Px(2)), _faint, "Middle-click something in the world", right - tx);
|
||||
Clip(dl, sf, Fs(sf), new Vector2(tx, ip.Y + icon - Fs(sf)), _faint, "or select it yourself: the bot's picks don't count", right - tx);
|
||||
ImGui.SetCursorScreenPos(origin);
|
||||
ImGui.Dummy(new Vector2(width, total));
|
||||
return total;
|
||||
}
|
||||
|
||||
Clip(dl, nf, Fs(nf), new Vector2(tx, ip.Y), v.Gone ? _faint : _text, doc.Name, textRight - tx);
|
||||
float y2 = ip.Y + Fs(nf) + Px(2);
|
||||
if (doc.Kind.Length > 0) Clip(dl, kf, Fs(kf), new Vector2(tx, y2), _accent, doc.Kind, right - tx);
|
||||
string facts = Facts(doc);
|
||||
if (facts.Length > 0) Clip(dl, sf, Fs(sf), new Vector2(tx, ip.Y + icon - Fs(sf)), _dim, facts, right - tx);
|
||||
|
||||
// ── The bars ──
|
||||
float y = origin.Y + headH;
|
||||
foreach (AppraiseBar b in doc.Bars)
|
||||
{
|
||||
float lw = Px(48);
|
||||
Clip(dl, sf, Fs(sf), new Vector2(origin.X + pad, y + (Px(BarH) - Fs(sf)) * 0.5f), _dim, b.Label, lw);
|
||||
Vector2 b0 = new(origin.X + pad + lw, y), b1 = new(right, y + Px(BarH));
|
||||
dl.AddRectFilled(b0, b1, _inset, Px(2));
|
||||
float f = Math.Clamp(b.Ratio, 0f, 1f);
|
||||
uint fill = b.Kind switch { AppraiseBarKind.Health => HealthColor, AppraiseBarKind.Stamina => StaminaColor, _ => ManaColor };
|
||||
if (f > 0f) dl.AddRectFilled(b0, new Vector2(b0.X + (b1.X - b0.X) * f, b1.Y), fill, Px(2));
|
||||
dl.AddRect(b0, b1, _line, Px(2));
|
||||
string label = (b.Max > 0 ? $"{b.Current.ToString("N0", CultureInfo.InvariantCulture)} / {b.Max.ToString("N0", CultureInfo.InvariantCulture)} " : "")
|
||||
+ MathF.Round(f * 100f).ToString(CultureInfo.InvariantCulture) + "%";
|
||||
float w = sf.CalcTextSizeA(Fs(sf), float.MaxValue, 0f, label).X;
|
||||
if (w + Px(8) < b1.X - b0.X)
|
||||
dl.AddText(sf, Fs(sf), new Vector2(MathF.Round(b1.X - w - Px(4)), MathF.Round(y + (Px(BarH) - Fs(sf)) * 0.5f)), White, label);
|
||||
y += Px(BarH) + Px(4);
|
||||
}
|
||||
|
||||
// ── A creature's attributes: three columns, two rows ──
|
||||
if (doc.Attributes.Count > 0)
|
||||
{
|
||||
float colW = (right - origin.X - pad) / 3f;
|
||||
for (int i = 0; i < doc.Attributes.Count; i++)
|
||||
{
|
||||
var (label, value, buffed, up) = doc.Attributes[i];
|
||||
float cx = origin.X + pad + (i % 3) * colW, cy = y + (i / 3) * (Fs(kf) + Px(3));
|
||||
dl.AddText(kf, Fs(kf), new Vector2(cx, cy), _dim, Short(label));
|
||||
string num = value.ToString(CultureInfo.InvariantCulture);
|
||||
uint c = !buffed ? _text : up ? _good : _bad;
|
||||
dl.AddText(kf, Fs(kf), new Vector2(cx + Px(34), cy), c, num);
|
||||
}
|
||||
y += attrH;
|
||||
}
|
||||
|
||||
// ── The body: sections, description, every property (scrolls past MaxBodyH) ──
|
||||
if (bodyWant <= 0) bodyH = Px(1);
|
||||
ImGui.SetCursorScreenPos(new Vector2(origin.X + Px(1), y));
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, Vector2.Zero);
|
||||
ImGui.PushStyleColor(ImGuiCol.ScrollbarBg, 0u);
|
||||
bool child = ImGui.BeginChild("##appr_body", new Vector2(width - Px(2), Math.Max(Px(1), bodyH)), ImGuiChildFlags.None,
|
||||
ImGuiWindowFlags.NoBackground | (bodyWant > Px(MaxBodyH) ? ImGuiWindowFlags.None : ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse));
|
||||
ImGui.PopStyleColor();
|
||||
ImGui.PopStyleVar();
|
||||
if (child)
|
||||
{
|
||||
try { _bodyContentH = Body(doc, width - Px(2) - (bodyWant > Px(MaxBodyH) ? ImGui.GetStyle().ScrollbarSize : 0)); }
|
||||
finally { ImGui.EndChild(); }
|
||||
}
|
||||
else ImGui.EndChild();
|
||||
y += bodyH > Px(1) ? bodyH + Px(2) : 0;
|
||||
|
||||
// ── The footer: how it was picked, and whether it is appraised ──
|
||||
string foot = v.Source + (v.Gone ? " · no longer in view" : doc.Identified ? "" : " · not appraised yet");
|
||||
Clip(dl, sf, Fs(sf), new Vector2(origin.X + pad, origin.Y + total - footH + Px(2)), _faint, foot, width - 2 * pad);
|
||||
|
||||
ImGui.SetCursorScreenPos(origin);
|
||||
ImGui.Dummy(new Vector2(width, total));
|
||||
return total;
|
||||
}
|
||||
|
||||
/// <summary>The body's lines in the child window; returns their height. Render thread.</summary>
|
||||
private float Body(AppraisalDoc doc, float width)
|
||||
{
|
||||
ImDrawListPtr dl = ImGui.GetWindowDrawList();
|
||||
Vector2 o = ImGui.GetCursorScreenPos();
|
||||
float pad = Px(Pad), x = o.X + pad - Px(1), wrapW = width - 2 * pad;
|
||||
float y = o.Y;
|
||||
ImFontPtr hf = Font(RynthUiFont.Narrow9), lf = Font(RynthUiFont.Ui10), mf = Font(RynthUiFont.Dash9);
|
||||
|
||||
foreach (AppraiseSection s in doc.Sections)
|
||||
{
|
||||
if (s.Title.Length > 0)
|
||||
{
|
||||
y += Px(3);
|
||||
string t = s.Title.ToUpperInvariant();
|
||||
dl.AddText(hf, Fs(hf), new Vector2(x, y), _faint, t);
|
||||
float tw = hf.CalcTextSizeA(Fs(hf), float.MaxValue, 0f, t).X;
|
||||
float ly = MathF.Round(y + Fs(hf) * 0.55f);
|
||||
dl.AddLine(new Vector2(x + tw + Px(6), ly), new Vector2(x + wrapW, ly), _line);
|
||||
y += Fs(hf) + Px(2);
|
||||
}
|
||||
foreach (AppraiseLine l in s.Lines)
|
||||
y = Wrapped(dl, lf, new Vector2(x, y), wrapW, l.Text, Tone(l.Tone)) + Px(1);
|
||||
}
|
||||
|
||||
if (doc.Description.Length > 0)
|
||||
{
|
||||
y += Px(4);
|
||||
y = Wrapped(dl, lf, new Vector2(x, y), wrapW, doc.Description, _dim) + Px(2);
|
||||
}
|
||||
|
||||
// Every property, folded.
|
||||
if (doc.Raw.Count > 0)
|
||||
{
|
||||
y += Px(4);
|
||||
string head = (_rawOpen ? "v " : "> ") + "All properties (" + doc.Raw.Count.ToString(CultureInfo.InvariantCulture) + ")";
|
||||
ImGui.SetCursorScreenPos(new Vector2(x, y));
|
||||
if (ImGui.InvisibleButton("##appr_raw", new Vector2(wrapW, Fs(hf) + Px(2)))) _rawOpen = !_rawOpen;
|
||||
bool hot = ImGui.IsItemHovered();
|
||||
SafeImGui.SetItemTooltip("Every property the engine holds for it, by ACE's names (what /ub propertydump lists).");
|
||||
dl.AddText(hf, Fs(hf), new Vector2(x, y), hot ? _text : _faint, head);
|
||||
y += Fs(hf) + Px(3);
|
||||
if (_rawOpen)
|
||||
{
|
||||
float kindW = mf.CalcTextSizeA(Fs(mf), float.MaxValue, 0f, "InstanceId 9999 ").X;
|
||||
foreach (AppraiseRaw r in doc.Raw)
|
||||
{
|
||||
string k = r.Kind + " " + r.Key.ToString(CultureInfo.InvariantCulture);
|
||||
dl.AddText(mf, Fs(mf), new Vector2(x, y), _faint, k);
|
||||
float nx = x + kindW;
|
||||
string nv = r.Name + " = " + r.Value;
|
||||
y = Wrapped(dl, mf, new Vector2(nx, y), wrapW - kindW, nv, r.Name == "?" ? _faint : _dim) + Px(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
y += Px(4);
|
||||
float h = y - o.Y;
|
||||
ImGui.SetCursorScreenPos(o);
|
||||
ImGui.Dummy(new Vector2(Math.Max(1, width), Math.Max(1, h)));
|
||||
return h;
|
||||
}
|
||||
|
||||
private uint Tone(AppraiseTone t) => t switch
|
||||
{
|
||||
AppraiseTone.Dim => _dim,
|
||||
AppraiseTone.Good => _good,
|
||||
AppraiseTone.Bad => _bad,
|
||||
AppraiseTone.Magic => MagicColor,
|
||||
AppraiseTone.Gold => _gold,
|
||||
_ => _text,
|
||||
};
|
||||
|
||||
private static string Facts(AppraisalDoc doc)
|
||||
{
|
||||
var parts = new List<string>(doc.Facts.Count);
|
||||
foreach (var (label, value) in doc.Facts) parts.Add(label + " " + value);
|
||||
return string.Join(" · ", parts);
|
||||
}
|
||||
|
||||
private static string Short(string attribute) => attribute switch
|
||||
{
|
||||
"Strength" => "Str", "Endurance" => "End", "Quickness" => "Quick", "Coordination" => "Coord", "Focus" => "Focus", "Self" => "Self", _ => attribute,
|
||||
};
|
||||
|
||||
// ── The menu ─────────────────────────────────────────────────────────────
|
||||
|
||||
private const string MenuId = "##appr_menu";
|
||||
|
||||
private void Menu(AppraisalView v)
|
||||
{
|
||||
if (!ImGui.IsPopupOpen(MenuId)) return;
|
||||
ImGui.PushStyleColor(ImGuiCol.PopupBg, A(_bg, 0.98f));
|
||||
ImGui.PushStyleColor(ImGuiCol.Border, _line);
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.PopupRounding, Px(4));
|
||||
ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(Px(6), Px(5)));
|
||||
bool open = ImGui.BeginPopup(MenuId);
|
||||
ImGui.PopStyleVar(2);
|
||||
ImGui.PopStyleColor(2);
|
||||
if (!open) return;
|
||||
try
|
||||
{
|
||||
AppraisalDoc? doc = v.Ready ? v.Doc : null;
|
||||
if (doc != null) SafeImGui.TextDisabled(doc.Name);
|
||||
else ImGui.TextDisabled("Nothing appraised yet");
|
||||
ImGui.Separator();
|
||||
if (ImGui.MenuItem("Copy as text", null, false, doc != null) && doc != null) ImGui.SetClipboardText(doc.ToText());
|
||||
SafeImGui.SetItemTooltip("The whole appraisal, to paste in chat or a note.");
|
||||
if (ImGui.MenuItem("Appraise again", null, false, doc != null && !v.Gone)) Refresh?.Invoke();
|
||||
if (ImGui.MenuItem("Select it", null, false, doc != null && !v.Gone) && doc != null) Select?.Invoke(doc.Id);
|
||||
SafeImGui.SetItemTooltip("Make it the game's selection (as a click on it does).");
|
||||
if (ImGui.MenuItem("Pinned (only a middle-click changes it)", null, v.Pinned)) TogglePin?.Invoke();
|
||||
if (ImGui.MenuItem("Show every property", null, _rawOpen, doc != null)) _rawOpen = !_rawOpen;
|
||||
if (ImGui.MenuItem(_popped ? "Dock back into the game window" : "Pop out of the game window"))
|
||||
_host.SetPanelPopOut(Title, RynthPanelPopOut.Toggle);
|
||||
SafeImGui.SetItemTooltip(_popped ? "Back inside the game window, where it was." : "Its own window, which you can put on another screen (/rdef appraisal popout).");
|
||||
ImGui.Separator();
|
||||
if (ImGui.MenuItem("Hide the Appraisal window")) _host.SetPanelOpen(Title, RynthPanelOpen.Close);
|
||||
SafeImGui.SetItemTooltip("/rdef appraisal shows it again; a middle-click on something does too.");
|
||||
}
|
||||
finally { ImGui.EndPopup(); }
|
||||
}
|
||||
|
||||
// ── Drawing helpers ──────────────────────────────────────────────────────
|
||||
|
||||
private bool Chip(string id, string icon, Vector2 pos, uint color, string tip, bool held = false)
|
||||
{
|
||||
Vector2 size = new(Px(ChipSize), Px(ChipSize));
|
||||
ImGui.SetCursorScreenPos(pos);
|
||||
bool clicked = ImGui.InvisibleButton(id, size);
|
||||
bool hot = ImGui.IsItemHovered();
|
||||
SafeImGui.SetItemTooltip(tip);
|
||||
ImDrawListPtr dl = ImGui.GetWindowDrawList();
|
||||
if (hot || held) dl.AddRectFilled(pos, pos + size, _key, Px(3));
|
||||
DrawIcon(dl, icon, pos, size, Px(11), hot ? _text : color);
|
||||
return clicked;
|
||||
}
|
||||
|
||||
/// <summary>Word-wrapped text from <paramref name="pos"/> within <paramref name="width"/>; returns the y under it.</summary>
|
||||
private float Wrapped(ImDrawListPtr dl, ImFontPtr f, Vector2 pos, float width, string text, uint color)
|
||||
{
|
||||
float size = Fs(f);
|
||||
float y = pos.Y;
|
||||
foreach (string line in WrapLines(f, size, text, Math.Max(Px(20), width)))
|
||||
{
|
||||
dl.AddText(f, size, new Vector2(MathF.Round(pos.X), MathF.Round(y)), color, line);
|
||||
y += size + Px(1);
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
private static IEnumerable<string> WrapLines(ImFontPtr f, float size, string text, float width)
|
||||
{
|
||||
foreach (string para in text.Replace("\r", "").Split('\n'))
|
||||
{
|
||||
if (para.Length == 0) { yield return ""; continue; }
|
||||
int start = 0;
|
||||
while (start < para.Length)
|
||||
{
|
||||
int end = para.Length;
|
||||
if (f.CalcTextSizeA(size, float.MaxValue, 0f, para[start..end]).X > width)
|
||||
{
|
||||
// The longest run of whole words that fits, else as many characters as fit.
|
||||
int lastSpace = -1, i = start + 1;
|
||||
for (; i <= para.Length; i++)
|
||||
{
|
||||
if (f.CalcTextSizeA(size, float.MaxValue, 0f, para[start..i]).X > width) break;
|
||||
if (i < para.Length && para[i] == ' ') lastSpace = i;
|
||||
}
|
||||
end = lastSpace > start ? lastSpace : Math.Max(start + 1, i - 1);
|
||||
}
|
||||
yield return para[start..end].TrimEnd();
|
||||
start = end;
|
||||
while (start < para.Length && para[start] == ' ') start++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void Clip(ImDrawListPtr dl, ImFontPtr f, float size, Vector2 pos, uint color, string text, float room)
|
||||
{
|
||||
if (text.Length == 0 || room <= 4) return;
|
||||
float w = f.CalcTextSizeA(size, float.MaxValue, 0f, text).X;
|
||||
if (w > room)
|
||||
{
|
||||
int n = text.Length;
|
||||
while (n > 1 && f.CalcTextSizeA(size, float.MaxValue, 0f, text[..n] + "...").X > room) n--;
|
||||
text = text[..n] + "...";
|
||||
}
|
||||
dl.AddText(f, size, new Vector2(MathF.Round(pos.X), MathF.Round(pos.Y)), color, text);
|
||||
}
|
||||
|
||||
private static unsafe void DrawIcon(ImDrawListPtr dl, string glyph, Vector2 min, Vector2 size, float px, uint color)
|
||||
{
|
||||
if (string.IsNullOrEmpty(glyph)) return;
|
||||
ImFontPtr font = Font(RynthUiFont.Ui18);
|
||||
if (font.NativePtr == null) return;
|
||||
byte* g = (byte*)ImGuiNative.ImFont_FindGlyphNoFallback(font.NativePtr, glyph[0]);
|
||||
if (g == null) return;
|
||||
float advance = *(float*)(g + 4);
|
||||
if (advance <= 0) return;
|
||||
float* box = (float*)(g + 8);
|
||||
float scale = px / advance;
|
||||
Vector2 centre = new((box[0] + box[2]) * 0.5f * scale, (box[1] + box[3]) * 0.5f * scale);
|
||||
Vector2 at = min + size * 0.5f - centre;
|
||||
dl.AddText(font, font.FontSize * scale, new Vector2(MathF.Round(at.X), MathF.Round(at.Y)), color, glyph);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ using System;
|
|||
namespace RynthCore.Plugin.RynthDefective.Model;
|
||||
|
||||
internal enum DefVerb { Toggle, Help, Use, Set, Clear, Bind, Unbind, Weapons, Favourite, Slots, List, Status, Error, Panels, Selection, Settings, Spell, Corpses,
|
||||
Quantity, Split, Give, Buy, DayNight, Bars, Shortcuts }
|
||||
Quantity, Split, Give, Buy, DayNight, Bars, Shortcuts, Appraisal }
|
||||
|
||||
/// <summary>
|
||||
/// A parsed "/rdef ..." line. Use: <see cref="Slot"/> (1-based) or <see cref="Text"/> (an item name).
|
||||
|
|
@ -19,7 +19,7 @@ internal static class DefCommandParser
|
|||
{
|
||||
public const string Usage =
|
||||
"/rdef [use <slot or item name> | set <slot> [item name] | spell <slot> <spell name> | clear <slot> | bind <slot> <key> | unbind <slot> | "
|
||||
+ "weapons [search] | fav | slots <count> | list | status | settings | panels (the game panel buttons) | selection | corpses [clear] | "
|
||||
+ "weapons [search] | fav | slots <count> | list | status | settings | panels (the game panel buttons) | selection | appraisal [pin|unpin|again|popout|dock] | corpses [clear] | "
|
||||
+ "bars [add | remove <bar> | slots <bar> <count> | show <bar>] | shortcuts clearbusy [on|off] | "
|
||||
+ "qty [number|max|half] | split [number] [into <pack>] | give [number] | buy [number] [item name] | daynight [show|hide]]";
|
||||
|
||||
|
|
@ -54,6 +54,8 @@ internal static class DefCommandParser
|
|||
case "panels": case "panel": return new DefCommand(DefVerb.Panels);
|
||||
case "settings": case "options": case "setup": return new DefCommand(DefVerb.Settings);
|
||||
case "corpses": case "corpse": return new DefCommand(DefVerb.Corpses, Text: rest);
|
||||
// The Appraisal window (2026-11-28): Text "", "pin", "unpin", "again", or an object id (a test hook).
|
||||
case "appraisal": case "appraise": case "examine": return new DefCommand(DefVerb.Appraisal, Text: rest);
|
||||
case "selection": case "target":
|
||||
// "/rdef selection 0x80001234": select that object (a test hook for the Selection window).
|
||||
return new DefCommand(DefVerb.Selection, Text: rest);
|
||||
|
|
|
|||
|
|
@ -128,6 +128,11 @@ internal sealed class DefSettings
|
|||
/// within 4 s; this only saves those seconds.
|
||||
/// </summary>
|
||||
public bool ClearStuckBusy;
|
||||
/// <summary>
|
||||
/// The Appraisal window is pinned (2026-11-28): only a middle-click changes what it shows, not the
|
||||
/// player's own selections. Off (the default, and what a file from before reads as): both do.
|
||||
/// </summary>
|
||||
public bool AppraisalPinned;
|
||||
public bool BarOpen;
|
||||
public bool PickerOpen;
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,14 @@ internal static class DefReplies
|
|||
_ => (false, $"This RynthCore has no {title} window (it needs plugin API v90)."),
|
||||
};
|
||||
|
||||
/// <summary>A window after a pop out / dock: <paramref name="state"/> 1 popped out, 0 docked, -1 not open (or no such window).</summary>
|
||||
public static (bool Ok, string Text) PoppedOut(string title, int state) => state switch
|
||||
{
|
||||
1 => (true, $"{title} popped out: its own window, which you can put on another screen."),
|
||||
0 => (true, $"{title} docked back into the game window."),
|
||||
_ => (false, $"The {title} isn't open: open it first (/rdef appraisal), then pop it out."),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// /rdef daynight [show|hide]: the Day/Night timer after it (<paramref name="state"/> as <see cref="Window"/>),
|
||||
/// then the time now when the clock can be read (null = not in world): "Day/Night timer shown. Night now
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ internal sealed class DefStore
|
|||
st.IndependentBar = Bool(s, "independentBar", st.IndependentBar); // missing (a file from before 2026-10-27): off
|
||||
st.QuantityBox = Bool(s, "quantityBox", st.QuantityBox); // missing (a file from before 2026-10-30): on
|
||||
st.ClearStuckBusy = Bool(s, "clearStuckBusy", st.ClearStuckBusy); // missing (a file from before 2026-11-04): off
|
||||
st.AppraisalPinned = Bool(s, "appraisalPinned", st.AppraisalPinned); // missing (a file from before 2026-11-28): off
|
||||
st.BarOpen = Bool(s, "barOpen", st.BarOpen);
|
||||
st.PickerOpen = Bool(s, "pickerOpen", st.PickerOpen);
|
||||
st.Clamp();
|
||||
|
|
@ -192,6 +193,7 @@ internal sealed class DefStore
|
|||
w.WriteBoolean("independentBar", s.IndependentBar);
|
||||
w.WriteBoolean("quantityBox", s.QuantityBox);
|
||||
w.WriteBoolean("clearStuckBusy", s.ClearStuckBusy);
|
||||
w.WriteBoolean("appraisalPinned", s.AppraisalPinned);
|
||||
w.WriteBoolean("barOpen", s.BarOpen);
|
||||
w.WriteBoolean("pickerOpen", s.PickerOpen);
|
||||
w.WriteEndObject();
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ public static unsafe class PluginExports
|
|||
if (name == RynthDefectivePlugin.BarSurface) result = plugin.RenderBar(popped, out wantH);
|
||||
else if (name == RynthDefectivePlugin.PanelsSurface) result = plugin.RenderPanels(out wantH);
|
||||
else if (name == RynthDefectivePlugin.SelectionSurface) result = plugin.RenderSelection(out wantH);
|
||||
else if (name == RynthDefectivePlugin.AppraisalSurface) result = plugin.RenderAppraisal(popped, out wantH);
|
||||
else if (name == RynthDefectivePlugin.CorpsesSurface) result = plugin.RenderCorpses(out wantH);
|
||||
else if (name == RynthDefectivePlugin.DayNightSurface) result = plugin.RenderDayNight(out wantH);
|
||||
else if (RynthDefectivePlugin.TryExtraSurface(name, out int extra)) result = plugin.RenderExtraBar(extra, popped, out wantH);
|
||||
|
|
|
|||
|
|
@ -129,6 +129,32 @@ Foredawn-and-Half) are 63.5 real minutes each; the clock and calendar are RynthA
|
|||
(`getisday`, `getminutesuntilnight`). It shows "—" until you're in the world: the game clock isn't read before.
|
||||
`/rdef daynight` also says the time in chat. Drag it anywhere; Ctrl+wheel resizes it; right-click hides it.
|
||||
|
||||
## The Appraisal window
|
||||
|
||||
Retail's examine panel, roughly, that stays on **your** pick (its RynthCore bar button is the magnifying glass;
|
||||
`/rdef appraisal`): the picture and name, what it is (Heavy Weapons (Sword), Armor, Level 112 · Olthoi),
|
||||
value, burden, stack and uses, the bars (a creature's health, stamina and mana; an item's mana), a creature's
|
||||
six attributes (green when buffed, red when debuffed), then the appraisal's lines in retail's words under small
|
||||
headings (Weapon / Caster, Armor, Magic, Requirements, Properties), the description, and **All properties**
|
||||
(every property the engine holds, by ACE's names, folded).
|
||||
|
||||
What changes it:
|
||||
|
||||
* **A middle-click** on anything in the 3D world: the object under the cursor, the one whose name AC shows.
|
||||
Your selection doesn't change, so a running bot keeps its target. A middle **drag** is still mouse look.
|
||||
A middle-click opens the window when it's shut. In RynthCore's own inventory window a middle-click works too.
|
||||
* **Your own selection**: a click in the world or a pack, the selection keys, a radar dot or nameplate.
|
||||
Pinned (the pin in its title, or `/rdef appraisal pin`), only a middle-click changes it.
|
||||
* **Never the bot's selections**: anything a plugin selects through the API (RynthAi's targets, its looting).
|
||||
|
||||
A new pick is appraised (the server is asked unless it just answered); a creature's health is asked for every
|
||||
2 s while it shows, and it is assessed again every 15 s. The arrows in its title appraise it again. Right-click
|
||||
the title: copy the appraisal as text, appraise again, select it, pin, show every property, pop out, hide. The
|
||||
square in its title (or `/rdef appraisal popout`, `/rdef appraisal dock`) pops it out of the game window into its
|
||||
own window, for another screen, and docks it back. Something
|
||||
that leaves view keeps its last appraisal ("no longer in view"). Needs engine API 100 (the player's picks); the
|
||||
window isn't there on an older engine.
|
||||
|
||||
## Busy, combat and RynthAi
|
||||
|
||||
* One item action at a time: a request waits while the client is busy, a gesture animates, RynthAi waits on
|
||||
|
|
@ -165,6 +191,7 @@ Foredawn-and-Half) are 63.5 real minutes each; the clock and calendar are RynthA
|
|||
/rdef show / hide the bar
|
||||
/rdef settings RynthDefective's settings window
|
||||
/rdef panels | selection show / hide the Game Panels buttons, the Selection window
|
||||
/rdef appraisal [pin|unpin|again|popout|dock] show / hide the Appraisal window; pin it; appraise again; pop out
|
||||
/rdef use <slot | item name> use the slot's item, or the carried item with that name
|
||||
/rdef set <slot> [item name] put the selected item (or the named one) in a slot
|
||||
/rdef spell <slot> <name> put one of your spells in a slot (it casts it)
|
||||
|
|
@ -206,5 +233,5 @@ Pages, arrow auto-equip, gear highlight, summon cooldown counters and the war-ma
|
|||
## Needs
|
||||
|
||||
RynthCore engine API 71 with ImGui for the windows (op level 2 for pictures; text buttons without it);
|
||||
API 90 for the Shortcuts bar, Game Panels and Selection. `/rdef use` works on any engine with UseObject.
|
||||
API 90 for the Shortcuts bar, Game Panels and Selection; API 100 for the Appraisal window. `/rdef use` works on any engine with UseObject.
|
||||
The quantity commands: splitting on any engine, giving with a count API 62, buying API 67.
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
pictures) are checked first; so are the UseDone count (v63), wield/refusal info (v70) and
|
||||
the chat parser the key binding goes through. Below v71 it still uses items (/rdef use). -->
|
||||
<RynthPluginMinEngineApi>66</RynthPluginMinEngineApi>
|
||||
<RynthPluginDescription>Draws the Shortcuts bar (the game's 18 slots and its own), the Game Panels buttons and the Selection window (with a quantity box: split, give or buy that many), and a Day/Night timer: one-touch kits, potions, weapons and spells by slot or key, and a fast weapon picker. Settings: the bar's gear or /rdef settings.</RynthPluginDescription>
|
||||
<RynthPluginDescription>Draws the Shortcuts bar (the game's 18 slots and its own), the Game Panels buttons and the Selection window (with a quantity box: split, give or buy that many), the Appraisal window (what you middle-click or select yourself, never the bot's picks), and a Day/Night timer: one-touch kits, potions, weapons and spells by slot or key, and a fast weapon picker. Settings: the bar's gear or /rdef settings.</RynthPluginDescription>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -57,6 +57,12 @@
|
|||
(linked as RynthInventory and RynthOracle link it; Model/Spells.cs reads it). -->
|
||||
<EmbeddedResource Include="..\RynthCore.Plugin.RynthAi\Combat\SpellData.txt" LogicalName="RynthDefective.SpellData.txt" Link="Shared\SpellData.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<!-- The Appraisal window (2026-11-28): ACE's property names (the "All properties" list) and the skill, material,
|
||||
set and creature names of RynthAi's Mag-style item info, linked in (both pure tables). -->
|
||||
<Compile Include="..\RynthCore.Plugin.RynthAi\Meta\PropertyNames.cs" Link="Shared\PropertyNames.cs" />
|
||||
<Compile Include="..\RynthCore.Plugin.RynthAi\ItemInfo\MagItemInfoTables.cs" Link="Shared\MagItemInfoTables.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<!-- The shortcut bar (2026-10-22): drawn with ImGui.NET bound to the engine's cimgui, in the
|
||||
engine's look (Shared\RynthUi; plugin API v90 hosts the frameless window and gives AC's
|
||||
|
|
|
|||
|
|
@ -0,0 +1,246 @@
|
|||
// ============================================================================
|
||||
// RynthDefective - RynthDefectivePlugin.Appraisal.cs
|
||||
// The Appraisal window's tick (2026-11-28; Appraisal/AppraisalWindow.cs draws
|
||||
// it, Appraisal/AppraisalText.cs words it).
|
||||
//
|
||||
// What it shows is the PLAYER's pick, from the engine (plugin API v100
|
||||
// GetPlayerPick): a middle-click on something in the world (the object under
|
||||
// the cursor; AC's selection doesn't change, so a running bot keeps its
|
||||
// target), or a selection the player made (a click in the world or a pack,
|
||||
// the selection keys, a radar dot). Selections a plugin makes through the API
|
||||
// (RynthAi's targets and loot) never reach it. Pinned (the window's pin, saved
|
||||
// in the character file): only a middle-click changes it.
|
||||
//
|
||||
// A new pick is appraised (RequestId) unless the server answered for it in the
|
||||
// last few seconds; a creature's health is asked for every 2 s while it shows,
|
||||
// and it is assessed again every 15 s. A middle-click opens the window when it
|
||||
// is shut. The view is rebuilt 4 times a second while the window draws.
|
||||
//
|
||||
// Needs API v100 (the pick); on an older engine the window isn't declared.
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using RynthCore.Plugin.RynthDefective.Appraisal;
|
||||
using RynthCore.Plugin.RynthDefective.Model;
|
||||
using RynthCore.PluginSdk;
|
||||
|
||||
namespace RynthCore.Plugin.RynthDefective;
|
||||
|
||||
public sealed partial class RynthDefectivePlugin
|
||||
{
|
||||
internal const string AppraisalSurface = "window:appraisal";
|
||||
|
||||
private AppraisalWindow? _appraisalWindow; // render thread
|
||||
private volatile AppraisalView _appraisalView = AppraisalView.NotReady;
|
||||
private long _appraisalDrawnMs = long.MinValue / 2, _nextAppraisalMs, _nextAppraisalHealthMs, _nextAppraisalIdMs;
|
||||
private int _pickSeq = -1;
|
||||
private uint _appraisalId;
|
||||
private string _appraisalSource = string.Empty;
|
||||
private long _appraisalPickedMs;
|
||||
private AppraisalDoc? _appraisalLast;
|
||||
private int _appraisalFailures;
|
||||
private volatile AppraisalHealth? _appraisalHealth;
|
||||
private sealed record AppraisalHealth(uint Id, float Ratio);
|
||||
|
||||
private const long AppraisalBuildMs = 250, AppraisalHealthMs = 2000, CreatureReassessMs = 15000, RecentIdSeconds = 5;
|
||||
|
||||
/// <summary>The engine has v100's player picks: the Appraisal window is declared.</summary>
|
||||
internal bool UsesAppraisal => UsesShortcutBar && Host.HasPlayerPick;
|
||||
|
||||
private bool AppraisalPinned => _identityKnown && _session.Data.Settings.AppraisalPinned;
|
||||
|
||||
/// <summary>RynthPluginRenderEmbed "window:appraisal" (":popout" when popped out). 1 drawn, 0 not ready, -2 failed (three in a row). Render thread.</summary>
|
||||
internal int RenderAppraisal(bool popped, out float wantHeight)
|
||||
{
|
||||
wantHeight = 0;
|
||||
if (!UsesAppraisal) return 0;
|
||||
System.Threading.Volatile.Write(ref _appraisalDrawnMs, Environment.TickCount64);
|
||||
try
|
||||
{
|
||||
_appraisalWindow ??= new AppraisalWindow(Host)
|
||||
{
|
||||
Refresh = () => QueueBar(AppraiseAgain),
|
||||
TogglePin = () => QueueBar(ToggleAppraisalPin),
|
||||
Select = id => QueueBar(() => { if (!Host.SelectItem(id)) Print("That can't be selected now."); }),
|
||||
};
|
||||
wantHeight = _appraisalWindow.Draw(_appraisalView, popped);
|
||||
_appraisalFailures = 0;
|
||||
return 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Host.Log($"[RynthDefective] appraisal draw failed: {ex.GetType().Name}: {ex.Message}");
|
||||
return ++_appraisalFailures >= 3 ? -2 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Health from AC for the appraised creature (OnUpdateHealth, any thread).</summary>
|
||||
private void NoteAppraisalHealth(uint targetId, float ratio)
|
||||
{
|
||||
if (targetId != 0 && targetId == _appraisalId) _appraisalHealth = new AppraisalHealth(targetId, ratio);
|
||||
}
|
||||
|
||||
/// <summary>Plugin tick: a new pick, the asks to the server, and the view while the window draws.</summary>
|
||||
private void TickAppraisal(long now)
|
||||
{
|
||||
if (!UsesAppraisal || !_identityKnown) return;
|
||||
try
|
||||
{
|
||||
TakePick(now);
|
||||
bool shown = now - System.Threading.Volatile.Read(ref _appraisalDrawnMs) <= 2000;
|
||||
if (!shown || _appraisalId == 0) { if (_appraisalId == 0) _appraisalView = new AppraisalView(true, null, "", AppraisalPinned, false); return; }
|
||||
AskServer(now);
|
||||
if (now < _nextAppraisalMs) return;
|
||||
_nextAppraisalMs = now + AppraisalBuildMs;
|
||||
_appraisalView = BuildAppraisal(now);
|
||||
}
|
||||
catch (Exception ex) { Host.Log($"[RynthDefective] appraisal read failed: {ex.GetType().Name}: {ex.Message}"); }
|
||||
}
|
||||
|
||||
/// <summary>The engine's last player pick, when it is new and this window takes it.</summary>
|
||||
private void TakePick(long now)
|
||||
{
|
||||
int seq = Host.GetPlayerPick(out uint id, out RynthPickKind kind);
|
||||
if (_pickSeq < 0) { _pickSeq = seq; if (seq > 0 && id != 0) Adopt(id, kind, now, open: false); return; } // the last pick before a reload
|
||||
if (seq == _pickSeq || id == 0) return;
|
||||
_pickSeq = seq;
|
||||
if (kind == RynthPickKind.Selected && AppraisalPinned) return;
|
||||
Adopt(id, kind, now, open: kind == RynthPickKind.MiddleClick);
|
||||
}
|
||||
|
||||
private void Adopt(uint id, RynthPickKind kind, long now, bool open)
|
||||
{
|
||||
bool same = id == _appraisalId;
|
||||
_appraisalId = id;
|
||||
_appraisalPickedMs = now;
|
||||
_appraisalSource = kind == RynthPickKind.MiddleClick ? "Middle-clicked" : "Your selection";
|
||||
if (!same) { _appraisalHealth = null; _appraisalLast = null; }
|
||||
_nextAppraisalMs = 0;
|
||||
_nextAppraisalHealthMs = 0;
|
||||
// A new pick is appraised unless the server just answered for it (AC appraises a selection itself).
|
||||
if (!RecentlyIdentified(id)) Host.RequestId(id);
|
||||
_nextAppraisalIdMs = now + CreatureReassessMs;
|
||||
if (open && Host.SetPanelOpen(AppraisalWindow.Title, RynthPanelOpen.Ask) == 0)
|
||||
Host.SetPanelOpen(AppraisalWindow.Title, RynthPanelOpen.Open);
|
||||
}
|
||||
|
||||
private bool RecentlyIdentified(uint id)
|
||||
{
|
||||
long last = Host.GetLastIdTime(id);
|
||||
return last > 0 && DateTimeOffset.UtcNow.ToUnixTimeSeconds() - last <= RecentIdSeconds;
|
||||
}
|
||||
|
||||
/// <summary>A creature's health every 2 s, and an assess every 15 s while it shows.</summary>
|
||||
private void AskServer(long now)
|
||||
{
|
||||
bool creature = Host.TryGetItemType(_appraisalId, out uint type) && (type & CreatureType) != 0;
|
||||
if (!creature) return;
|
||||
if (now >= _nextAppraisalHealthMs)
|
||||
{
|
||||
_nextAppraisalHealthMs = now + AppraisalHealthMs;
|
||||
Host.QueryHealth(_appraisalId);
|
||||
}
|
||||
if (now >= _nextAppraisalIdMs)
|
||||
{
|
||||
_nextAppraisalIdMs = now + CreatureReassessMs;
|
||||
Host.RequestId(_appraisalId);
|
||||
}
|
||||
}
|
||||
|
||||
private AppraisalView BuildAppraisal(long now)
|
||||
{
|
||||
uint id = _appraisalId;
|
||||
string source = _appraisalSource + " · " + Ago(now - _appraisalPickedMs);
|
||||
if (!Host.TryGetObjectProperties(id, out ObjectProperties? p) || p == null)
|
||||
{
|
||||
// Gone from view (a despawn, out of range): keep what was last read.
|
||||
return new AppraisalView(true, _appraisalLast, source, AppraisalPinned, Gone: true);
|
||||
}
|
||||
if (p.QualitiesPending && _appraisalLast != null)
|
||||
return new AppraisalView(true, _appraisalLast, source, AppraisalPinned, false); // the engine reads AC's tables next tick
|
||||
|
||||
var input = new AppraisalInput
|
||||
{
|
||||
Id = id,
|
||||
Name = Host.TryGetObjectName(id, out string n) ? n : string.Empty,
|
||||
ItemType = Host.TryGetItemType(id, out uint type) ? type : 0,
|
||||
Identified = p.HasIdData,
|
||||
IsPlayer = p.IsPlayer || IsPlayerObject(id),
|
||||
Ints = p.Ints, Int64s = p.Int64s, Bools = p.Bools, Floats = p.Floats,
|
||||
Strings = p.Strings, DataIds = p.DataIds, InstanceIds = p.InstanceIds, Spells = p.Spells,
|
||||
SpellName = SpellTable.Name,
|
||||
};
|
||||
bool creature = (input.ItemType & CreatureType) != 0;
|
||||
if (creature)
|
||||
{
|
||||
if (Host.TryGetTargetVitals(id, out uint h, out uint hm, out uint s, out uint sm, out uint m, out uint mm) && hm > 0)
|
||||
input.Vitals = (h, hm, s, sm, m, mm);
|
||||
Span<uint> attrs = stackalloc uint[6];
|
||||
if (Host.TryGetCreatureAttributes(id, attrs, out uint bits) && attrs[0] + attrs[1] + attrs[2] + attrs[3] + attrs[4] + attrs[5] > 0)
|
||||
{
|
||||
input.Attributes = attrs.ToArray();
|
||||
input.EnchantBits = bits;
|
||||
}
|
||||
if (_appraisalHealth is { } hs && hs.Id == id) input.HealthRatio = hs.Ratio;
|
||||
}
|
||||
AppraisalDoc doc = AppraisalText.Build(input);
|
||||
_appraisalLast = doc;
|
||||
return new AppraisalView(true, doc, source, AppraisalPinned, false);
|
||||
}
|
||||
|
||||
/// <summary>A player's character (the engine flags the player itself; others by their ObjectDescriptionFlags Player bit).</summary>
|
||||
private bool IsPlayerObject(uint id) =>
|
||||
id == Host.GetPlayerId() || Host.TryGetObjectBitfield(id, out uint bits) && (bits & 0x8) != 0;
|
||||
|
||||
private void AppraiseAgain()
|
||||
{
|
||||
if (_appraisalId == 0) { PrintFail("Nothing is in the Appraisal window."); return; }
|
||||
if (!Host.RequestId(_appraisalId)) PrintFail("The server can't be asked now.");
|
||||
_nextAppraisalMs = 0;
|
||||
}
|
||||
|
||||
private void ToggleAppraisalPin()
|
||||
{
|
||||
if (!_identityKnown) return;
|
||||
_session.Data.Settings.AppraisalPinned = !_session.Data.Settings.AppraisalPinned;
|
||||
RequestSave();
|
||||
_nextAppraisalMs = 0;
|
||||
Print(_session.Data.Settings.AppraisalPinned
|
||||
? "Appraisal pinned: only a middle-click changes it."
|
||||
: "Appraisal follows your own clicks and middle-clicks.");
|
||||
}
|
||||
|
||||
/// <summary>/rdef appraisal [pin|unpin|0x8000ABCD]: the window, the pin, or (a test hook) appraise that object.</summary>
|
||||
private void RunAppraisalCommand(string text)
|
||||
{
|
||||
if (!UsesAppraisal) { PrintFail("This RynthCore can't show the Appraisal window (it needs plugin API v100)."); return; }
|
||||
string t = text.Trim();
|
||||
if (t.Length == 0)
|
||||
{
|
||||
Answer(DefReplies.Window("Appraisal window", Host.SetPanelOpen(AppraisalWindow.Title, RynthPanelOpen.Toggle)));
|
||||
return;
|
||||
}
|
||||
switch (t.ToLowerInvariant())
|
||||
{
|
||||
case "pin": if (!_session.Data.Settings.AppraisalPinned) ToggleAppraisalPin(); else Print("Appraisal is already pinned."); return;
|
||||
case "unpin": if (_session.Data.Settings.AppraisalPinned) ToggleAppraisalPin(); else Print("Appraisal already follows your clicks."); return;
|
||||
case "again": case "refresh": AppraiseAgain(); return;
|
||||
case "popout": case "pop": case "out":
|
||||
Answer(DefReplies.PoppedOut("Appraisal window", Host.SetPanelPopOut(AppraisalWindow.Title, RynthPanelPopOut.PopOut))); return;
|
||||
case "dock": case "in":
|
||||
Answer(DefReplies.PoppedOut("Appraisal window", Host.SetPanelPopOut(AppraisalWindow.Title, RynthPanelPopOut.Dock))); return;
|
||||
}
|
||||
if (DefReplies.TryParseSelection(t, out uint pick, out string why))
|
||||
{
|
||||
Adopt(pick, RynthPickKind.MiddleClick, Environment.TickCount64, open: true);
|
||||
Print($"Appraising {_session.ObjectName(pick)} (0x{pick:X8}).");
|
||||
}
|
||||
else PrintFail(why + " Usage: /rdef appraisal [pin | unpin | again | popout | dock | 0x8000ABCD]");
|
||||
}
|
||||
|
||||
private static string Ago(long ms)
|
||||
{
|
||||
long s = Math.Max(0, ms / 1000);
|
||||
return s < 5 ? "just now" : s < 60 ? $"{s} s ago" : s < 3600 ? $"{s / 60} min ago" : $"{s / 3600} h ago";
|
||||
}
|
||||
}
|
||||
|
|
@ -94,6 +94,13 @@ public sealed partial class RynthDefectivePlugin : IBarActions
|
|||
"\",\"icon\":\"\\u" + ((int)RynthIcons.Crosshair[0]).ToString("X4", CultureInfo.InvariantCulture) +
|
||||
"\",\"width\":280,\"height\":46,\"minWidth\":120,\"minHeight\":24,\"bar\":false,\"edgeToEdge\":true," +
|
||||
"\"chrome\":\"none\",\"fitHeight\":true,\"corner\":\"top\",\"scale\":\"draw\"}";
|
||||
// The Appraisal window (2026-11-28, API v100's player picks; an engine before v100 hosts at most 8
|
||||
// windows, so it isn't declared there): a bar button of its own, first at the right.
|
||||
string appraisal = !UsesAppraisal ? "" :
|
||||
",{\"id\":\"appraisal\",\"title\":\"" + Appraisal.AppraisalWindow.Title + "\",\"surface\":\"" + AppraisalSurface +
|
||||
"\",\"icon\":\"\\u" + ((int)RynthIcons.MagnifyingGlass[0]).ToString("X4", CultureInfo.InvariantCulture) +
|
||||
"\",\"width\":300,\"height\":220,\"minWidth\":200,\"minHeight\":60,\"bar\":true,\"edgeToEdge\":true," +
|
||||
"\"chrome\":\"none\",\"fitHeight\":true,\"corner\":\"topRight\",\"scale\":\"draw\"}";
|
||||
// Where your corpses are (a bar button of its own).
|
||||
string corpses = ",{\"id\":\"corpses\",\"title\":\"" + Corpses.CorpsesWindow.Title + "\",\"surface\":\"" + CorpsesSurface +
|
||||
"\",\"icon\":\"\\u" + ((int)RynthIcons.Skull[0]).ToString("X4", CultureInfo.InvariantCulture) +
|
||||
|
|
@ -104,14 +111,15 @@ public sealed partial class RynthDefectivePlugin : IBarActions
|
|||
"\",\"icon\":\"\\u" + ((int)RynthIcons.Sun[0]).ToString("X4", CultureInfo.InvariantCulture) +
|
||||
"\",\"width\":150,\"height\":26,\"minWidth\":70,\"minHeight\":20,\"bar\":true,\"edgeToEdge\":true," +
|
||||
"\"chrome\":\"none\",\"fitHeight\":true,\"scale\":\"draw\"}";
|
||||
// The extra bars (the engine hosts at most 8 windows for a plugin: these five and up to three of them).
|
||||
// The extra bars (an engine before v100 hosts at most 8 windows for a plugin: these five and up to three
|
||||
// of them; v100 hosts 12, and the Appraisal window makes nine).
|
||||
string extras = "";
|
||||
foreach (int n in _extraNumbers)
|
||||
extras += ",{\"id\":\"bar" + n.ToString(CultureInfo.InvariantCulture) + "\",\"title\":\"" + ExtraBar.TitleOf(n) + "\",\"surface\":\""
|
||||
+ ExtraBar.SurfaceOf(n) + "\",\"icon\":\"\\u" + ((int)RynthIcons.Lightning[0]).ToString("X4", CultureInfo.InvariantCulture) +
|
||||
"\",\"width\":300,\"height\":80,\"minWidth\":90,\"minHeight\":40,\"bar\":false,\"edgeToEdge\":true," +
|
||||
"\"chrome\":\"none\",\"fitHeight\":true,\"scale\":\"draw\"}";
|
||||
return "{\"version\":1,\"windows\":[" + bar + panels + selection + corpses + dayNight + extras + "]}";
|
||||
return "{\"version\":1,\"windows\":[" + bar + panels + selection + appraisal + corpses + dayNight + extras + "]}";
|
||||
}
|
||||
|
||||
/// <summary>"window:bar2" ... "window:bar4": an extra bar's surface, and its number.</summary>
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ public sealed partial class RynthDefectivePlugin
|
|||
{
|
||||
if (targetId != 0 && targetId == _selectionId)
|
||||
_health = new HealthSeen(targetId, healthRatio, currentHealth, maxHealth);
|
||||
NoteAppraisalHealth(targetId, healthRatio);
|
||||
}
|
||||
|
||||
/// <summary>RynthPluginRenderEmbed "window:selection". 1 drawn, 0 not ready, -2 failed (three in a row). Render thread.</summary>
|
||||
|
|
|
|||
|
|
@ -214,6 +214,9 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase
|
|||
if (UsesShortcutBar) Answer(DefReplies.Window("Selection window", Host.SetPanelOpen(RynthCore.Plugin.RynthDefective.ShortcutBar.SelectionWindow.Title, RynthPanelOpen.Toggle)));
|
||||
else PrintFail("This RynthCore can't show the selection window (it needs plugin API v90).");
|
||||
break;
|
||||
case DefVerb.Appraisal:
|
||||
RunAppraisalCommand(c.Text);
|
||||
break;
|
||||
case DefVerb.Settings:
|
||||
ShowSettingsWindow(true);
|
||||
Print("Settings shown.");
|
||||
|
|
@ -412,7 +415,8 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase
|
|||
/// <summary>Whether one of the windows RynthDefective draws shows (by its title); null = not on this engine.</summary>
|
||||
private bool? PanelShown(string title)
|
||||
{
|
||||
if (!UsesShortcutBar || (title == ShortcutBar.PanelButtonsWindow.Title && !UsesPanelButtons)) return null;
|
||||
if (!UsesShortcutBar || (title == ShortcutBar.PanelButtonsWindow.Title && !UsesPanelButtons)
|
||||
|| (title == Appraisal.AppraisalWindow.Title && !UsesAppraisal)) return null;
|
||||
int state = Host.SetPanelOpen(title, RynthPanelOpen.Ask);
|
||||
return state < 0 ? null : state == 1;
|
||||
}
|
||||
|
|
@ -486,6 +490,7 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase
|
|||
if (_saveDueMs != 0 && now >= _saveDueMs) SaveNow();
|
||||
TickBar(now);
|
||||
TickSelection(now);
|
||||
TickAppraisal(now);
|
||||
TickQuantity(now);
|
||||
TickCorpses(now);
|
||||
TickDayNight(now);
|
||||
|
|
|
|||
|
|
@ -556,6 +556,8 @@ internal sealed class ShortcutBarWindow
|
|||
if (_host.HasAcPanels) PanelToggle(PanelButtonsWindow.Title, "Game panel buttons",
|
||||
"The buttons for the game's own panels (pack, spellbook, map ...), first in the bottom-right corner (/rdef panels).");
|
||||
PanelToggle(SelectionWindow.Title, "Selection", "What is selected, how far and which way, and a creature's health (/rdef selection).");
|
||||
if (_host.HasPlayerPick) PanelToggle(Appraisal.AppraisalWindow.Title, "Appraisal",
|
||||
"The appraisal of what you pick: middle-click something in the world, or select it yourself; never the bot's picks (/rdef appraisal).");
|
||||
}
|
||||
|
||||
private void PanelToggle(string title, string label, string tip)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ internal sealed class BarSettingsView
|
|||
public const string BarTitle = ShortcutBar.ShortcutBarWindow.Title;
|
||||
public const string PanelsTitle = ShortcutBar.PanelButtonsWindow.Title;
|
||||
public const string SelectionTitle = ShortcutBar.SelectionWindow.Title;
|
||||
public const string AppraisalTitle = Appraisal.AppraisalWindow.Title;
|
||||
|
||||
private readonly DefSession _s;
|
||||
|
||||
|
|
@ -65,6 +66,15 @@ internal sealed class BarSettingsView
|
|||
+ "Give that many to the last player or NPC you selected, or Buy that many from the open vendor.\n"
|
||||
+ "/rdef qty, /rdef split, /rdef give and /rdef buy do the same with it off. Kept for this character.");
|
||||
}
|
||||
WindowBox(w, AppraisalTitle, "Appraisal", "set.win.appr",
|
||||
"The appraisal of what YOU pick: middle-click something in the world (your selection doesn't change), or select it yourself. "
|
||||
+ "The bot's selections never change it (/rdef appraisal).");
|
||||
if (WindowShown(AppraisalTitle) != null)
|
||||
{
|
||||
w.Checkbox("Appraisal: pinned (only a middle-click changes it)", "set.appr.pin", st.AppraisalPinned, v => { st.AppraisalPinned = v; Changed(); });
|
||||
w.Tooltip("On: your own clicks and selection keys don't change the Appraisal window; only a middle-click does.\n"
|
||||
+ "Off (the default): both do. The bot's selections never do. Kept for this character (/rdef appraisal pin | unpin).");
|
||||
}
|
||||
|
||||
w.SeparatorText("Shortcuts bar");
|
||||
w.Checkbox("Independent of the game's toolbar", "set.indep", st.IndependentBar, v => Tell(_s.SetIndependent(v)));
|
||||
|
|
|
|||
Loading…
Reference in a new issue