RynthSuite/Tools/RynthCore.MonsterEditor/Models.cs
Daniel Wallace 7cbc6fdca9 RynthAi: monster rule Priority 0 means never attacked
A monster whose applicable rule (its own row, else Default) has Priority <= 0
is dropped in ScanNearbyTargets before the LOS check, so it is never a target
(acquire, re-lock, kill-shot alternate, next pick) and is not counted by any
consumer of the scan list or the no-LOS count: HasTargets, HasNearbyMonsters,
HasEngageableTarget, HasCloseThreat, IsUnderCloseAttack (nav hold, combat
entry, stance, buff/rest, loot starvation, corpse gates, pets). An active
target that becomes ignored is dropped at once. There is no exception for a
Priority 0 monster that attacks the player; the HP failsafe still protects
the player.

Combat hook: ctx.monsters (RynthAi.Combat GetScanned) reads the same scan
list, so an ignored monster is left out of it, even while it hits us, and
ScriptAttackProblem rejects a script answer at a Priority 0 target before the
fight-target match (a fight target whose rule changed to 0 is still the
active target until Think drops it), so RynthAi casts its own choice.
ScriptHealProblem rejects a script heal (a drain) at one the same way
(CombatManager.IsIgnored).

MonsterEditor: the P column shows "ign" for 0 and carries a tooltip on the
header, cell and editor. README documents monster rules.

Tests: IgnoreMonsterTests, a loot-starvation case in LootCorpseTests, and two
CombatHookTests (ctx.monsters leaves out an ignored monster; a script answer
at one is rejected, both even while it hits us; a script heal at a fight target
turned to Priority 0 is rejected).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-12 17:34:34 -07:00

94 lines
5.5 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace RynthCore.MonsterEditor;
/// <summary>The editor's copy of RynthAi's MonsterRule (Plugins/RynthCore.Plugin.RynthAi/LegacyUi/
/// LegacyUiSettings.cs), read from and saved to the same monsters file. A field the plugin has and
/// this class doesn't still survives a save, through <see cref="ExtraFields"/>.</summary>
public class MonsterRule : INotifyPropertyChanged
{
private string _name = "New Monster";
private string _category = "";
private string _matchExpression = "";
private int _priority = 1;
private string _damageType = "Auto";
private int _weaponId;
private bool _fester, _broadside, _gravityWell, _imperil, _yield, _vuln;
private bool _useArc, _useBolt = true, _useRing, _useStreak, _useBlast, _useWall;
private string _exVuln = "None";
private int _offhandId;
private string _petDamage = "PAuto";
public string Name { get => _name; set { _name = value; OnPropertyChanged(); } }
/// <summary>The plugin's rule group label. Kept and editable here (before 2026-10-05 an
/// editor save dropped it).</summary>
public string Category { get => _category; set { _category = value ?? ""; OnPropertyChanged(); } }
/// <summary>The plugin's match expression (CombatManager.GetRuleForTarget): when set, the
/// rule matches when the expression is true (and the name, if any, is in the target's).
/// Empty = match by name only. Kept and editable here (before 2026-10-05 an editor save
/// dropped it, so expression rules fell back to name-only).</summary>
public string MatchExpression { get => _matchExpression; set { _matchExpression = value ?? ""; OnPropertyChanged(); } }
/// <summary>Target order: a higher Priority is fought first. 0 (or less) means IGNORE: RynthAi never targets the
/// monster, even one attacking the player, and does not wait on it.</summary>
public int Priority { get => _priority; set { _priority = value; OnPropertyChanged(); OnPropertyChanged(nameof(PriorityText)); } }
/// <summary>What the Priority column shows: the number, or "ign" for Priority 0 (ignore).</summary>
[JsonIgnore]
public string PriorityText => _priority <= 0 ? "ign" : _priority.ToString();
public string DamageType { get => _damageType; set { _damageType = value; OnPropertyChanged(); } }
public int WeaponId { get => _weaponId; set { _weaponId = value; OnPropertyChanged(); } }
public bool Fester { get => _fester; set { _fester = value; OnPropertyChanged(); } }
public bool Broadside { get => _broadside; set { _broadside = value; OnPropertyChanged(); } }
public bool GravityWell { get => _gravityWell; set { _gravityWell = value; OnPropertyChanged(); } }
public bool Imperil { get => _imperil; set { _imperil = value; OnPropertyChanged(); } }
public bool Yield { get => _yield; set { _yield = value; OnPropertyChanged(); } }
public bool Vuln { get => _vuln; set { _vuln = value; OnPropertyChanged(); } }
public bool UseArc { get => _useArc; set { _useArc = value; OnPropertyChanged(); } }
public bool UseBolt { get => _useBolt; set { _useBolt = value; OnPropertyChanged(); } }
public bool UseRing { get => _useRing; set { _useRing = value; OnPropertyChanged(); } }
public bool UseStreak { get => _useStreak; set { _useStreak = value; OnPropertyChanged(); } }
public bool UseBlast { get => _useBlast; set { _useBlast = value; OnPropertyChanged(); } }
public bool UseWall { get => _useWall; set { _useWall = value; OnPropertyChanged(); } }
public string ExVuln { get => _exVuln; set { _exVuln = value; OnPropertyChanged(); } }
public int OffhandId { get => _offhandId; set { _offhandId = value; OnPropertyChanged(); } }
public string PetDamage { get => _petDamage; set { _petDamage = value; OnPropertyChanged(); } }
/// <summary>Every field in the file this class doesn't know (e.g. the plugin's CustomDebuffs,
/// or one added later), written back unchanged.</summary>
[JsonExtensionData]
public Dictionary<string, JsonElement>? ExtraFields { get; set; }
[JsonIgnore]
public bool IsDefault => string.Equals(_name, "Default", System.StringComparison.OrdinalIgnoreCase);
public event PropertyChangedEventHandler? PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string? name = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public class ItemRule
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Action { get; set; } = "Loot";
public string Element { get; set; } = "Slash";
public bool KeepBuffed { get; set; } = true;
}
/// <summary>Minimal slice of the settings profile — only what the editor needs for dropdowns.</summary>
public class EditorSettings
{
public List<MonsterRule> MonsterRules { get; set; } = new();
public List<ItemRule> ItemRules { get; set; } = new();
}
/// <summary>Used by weapon/offhand ComboBoxes: maps weapon ID → display name.</summary>
public class WeaponOption
{
public int Id { get; set; }
public string DisplayName { get; set; } = string.Empty;
public override string ToString() => DisplayName;
}