RynthSuite/Tools/RynthDefective.Tests/AppraisalTests.cs

164 lines
11 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using RynthCore.Plugin.RynthDefective.Appraisal;
using RynthCore.Plugin.RynthDefective.Model;
namespace RynthDefective.Tests
{
// The Appraisal window's words (2026-11-28): retail's examine lines for a weapon, armor, a caster, a
// creature and a player, the wield requirements, the flags, and the "All properties" list.
internal static partial class Program
{
private static AppraisalInput Item(uint itemType, params (uint Key, int Value)[] ints)
{
var o = new AppraisalInput { Id = 0x8000_1234, Name = "Test Item", ItemType = itemType, Identified = true, SpellName = SpellTable.Name };
o.Ints[1] = (int)itemType;
foreach (var (k, v) in ints) o.Ints[k] = v;
return o;
}
private static List<string> Lines(AppraisalDoc d, string section) =>
d.Sections.FirstOrDefault(s => s.Title == section)?.Lines.Select(l => l.Text).ToList() ?? new List<string>();
private static void AppraiseWeapon()
{
// A heavy sword: 50 max, variance 0.5, slash/pierce, speed 35, +12% attack, +15% melee defense.
var o = Item(0x1, (19, 12345), (5, 150), (48, 0x2C), (353, 2), (44, 50), (45, 0x3), (49, 35),
(158, 1), (159, 0x2C), (160, 400), (270, 7), (272, 180), (105, 8), (131, 64), (265, 13), (370, 3), (372, 1), (179, 0x4), (166, 1));
o.Floats[22] = 0.5; o.Floats[62] = 1.12; o.Floats[29] = 1.15; o.Floats[138] = 2.5;
o.Spells.Add(6);
AppraisalDoc d = AppraisalText.Build(o);
Eq(d.Kind, "Heavy Weapons (Sword)", "kind");
Check(d.Facts.Contains(("Value", "12,345")) && d.Facts.Contains(("Burden", "150")), "value and burden: " + string.Join("; ", d.Facts));
var w = Lines(d, "Weapon");
Check(w.Contains("Skill: Heavy Weapons (Sword)"), "skill line: " + string.Join(" | ", w));
Check(w.Contains("Damage: 25 - 50, Slashing/Piercing"), "damage line");
Check(w.Contains("Speed: Average (35)"), "speed line");
Check(w.Contains("Bonus to Attack Skill: +12%."), "attack bonus");
Check(w.Contains("Bonus to Melee Defense: +15%."), "melee defense bonus");
Check(w.Contains("Slayer: Olthoi (x2.5 damage)"), "slayer");
Check(w.Contains("Imbued: Armor Rending"), "imbue");
var r = Lines(d, "Requirements");
Check(r.Contains("Wield requires Heavy Weapons 400") && r.Contains("Wield requires level 180"), "wield lines: " + string.Join(" | ", r));
var p = Lines(d, "Properties");
Check(p.Contains("Workmanship: Utterly flawless (8)") && p.Contains("Material: Steel") && p.Contains("Set: Soldier's Set"), "workmanship, material, set: " + string.Join(" | ", p));
Check(p.Contains("Ratings: Damage +3, Crit +1"), "ratings");
Check(Lines(d, "Magic").Contains("Spells: Heal Self I"), "spells by name");
Check(!d.IsCreature && d.Bars.Count == 0, "an item without mana has no bars");
}
private static void AppraiseArmorAndMana()
{
var o = Item(0x2, (28, 600), (4, 0x0400 | 0x0800 | 0x1000 | 0x2000), (107, 1234), (108, 2000), (106, 400), (109, 300), (33, 1), (114, 1), (36, 9999));
o.Floats[13] = 1.2; o.Floats[14] = 0.6; o.Floats[5] = -1.0 / 20.0;
o.Bools[91] = true;
AppraisalDoc d = AppraisalText.Build(o);
Eq(d.Kind, "Armor", "kind");
var a = Lines(d, "Armor");
Check(a.Contains("Armor Level: 600") && a.Contains("Slashing: Above Average (720)") && a.Contains("Piercing: Below Average (360)"), "protections: " + string.Join(" | ", a));
Check(a.Contains("Covers: Chest, Abdomen, Upper Arms, Lower Arms"), "coverage");
var m = Lines(d, "Magic");
Check(m.Contains("Mana: 1,234 / 2,000") && m.Contains("Mana Cost: 1 point per 20 seconds.") && m.Contains("Spellcraft: 400."), "mana lines: " + string.Join(" | ", m));
Check(Lines(d, "Requirements").Contains("Activation requires Arcane Lore: 300"), "arcane lore");
Check(Lines(d, "Properties").Contains("Properties: Bonded, Attuned (can't be given), Retained, Unenchantable"), "flags: " + string.Join(" | ", Lines(d, "Properties")));
Check(d.Bars.Count == 1 && d.Bars[0].Kind == AppraiseBarKind.Mana && d.Bars[0].Current == 1234 && d.Bars[0].Max == 2000, "the mana bar");
}
private static void AppraiseCaster()
{
var o = Item(0x8000, (45, 0x10));
o.Floats[144] = 0.05; o.Floats[152] = 1.15; o.Floats[150] = 1.10;
AppraisalDoc d = AppraisalText.Build(o);
var c = Lines(d, "Caster");
Check(c.Contains("Bonus to Mana Conversion: +5%."), "mana conversion: " + string.Join(" | ", c));
Check(c.Contains("Damage bonus for Fire spells: +15% vs. Monsters, +3.75% vs. Players."), "elemental bonus");
Check(c.Contains("Bonus to Magic Defense: +10%."), "magic defense");
}
private static void AppraiseCreatureAndPlayer()
{
var m = Item(0x10, (25, 112), (2, 1));
m.Name = "Olthoi Soldier";
m.Vitals = (500, 1000, 200, 400, 0, 0);
m.HealthRatio = 0.4f;
m.Attributes = new uint[] { 200, 180, 190, 210, 100, 90 };
m.EnchantBits = (1u << 0) | (1u << 16) | (1u << 3); // Strength up, Coordination down
AppraisalDoc d = AppraisalText.Build(m);
Check(d.IsCreature, "a creature");
Eq(d.Kind, "Level 112 · Olthoi", "creature kind");
Check(d.Bars.Count == 2 && d.Bars[0].Label == "Health" && Math.Abs(d.Bars[0].Ratio - 0.4f) < 1e-6 && d.Bars[1].Label == "Stamina", "health (the server's ratio) and stamina; no mana bar without max mana");
Check(d.Attributes.Count == 6 && d.Attributes[0] == ("Strength", 200u, true, true) && d.Attributes[3] == ("Coordination", 210u, true, false), "attributes and their buffs");
Check(d.Facts.Count == 0, "no value or burden for a creature");
var p = Item(0x10, (25, 275), (188, 1), (113, 1), (134, 4), (30, 5));
p.IsPlayer = true;
p.Strings[2] = "the Bold"; p.Strings[47] = "Test Allegiance";
AppraisalDoc pd = AppraisalText.Build(p);
Eq(pd.Kind, "Level 275 · Aluvian Male", "player kind");
var c = Lines(pd, "Character");
Check(c.Contains("Title: the Bold") && c.Contains("Player Killer") && c.Contains("Allegiance: Test Allegiance") && c.Contains("Rank: 5"), "character lines: " + string.Join(" | ", c));
var unknown = Item(0x10);
unknown.Identified = false;
AppraisalDoc ud = AppraisalText.Build(unknown);
Check(ud.Sections.Any(s => s.Lines.Any(l => l.Text.StartsWith("Not assessed yet", StringComparison.Ordinal))), "an unassessed creature says so");
}
private static void AppraiseWordsAndRaw()
{
Eq(AppraisalText.WieldLine(8, 0x0B, 3), "Wield requires specialized Sword", "training requirement");
Eq(AppraisalText.WieldLine(3, 1, 200), "Wield requires Strength 200", "attribute requirement");
Eq(AppraisalText.WieldLine(12, 0, 3), "Wield requires Sho race", "heritage requirement");
Eq(AppraisalText.SpeedName(10), "Very Fast", "speed 10");
Eq(AppraisalText.SpeedName(80), "Very Slow", "speed 80");
Eq(AppraisalText.Pct(0.0375), "+3.75%", "a fractional percent");
Eq(AppraisalText.Pct(-0.05), "-5%", "a negative percent");
Eq(AppraisalText.Coverage(0x4000 | 0x8000 | 0x10000), "Head, Hands, Feet", "coverage order");
var o = Item(0x8, (19, 10));
o.Strings[16] = "A long description.";
o.Floats[5] = -0.05;
o.DataIds[37] = 0x21; // ItemSkillLimit: Life Magic
o.Ints[115] = 250;
o.InstanceIds[2] = 0x5000_0001;
o.Spells.Add(6);
AppraisalDoc d = AppraisalText.Build(o);
Eq(d.Description, "A long description.", "the long description");
Check(Lines(d, "Requirements").Contains("Activation requires Life Magic: 250"), "activation skill");
Check(d.Raw.Any(r => r.Kind == "Int" && r.Key == 19 && r.Name == "Value" && r.Value == "10"), "raw: an int by name");
Check(d.Raw.Any(r => r.Kind == "Float" && r.Name == "ManaRate" && r.Value == "-0.05"), "raw: a float");
Check(d.Raw.Any(r => r.Kind == "InstanceId" && r.Value == "0x50000001"), "raw: an instance id");
Check(d.Raw.Any(r => r.Kind == "Spell" && r.Name == "Heal Self I"), "raw: the spell by name");
int ints = d.Raw.Count(r => r.Kind == "Int");
Eq(ints, o.Ints.Count, "every int listed once");
string text = d.ToText();
Check(text.StartsWith("Test Item", StringComparison.Ordinal) && text.Contains("Value: 10") && text.Contains("A long description."), "copy as text");
}
private static void AppraiseCommand()
{
DefCommand c = DefCommandParser.Parse("appraisal");
Check(c.Verb == DefVerb.Appraisal && c.Text == "", "/rdef appraisal");
c = DefCommandParser.Parse("appraise pin");
Check(c.Verb == DefVerb.Appraisal && c.Text == "pin", "/rdef appraise pin");
c = DefCommandParser.Parse("examine 0x80001234");
Check(c.Verb == DefVerb.Appraisal && c.Text == "0x80001234", "/rdef examine <id>");
c = DefCommandParser.Parse("appraisal popout");
Check(c.Verb == DefVerb.Appraisal && c.Text == "popout", "/rdef appraisal popout");
// Pop out / dock answers.
Check(DefReplies.PoppedOut("Appraisal window", 1).Ok && DefReplies.PoppedOut("Appraisal window", 1).Text.Contains("popped out"), "popped out");
Check(DefReplies.PoppedOut("Appraisal window", 0).Ok && DefReplies.PoppedOut("Appraisal window", 0).Text.Contains("docked"), "docked");
Check(!DefReplies.PoppedOut("Appraisal window", -1).Ok && DefReplies.PoppedOut("Appraisal window", -1).Text.Contains("open it first"), "not open: says to open it");
// The pin, in the character's file.
var d = new DefData();
d.Settings.AppraisalPinned = true;
Check(DefStore.Parse(System.Text.Json.JsonDocument.Parse(DefStore.ToJson(d)).RootElement).Settings.AppraisalPinned, "pinned: saved and read");
Check(!DefStore.Parse(System.Text.Json.JsonDocument.Parse("{\"settings\":{\"quantityBox\":true}}").RootElement).Settings.AppraisalPinned, "a file from before: not pinned");
}
}
}