Snapshot for release 2026.10.18.1 (internal 13e23b6)
This commit is contained in:
parent
c7807b6e1c
commit
5419838250
18 changed files with 856 additions and 54 deletions
|
|
@ -19,6 +19,9 @@ public partial class BuffManager : IDisposable
|
|||
private DateTime _lastCastAttempt = DateTime.MinValue;
|
||||
/// <summary>When buffing last sent a cast (buff, vital or refill). The buffing-coma watchdog's sign of progress.</summary>
|
||||
public DateTime LastCastAttemptAt => _lastCastAttempt;
|
||||
/// <summary>When the last heal, restam or remana spell went out (Weapons Back After Heals).</summary>
|
||||
public DateTime LastVitalCastAt => _lastVitalCastAt;
|
||||
private DateTime _lastVitalCastAt = DateTime.MinValue;
|
||||
// Throttles ChangeCombatMode(Magic) from EnsureMagicMode's "wand wielded but
|
||||
// mode != Magic" branch. Without this, when the server rejects/silently-drops
|
||||
// mode flips (e.g. wedged-target combat state), the branch fires every tick
|
||||
|
|
@ -2231,6 +2234,7 @@ public partial class BuffManager : IDisposable
|
|||
return VitalNo($"the client refused the cast (spell {spellId})");
|
||||
}
|
||||
sent = true;
|
||||
_lastVitalCastAt = DateTime.Now;
|
||||
if (IsRecoveryVital(what)) NoteRecoveryAttempt();
|
||||
NoteCastIssued(spellId);
|
||||
if (_pendingVitalLabel == LabelMana) _manaStarvedLogged = false; // the next starved spell logs again
|
||||
|
|
@ -2257,11 +2261,21 @@ public partial class BuffManager : IDisposable
|
|||
if (_worldObjectCache == null) return false;
|
||||
foreach (var rule in _settings.ConsumableRules)
|
||||
if (Array.FindIndex(types, t => t.Equals(rule.Type, StringComparison.OrdinalIgnoreCase)) >= 0
|
||||
&& !IsKitName(rule.Name)
|
||||
&& ConsumableLookup.Resolve(_worldObjectCache, rule) != null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A healing or stamina kit: used on yourself (the kit path), never drunk. A Greater Stamina
|
||||
/// Kit on the Items list was typed "Stamina", the old name for stamina potions, and the potion
|
||||
/// step used it with no target every 3 s, the server never answering, Revitalize never cast
|
||||
/// (Drakkon, 2026-10-17).
|
||||
/// </summary>
|
||||
internal static bool IsKitName(string? name) =>
|
||||
!string.IsNullOrEmpty(name) && name.TrimEnd().EndsWith(" Kit", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary><paramref name="listedOnly"/>: only the Consumables list, not any potion in the pack.</summary>
|
||||
private bool AttemptPotion(bool listedOnly, params string[] types)
|
||||
{
|
||||
|
|
@ -2270,7 +2284,9 @@ public partial class BuffManager : IDisposable
|
|||
foreach (var rule in _settings.ConsumableRules)
|
||||
{
|
||||
if (Array.FindIndex(types, t => t.Equals(rule.Type, StringComparison.OrdinalIgnoreCase)) < 0) continue;
|
||||
if (IsKitName(rule.Name)) continue; // the kit path uses it, on yourself
|
||||
if (ConsumableLookup.Resolve(_worldObjectCache, rule) is not WorldObject potion) continue;
|
||||
if (IsKitName(potion.Name)) continue;
|
||||
if (HeldCastBlocksItemUse(out string heldWhy)) return VitalNo(heldWhy);
|
||||
_host.Log($"[RynthAi] Vitals: drinking {rule.Name} ({rule.Type})" + (potion.Id != rule.Id ? " from a new stack." : "."));
|
||||
_host.UseFor(unchecked((uint)potion.Id), "Buff", $"vitals: drink {rule.Name} ({rule.Type}) from the Items list");
|
||||
|
|
@ -2286,6 +2302,7 @@ public partial class BuffManager : IDisposable
|
|||
{
|
||||
string? kind = RynthCore.Plugin.RynthAi.LegacyUi.LegacyWeaponsUi.PotionType(wo);
|
||||
if (kind == null || Array.FindIndex(types, t => t.Equals(kind, StringComparison.OrdinalIgnoreCase)) < 0) continue;
|
||||
if (IsKitName(wo.Name)) continue;
|
||||
if (HeldCastBlocksItemUse(out string heldWhy)) return VitalNo(heldWhy);
|
||||
_host.Log($"[RynthAi] Vitals: using {wo.Name} from the pack ({kind}).");
|
||||
_host.UseFor(unchecked((uint)wo.Id), "Buff", $"vitals: {kind} potion from the pack");
|
||||
|
|
@ -2416,7 +2433,9 @@ public partial class BuffManager : IDisposable
|
|||
WorldObject? kit = null;
|
||||
bool fromPack = false;
|
||||
foreach (var r in _settings.ConsumableRules)
|
||||
if (r.Type.Equals("HealthKit", StringComparison.OrdinalIgnoreCase) && ConsumableLookup.Resolve(_worldObjectCache, r) is WorldObject wo) { kit = wo; break; }
|
||||
if (r.Type.Equals("HealthKit", StringComparison.OrdinalIgnoreCase)
|
||||
&& !(r.Name ?? "").Contains("Stamina Kit", StringComparison.OrdinalIgnoreCase) // a stamina kit heals no health
|
||||
&& ConsumableLookup.Resolve(_worldObjectCache, r) is WorldObject wo) { kit = wo; break; }
|
||||
if (kit == null) { kit = BestPackHealingKit(); fromPack = true; }
|
||||
if (kit == null) return VitalNo("no healing kit");
|
||||
if (KitRetryWait(out string kitWait)) return VitalNo(kitWait);
|
||||
|
|
@ -4962,6 +4981,7 @@ public partial class BuffManager : IDisposable
|
|||
_bowDequipPendingId = 0;
|
||||
_bowDequipAttempts = 0;
|
||||
_wieldGateFailCount = 0;
|
||||
_wandWieldFails.Clear();
|
||||
// In Magic, but the stance we asked for may still be settling: yield the tick.
|
||||
return StanceSettled(urgentHeal);
|
||||
}
|
||||
|
|
@ -5011,12 +5031,13 @@ public partial class BuffManager : IDisposable
|
|||
alreadyWielded = wandObj.Values(LongValueKey.CurrentWieldedLocation, 0) > 0;
|
||||
|
||||
// Secondary check via API if primary didn't confirm
|
||||
if (!alreadyWielded && _host.HasGetObjectWielderInfo)
|
||||
if (EquippedState.IsWielded(_host, wandId) is bool trackedWand) alreadyWielded = trackedWand; // the server's word
|
||||
else if (!alreadyWielded && _host.HasGetObjectWielderInfo)
|
||||
{
|
||||
uint playerId = _host.GetPlayerId();
|
||||
if (playerId != 0 &&
|
||||
_host.TryGetObjectWielderInfo((uint)wandId, out uint wielder, out _) &&
|
||||
wielder == playerId)
|
||||
wielder == playerId && _worldObjectCache?.InPackWalk(wandId) != true) // a stale record (the wand in a pack)
|
||||
alreadyWielded = true;
|
||||
}
|
||||
|
||||
|
|
@ -5056,6 +5077,7 @@ public partial class BuffManager : IDisposable
|
|||
}
|
||||
_host.Log($"[WieldGate] UseObject(0x{(uint)_pendingWieldId:X8}) not confirmed in " +
|
||||
$"{WieldResolveTimeoutMs:0}ms — cooling down {WieldCooldownMs:0}ms");
|
||||
NoteWandWieldFailed(_pendingWieldId);
|
||||
_pendingWieldId = 0;
|
||||
_wieldCooldownUntil = now.AddMilliseconds(WieldCooldownMs);
|
||||
// FIX: bound the previously-infinite wield loop. If the wand still won't
|
||||
|
|
@ -5125,7 +5147,18 @@ public partial class BuffManager : IDisposable
|
|||
}
|
||||
|
||||
_pendingWieldDirect = bowId != 0 && !PackFirst;
|
||||
_host.UseFor((uint)wandId, "Buff", _pendingWieldDirect ? "buffing: switch to the wand" : "buffing: wield the wand");
|
||||
// Hands free: wield the caster into the Held slot (GetAndWieldItem, the paperdoll drag),
|
||||
// as the off hand does. A use only wields a plain caster: a caster with a spell of its own
|
||||
// (Electric Baton, Acid Staff) takes the use as "cast it" and the client says it must be
|
||||
// wielded first (Drakkon, 2026-10-18 14:00). With a weapon still in hand the use stays
|
||||
// (the client swaps); when that misses, the next swap empties the hands first.
|
||||
if (!_pendingWieldDirect && _host.HasWieldItem)
|
||||
{
|
||||
_host.WieldItem((uint)wandId, HeldSlot);
|
||||
_host.Log($"[WieldGate] wielding 0x{(uint)wandId:X8} '{_worldObjectCache?[wandId]?.Name}' into the Held slot");
|
||||
}
|
||||
else
|
||||
_host.UseFor((uint)wandId, "Buff", _pendingWieldDirect ? "buffing: switch to the wand" : "buffing: wield the wand");
|
||||
NoteStanceRequest();
|
||||
_pendingWieldClaim = _weaponSwapGate?.Claims ?? 0;
|
||||
_pendingWieldId = wandId;
|
||||
|
|
@ -5254,8 +5287,9 @@ public partial class BuffManager : IDisposable
|
|||
if (_host.HasGetObjectWielderInfo)
|
||||
{
|
||||
uint pid = _host.GetPlayerId();
|
||||
if (EquippedState.IsWielded(_host, id) is bool tracked) return tracked;
|
||||
if (pid != 0 && _host.TryGetObjectWielderInfo((uint)id, out uint wielder, out _))
|
||||
return wielder == pid;
|
||||
return wielder == pid && _worldObjectCache?.InPackWalk(id) != true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -5305,7 +5339,95 @@ public partial class BuffManager : IDisposable
|
|||
if (_worldObjectCache == null) return 0;
|
||||
var cache = _worldObjectCache;
|
||||
return WeaponList.FindWand(_settings.ItemRules, i => cache[i], wo => WorldObjectCache.IsWieldedByPlayer(_host, wo),
|
||||
cache.GetInventory(), _settings.WieldUnlistedWandWhenNoneListed, out _);
|
||||
cache.GetInventory(), _settings.WieldUnlistedWandWhenNoneListed, out _, SkipBuffWand, BuffWandRank);
|
||||
}
|
||||
|
||||
/// <summary>0 = no wield requirement (a plain caster: the surest), 1 = a requirement it meets.</summary>
|
||||
private int BuffWandRank(WorldObject wo) => WieldRequirements.Has(_host, unchecked((uint)wo.Id)) ? 1 : 0;
|
||||
|
||||
// Identify requests for listed casters whose requirements aren't known yet: (count, last ask).
|
||||
private readonly Dictionary<int, (int Count, DateTime At)> _wandIdAsked = new();
|
||||
private const int WandIdMaxAsks = 3;
|
||||
private const double WandIdRetrySec = 10;
|
||||
|
||||
// ── Buff wands that can't be wielded ────────────────────────────────────
|
||||
// 2026-10-18 01:00-01:24: Drakkon's buff wand was gone, the next caster on his Items list was
|
||||
// an Electric Baton that needs War Magic (untrained). Buffing sent its wield every ~8 s for
|
||||
// 24 minutes, the server never answered, every buff was parked "fighting unbuffed" in turn,
|
||||
// and Heal Self (which never gives up on the wand) couldn't go when he needed it: he died.
|
||||
private readonly Dictionary<int, int> _wandWieldFails = new();
|
||||
private readonly Dictionary<int, DateTime> _wandSkipUntil = new();
|
||||
private readonly HashSet<int> _wandReqNoted = new();
|
||||
internal const int WandWieldFailMax = 2;
|
||||
internal const double WandSkipMin = 30;
|
||||
|
||||
// PropertyInt WieldRequirements (158), WieldSkillType (159), WieldDifficulty (160); ACE
|
||||
// WieldRequirement 1 = Skill (buffed), 2 = RawSkill (base), 8 = Training.
|
||||
private const uint PropWieldReq = 158, PropWieldSkill = 159, PropWieldDiff = 160;
|
||||
// EquipMask Held: the casters' slot.
|
||||
private const uint HeldSlot = 0x01000000;
|
||||
|
||||
/// <summary>A caster buffing must not try: its wield requirement isn't met, or its wields kept failing.</summary>
|
||||
private bool SkipBuffWand(WorldObject wo)
|
||||
{
|
||||
if (_wandSkipUntil.TryGetValue(wo.Id, out DateTime until))
|
||||
{
|
||||
if (DateTime.Now < until) return true;
|
||||
_wandSkipUntil.Remove(wo.Id);
|
||||
_wandWieldFails.Remove(wo.Id);
|
||||
}
|
||||
// Not identified yet: its requirements aren't known (the Acid Staff was tried unidentified and
|
||||
// the client refused it, 2026-10-18). Ask, and skip it until the answer is in; after
|
||||
// WandIdMaxAsks unanswered asks it is tried anyway (a server refusal still rules it out).
|
||||
uint uid = unchecked((uint)wo.Id);
|
||||
if (_host.HasRequestId && !_host.HasAppraisalData(uid))
|
||||
{
|
||||
_wandIdAsked.TryGetValue(wo.Id, out var asked);
|
||||
if (asked.Count < WandIdMaxAsks)
|
||||
{
|
||||
if ((DateTime.Now - asked.At).TotalSeconds >= WandIdRetrySec)
|
||||
{
|
||||
_host.RequestId(uid);
|
||||
_wandIdAsked[wo.Id] = (asked.Count + 1, DateTime.Now);
|
||||
_host.Log($"[WieldGate] identifying 0x{uid:X8} '{wo.Name}' before using it to buff (its wield requirement isn't known yet)");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
string? why = UnmetWandRequirement(wo.Id);
|
||||
if (why == null) return false;
|
||||
if (_wandReqNoted.Add(wo.Id))
|
||||
{
|
||||
_host.Log($"[WieldGate] not using 0x{(uint)wo.Id:X8} '{wo.Name}' to buff: {why}");
|
||||
_host.WriteToChat($"[RynthAi] Buffing: {wo.Name} can't be wielded ({why}), so it isn't used to buff.", 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>The caster's wield requirement the character doesn't meet (null = met, none, or not known).</summary>
|
||||
private string? UnmetWandRequirement(int id) => WieldRequirements.Unmet(_host, _charSkills, unchecked((uint)id));
|
||||
|
||||
/// <summary>A wield of <paramref name="wandId"/> went unanswered: after WandWieldFailMax, leave it out for WandSkipMin.</summary>
|
||||
private void NoteWandWieldFailed(int wandId)
|
||||
{
|
||||
if (wandId == 0) return;
|
||||
int n = _wandWieldFails.TryGetValue(wandId, out int f) ? f + 1 : 1;
|
||||
_wandWieldFails[wandId] = n;
|
||||
// The server said "skill too low" (WeenieError 0x0468) for this very wand: no second try.
|
||||
// Unbuffed after a death every caster on the list can be under its requirement; one try
|
||||
// each gets to the bare-handed Magic stance (AC casts without a wand) in seconds, not minutes.
|
||||
// Any refusal naming this wand is final (with the Held-slot wield the server answers a refused
|
||||
// wield with InventoryServerSaveFailed for the item); "too busy" is not a refusal.
|
||||
bool tooLow = _host.HasGetLastWeenieError && _host.TryGetLastWeenieError(out _, out uint wErr, out _, out uint wObj)
|
||||
&& wObj == unchecked((uint)wandId) && wErr != 0 && wErr != 0x1D;
|
||||
if (n < WandWieldFailMax && !tooLow) return;
|
||||
_wandSkipUntil[wandId] = DateTime.Now.AddMinutes(WandSkipMin);
|
||||
_wandWieldFails.Remove(wandId);
|
||||
string name = _worldObjectCache?[wandId]?.Name ?? "?";
|
||||
_host.Log($"[WieldGate] 0x{(uint)wandId:X8} '{name}' didn't wield after {n} tries: left out of buffing for {WandSkipMin:0} min");
|
||||
_host.WriteToChat(tooLow
|
||||
? $"[RynthAi] Buffing: your skill is too low to wield {name}. Left out for {WandSkipMin:0} min (with no caster left, buffs are cast bare-handed)."
|
||||
: $"[RynthAi] Buffing: {name} wouldn't wield ({n} tries, no answer from the server). Left out for {WandSkipMin:0} min; check its wield requirement.", 1);
|
||||
}
|
||||
|
||||
private static bool IsWandObject(WorldObject wo) => WeaponList.IsWand(wo);
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ public partial class CombatManager
|
|||
|
||||
// The off hand that was in the slot when the current swap was decided (for no flip-flop).
|
||||
private int _offSwapFrom;
|
||||
// The last item RynthAi wielded into the off hand (0 = none, or it has since gone to the main
|
||||
// hand or the pack). The slot reads can miss it (2026-10-17): with two weapons wielded, this one
|
||||
// is the off hand's.
|
||||
private int _offhandSentId;
|
||||
// An off hand RynthAi took off itself (for a main weapon, or buffing's wand): put back later.
|
||||
private int _stowedOffhandId;
|
||||
// The off-hand mode for the target combat is equipping for (the wand path reads it).
|
||||
|
|
@ -57,6 +61,7 @@ public partial class CombatManager
|
|||
_offDequipPendingId = _offDequipTries = 0;
|
||||
_offDequipAt = _offDequipRestUntil = DateTime.MinValue;
|
||||
_offSwapFrom = _stowedOffhandId = 0;
|
||||
_offhandSentId = 0;
|
||||
_offSlotId = 0;
|
||||
_offSlotReadAt = DateTime.MinValue;
|
||||
_lastOffPlan = (-1, "");
|
||||
|
|
@ -115,6 +120,14 @@ public partial class CombatManager
|
|||
return _offSlotId;
|
||||
_offSlotReadAt = now;
|
||||
int found = 0;
|
||||
// The server's word when the engine has it: what is in the Shield slot.
|
||||
if (EquippedState.TryGet(_host, out var eqOff))
|
||||
{
|
||||
foreach (var kv in eqOff)
|
||||
if ((kv.Value & OffhandRules.ShieldSlot) != 0) { found = kv.Key; break; }
|
||||
_offSlotId = found;
|
||||
return found;
|
||||
}
|
||||
try
|
||||
{
|
||||
foreach (var wo in _worldFilter.GetDirectInventory(forceRefresh: true))
|
||||
|
|
@ -128,7 +141,23 @@ public partial class CombatManager
|
|||
{
|
||||
if (r.Id == 0 || pid == 0) continue;
|
||||
if (_host.TryGetObjectWielderInfo(unchecked((uint)r.Id), out uint wielder, out uint loc)
|
||||
&& wielder == pid && (loc & OffhandRules.ShieldSlot) != 0) { found = r.Id; break; }
|
||||
&& wielder == pid && (loc & OffhandRules.ShieldSlot) != 0 && !InPackNow(r.Id)) { found = r.Id; break; }
|
||||
}
|
||||
}
|
||||
// Nothing reads as in the Shield slot: what RynthAi put there, while it is still wielded
|
||||
// beside another weapon (alone it may have become the main hand's).
|
||||
if (found == 0 && _offhandSentId != 0)
|
||||
{
|
||||
var sentWo = _worldFilter[_offhandSentId];
|
||||
if (sentWo == null || !WorldObjectCache.IsWieldedByPlayer(_host, sentWo)) _offhandSentId = 0;
|
||||
else
|
||||
{
|
||||
foreach (var wo in _worldFilter.GetDirectInventory(forceRefresh: false))
|
||||
{
|
||||
if (wo.Id == _offhandSentId || WorldObjectCache.IsAmmo(wo)) continue;
|
||||
bool weapon = wo.ObjectClass == AcObjectClass.MeleeWeapon || wo.ObjectClass == AcObjectClass.MissileWeapon || IsWandObject(wo);
|
||||
if (weapon && WorldObjectCache.IsWieldedByPlayer(_host, wo)) { found = _offhandSentId; break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -285,6 +314,7 @@ public partial class CombatManager
|
|||
if (!gateHeld && _weaponSwapGate != null && !_weaponSwapGate.TryBeginSwap("combat-offhand-dequip")) return OffPrep.Busy;
|
||||
|
||||
_host.MoveItemInternal(unchecked((uint)offId), unchecked((uint)packId), 0, 1);
|
||||
if (offId == _offhandSentId) _offhandSentId = 0;
|
||||
_weaponSwapGate?.NoteMove(offId, wieldedNow: true);
|
||||
_offDequipPendingId = offId;
|
||||
_offDequipAt = now;
|
||||
|
|
@ -380,6 +410,7 @@ public partial class CombatManager
|
|||
if (_host.HasGetLastUseDone && _host.TryGetLastUseDone(out int uSeq, out _)) _swapUseDoneSeq = uSeq;
|
||||
if (_host.HasGetLastWeenieError && _host.TryGetLastWeenieError(out int wSeq, out _, out _, out _)) _swapWeenieSeq = wSeq;
|
||||
OffhandTracker.Sent(plan.Id, _offSwapFrom, now);
|
||||
_offhandSentId = plan.Id;
|
||||
_weaponSwapGate?.NoteMove(plan.Id, wieldedNow: false);
|
||||
_offSwapFrom = 0;
|
||||
_lastEquipTime = now;
|
||||
|
|
|
|||
|
|
@ -2990,6 +2990,7 @@ public partial class CombatManager : IDisposable
|
|||
|
||||
if (activeTargetId == 0)
|
||||
{
|
||||
if (RearmAfterVitalsStep()) return true;
|
||||
// No valid target — go to Peace immediately to stop the client
|
||||
// from auto-running toward a distant monster. The 500ms cooldown
|
||||
// prevents ChangeCombatMode spam while idling between spawns.
|
||||
|
|
@ -4296,8 +4297,15 @@ public partial class CombatManager : IDisposable
|
|||
}
|
||||
|
||||
private (int TargetId, MonsterRule? Rule, List<ItemRule> List, int Count, int Hand, DateTime At, WeaponPlan Plan)? _planCache;
|
||||
/// <summary>The character can wield <paramref name="id"/> now: no unmet requirement, not refused lately.</summary>
|
||||
private bool CanWieldNow(int id) =>
|
||||
!SkillTooLowFor(id) && WieldRequirements.Unmet(_host, _charSkills, unchecked((uint)id)) == null;
|
||||
|
||||
// Listed weapons whose wield requirement isn't met (logged once each).
|
||||
private readonly HashSet<int> _wieldReqNoted = new();
|
||||
// Listed weapons found not to be ours (logged once each).
|
||||
private readonly HashSet<int> _notCarriedNoted = new();
|
||||
internal const double NotCarriedGraceMs = 5000;
|
||||
private const double PlanCacheMs = 250;
|
||||
|
||||
private WeaponPlan ComputePlan(WorldObject target, MonsterRule? rule)
|
||||
|
|
@ -4317,10 +4325,13 @@ public partial class CombatManager : IDisposable
|
|||
{
|
||||
uint pick = _damageStore.GetManualWeapon(wcid);
|
||||
if (pick == 0) { pick = _damageStore.GetDefaultWeapon(); fixedSource = "Damage tab default"; fixedIsDefault = true; }
|
||||
if (pick != 0 && SkillTooLowFor((int)pick)) pick = 0; // logged when it was refused
|
||||
// Not usable by this character right now (a requirement, or refused): left out quietly, it
|
||||
// is logged where the list drops it. A listed weapon for another build stays listed.
|
||||
if (pick != 0 && !CanWieldNow((int)pick)) pick = 0;
|
||||
if (pick != 0 && !listed.Any(c => c.Id == (int)pick)) { NoteUnlisted((int)pick, fixedSource); pick = 0; }
|
||||
fixedId = (int)pick;
|
||||
uint best = _damageStore.GetBestWeapon(wcid);
|
||||
if (best != 0 && !CanWieldNow((int)best)) best = 0;
|
||||
if (best != 0 && !listed.Any(c => c.Id == (int)best)) { NoteUnlisted((int)best, "Damage tab learned"); best = 0; }
|
||||
learnedId = (int)best;
|
||||
}
|
||||
|
|
@ -4461,12 +4472,30 @@ public partial class CombatManager : IDisposable
|
|||
// Flaming Greataxe was tried three times, the character standing in the fight, 2026-10-14).
|
||||
if (r.Id != inHand && _worldFilter.PlayerHas(r.Id) == false)
|
||||
{
|
||||
if (_notCarriedNoted.Add(r.Id))
|
||||
_host.Log($"[EquipDiag] listed weapon 0x{(uint)r.Id:X8} '{wo.Name}' isn't in your pack (sold, dropped or traded?): skipped");
|
||||
continue;
|
||||
// Not within NotCarriedGraceMs of a wield or move of ours: mid-swap a weapon is
|
||||
// briefly in neither hand nor the pack walk. Drakkon's Acid Hand Wraps were dropped
|
||||
// from the choice that way on 2026-10-17 and he fought bare-handed.
|
||||
if ((DateTime.Now - _lastEquipTime).TotalMilliseconds >= NotCarriedGraceMs)
|
||||
{
|
||||
if (_notCarriedNoted.Add(r.Id))
|
||||
_host.Log($"[EquipDiag] listed weapon 0x{(uint)r.Id:X8} '{wo.Name}' isn't in your pack (sold, dropped or traded?): skipped");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else _notCarriedNoted.Remove(r.Id);
|
||||
if (!admitCasters && !IsUsableCombatWeapon(r.Id)) { (leftOut ??= new List<int>()).Add(r.Id); continue; }
|
||||
if (r.Id != inHand && SkillTooLowFor(r.Id)) continue;
|
||||
// A wield requirement the character doesn't meet: the client refuses the wield without
|
||||
// asking the server, so no "skill too low" answer ever comes (the Tetsubo, 2026-10-18).
|
||||
if (r.Id != inHand && WieldRequirements.Unmet(_host, _charSkills, unchecked((uint)r.Id)) is string unmet)
|
||||
{
|
||||
if (_wieldReqNoted.Add(r.Id))
|
||||
{
|
||||
_host.Log($"[EquipDiag] listed weapon 0x{(uint)r.Id:X8} '{wo.Name}' can't be wielded ({unmet}): left out of the weapon choice");
|
||||
_host.WriteToChat($"[RynthAi] {wo.Name} can't be wielded ({unmet}), so combat doesn't use it.", 1);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (list.Any(c => c.Id == r.Id)) continue;
|
||||
if (wo.ObjectClass == AcObjectClass.MissileWeapon && IsAmmoItem(wo)) continue; // listed arrows are the ammo choice, never a weapon to wield
|
||||
if (IsShieldItem(wo)) continue; // listed shields are the off hand's (CombatManager.Offhand.cs)
|
||||
|
|
@ -4492,8 +4521,24 @@ public partial class CombatManager : IDisposable
|
|||
if (!fresh && (now - _inHandReadAt).TotalMilliseconds < InHandReadMs) return _inHandId;
|
||||
_inHandReadAt = now;
|
||||
int found = 0;
|
||||
// The server's word when the engine has it: a weapon in a main-hand slot.
|
||||
if (EquippedState.TryGet(_host, out var eqMain))
|
||||
{
|
||||
foreach (var kv in eqMain)
|
||||
{
|
||||
if ((kv.Value & MainHandSlots) == 0) continue;
|
||||
var wo = _worldFilter[kv.Key];
|
||||
if (wo == null || WorldObjectCache.IsAmmo(wo)) continue;
|
||||
bool weapon = wo.ObjectClass == AcObjectClass.MeleeWeapon || wo.ObjectClass == AcObjectClass.MissileWeapon || IsWandObject(wo);
|
||||
if (!weapon) continue;
|
||||
if (found == 0 || _settings.ItemRules.Any(r => r.Id == wo.Id)) found = wo.Id;
|
||||
}
|
||||
_inHandId = found;
|
||||
return found;
|
||||
}
|
||||
try
|
||||
{
|
||||
var wielded = new List<WorldObject>(2);
|
||||
foreach (var wo in _worldFilter.GetDirectInventory(forceRefresh: true))
|
||||
{
|
||||
if (WorldObjectCache.IsAmmo(wo)) continue;
|
||||
|
|
@ -4506,6 +4551,19 @@ public partial class CombatManager : IDisposable
|
|||
|| wo.ObjectClass == AcObjectClass.MissileWeapon
|
||||
|| IsWandObject(wo);
|
||||
if (!weapon || !WorldObjectCache.IsWieldedByPlayer(_host, wo)) continue;
|
||||
wielded.Add(wo);
|
||||
}
|
||||
// Still two (the slot read nothing for either): the one RynthAi put in the off hand is
|
||||
// the off hand's. The slot reads aren't reliable: on 2026-10-17 the off-hand Frost Hand
|
||||
// Wraps read as the main weapon again, a swap went out for the Acid pair already in the
|
||||
// main hand, and Drakkon fought bare-handed.
|
||||
if (wielded.Count > 1 && _offhandSentId != 0 && wielded.Exists(w => w.Id == _offhandSentId))
|
||||
{
|
||||
NoteTwoInHand(wielded);
|
||||
wielded.RemoveAll(w => w.Id == _offhandSentId);
|
||||
}
|
||||
foreach (var wo in wielded)
|
||||
{
|
||||
// Two in hand (a wand and a sword mid-swap): a listed one wins.
|
||||
if (found == 0 || _settings.ItemRules.Any(r => r.Id == wo.Id)) found = wo.Id;
|
||||
}
|
||||
|
|
@ -4515,15 +4573,150 @@ public partial class CombatManager : IDisposable
|
|||
return found;
|
||||
}
|
||||
|
||||
/// <summary>Where the player wields <paramref name="wo"/>: CurrentWieldedLocation, else the weenie's wielder record (0 = not known).</summary>
|
||||
// ── Weapons Back After Heals (RearmAfterVitals) ─────────────────────────────
|
||||
// The weapons of the last swing (main hand, off hand; 0 = none), and the vitals spell re-armed for.
|
||||
private int _fightMainId, _fightOffId;
|
||||
private DateTime _rearmedFor = DateTime.MinValue, _rearmStartedAt = DateTime.MinValue;
|
||||
private const double RearmSettleMs = 1000, RearmGiveUpMs = 15_000;
|
||||
|
||||
/// <summary>When the last heal, restam or remana spell went out (BuffManager); set by the plugin.</summary>
|
||||
public Func<DateTime>? LastVitalCastAt { get; set; }
|
||||
/// <summary>True while buffing wants the tick (a cast pending, a vital to refill, buffs to cast); set by the plugin.</summary>
|
||||
public Func<bool>? BuffingWantsTick { get; set; }
|
||||
|
||||
/// <summary>A swing went out: what is in the hands is the fight's weapons (casters aside).</summary>
|
||||
private void NoteFightWeapons()
|
||||
{
|
||||
int main = InHandWeaponId();
|
||||
if (main == 0 || WeaponKind(main) == CombatMode.Magic) return;
|
||||
_fightMainId = main;
|
||||
_fightOffId = OffhandInSlot();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// No target, and a heal / restam / remana spell went out since the last re-arm: put the last
|
||||
/// fight's weapons back on (main hand, then off hand) once buffing is done with the tick. True
|
||||
/// while a step of it is in flight (the idle branch waits). Bounded by RearmGiveUpMs.
|
||||
/// </summary>
|
||||
private bool RearmAfterVitalsStep()
|
||||
{
|
||||
if (!_settings.RearmAfterVitals || _fightMainId == 0) return false;
|
||||
DateTime vital = LastVitalCastAt?.Invoke() ?? DateTime.MinValue;
|
||||
if (vital == DateTime.MinValue || vital <= _rearmedFor) return false;
|
||||
DateTime now = DateTime.Now;
|
||||
if ((now - vital).TotalMilliseconds < RearmSettleMs) return false; // another vitals spell may follow
|
||||
bool buffing;
|
||||
try { buffing = BuffingWantsTick?.Invoke() == true; } catch { buffing = true; }
|
||||
if (buffing || IsCastInFlight() || BusyCount != 0) return false;
|
||||
|
||||
if (_rearmStartedAt < vital) _rearmStartedAt = now;
|
||||
if ((now - _rearmStartedAt).TotalMilliseconds > RearmGiveUpMs)
|
||||
{
|
||||
_rearmedFor = vital;
|
||||
_host.Log($"[EquipDiag] weapons back after heals: gave up after {RearmGiveUpMs / 1000:0} s (main 0x{(uint)_fightMainId:X8} '{WeaponName(_fightMainId)}', off hand 0x{(uint)_fightOffId:X8} '{WeaponName(_fightOffId)}')");
|
||||
return false;
|
||||
}
|
||||
// Still ours to wield: listed, carried, not refused for skill.
|
||||
if (!_settings.ItemRules.Any(r => r.Id == _fightMainId) || _worldFilter.PlayerHas(_fightMainId) == false || SkillTooLowFor(_fightMainId))
|
||||
{
|
||||
_rearmedFor = vital;
|
||||
return false;
|
||||
}
|
||||
|
||||
int inHand = InHandWeaponId();
|
||||
if (inHand != _fightMainId)
|
||||
{
|
||||
if (SwapTracker.PendingId != 0) { FoldServerAnswer(SwapTracker, now); return true; } // our wield is on its way
|
||||
var step = SwapStep(_fightMainId, inHand);
|
||||
if (step == WeaponSwapTracker.Step.Wait) return true;
|
||||
if (step != WeaponSwapTracker.Step.Swap) { _rearmedFor = vital; return false; }
|
||||
if (_weaponSwapGate != null && !_weaponSwapGate.TryBeginSwap("rearm-after-vitals")) return true;
|
||||
var prep = ClearOffhandFor(_fightMainId, OffhandMode.Auto, gateHeld: true);
|
||||
if (prep == OffPrep.Busy) return true;
|
||||
if (prep == OffPrep.Blocked) { _rearmedFor = vital; return false; }
|
||||
SendWield(_fightMainId, inHand, "weapons back after heals");
|
||||
return true;
|
||||
}
|
||||
|
||||
int off = OffhandInSlot();
|
||||
if (_fightOffId != 0 && off != _fightOffId && _fightOffId != _fightMainId
|
||||
&& _worldFilter.PlayerHas(_fightOffId) != false && _settings.ItemRules.Any(r => r.Id == _fightOffId))
|
||||
{
|
||||
FoldServerAnswer(OffhandTracker, now);
|
||||
if (OffhandTracker.PendingId != 0) return true;
|
||||
if (off != 0) { DequipOffhand(off, $"to put 0x{(uint)_fightOffId:X8} '{WeaponName(_fightOffId)}' back"); return true; }
|
||||
var wo = _worldFilter[_fightOffId];
|
||||
if (wo != null && _host.HasWieldItem && (_weaponSwapGate == null || _weaponSwapGate.TryBeginSwap("rearm-after-vitals-offhand")))
|
||||
{
|
||||
var stepOff = OffhandTracker.Next(_fightOffId, off, now, WeaponName);
|
||||
if (stepOff == WeaponSwapTracker.Step.Swap && _host.WieldItem(unchecked((uint)_fightOffId), OffhandRules.ShieldSlot))
|
||||
{
|
||||
if (_host.HasGetLastUseDone && _host.TryGetLastUseDone(out int uSeq, out _)) _swapUseDoneSeq = uSeq;
|
||||
if (_host.HasGetLastWeenieError && _host.TryGetLastWeenieError(out int wSeq, out _, out _, out _)) _swapWeenieSeq = wSeq;
|
||||
OffhandTracker.Sent(_fightOffId, 0, now);
|
||||
_weaponSwapGate?.NoteMove(_fightOffId, wieldedNow: false);
|
||||
_offhandSentId = _fightOffId;
|
||||
_lastEquipTime = now;
|
||||
_host.Log($"[EquipDiag] weapons back after heals: off hand 0x{(uint)_fightOffId:X8} '{wo.Name}'");
|
||||
return true;
|
||||
}
|
||||
if (stepOff == WeaponSwapTracker.Step.Wait) return true;
|
||||
}
|
||||
_rearmedFor = vital; // the off hand can't go on now: the main hand is back, that will do
|
||||
return false;
|
||||
}
|
||||
|
||||
_rearmedFor = vital;
|
||||
_host.Log($"[EquipDiag] weapons back after heals: 0x{(uint)_fightMainId:X8} '{WeaponName(_fightMainId)}'" +
|
||||
(_fightOffId != 0 ? $" and 0x{(uint)_fightOffId:X8} '{WeaponName(_fightOffId)}'" : "") + " in hand");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Logged once per pair: what the slot reads say for two wielded weapons (the off-hand diagnosis).
|
||||
private readonly HashSet<string> _twoInHandNoted = new();
|
||||
|
||||
private void NoteTwoInHand(List<WorldObject> wielded)
|
||||
{
|
||||
var parts = new List<string>();
|
||||
foreach (var w in wielded)
|
||||
{
|
||||
int cur = w.Values(LongValueKey.CurrentWieldedLocation, 0);
|
||||
uint loc = 0;
|
||||
try { if (_host.HasGetObjectWielderInfo) _host.TryGetObjectWielderInfo(unchecked((uint)w.Id), out _, out loc); } catch { }
|
||||
parts.Add($"0x{(uint)w.Id:X8} '{w.Name}' slot=0x{cur:X} wielderLoc=0x{loc:X}");
|
||||
}
|
||||
string key = string.Join("|", parts);
|
||||
if (_twoInHandNoted.Count > 64) _twoInHandNoted.Clear();
|
||||
if (_twoInHandNoted.Add(key))
|
||||
_host.Log($"[EquipDiag] two weapons read as in hand ({string.Join(", ", parts)}): 0x{(uint)_offhandSentId:X8} '{WeaponName(_offhandSentId)}' went into the off hand, so it is the off hand's");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The client's container walk (at most 1 s old) found <paramref name="id"/> inside a pack. The
|
||||
/// weenie's wielder record can still name the player after a weapon went into a pack (buffing's
|
||||
/// wand swap): every wielder-record read checks this first. Drakkon attacked bare-handed with
|
||||
/// his Acid Hand Wraps "wielded" in the pack (2026-10-17 12:09, died; again 10-18 00:07).
|
||||
/// </summary>
|
||||
private bool InPackNow(int id)
|
||||
{
|
||||
try { _worldFilter.GetDirectInventory(forceRefresh: false); } catch { }
|
||||
return _worldFilter.InPackWalk(id);
|
||||
}
|
||||
|
||||
// EquipMask main-hand slots: MeleeWeapon, MissileWeapon, Held (casters), TwoHanded.
|
||||
private const int MainHandSlots = 0x00100000 | 0x00400000 | 0x01000000 | 0x02000000;
|
||||
|
||||
/// <summary>Where the player wields <paramref name="wo"/>: the tracker's slot, else CurrentWieldedLocation, else the weenie's wielder record (0 = not known).</summary>
|
||||
private int WieldedSlotOf(WorldObject wo)
|
||||
{
|
||||
if (EquippedState.SlotOf(_host, wo.Id) is int tracked) return tracked;
|
||||
int slot = wo.Values(LongValueKey.CurrentWieldedLocation, 0);
|
||||
if (slot != 0 || !_host.HasGetObjectWielderInfo) return slot;
|
||||
try
|
||||
{
|
||||
uint pid = _host.GetPlayerId();
|
||||
if (pid != 0 && _host.TryGetObjectWielderInfo(unchecked((uint)wo.Id), out uint wielder, out uint loc) && wielder == pid)
|
||||
if (pid != 0 && _host.TryGetObjectWielderInfo(unchecked((uint)wo.Id), out uint wielder, out uint loc) && wielder == pid
|
||||
&& !InPackNow(wo.Id))
|
||||
return unchecked((int)loc);
|
||||
}
|
||||
catch { }
|
||||
|
|
@ -4609,7 +4802,7 @@ public partial class CombatManager : IDisposable
|
|||
return false;
|
||||
}
|
||||
|
||||
private void NoteSkillTooLow(int id)
|
||||
private void NoteSkillTooLow(int id, string? why = null)
|
||||
{
|
||||
if (id == 0) return;
|
||||
bool first = !_skillTooLowUntil.ContainsKey(id);
|
||||
|
|
@ -4617,7 +4810,7 @@ public partial class CombatManager : IDisposable
|
|||
_planCache = null;
|
||||
if (first)
|
||||
{
|
||||
string msg = $"0x{(uint)id:X8} '{WeaponName(id)}': the server says your skill is too low to wield it - left out of the weapon choice for {SkillTooLowSkipMin:0} min";
|
||||
string msg = $"0x{(uint)id:X8} '{WeaponName(id)}': {why ?? "the server says your skill is too low to wield it"} - left out of the weapon choice for {SkillTooLowSkipMin:0} min";
|
||||
_host.Log($"[EquipDiag] {msg}");
|
||||
_host.WriteToChat($"[RynthAi] {msg}.", 1);
|
||||
}
|
||||
|
|
@ -4636,7 +4829,13 @@ public partial class CombatManager : IDisposable
|
|||
{
|
||||
_host.Log($"[EquipDiag] {SwapTracker.Notice}");
|
||||
SwapTracker.Notice = null;
|
||||
// The server's own list (v87) says it never reached the hand: the wield can't work
|
||||
// (the client refused it unasked). Out of the choice like a "skill too low" answer,
|
||||
// not retried every 2 minutes with the off hand taken off each time (the Tetsubo, 2026-10-18).
|
||||
if (SwapTracker.GaveUpId is int gaveUp && EquippedState.TryGet(_host, out _))
|
||||
NoteSkillTooLow(gaveUp, "it never reached your hand (the client refused the wield)");
|
||||
}
|
||||
SwapTracker.GaveUpId = null;
|
||||
if (step == WeaponSwapTracker.Step.Hold && (DateTime.Now - _lastSwapHoldLogAt).TotalSeconds > 10)
|
||||
{
|
||||
_lastSwapHoldLogAt = DateTime.Now;
|
||||
|
|
@ -4731,6 +4930,8 @@ public partial class CombatManager : IDisposable
|
|||
if (_host.HasGetLastUseDone && _host.TryGetLastUseDone(out int uSeq, out _)) _swapUseDoneSeq = uSeq;
|
||||
if (_host.HasGetLastWeenieError && _host.TryGetLastWeenieError(out int wSeq, out _, out _, out _)) _swapWeenieSeq = wSeq;
|
||||
SwapTracker.Sent(weaponId, inHandId, now);
|
||||
EquippedState.Invalidate();
|
||||
if (weaponId == _offhandSentId) _offhandSentId = 0;
|
||||
_inHandReadAt = DateTime.MinValue; // read the hand fresh next time
|
||||
_offSlotReadAt = DateTime.MinValue; // and the off hand
|
||||
_lastEquipTime = now;
|
||||
|
|
@ -4817,6 +5018,25 @@ public partial class CombatManager : IDisposable
|
|||
private bool SwapToChosenSameKind(int weaponId, int desiredMode)
|
||||
{
|
||||
int inHand = InHandWeaponId();
|
||||
// Empty hands in the stance already, the chosen weapon positively in a pack: wield it. The
|
||||
// positive-read rule below guards against a UseObject on a weapon that is really wielded
|
||||
// (it would take it off); a weapon the container walk finds in a pack can't be. Without
|
||||
// this Drakkon fought bare-handed in Melee stance after buffing's wand swap (2026-10-17/18).
|
||||
if (inHand == 0 && weaponId != 0 && (EquippedState.IsWielded(_host, weaponId) is bool trk ? !trk : InPackNow(weaponId)))
|
||||
{
|
||||
switch (SwapStep(weaponId, 0))
|
||||
{
|
||||
case WeaponSwapTracker.Step.Wait: return true;
|
||||
case WeaponSwapTracker.Step.Swap:
|
||||
var offPrep = ClearOffhandFor(weaponId, _curOffhandMode);
|
||||
if (offPrep == OffPrep.Busy) return true;
|
||||
if (offPrep == OffPrep.Blocked) return false;
|
||||
if (_weaponSwapGate != null && !_weaponSwapGate.TryBeginSwap("combat-empty-hands")) return true;
|
||||
SendWield(weaponId, 0, "empty hands: wield");
|
||||
return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
if (inHand == 0 || inHand == weaponId) { SwapTracker.Confirmed(weaponId, DateTime.Now); if (inHand == weaponId) _equippedWeaponId = weaponId; return false; }
|
||||
if (WeaponKind(inHand) != desiredMode) return false; // a cross-kind case; the branches below handle it
|
||||
|
||||
|
|
@ -4991,7 +5211,8 @@ public partial class CombatManager : IDisposable
|
|||
|
||||
// Use CurrentWieldedLocation (stype=10) — has an InqInt fallback that works even
|
||||
// when the phys-obj offset probe hasn't fired yet (unlike TryGetObjectWielderInfo).
|
||||
bool alreadyWielded = weaponObj.Values(LongValueKey.CurrentWieldedLocation, 0) > 0;
|
||||
bool? trackedWield = EquippedState.IsWielded(_host, targetWeaponId); // the server's word, when the engine has it
|
||||
bool alreadyWielded = trackedWield ?? weaponObj.Values(LongValueKey.CurrentWieldedLocation, 0) > 0;
|
||||
|
||||
// Secondary check — BuffManager.EnsureMagicMode has always had this and this
|
||||
// path never did, which is the whole reason buffing could flip the stance and
|
||||
|
|
@ -5002,11 +5223,12 @@ public partial class CombatManager : IDisposable
|
|||
// (a no-op MOVE) forever and never sends the stance flip that was the only
|
||||
// thing actually missing. Confirmed live 2026-09-02: entering Magic mode by
|
||||
// hand immediately unstuck combat.
|
||||
if (!alreadyWielded && _host.HasGetObjectWielderInfo)
|
||||
if (trackedWield == null && !alreadyWielded && _host.HasGetObjectWielderInfo)
|
||||
{
|
||||
uint pid = _host.GetPlayerId();
|
||||
if (pid != 0 && _host.TryGetObjectWielderInfo((uint)targetWeaponId, out uint wielder, out _)
|
||||
&& wielder == pid)
|
||||
&& wielder == pid
|
||||
&& !InPackNow(targetWeaponId)) // the record can still name the player after the weapon went into a pack
|
||||
{
|
||||
alreadyWielded = true;
|
||||
// Must re-arm the throttle, as every other [EquipDiag] site does.
|
||||
|
|
@ -5369,6 +5591,7 @@ public partial class CombatManager : IDisposable
|
|||
private bool IsWieldedLive(int id)
|
||||
{
|
||||
if (id == 0) return false;
|
||||
if (EquippedState.IsWielded(_host, id) is bool tracked) return tracked;
|
||||
foreach (var wo in _worldFilter.GetDirectInventory(forceRefresh: true))
|
||||
if (wo.Id == id)
|
||||
return WorldObjectCache.IsWieldedByPlayer(_host, wo);
|
||||
|
|
@ -5376,7 +5599,7 @@ public partial class CombatManager : IDisposable
|
|||
{
|
||||
uint pid = _host.GetPlayerId();
|
||||
if (pid != 0 && _host.TryGetObjectWielderInfo((uint)id, out uint wielder, out _))
|
||||
return wielder == pid;
|
||||
return wielder == pid && !InPackNow(id);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -5908,6 +6131,7 @@ public partial class CombatManager : IDisposable
|
|||
_host.MeleeAttack(targetId, acHeight, power);
|
||||
|
||||
RynthCore.Plugin.Shared.ActionPacer.NoteAttackSent(); // nothing else starts before this swing plays
|
||||
NoteFightWeapons();
|
||||
_serverAttackTargetId = activeTargetId;
|
||||
_attacksSinceEvidence++;
|
||||
LastCombatSkipReason = "attack"; // D4 record-only: physical attack sent this tick
|
||||
|
|
|
|||
56
Plugins/RynthCore.Plugin.RynthAi/Combat/EquippedState.cs
Normal file
56
Plugins/RynthCore.Plugin.RynthAi/Combat/EquippedState.cs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RynthCore.PluginSdk;
|
||||
|
||||
namespace RynthCore.Plugin.RynthAi;
|
||||
|
||||
/// <summary>
|
||||
/// What the player wields and where, from the engine's EquipmentTracker (API v87: the server's
|
||||
/// WieldObject / InventoryPutObjInContainer / InventoryPutObjectIn3D messages, the way Decal knows
|
||||
/// it). When the engine has it, it is the only answer to "is it in hand?": the client's own
|
||||
/// fields go stale on this client (CurrentWieldedLocation reads 0, the wielder record keeps the
|
||||
/// player after the item went into a pack), and the guesses around them had Drakkon fighting
|
||||
/// bare-handed and dying (2026-10-17/18). Read at most every <see cref="TtlMs"/>; any thread.
|
||||
/// </summary>
|
||||
internal static class EquippedState
|
||||
{
|
||||
private const long TtlMs = 100;
|
||||
private static readonly object Gate = new();
|
||||
private static Dictionary<int, int> _map = new();
|
||||
private static long _at;
|
||||
private static bool _fresh; // a read is cached (a flag, not a sentinel time: now - long.MinValue overflows)
|
||||
private static bool _ok;
|
||||
|
||||
/// <summary>Tests: a fixed clock (null = Environment.TickCount64).</summary>
|
||||
internal static Func<long>? Clock;
|
||||
|
||||
/// <summary>The wielded items (id -> EquipMask). False when the engine has no tracker or it can't start yet.</summary>
|
||||
public static bool TryGet(RynthCoreHost host, out Dictionary<int, int> map)
|
||||
{
|
||||
long now = Clock?.Invoke() ?? Environment.TickCount64;
|
||||
lock (Gate)
|
||||
{
|
||||
if (_fresh && now - _at < TtlMs) { map = _map; return _ok; }
|
||||
_at = now;
|
||||
_fresh = true;
|
||||
if (!host.HasGetWieldedItems || !host.TryGetWieldedItems(out var items)) { _ok = false; map = _map = new(); return false; }
|
||||
var m = new Dictionary<int, int>(items.Length);
|
||||
foreach (var (id, loc) in items) m[unchecked((int)id)] = unchecked((int)loc);
|
||||
_map = m;
|
||||
_ok = true;
|
||||
map = m;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Wielded per the tracker; null when there is no tracker (the caller's own logic then).</summary>
|
||||
public static bool? IsWielded(RynthCoreHost host, int id) =>
|
||||
TryGet(host, out var map) ? map.ContainsKey(id) : null;
|
||||
|
||||
/// <summary>The slot per the tracker (0 = not wielded); null when there is no tracker.</summary>
|
||||
public static int? SlotOf(RynthCoreHost host, int id) =>
|
||||
TryGet(host, out var map) ? (map.TryGetValue(id, out int loc) ? loc : 0) : null;
|
||||
|
||||
/// <summary>Drop the cached read (a wield or move was just sent, or tests).</summary>
|
||||
public static void Invalidate() { lock (Gate) _fresh = false; }
|
||||
}
|
||||
|
|
@ -219,47 +219,46 @@ internal static class WeaponList
|
|||
/// class; never by name). 0 = none.
|
||||
/// </summary>
|
||||
public static int FindWand(IEnumerable<ItemRule> rules, Func<int, WorldObject?> lookup, Func<WorldObject, bool> isWielded,
|
||||
IEnumerable<WorldObject> inventory, bool allowUnlisted, out bool unlisted)
|
||||
IEnumerable<WorldObject> inventory, bool allowUnlisted, out bool unlisted, Func<WorldObject, bool>? skip = null,
|
||||
Func<WorldObject, int>? rank = null)
|
||||
{
|
||||
// 2026-10-18 deep dive (Drakkon): the wand is the caster in hand, else a listed caster that is
|
||||
// carried and not skipped (lowest rank first, then list order). Any other caster from the pack
|
||||
// only when nothing listed is carried: no caster on the Items list, or every listed one was
|
||||
// dropped or lost (owner, 2026-10-18), and allowUnlisted. A listed caster that is carried but
|
||||
// can't be wielded never opens the pack: the old fallback had Drakkon trying casters he never
|
||||
// listed, and the same-name stand-in took any pack item named "Wand" for his lost one.
|
||||
unlisted = false;
|
||||
int first = 0;
|
||||
bool anyListedCarried = false;
|
||||
// Only a wand the character still carries (in the pack or in hand). A listed wand the
|
||||
// client saw once but that left the pack (sold, given, on a mule) used to be returned:
|
||||
// the server ignores a wield of it, every buff got parked "fighting unbuffed", and
|
||||
// Drakkon died over and over (2026-10-11, wand 0x8000EF07 shown as '?').
|
||||
var pack = inventory as ICollection<WorldObject> ?? new List<WorldObject>(inventory);
|
||||
var carried = new HashSet<int>();
|
||||
foreach (var wo in pack) carried.Add(wo.Id);
|
||||
var gone = new List<(ItemRule Rule, WorldObject Wo)>();
|
||||
// A caster already in hand is the one to use, listed or not: it is wielded, so it can be.
|
||||
foreach (var wo in pack)
|
||||
if (IsWand(wo) && isWielded(wo)) return wo.Id;
|
||||
bool anyListedCarried = false;
|
||||
int best = 0, bestRank = int.MaxValue;
|
||||
foreach (var r in rules)
|
||||
{
|
||||
var wo = lookup(r.Id);
|
||||
if (wo == null) continue;
|
||||
if (!IsWand(wo)) continue;
|
||||
if (wo == null || !IsWand(wo)) continue;
|
||||
if (isWielded(wo)) return r.Id;
|
||||
if (!carried.Contains(wo.Id)) { gone.Add((r, wo)); continue; }
|
||||
// Only a wand the character still carries: a listed wand that left the pack (sold, given,
|
||||
// on a mule) gets no answer from the server (2026-10-11, wand 0x8000EF07 shown as '?').
|
||||
if (!carried.Contains(wo.Id)) continue;
|
||||
anyListedCarried = true;
|
||||
if (first == 0) first = r.Id;
|
||||
if (skip != null && skip(wo)) continue; // can't be wielded (requirement, not identified yet, refused)
|
||||
int k = rank?.Invoke(wo) ?? 0;
|
||||
if (k < bestRank) { best = r.Id; bestRank = k; }
|
||||
}
|
||||
if (first != 0) return first;
|
||||
// A listed wand no longer carried: another of the same name in the pack stands in for it.
|
||||
foreach (var (r, wo) in gone)
|
||||
{
|
||||
string name = !string.IsNullOrWhiteSpace(r.Name) ? r.Name : wo.Name ?? "";
|
||||
if (name.Length < 3 || name == "?") continue;
|
||||
foreach (var p in pack)
|
||||
if (IsWand(p) && string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase))
|
||||
return p.Id;
|
||||
}
|
||||
if (anyListedCarried || !allowUnlisted) return 0;
|
||||
if (best != 0 || anyListedCarried || !allowUnlisted) return best;
|
||||
foreach (var wo in pack)
|
||||
if (wo.ObjectClass == AcObjectClass.WandStaffOrb)
|
||||
{
|
||||
unlisted = true;
|
||||
return wo.Id;
|
||||
}
|
||||
return 0;
|
||||
{
|
||||
if (wo.ObjectClass != AcObjectClass.WandStaffOrb || (skip != null && skip(wo))) continue;
|
||||
int k = rank?.Invoke(wo) ?? 0;
|
||||
if (k < bestRank) { best = wo.Id; bestRank = k; }
|
||||
}
|
||||
unlisted = best != 0;
|
||||
return best;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -70,6 +70,8 @@ internal sealed class WeaponSwapTracker
|
|||
public string HoldReason { get; private set; } = "";
|
||||
/// <summary>A line to log once (a give-up), then cleared by the caller reading it.</summary>
|
||||
public string? Notice { get; set; }
|
||||
/// <summary>The weapon given up on in the last <see cref="Next"/> (its tries used up), else null; the caller clears it.</summary>
|
||||
public int? GaveUpId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// What to do about <paramref name="chosenId"/> with <paramref name="inHandId"/> in hand
|
||||
|
|
@ -222,6 +224,7 @@ internal sealed class WeaponSwapTracker
|
|||
if (!_tries.TryGetValue(id, out int tries) || tries < MaxTries) return;
|
||||
_tries.Remove(id);
|
||||
_restUntil[id] = now.AddMilliseconds(GiveUpMs);
|
||||
GaveUpId = id;
|
||||
string name = nameOf?.Invoke(id) ?? "";
|
||||
Notice = $"0x{(uint)id:X8} '{name}' didn't wield after {MaxTries} tries ({why}) — fighting with what's in hand for {GiveUpMs / 60000:0.#} min";
|
||||
}
|
||||
|
|
|
|||
85
Plugins/RynthCore.Plugin.RynthAi/Combat/WieldRequirements.cs
Normal file
85
Plugins/RynthCore.Plugin.RynthAi/Combat/WieldRequirements.cs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
using System;
|
||||
using RynthCore.PluginSdk;
|
||||
|
||||
namespace RynthCore.Plugin.RynthAi;
|
||||
|
||||
/// <summary>
|
||||
/// An item's wield requirements against the character (ACE: PropertyInt WieldRequirements 158 /
|
||||
/// WieldSkillType 159 / WieldDifficulty 160, and the 2nd-4th sets 270-278; WieldRequirement 1 Skill,
|
||||
/// 2 RawSkill, 7 Level, 8 Training). The client refuses a wield it can't meet without asking the
|
||||
/// server, so a refused wield never got an answer and was retried: Drakkon's Tetsubo (Two Handed
|
||||
/// Combat, untrained) took the off-hand weapon off for every fight (2026-10-18), his Electric Baton
|
||||
/// and Acid Staff (War Magic) held up buffing. Read from the item's appraisal; unknown = not known
|
||||
/// (the caller decides), never "met".
|
||||
/// </summary>
|
||||
internal static class WieldRequirements
|
||||
{
|
||||
private static readonly (uint Req, uint Skill, uint Diff)[] Sets =
|
||||
{
|
||||
(158, 159, 160), (270, 271, 272), (273, 274, 275), (276, 277, 278),
|
||||
};
|
||||
private const uint PropLevel = 25;
|
||||
|
||||
/// <summary>The first requirement of <paramref name="itemId"/> the character doesn't meet, or null (met, none, or not known).</summary>
|
||||
public static string? Unmet(RynthCoreHost host, CharacterSkills? skills, uint itemId)
|
||||
{
|
||||
if (!host.HasGetObjectIntProperty) return null;
|
||||
foreach (var (pReq, pSkill, pDiff) in Sets)
|
||||
{
|
||||
if (!host.TryGetObjectIntProperty(itemId, pReq, out int req) || req == 0) continue;
|
||||
host.TryGetObjectIntProperty(itemId, pDiff, out int diff);
|
||||
switch (req)
|
||||
{
|
||||
case 1: case 2: case 8: // Skill (buffed), RawSkill (base: only the buffed one is read), Training
|
||||
{
|
||||
if (skills == null || !host.TryGetObjectIntProperty(itemId, pSkill, out int stype)) continue;
|
||||
AcSkillType? skill = SkillOf((uint)stype);
|
||||
if (skill == null) continue;
|
||||
var s = skills[skill.Value];
|
||||
string name = Name(skill.Value);
|
||||
if (s.Training < 2) return $"needs {name}, untrained";
|
||||
if (req == 8) continue;
|
||||
if (diff > 0 && s.Buffed > 0 && s.Buffed < diff) return $"needs {name} {diff}, you have {s.Buffed}";
|
||||
continue;
|
||||
}
|
||||
case 7: // Level
|
||||
{
|
||||
uint pid = host.GetPlayerId();
|
||||
if (pid != 0 && host.TryGetObjectIntProperty(pid, PropLevel, out int level) && level > 0 && diff > 0 && level < diff)
|
||||
return $"needs level {diff}, you are {level}";
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>The item has a wield requirement (any set) per its appraisal.</summary>
|
||||
public static bool Has(RynthCoreHost host, uint itemId)
|
||||
{
|
||||
if (!host.HasGetObjectIntProperty) return false;
|
||||
foreach (var (pReq, _, _) in Sets)
|
||||
if (host.TryGetObjectIntProperty(itemId, pReq, out int req) && req != 0) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static AcSkillType? SkillOf(uint stype)
|
||||
{
|
||||
if (stype == 0) return null;
|
||||
foreach (AcSkillType k in Enum.GetValues(typeof(AcSkillType)))
|
||||
if (CharacterSkills.AcSkillTypeToSTypeSkill(k) == stype) return k;
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string Name(AcSkillType k)
|
||||
{
|
||||
string s = k.ToString();
|
||||
var sb = new System.Text.StringBuilder(s.Length + 4);
|
||||
for (int i = 0; i < s.Length; i++)
|
||||
{
|
||||
if (i > 0 && char.IsUpper(s[i])) sb.Append(' ');
|
||||
sb.Append(s[i]);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
|
@ -343,6 +343,15 @@ public class WorldObjectCache
|
|||
private const int MaxInitialScanRetries = 15;
|
||||
private readonly List<WorldObject> _directInventory = new();
|
||||
private readonly HashSet<int> _directInventoryIds = new();
|
||||
// The ids the last container walk found inside a pack: a side pack, or the main pack when the
|
||||
// item's container field is set. The player's own contents also hold what the player wields.
|
||||
private readonly HashSet<int> _packWalkIds = new();
|
||||
|
||||
/// <summary>True when the last container walk (GetDirectInventory) found <paramref name="id"/> inside a pack.</summary>
|
||||
public bool InPackWalk(int id)
|
||||
{
|
||||
lock (_gate) return _packWalkIds.Contains(id);
|
||||
}
|
||||
private readonly Dictionary<int, int> _directInventoryIndex = new();
|
||||
private DateTime _lastDirectInventoryScan = DateTime.MinValue;
|
||||
private const int DirectInventoryCooldownMs = 1000;
|
||||
|
|
@ -1395,6 +1404,7 @@ public class WorldObjectCache
|
|||
_directInventory.Clear();
|
||||
_directInventoryIds.Clear();
|
||||
_directInventoryIndex.Clear();
|
||||
_packWalkIds.Clear();
|
||||
|
||||
uint playerId = _host.GetPlayerId();
|
||||
if (playerId == 0)
|
||||
|
|
@ -1428,6 +1438,16 @@ public class WorldObjectCache
|
|||
// parent/slot for the remote inventory view (stashed onto the WorldObject).
|
||||
if (!TryAddDirectInventoryItem(itemId, playerId, containerId, i, out bool isContainer))
|
||||
continue;
|
||||
// The player's own contents can list what the player wields (the 07:27 export had the
|
||||
// wielded Sceptre in it, 2026-10-18), and reading a wielded caster as "in the pack" made
|
||||
// buffing ignore it and try every other one. So only a side pack, or the main pack with
|
||||
// the item's own container field set and no wielder, means "in a pack". Buffing's wand
|
||||
// swap puts the weapons into a side pack (the stale-record case of 2026-10-17/18).
|
||||
if (containerId != playerId) _packWalkIds.Add(unchecked((int)itemId));
|
||||
else if (_host.HasGetObjectOwnershipInfo
|
||||
&& _host.TryGetObjectOwnershipInfo(itemId, out uint inContainer, out uint byWielder, out _)
|
||||
&& inContainer != 0 && byWielder == 0)
|
||||
_packWalkIds.Add(unchecked((int)itemId));
|
||||
|
||||
if (isContainer && seenContainers.Add(itemId))
|
||||
pendingContainers.Enqueue(itemId);
|
||||
|
|
@ -1490,6 +1510,13 @@ public class WorldObjectCache
|
|||
/// </summary>
|
||||
public static bool IsWieldedByPlayer(RynthCoreHost host, WorldObject wo)
|
||||
{
|
||||
// The server's word (the engine's EquipmentTracker, API v87) when the engine has it.
|
||||
if (EquippedState.IsWielded(host, wo.Id) is bool tracked) return tracked;
|
||||
// Found inside a pack by the client's container walk: not wielded, whatever the weenie's
|
||||
// wielder record still says. It kept the player after buffing put both Hand Wraps into the
|
||||
// pack for the wand (2026-10-17), so combat took Drakkon as armed, never wielded anything,
|
||||
// and he fought bare-handed for 19 s until he died.
|
||||
if (wo.Cache != null && wo.Cache.InPackWalk(wo.Id)) return false;
|
||||
if (wo.Values(LongValueKey.CurrentWieldedLocation, 0) > 0) return true;
|
||||
if (wo.Values(LongValueKey.EquippedSlots, 0) != 0) return true;
|
||||
if (!host.HasGetObjectWielderInfo) return false;
|
||||
|
|
|
|||
|
|
@ -313,6 +313,9 @@ internal sealed class LegacyAdvancedSettingsUi
|
|||
|
||||
ImGui.Spacing();
|
||||
ImGui.Checkbox("Peace Mode When Idle", ref _settings.PeaceModeWhenIdle);
|
||||
ImGui.Checkbox("Weapons Back After Heals", ref _settings.RearmAfterVitals);
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip("After a heal, restam or remana spell with nothing to fight, put the last fight's weapons (main hand and off hand) back on.");
|
||||
ImGui.Checkbox("Start Macro On Login", ref _settings.StartMacroOnLogin);
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip("Automatically starts the macro when RynthAi loads.");
|
||||
|
|
|
|||
|
|
@ -1013,6 +1013,7 @@ internal sealed partial class LegacyDashboardRenderer
|
|||
TargetFPSBackground = s.TargetFPSBackground,
|
||||
EnableAutocram = s.EnableAutocram,
|
||||
PeaceModeWhenIdle = s.PeaceModeWhenIdle,
|
||||
RearmAfterVitals = s.RearmAfterVitals,
|
||||
StartMacroOnLogin = s.StartMacroOnLogin,
|
||||
PatrolOnLogin = s.PatrolOnLogin,
|
||||
YieldToVTank = s.YieldToVTank,
|
||||
|
|
@ -1250,6 +1251,7 @@ internal sealed partial class LegacyDashboardRenderer
|
|||
s.TargetFPSBackground = p.TargetFPSBackground;
|
||||
s.EnableAutocram = p.EnableAutocram;
|
||||
s.PeaceModeWhenIdle = p.PeaceModeWhenIdle;
|
||||
if (p.RearmAfterVitals is bool rav) s.RearmAfterVitals = rav;
|
||||
s.StartMacroOnLogin = p.StartMacroOnLogin;
|
||||
s.PatrolOnLogin = p.PatrolOnLogin;
|
||||
s.YieldToVTank = p.YieldToVTank;
|
||||
|
|
@ -1848,6 +1850,7 @@ internal sealed partial class LegacyDashboardRenderer
|
|||
dst.LootOnlyRareCorpses = tmp.LootOnlyRareCorpses;
|
||||
dst.EnableGroundLoot = tmp.EnableGroundLoot;
|
||||
dst.PeaceModeWhenIdle = tmp.PeaceModeWhenIdle;
|
||||
dst.RearmAfterVitals = tmp.RearmAfterVitals;
|
||||
dst.RebuffWhenIdle = tmp.RebuffWhenIdle;
|
||||
dst.RebuffSecondsRemaining = tmp.RebuffSecondsRemaining;
|
||||
dst.RebuffTopOffSecondsRemaining = tmp.RebuffTopOffSecondsRemaining;
|
||||
|
|
|
|||
|
|
@ -284,6 +284,9 @@ public sealed class LegacyUiSettings
|
|||
/// <summary>Also pick up loose ground items that match the loot profile, within the corpse max range.</summary>
|
||||
public bool EnableGroundLoot;
|
||||
public bool PeaceModeWhenIdle = true;
|
||||
/// <summary>After a heal, restam or remana spell with no monster to fight, put the last fight's
|
||||
/// weapons (main hand and off hand) back on instead of waiting for the next target.</summary>
|
||||
public bool RearmAfterVitals;
|
||||
public bool RebuffWhenIdle;
|
||||
/// <summary>
|
||||
/// Re-cast a self buff when its remaining duration drops below this many seconds.
|
||||
|
|
@ -986,6 +989,8 @@ public sealed class SettingsBridgePayload
|
|||
public int TargetFPSBackground { get; set; }
|
||||
public bool EnableAutocram { get; set; }
|
||||
public bool PeaceModeWhenIdle { get; set; }
|
||||
// Optional: an engine without the row doesn't send it, and that must not turn it off.
|
||||
public bool? RearmAfterVitals { get; set; }
|
||||
public bool StartMacroOnLogin { get; set; }
|
||||
public bool PatrolOnLogin { get; set; }
|
||||
// Dungeon patrol. Nullable: an engine that predates them doesn't send them, and its save
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ internal sealed class LegacyWeaponsUi
|
|||
{
|
||||
switch (wo.ObjectClass)
|
||||
{
|
||||
case AcObjectClass.HealingKit: return "HealthKit";
|
||||
case AcObjectClass.HealingKit: return (wo.Name ?? "").Contains("Stamina", StringComparison.OrdinalIgnoreCase) ? "StaminaKit" : "HealthKit";
|
||||
case AcObjectClass.Food: return PotionType(wo);
|
||||
case AcObjectClass.Lockpick: return "Lockpick";
|
||||
case AcObjectClass.Misc:
|
||||
|
|
@ -235,9 +235,10 @@ internal sealed class LegacyWeaponsUi
|
|||
name.Contains("Mana Stone", StringComparison.OrdinalIgnoreCase))
|
||||
return "ManaStone";
|
||||
|
||||
// Stamina items
|
||||
// Stamina items. A stamina kit is used on yourself, not drunk: its own type, so the
|
||||
// potion step never takes it ("Stamina" is the old name for stamina potions).
|
||||
if (name.Contains("Stamina", StringComparison.OrdinalIgnoreCase))
|
||||
return "Stamina";
|
||||
return name.TrimEnd().EndsWith(" Kit", StringComparison.OrdinalIgnoreCase) ? "StaminaKit" : "Stamina";
|
||||
|
||||
// Lockpicks
|
||||
if (name.Contains("Lockpick", StringComparison.OrdinalIgnoreCase) ||
|
||||
|
|
|
|||
|
|
@ -2905,8 +2905,9 @@ internal sealed class ExpressionEngine
|
|||
if (_host.HasGetObjectWielderInfo)
|
||||
{
|
||||
uint pid = _host.GetPlayerId();
|
||||
if (EquippedState.IsWielded(_host, id) is bool tracked) return tracked;
|
||||
if (pid != 0 && _host.TryGetObjectWielderInfo((uint)id, out uint wielder, out _))
|
||||
return wielder == pid;
|
||||
return wielder == pid && _worldObjectCache?.InPackWalk(id) != true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -3602,6 +3603,7 @@ internal sealed class ExpressionEngine
|
|||
["EnableCombineSalvage"]= (() => B(s.EnableCombineSalvage),v => s.EnableCombineSalvage= ToDouble(v) != 0),
|
||||
["SalvageWithoutPanel"] = (() => B(s.SalvageWithoutPanel), v => s.SalvageWithoutPanel = ToDouble(v) != 0),
|
||||
["PeaceModeWhenIdle"] = (() => B(s.PeaceModeWhenIdle), v => s.PeaceModeWhenIdle = ToDouble(v) != 0),
|
||||
["RearmAfterVitals"] = (() => B(s.RearmAfterVitals), v => s.RearmAfterVitals = ToDouble(v) != 0),
|
||||
["RebuffWhenIdle"] = (() => B(s.RebuffWhenIdle), v => s.RebuffWhenIdle = ToDouble(v) != 0),
|
||||
["UsePotions"] = (() => B(s.UsePotions), v => s.UsePotions = ToDouble(v) != 0),
|
||||
["UseBuffItems"] = (() => B(s.UseBuffItems), v => s.UseBuffItems = ToDouble(v) != 0),
|
||||
|
|
|
|||
|
|
@ -691,6 +691,10 @@ public sealed partial class RynthAiPlugin : RynthPluginBase
|
|||
_combatManager.SetWeaponSwapGate(_weaponSwapGate);
|
||||
_combatManager.Vitals = _vitals; // the script hook's request carries the player's vitals
|
||||
_combatManager.HoldIdlePeace = LootHoldsIdlePeace;
|
||||
_combatManager.LastVitalCastAt = () => _buffManager?.LastVitalCastAt ?? DateTime.MinValue;
|
||||
_combatManager.BuffingWantsTick = () => _buffManager != null
|
||||
&& (_buffManager.PendingSpellId != 0 || _buffManager.WantsVitalRecharge
|
||||
|| (_dashboard?.Settings?.EnableBuffing == true && _buffManager.NeedsAnyBuff()));
|
||||
_combatManager.HoldNewTarget = BoostLootHoldsNewTarget; // Boost Loot Priority: one kill, one loot
|
||||
_combatManager.ManaReserveHold = spellId => _buffManager?.OffensiveCastHold(spellId); // the mana reserve
|
||||
_combatManager.ManaCanEverAfford = spellId => _buffManager?.CanEverAfford(spellId) ?? true; // script hook: never-payable spells
|
||||
|
|
|
|||
|
|
@ -51,6 +51,14 @@ internal static unsafe class FakeHost
|
|||
/// <summary>Item id -> container id. When it has entries at Create() time the host also gets
|
||||
/// GetObjectOwnershipInfo (opt-in, so tests written without it see no ownership, as before).</summary>
|
||||
public static readonly Dictionary<uint, uint> Containers = new();
|
||||
/// <summary>Extra ids GetContainerContents lists for a container without them being in it (the
|
||||
/// client lists what the player wields in the player's own contents; ownership says no container).</summary>
|
||||
public static readonly Dictionary<uint, List<uint>> ContentsExtra = new();
|
||||
/// <summary>Opt-in (set before Create): v87 GetWieldedItems answering <see cref="Equipped"/> (the
|
||||
/// engine's EquipmentTracker: item -> EquipMask). <see cref="EquippedNotReady"/> answers -1.</summary>
|
||||
public static bool EquippedCalls;
|
||||
public static bool EquippedNotReady;
|
||||
public static readonly Dictionary<uint, uint> Equipped = new();
|
||||
/// <summary>Item id -> the creature wielding it (GetObjectOwnershipInfo's wielder). Entries here
|
||||
/// also install GetObjectOwnershipInfo; an id in neither map reads as unknown ownership.</summary>
|
||||
public static readonly Dictionary<uint, uint> Wielders = new();
|
||||
|
|
@ -252,12 +260,14 @@ internal static unsafe class FakeHost
|
|||
|
||||
public static void Reset()
|
||||
{
|
||||
EquippedCalls = false; EquippedNotReady = false; Equipped.Clear();
|
||||
RynthCore.Plugin.RynthAi.EquippedState.Invalidate();
|
||||
Nav3DCalls = false; Nav3DRings.Clear(); Nav3DLines.Clear(); Nav3DTriangles.Clear();
|
||||
Names.Clear(); Positions.Clear(); ItemTypes.Clear();
|
||||
Ints.Clear(); Doubles.Clear(); Quads.Clear(); Bools.Clear(); Strings.Clear();
|
||||
Skills.Clear(); SkillLevels.Clear(); Attributes.Clear();
|
||||
SpellIds.Clear(); DataIds.Clear(); InstanceIds.Clear(); Palettes.Clear(); KnownSpells.Clear(); NotAttackable.Clear(); Enchantments.Clear();
|
||||
Containers.Clear(); Wielders.Clear(); Bitfields.Clear();
|
||||
Containers.Clear(); ContentsExtra.Clear(); Wielders.Clear(); Bitfields.Clear();
|
||||
ServerTime = 0; Vitae = 1.0f; Portaling = false; PlayerPose = default; HasPose = true;
|
||||
Vitals = default; BaseVitals = default; WorldName = ""; AccountName = "";
|
||||
HeadingDeg = 0; Wcids.Clear(); Spellbook.Clear(); PlayerIdValue = 0;
|
||||
|
|
@ -319,6 +329,8 @@ internal static unsafe class FakeHost
|
|||
api.GetPlayerIdFn = (IntPtr)(delegate* unmanaged[Cdecl]<uint>)&GetPlayerId;
|
||||
if (Containers.Count > 0 || Wielders.Count > 0)
|
||||
api.GetObjectOwnershipInfoFn = (IntPtr)(delegate* unmanaged[Cdecl]<uint, uint*, uint*, uint*, int>)&GetObjectOwnershipInfo;
|
||||
if (EquippedCalls)
|
||||
api.GetWieldedItemsFn = (IntPtr)(delegate* unmanaged[Cdecl]<uint*, uint*, int, int>)&GetWieldedItems;
|
||||
if (ContentsCalls)
|
||||
api.GetContainerContentsFn = (IntPtr)(delegate* unmanaged[Cdecl]<uint, uint*, int, int>)&GetContainerContents;
|
||||
if (Bitfields.Count > 0)
|
||||
|
|
@ -449,6 +461,7 @@ internal static unsafe class FakeHost
|
|||
api.GetObjectPropertiesFn = (IntPtr)(delegate* unmanaged[Cdecl]<uint, byte*, int, int>)&GetObjectProperties;
|
||||
}
|
||||
LastApi = api;
|
||||
if (EquippedCalls) api.Version = Math.Max(api.Version, 87u); // v87 GetWieldedItems
|
||||
return new RynthCoreHost(api);
|
||||
}
|
||||
|
||||
|
|
@ -568,12 +581,28 @@ internal static unsafe class FakeHost
|
|||
return 1;
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static int GetWieldedItems(uint* ids, uint* locations, int max)
|
||||
{
|
||||
if (EquippedNotReady) return -1;
|
||||
int n = 0;
|
||||
foreach (var kv in Equipped)
|
||||
{
|
||||
if (n >= max) break;
|
||||
ids[n] = kv.Key; locations[n] = kv.Value; n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static int GetContainerContents(uint container, uint* output, int max)
|
||||
{
|
||||
int n = 0;
|
||||
foreach (var kv in Containers)
|
||||
if (kv.Value == container && n < max) output[n++] = kv.Key;
|
||||
if (ContentsExtra.TryGetValue(container, out var extra))
|
||||
foreach (uint id in extra)
|
||||
if (n < max) output[n++] = id;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,14 @@ internal static class OffhandTests
|
|||
r.Add("offhand: dual wield with the Dual Wield skill", DualWield);
|
||||
r.Add("offhand: the weapon in hand is the main hand's when the wielded slot reads 0 (the weenie's wielder record)", InHandFromWielderInfo);
|
||||
r.Add("weapons: a weapon refused 'skill too low' is left out of the choice (the off hand stays)", SkillTooLowLeftOut);
|
||||
r.Add("offhand: two weapons wielded and no slot read says which: the one RynthAi put in the off hand is the off hand's", OffhandRemembered);
|
||||
r.Add("weapons: a weapon in a pack is not in hand, though its wielder record still says the player", PackedIsNotWielded);
|
||||
r.Add("weapons: the equip step wields a weapon whose stale wielder record says 'in hand' while it is in a pack", EquipIgnoresStaleRecord);
|
||||
r.Add("weapons: a wielded item the client lists in the player's own contents is still wielded", WieldedInOwnContentsIsWielded);
|
||||
r.Add("tracker (v87): the server's list decides what is in hand, whatever the client's stale fields say", TrackerDecidesInHand);
|
||||
r.Add("tracker (v87): the main hand and the off hand come from the server's slots", TrackerHands);
|
||||
r.Add("tracker (v87): not ready yet (-1): the old reads answer", TrackerNotReadyFallsBack);
|
||||
r.Add("weapons: a two-hander needing untrained Two Handed Combat is never chosen, so the off hand stays", UnmetRequirementNotChosen);
|
||||
r.Add("offhand: no Dual Wield skill -> the shield", NoSkillShield);
|
||||
r.Add("offhand: None -> hands off (a worn shield is never taken off)", NoneHandsOff);
|
||||
r.Add("offhand: an unlisted shield is never wielded", UnlistedNeverUsed);
|
||||
|
|
@ -120,9 +128,12 @@ internal static class OffhandTests
|
|||
private readonly MethodInfo _equip = typeof(CombatManager).GetMethod("EquipWeaponAndSetStance", BindingFlags.Instance | BindingFlags.NonPublic)!;
|
||||
private readonly FieldInfo _lastEquip = typeof(CombatManager).GetField("_lastEquipTime", BindingFlags.Instance | BindingFlags.NonPublic)!;
|
||||
|
||||
public Rig(bool dualWieldSkill = false, bool shieldOn = false, bool wieldCalls = true, bool wielderInfo = false, bool weenieErrors = false)
|
||||
public Rig(bool dualWieldSkill = false, bool shieldOn = false, bool wieldCalls = true, bool wielderInfo = false, bool weenieErrors = false,
|
||||
bool contents = false, bool tracker = false)
|
||||
{
|
||||
FakeHost.Reset();
|
||||
FakeHost.EquippedCalls = tracker; // v87 GetWieldedItems (answering FakeHost.Equipped)
|
||||
FakeHost.ContentsCalls = contents; // the client's container walk (answering FakeHost.Containers)
|
||||
FakeHost.WeaponCalls = true;
|
||||
FakeHost.SalvageCalls = wielderInfo; // GetObjectWielderInfo (answering FakeHost.Wielded)
|
||||
FakeHost.WeenieErrorCalls = weenieErrors;
|
||||
|
|
@ -142,6 +153,9 @@ internal static class OffhandTests
|
|||
if (shieldOn) Wield(Shield, ShieldSlot);
|
||||
FakeHost.Wcids[Monster] = Wcid;
|
||||
FakeHost.Skills[(Player, 49)] = dualWieldSkill ? (220, 2) : (10, 1);
|
||||
// With the container walk: a side pack in the main pack, which also turns on the
|
||||
// ownership read (GetObjectOwnershipInfo: the item's own container field).
|
||||
if (contents) { FakeHost.Names[Pack] = "Pack"; FakeHost.ItemTypes[Pack] = 0x200; FakeHost.Containers[Pack] = Player; }
|
||||
var host = FakeHost.Create(wielderInfo ? Player : 0);
|
||||
var cache = FakeHost.MakeCache(host, Player, new[] { Sword, Dagger, Great, Shield, Round, Bow, Arrows, Wand });
|
||||
C = new CombatManager(host, S, cache);
|
||||
|
|
@ -445,6 +459,142 @@ internal static class OffhandTests
|
|||
Check.Eq(unchecked((uint)rig.C.OffhandInSlot(fresh: true)), Dagger, "the off hand: the dagger");
|
||||
}
|
||||
|
||||
// 2026-10-17: the off-hand Frost Hand Wraps read as the main weapon again (no slot read said
|
||||
// Shield), a swap went out for the Acid pair already in the main hand, and Drakkon fought
|
||||
// bare-handed; the off-hand wield also waited out its full confirm time every fight.
|
||||
private static void OffhandRemembered()
|
||||
{
|
||||
var rig = new Rig(dualWieldSkill: true, wielderInfo: true);
|
||||
rig.List(Sword, Dagger);
|
||||
rig.S.PreferDualWield = true;
|
||||
rig.Tick();
|
||||
Check.Eq(rig.ShieldWields(Dagger), 1, "the dagger is wielded into the off hand");
|
||||
// Both now wielded, and both read as melee-slot items (no Shield slot anywhere).
|
||||
Rig.Unwield(Sword);
|
||||
FakeHost.Wielded[Sword] = (uint)MeleeSlot;
|
||||
FakeHost.Wielded[Dagger] = (uint)MeleeSlot;
|
||||
rig.C.InHandOverride = null;
|
||||
Check.Eq(unchecked((uint)rig.C.InHandWeaponId(fresh: true)), Sword, "the main hand: the sword");
|
||||
Check.Eq(unchecked((uint)rig.C.OffhandInSlot(fresh: true)), Dagger, "the off hand: the dagger RynthAi put there");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("two weapons read as in hand")), "the slot reads are logged");
|
||||
Check.True(rig.Tick(), "sword and dagger: ready, no wait on the off-hand confirm");
|
||||
}
|
||||
|
||||
// 2026-10-17: buffing put both Hand Wraps into the pack for the wand; their wielder records still
|
||||
// said the player, combat took him as armed, and Drakkon fought bare-handed until he died.
|
||||
private static void PackedIsNotWielded()
|
||||
{
|
||||
var rig = new Rig(wielderInfo: true, contents: true);
|
||||
rig.List(Sword, Dagger);
|
||||
Rig.Unwield(Sword);
|
||||
FakeHost.Containers[Sword] = Pack; // in a side pack (where buffing's wand swap puts it)
|
||||
FakeHost.Wielded[Sword] = (uint)MeleeSlot; // a wielder record left over from when it was wielded
|
||||
rig.C.InHandOverride = null;
|
||||
Check.Eq(rig.C.InHandWeaponId(fresh: true), 0, "nothing in hand: the sword is in the pack");
|
||||
FakeHost.Containers.Remove(Sword); // wielded again
|
||||
System.Threading.Thread.Sleep(300); // the walk refreshes after 250 ms of real time
|
||||
Check.Eq(unchecked((uint)rig.C.InHandWeaponId(fresh: true)), Sword, "back in hand: the sword");
|
||||
}
|
||||
|
||||
// 2026-10-18: the player's own contents hold the wielded items too (the export listed the
|
||||
// wielded Sceptre). Read as "in the pack", buffing ignored the caster in hand and tried every
|
||||
// other one; combat could take a wielded weapon for one in the pack.
|
||||
private static void WieldedInOwnContentsIsWielded()
|
||||
{
|
||||
var rig = new Rig(wielderInfo: true, contents: true);
|
||||
rig.List(Sword);
|
||||
Rig.Unwield(Sword);
|
||||
FakeHost.Wielded[Sword] = (uint)MeleeSlot; // wielded: the record says so
|
||||
FakeHost.ContentsExtra[Player] = new() { Sword }; // and the client lists it in the player's contents, with no container
|
||||
rig.C.InHandOverride = null;
|
||||
Check.Eq(unchecked((uint)rig.C.InHandWeaponId(fresh: true)), Sword, "in hand: the sword, though the walk lists it");
|
||||
}
|
||||
|
||||
// 2026-10-18 00:07: after buffing's wand swap the equip step read the Acid Hand Wraps as wielded
|
||||
// (their wielder record still named Drakkon) while they sat in the pack, and attacked bare-handed.
|
||||
private static void EquipIgnoresStaleRecord()
|
||||
{
|
||||
var rig = new Rig(wielderInfo: true, contents: true);
|
||||
rig.List(Sword);
|
||||
Rig.Unwield(Sword);
|
||||
FakeHost.Containers[Sword] = Pack; // in a side pack (where buffing's wand swap puts it)
|
||||
FakeHost.Wielded[Sword] = (uint)MeleeSlot; // the stale record
|
||||
rig.C.InHandOverride = null;
|
||||
rig.Tick();
|
||||
Check.True(FakeHost.Uses.Contains(Sword), "the sword is wielded, not taken as already in hand");
|
||||
}
|
||||
|
||||
// 2026-10-18: every read of the client's own fields had a way to be wrong (the slot reads 0, the
|
||||
// wielder record outlives the move into a pack, the player's contents list wielded items). With
|
||||
// the engine's tracker (the server's messages) the answer is the server's.
|
||||
private static void TrackerDecidesInHand()
|
||||
{
|
||||
var rig = new Rig(wielderInfo: true, tracker: true);
|
||||
rig.List(Sword);
|
||||
Rig.Wield(Sword, MeleeSlot); // the client's fields say: in hand
|
||||
FakeHost.Wielded[Sword] = (uint)MeleeSlot;
|
||||
rig.C.InHandOverride = null;
|
||||
RynthCore.Plugin.RynthAi.EquippedState.Invalidate();
|
||||
Check.Eq(rig.C.InHandWeaponId(fresh: true), 0, "the server says nothing is wielded: nothing in hand");
|
||||
rig.Tick();
|
||||
Check.True(FakeHost.Uses.Contains(Sword), "so the sword is wielded");
|
||||
|
||||
FakeHost.Equipped[Sword] = (uint)MeleeSlot; // the server's WieldObject
|
||||
RynthCore.Plugin.RynthAi.EquippedState.Invalidate();
|
||||
Check.Eq(unchecked((uint)rig.C.InHandWeaponId(fresh: true)), Sword, "now in hand");
|
||||
Rig.Unwield(Sword); FakeHost.Wielded.Remove(Sword); // the client's fields go blank: still in hand
|
||||
RynthCore.Plugin.RynthAi.EquippedState.Invalidate();
|
||||
Check.Eq(unchecked((uint)rig.C.InHandWeaponId(fresh: true)), Sword, "the client's blank fields don't matter");
|
||||
}
|
||||
|
||||
private static void TrackerHands()
|
||||
{
|
||||
var rig = new Rig(dualWieldSkill: true, wielderInfo: true, tracker: true);
|
||||
rig.List(Sword, Dagger);
|
||||
FakeHost.Equipped[Sword] = (uint)MeleeSlot;
|
||||
FakeHost.Equipped[Dagger] = (uint)ShieldSlot;
|
||||
Rig.Wield(Dagger, MeleeSlot); // a wrong client field: ignored
|
||||
rig.C.InHandOverride = null;
|
||||
RynthCore.Plugin.RynthAi.EquippedState.Invalidate();
|
||||
Check.Eq(unchecked((uint)rig.C.InHandWeaponId(fresh: true)), Sword, "main hand: the sword");
|
||||
Check.Eq(unchecked((uint)rig.C.OffhandInSlot(fresh: true)), Dagger, "off hand: the dagger");
|
||||
}
|
||||
|
||||
// 2026-10-18 14:14: the Damage tab picked a Tetsubo (Two Handed Combat, untrained); the client refused
|
||||
// the wield unasked, and every fight took the off-hand weapon off for it and put it back.
|
||||
private static void UnmetRequirementNotChosen()
|
||||
{
|
||||
var rig = new Rig(dualWieldSkill: true);
|
||||
rig.List(Sword, Dagger, Great);
|
||||
rig.S.PreferDualWield = true;
|
||||
FakeHost.Ints[(Great, 158)] = 2; // WieldRequirements: RawSkill
|
||||
FakeHost.Ints[(Great, 159)] = 41; // Two Handed Combat
|
||||
FakeHost.Ints[(Great, 160)] = 250;
|
||||
FakeHost.Skills[(Player, 41)] = (0, 1); // untrained
|
||||
Rig.Wield(Dagger, ShieldSlot);
|
||||
rig.Store.SetManualWeapon(Wcid, Great);
|
||||
for (int i = 0; i < 4; i++) { rig.Unpace(); rig.Tick(); }
|
||||
Check.False(FakeHost.Uses.Contains(Great), "the greatsword is never wielded");
|
||||
Check.False(FakeHost.Moves.Any(m => m.Id == Dagger), "the off-hand dagger never comes off for it");
|
||||
Check.False(rig.C.ListedCandidates().Any(c => c.Id == unchecked((int)Great)), "not a candidate");
|
||||
Check.True(FakeHost.Chat.Any(c => c.Contains("can't be wielded (needs Two Handed Combat, untrained)")), "the player is told: " + string.Join(" | ", FakeHost.Chat));
|
||||
|
||||
// A class switch: Two Handed Combat trained (and high enough): the greatsword is a candidate again.
|
||||
FakeHost.Skills[(Player, 41)] = (300, 2);
|
||||
System.Threading.Thread.Sleep(1100); // skill reads are cached for up to a second
|
||||
Check.True(rig.C.ListedCandidates().Any(c => c.Id == unchecked((int)Great)), "after training it: a candidate again, nothing to re-list");
|
||||
}
|
||||
|
||||
private static void TrackerNotReadyFallsBack()
|
||||
{
|
||||
var rig = new Rig(tracker: true);
|
||||
FakeHost.EquippedNotReady = true;
|
||||
rig.List(Sword);
|
||||
rig.C.InHandOverride = null;
|
||||
RynthCore.Plugin.RynthAi.EquippedState.Invalidate();
|
||||
Check.Eq(unchecked((uint)rig.C.InHandWeaponId(fresh: true)), Sword, "-1 from the engine: the client's slot read answers (the sword reads wielded)");
|
||||
}
|
||||
|
||||
// 2026-10-16: a Nodachi the character lacked the skill for was chosen whenever a monster was
|
||||
// weak to Slash: refused three times, then again two minutes later, the off hand dequipped each time.
|
||||
private static void SkillTooLowLeftOut()
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using RynthCore.Loot;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
using RynthCore.Plugin.RynthAi.LegacyUi;
|
||||
using RynthCore.Plugin.Shared;
|
||||
|
|
@ -35,6 +36,8 @@ internal static class OneTouchHealTests
|
|||
r.Add("one-touch: a request waits out a kit in flight, then goes; a second press while waiting is not a second heal", HealWaitsForKit);
|
||||
r.Add("one-touch: a request that stays blocked gives up after OneTouchWaitMs and says why", HealGivesUp);
|
||||
r.Add("one-touch: stamina takes a stamina kit, a listed potion out of Magic stance, else Revitalize", StaminaChoice);
|
||||
r.Add("vitals: a stamina kit is typed StaminaKit and never taken by the potion step (it was drunk with no target)", StaminaKitNeverDrunk);
|
||||
r.Add("buff wand: a caster that needs untrained War Magic is never picked to buff; the next listed one is", BuffWandSkipsUnwieldable);
|
||||
r.Add("one-touch: mana casts Stamina to Mana; with stamina at the floor it refills stamina first", ManaChoice);
|
||||
r.Add("one-touch: /ra heal, /ra stam and /ra mana request a pass (and say so before login)", Commands);
|
||||
}
|
||||
|
|
@ -274,6 +277,55 @@ internal static class OneTouchHealTests
|
|||
Check.True(IsFamily(FakeHost.Casts[0].SpellId, "Revitalize Self I"), "Revitalize Self");
|
||||
}
|
||||
|
||||
// 2026-10-17: Drakkon's Greater Stamina Kit sat on the Items list as type "Stamina" (the old
|
||||
// name for stamina potions). The kit failed Kit Min Success, and the potion step then used it
|
||||
// with no target every 3 s; the server never answered and Revitalize never went out.
|
||||
private static void StaminaKitNeverDrunk()
|
||||
{
|
||||
var kit = new WorldObject(0x60002001, "Greater Stamina Kit", AcObjectClass.HealingKit);
|
||||
Check.Eq(RynthCore.Plugin.RynthAi.LegacyUi.LegacyWeaponsUi.PackConsumableType(kit), "StaminaKit",
|
||||
"a stamina kit is its own type: not a health kit, not a stamina potion");
|
||||
Check.Eq(RynthCore.Plugin.RynthAi.LegacyUi.LegacyWeaponsUi.PackConsumableType(new WorldObject(0x60002002, "Peerless Healing Kit", AcObjectClass.HealingKit)),
|
||||
"HealthKit", "a healing kit stays a health kit");
|
||||
Check.True(BuffManager.IsKitName("Greater Stamina Kit"), "a kit by name: the potion step skips it");
|
||||
Check.False(BuffManager.IsKitName("Stamina Tincture"), "a potion is not a kit");
|
||||
}
|
||||
|
||||
// 2026-10-18 01:00-01:24: with the buff wand gone, buffing tried an Electric Baton that needs War
|
||||
// Magic (untrained) every 8 s for 24 minutes; Heal Self couldn't go and Drakkon died.
|
||||
private static void BuffWandSkipsUnwieldable()
|
||||
{
|
||||
var r = Make(CombatMode.Melee);
|
||||
const uint Baton = 0x80400070, Sceptre = 0x80400071;
|
||||
FakeHost.Ints[(Baton, 158)] = 2; // WieldRequirements: RawSkill
|
||||
FakeHost.Ints[(Baton, 159)] = 34; // War Magic
|
||||
FakeHost.Ints[(Baton, 160)] = 300;
|
||||
FakeHost.Skills[(Player, 34)] = (0, 1); // War Magic untrained
|
||||
FakeHost.Appraised.Add(Baton); FakeHost.Appraised.Add(Sceptre); // both identified: their requirements are known
|
||||
var skip = typeof(BuffManager).GetMethod("SkipBuffWand", BindingFlags.Instance | BindingFlags.NonPublic)!;
|
||||
var baton = new WorldObject(unchecked((int)Baton), "Electric Baton", AcObjectClass.WandStaffOrb);
|
||||
var sceptre = new WorldObject(unchecked((int)Sceptre), "Sceptre", AcObjectClass.WandStaffOrb);
|
||||
Check.True((bool)skip.Invoke(r.B, new object[] { baton })!, "the War Magic baton is skipped");
|
||||
Check.False((bool)skip.Invoke(r.B, new object[] { sceptre })!, "a caster with no requirement is not");
|
||||
Check.True(FakeHost.Chat.Any(c => c.Contains("Electric Baton can't be wielded")), "the player is told once: " + AllChat);
|
||||
// Not identified yet: skipped, and identified first (the Acid Staff was tried unidentified, 2026-10-18).
|
||||
var staff = new WorldObject(0x60400073, "Acid Staff", AcObjectClass.WandStaffOrb);
|
||||
Check.True((bool)skip.Invoke(r.B, new object[] { staff })!, "an unidentified caster is not tried");
|
||||
Check.True(FakeHost.IdRequests.Contains(0x60400073u), "it is identified first");
|
||||
|
||||
var rules = new[] { new ItemRule { Id = baton.Id, Name = baton.Name }, new ItemRule { Id = sceptre.Id, Name = sceptre.Name } };
|
||||
var objs = new[] { baton, sceptre };
|
||||
int pick = WeaponList.FindWand(rules, id => objs.FirstOrDefault(o => o.Id == id), _ => false, objs, false, out _,
|
||||
wo => wo.Id == baton.Id);
|
||||
Check.Eq(pick, sceptre.Id, "the finder passes over the skipped baton to the next listed caster");
|
||||
|
||||
// The player wielded an unlisted caster (the one he can wield): that is the buff wand.
|
||||
var bronze = new WorldObject(0x60400072, "Bronze Sceptre", AcObjectClass.WandStaffOrb);
|
||||
var withBronze = new[] { baton, sceptre, bronze };
|
||||
int inHand = WeaponList.FindWand(rules, id => withBronze.FirstOrDefault(o => o.Id == id), wo => wo.Id == bronze.Id, withBronze, false, out _);
|
||||
Check.Eq(inHand, bronze.Id, "a caster already in hand wins, listed or not");
|
||||
}
|
||||
|
||||
private static void ManaChoice()
|
||||
{
|
||||
var r = Make(CombatMode.Magic, st: 100, mn: 20);
|
||||
|
|
|
|||
|
|
@ -912,7 +912,13 @@ internal static class WeaponTests
|
|||
Check.Eq(unchecked((uint)got), ListedWand, "a listed wand in hand counts as carried");
|
||||
var sameName = new WorldObject(0x7000ABCD, cache[unchecked((int)ListedWand)]!.Name, AcObjectClass.WandStaffOrb);
|
||||
got = WeaponList.FindWand(rig.S.ItemRules, Look, _ => false, new[] { sameName }, allowUnlisted: false, out _);
|
||||
Check.Eq(got, 0x7000ABCD, "listed wand gone: another of the same name in the pack stands in");
|
||||
Check.Eq(got, 0, "listed wand gone, setting off: no same-name stand-in (it took unlisted 'Wand's, 2026-10-18)");
|
||||
got = WeaponList.FindWand(rig.S.ItemRules, Look, _ => false, new[] { sameName }, allowUnlisted: true, out unlisted);
|
||||
Check.Eq(got, 0x7000ABCD, "listed wand gone, setting on: any caster in the pack");
|
||||
Check.True(unlisted, "from the pack");
|
||||
got = WeaponList.FindWand(rig.S.ItemRules, Look, _ => false, invWithListed, allowUnlisted: true, out unlisted,
|
||||
skip: wo => wo.Id == unchecked((int)ListedWand));
|
||||
Check.Eq(got, 0, "the listed wand is carried but can't be wielded: no caster from the pack (owner, 2026-10-18)");
|
||||
|
||||
var none = new List<ItemRule>();
|
||||
got = WeaponList.FindWand(none, Look, _ => false, new[] { cache[unchecked((int)NamedJunk)]! }, allowUnlisted: true, out _);
|
||||
|
|
|
|||
Loading…
Reference in a new issue