RynthSuite as of 2026-09-26 (internal 7590e56): no caster combat without War/Void Magic; /ub usei finds carried items
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0a4b611a90
commit
bc0d4338f3
2 changed files with 56 additions and 4 deletions
|
|
@ -2466,17 +2466,21 @@ public class CombatManager : IDisposable
|
|||
if (targetWcid != 0 && _damageStore != null)
|
||||
{
|
||||
uint eff = _damageStore.GetEffectiveWeapon(targetWcid);
|
||||
if (eff != 0) { targetWeaponId = (int)eff; weaponSource = "DamageTab"; }
|
||||
if (eff != 0 && IsUsableCombatWeapon((int)eff)) { targetWeaponId = (int)eff; weaponSource = "DamageTab"; }
|
||||
}
|
||||
if (targetWeaponId == 0)
|
||||
{
|
||||
// No Damage-tab choice yet → element/wand auto (element from rule.DamageType or weakness).
|
||||
var bestWeapon = _settings.ItemRules.FirstOrDefault(i => i.Element.Equals(desired, StringComparison.OrdinalIgnoreCase))
|
||||
?? _settings.ItemRules.FirstOrDefault();
|
||||
// Casters are skipped when the character has no War/Void Magic: a wand listed
|
||||
// above the bow for the same element put a missile character in Magic mode,
|
||||
// casting war spells the server refused ("You don't have all the components")
|
||||
// while combat held the action lock and the route never ran.
|
||||
var bestWeapon = _settings.ItemRules.FirstOrDefault(i => i.Element.Equals(desired, StringComparison.OrdinalIgnoreCase) && IsUsableCombatWeapon(i.Id))
|
||||
?? _settings.ItemRules.FirstOrDefault(i => IsUsableCombatWeapon(i.Id));
|
||||
if (bestWeapon != null) { targetWeaponId = bestWeapon.Id; weaponSource = "ItemRules"; }
|
||||
}
|
||||
|
||||
if (targetWeaponId == 0)
|
||||
if (targetWeaponId == 0 && CanAttackWithMagic)
|
||||
{
|
||||
targetWeaponId = FindWandInItems();
|
||||
if (targetWeaponId != 0) weaponSource = "FindWandInItems";
|
||||
|
|
@ -3415,6 +3419,23 @@ public class CombatManager : IDisposable
|
|||
private static bool IsWandObject(WorldObject wo) =>
|
||||
wo.ObjectClass == AcObjectClass.WandStaffOrb || IsWandName(wo.Name);
|
||||
|
||||
/// <summary>War or Void Magic trained — the character can attack with a caster.
|
||||
/// Skills not read yet count as trained, like the other skill gates here.</summary>
|
||||
private bool CanAttackWithMagic =>
|
||||
_charSkills == null
|
||||
|| _charSkills[AcSkillType.WarMagic].Training >= 2
|
||||
|| _charSkills[AcSkillType.VoidMagic].Training >= 2;
|
||||
|
||||
/// <summary>A weapon combat may fight with: anything but a caster when the character
|
||||
/// has no attack magic. An id missing from the world cache stays a candidate — the
|
||||
/// caller already handles that. Debuff casting picks its wand separately.</summary>
|
||||
private bool IsUsableCombatWeapon(int id)
|
||||
{
|
||||
if (CanAttackWithMagic) return true;
|
||||
var wo = _worldFilter[id];
|
||||
return wo == null || !IsWandObject(wo);
|
||||
}
|
||||
|
||||
private static bool IsWandName(string name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return false;
|
||||
|
|
@ -3564,6 +3585,7 @@ public class CombatManager : IDisposable
|
|||
bool useVoid = element.Equals("Nether", StringComparison.OrdinalIgnoreCase);
|
||||
bool warTrained = _charSkills == null || _charSkills[AcSkillType.WarMagic].Training >= 2;
|
||||
bool voidTrained = _charSkills == null || _charSkills[AcSkillType.VoidMagic].Training >= 2;
|
||||
if (!warTrained && !voidTrained) return 0; // no attack magic — used to fall through to War anyway
|
||||
|
||||
if (useVoid && !voidTrained && warTrained) useVoid = false;
|
||||
if (!useVoid && !warTrained && voidTrained) useVoid = true;
|
||||
|
|
|
|||
|
|
@ -1890,6 +1890,20 @@ public sealed partial class RynthAiPlugin
|
|||
: string.Equals(wo.Name, name, StringComparison.OrdinalIgnoreCase))
|
||||
return wo;
|
||||
}
|
||||
|
||||
// The live walk above can miss carried items: off AC's main thread it only
|
||||
// knows names from the engine's name snapshot, and an item missing from it
|
||||
// drops out of the walk. Fall back to every object the cache knows and ask
|
||||
// the client who holds it — "/ub usei X" said "Not found" for an item that
|
||||
// "/ub use X" found, because the cache had it filed under the landscape.
|
||||
foreach (var wo in _objectCache.AllKnownObjects())
|
||||
{
|
||||
if ((partial
|
||||
? wo.Name.IndexOf(name, StringComparison.OrdinalIgnoreCase) >= 0
|
||||
: string.Equals(wo.Name, name, StringComparison.OrdinalIgnoreCase))
|
||||
&& IsCarriedByPlayer(wo.Id))
|
||||
return wo;
|
||||
}
|
||||
}
|
||||
|
||||
if (land)
|
||||
|
|
@ -1918,6 +1932,22 @@ public sealed partial class RynthAiPlugin
|
|||
return null;
|
||||
}
|
||||
|
||||
/// <summary>True when the client says the player holds this object: worn or
|
||||
/// wielded, in the main pack, or in a side pack (item → pack → player).</summary>
|
||||
private bool IsCarriedByPlayer(int objectId)
|
||||
{
|
||||
if (_playerId == 0 || !Host.HasGetObjectOwnershipInfo) return false;
|
||||
uint id = unchecked((uint)objectId);
|
||||
for (int depth = 0; depth < 3; depth++)
|
||||
{
|
||||
if (!Host.TryGetObjectOwnershipInfo(id, out uint container, out uint wielder, out _)) return false;
|
||||
if (wielder == _playerId || container == _playerId) return true;
|
||||
if (container == 0) return false;
|
||||
id = container;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void HandleUseCommand(string[] parts, bool inv, bool land, bool partial)
|
||||
{
|
||||
if (parts.Length < 3)
|
||||
|
|
|
|||
Loading…
Reference in a new issue