From eb0cba6c738cc01ac8d6b1d91de5e6243f46a088 Mon Sep 17 00:00:00 2001 From: Xian55 <367101+Xian55@users.noreply.github.com> Date: Sat, 11 Jan 2025 15:47:09 +0100 Subject: [PATCH 1/2] Addon: 1.7.63: Extract PetDefensive info --- Addons/DataToColor/Constants.lua | 2 ++ Addons/DataToColor/DataToColor.toc | 2 +- Addons/DataToColor/Query.lua | 20 +++++++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Addons/DataToColor/Constants.lua b/Addons/DataToColor/Constants.lua index ec40c264..693d5e31 100644 --- a/Addons/DataToColor/Constants.lua +++ b/Addons/DataToColor/Constants.lua @@ -82,3 +82,5 @@ DataToColor.C.MIRRORTIMER.BREATH = "BREATH" DataToColor.C.ActionType.Spell = "spell" DataToColor.C.ActionType.Macro = "macro" + +DataToColor.C.PET_MODE_DEFENSIVE = "PET_MODE_DEFENSIVE" \ No newline at end of file diff --git a/Addons/DataToColor/DataToColor.toc b/Addons/DataToColor/DataToColor.toc index bdb341b4..6807b2c8 100644 --- a/Addons/DataToColor/DataToColor.toc +++ b/Addons/DataToColor/DataToColor.toc @@ -3,7 +3,7 @@ ## Title: DataToColor ## Author: FreeHongKongMMO ## Notes: Displays data as colors -## Version: 1.7.62 +## Version: 1.7.63 ## RequiredDeps: ## OptionalDeps: Ace3, LibRangeCheck, LibClassicCasterino ## SavedVariables: diff --git a/Addons/DataToColor/Query.lua b/Addons/DataToColor/Query.lua index 70693746..c74f0621 100644 --- a/Addons/DataToColor/Query.lua +++ b/Addons/DataToColor/Query.lua @@ -52,6 +52,8 @@ local UnitRangedDamage = UnitRangedDamage local GameMenuFrame = GameMenuFrame +local HasPetUI = HasPetUI + -- bits local UnitAffectingCombat = UnitAffectingCombat @@ -164,7 +166,8 @@ function DataToColor:Bits2() ((DataToColor.autoFollow) and 2 or 0) ^ 19 + ((GameMenuFrame:IsShown() and 2 or 0)) ^ 20 + ((IsFlying() and 2 or 0)) ^ 21 + - ((DataToColor.moving and 2 or 0)) ^ 22 + ((DataToColor.moving and 2 or 0)) ^ 22 + + ((DataToColor:PetIsDefensive() and 2 or 0)) ^ 23 end function DataToColor:Bits3() @@ -611,3 +614,18 @@ function DataToColor:IsUnitHostile(unit, unittarget) (UnitReaction(unit, unittarget) or 0) <= 4 and not UnitIsFriend(unit, unittarget) end + +function DataToColor:PetIsDefensive() + if not HasPetUI() then + return false + end + + for i = 1, 10 do + local name, _, _, isActive = GetPetActionInfo(i) + if isActive and name == DataToColor.C.PET_MODE_DEFENSIVE then + return true + end + end + + return false +end \ No newline at end of file From 416a875ee8adba806820b84c8a79298c71083ebe Mon Sep 17 00:00:00 2001 From: Xian55 <367101+Xian55@users.noreply.github.com> Date: Sat, 11 Jan 2025 15:50:05 +0100 Subject: [PATCH 2/2] Core: TargetPetTargetGoal: Restrict when the Goal can run. It's expected to have Alive Pet with Active Defensive behaviour. Core: CombatGoal: Since Pet Defensive Behaviour is known use it as as an advantage. Otherwise when searching for 'FindPossibleThreats' use CombatLog.DamageTakenCount whether there's a danger in front or wait for damage taken from behind. --- Core/Addon/PlayerReader.cs | 2 +- Core/AddonComponent/AddonBits.cs | 3 + Core/Goals/CombatGoal.cs | 107 +++++++++++++++--------------- Core/Goals/TargetPetTargetGoal.cs | 5 ++ 4 files changed, 63 insertions(+), 54 deletions(-) diff --git a/Core/Addon/PlayerReader.cs b/Core/Addon/PlayerReader.cs index 7f8c5134..c25719f6 100644 --- a/Core/Addon/PlayerReader.cs +++ b/Core/Addon/PlayerReader.cs @@ -86,7 +86,7 @@ public PlayerReader( public int PetMaxHealth() => reader.GetInt(38); public int PetHealth() => reader.GetInt(39); public int PetHealthPercent() => (1 + PetHealth()) * 100 / (1 + PetMaxHealth()); - + public bool PetAlive() => PetHealth() > 0; public SpellInRange SpellInRange { get; } public bool WithInPullRange() => SpellInRange.WithinPullRange(this, Class); diff --git a/Core/AddonComponent/AddonBits.cs b/Core/AddonComponent/AddonBits.cs index 5c096aa3..e12919bf 100644 --- a/Core/AddonComponent/AddonBits.cs +++ b/Core/AddonComponent/AddonBits.cs @@ -61,6 +61,7 @@ public void Update(IAddonDataProvider reader) public bool FocusTarget_Hostile() => v2[Mask._7]; public bool MouseOver_Dead() => v2[Mask._8]; public bool PetTarget_Dead() => v2[Mask._9]; + public bool PetTarget_Alive() => !PetTarget_Dead(); public bool Stealthed() => v2[Mask._10]; public bool Target_Trivial() => v2[Mask._11]; public bool Target_NotTrivial() => !v2[Mask._11]; @@ -76,6 +77,8 @@ public void Update(IAddonDataProvider reader) public bool GameMenuWindowShown() => v2[Mask._20]; public bool Flying() => v2[Mask._21]; public bool Moving() => v2[Mask._22]; + public bool Pet_Defensive() => v2[Mask._23]; + public bool NotMoving() => !Moving(); // Combined diff --git a/Core/Goals/CombatGoal.cs b/Core/Goals/CombatGoal.cs index 5d841aaf..9bad441c 100644 --- a/Core/Goals/CombatGoal.cs +++ b/Core/Goals/CombatGoal.cs @@ -124,44 +124,43 @@ public override void Update() return; } - if (bits.Target()) + if (classConfig.AutoPetAttack && + bits.Pet() && + (!playerReader.PetTarget() || playerReader.PetTargetGuid != playerReader.TargetGuid) && + !input.PetAttack.OnCooldown()) { - if (classConfig.AutoPetAttack && - bits.Pet() && - (!playerReader.PetTarget() || playerReader.PetTargetGuid != playerReader.TargetGuid) && - !input.PetAttack.OnCooldown()) + input.PressPetAttack(); + } + + ReadOnlySpan span = Keys; + for (int i = 0; bits.Target_Alive() && i < span.Length; i++) + { + KeyAction keyAction = span[i]; + + if (castingHandler.SpellInQueue() && !keyAction.BaseAction) { - input.PressPetAttack(); + continue; } - ReadOnlySpan span = Keys; - for (int i = 0; bits.Target_Alive() && i < span.Length; i++) + if (castingHandler.CastIfReady(keyAction, + keyAction.Interrupts.Count > 0 + ? keyAction.CanBeInterrupted + : bits.Target_Alive)) { - KeyAction keyAction = span[i]; - - if (castingHandler.SpellInQueue() && !keyAction.BaseAction) - { - continue; - } - - if (castingHandler.CastIfReady(keyAction, - keyAction.Interrupts.Count > 0 - ? keyAction.CanBeInterrupted - : bits.Target_Alive)) - { - break; - } + break; } } - if (!bits.Target()) + if (!bits.Target() || (bits.Target() && bits.Target_Dead())) { logger.LogInformation("Lost target!"); if (combatLog.DamageTakenCount() > 0) { + logger.LogWarning("Search Possible Threats!"); stopMoving.Stop(); - FindNewTarget(); + + FindPossibleThreats(); } else { @@ -170,52 +169,54 @@ public override void Update() } } - private void FindNewTarget() + private void FindPossibleThreats() { - if (playerReader.PetTarget() && combatLog.DeadGuid.Value != playerReader.PetTargetGuid) + if (bits.Pet_Defensive()) { + float elapsedPetFoundTarget = wait.Until(CastingHandler.GCD, + () => playerReader.PetTarget() && bits.PetTarget_Alive()); + + if (elapsedPetFoundTarget < 0) + { + logger.LogWarning("Pet not found target!"); + input.PressClearTarget(); + return; + } + ResetCooldowns(); input.PressTargetPet(); input.PressTargetOfTarget(); wait.Update(); - if (!bits.Target_Dead()) - { - logger.LogWarning("---- New target from Pet target!"); - return; - } + logger.LogWarning($"Found new target by pet. {elapsedPetFoundTarget}ms"); - input.PressClearTarget(); + return; } - if (combatLog.DamageTakenCount() > 1) - { - logger.LogInformation("Checking target in front..."); - input.PressNearestTarget(); - wait.Update(); + logger.LogInformation("Checking target in front..."); + input.PressNearestTarget(); + wait.Update(); - if (bits.Target() && !bits.Target_Dead()) + if (bits.Target() && !bits.Target_Dead() && bits.Target_Hostile()) + { + if (bits.Target_Combat() && bits.TargetTarget_PlayerOrPet()) { - if (bits.Target_Combat() && bits.TargetTarget_PlayerOrPet()) - { - stopMoving.Stop(); - ResetCooldowns(); + ResetCooldowns(); - logger.LogWarning("Found new target!"); - wait.Update(); - return; - } - - input.PressClearTarget(); + logger.LogWarning("Found new target!"); wait.Update(); + return; } - else if (combatLog.DamageTakenCount() > 0) - { - logger.LogWarning($"---- Possible threats from behind {combatLog.DamageTakenCount()}. Waiting target by damage taken!"); - wait.Till(2500, bits.Target); - } + + logger.LogWarning("Dont pull non-hostile target!"); + input.PressClearTarget(); + wait.Update(); } + + logger.LogWarning($"Waiting for target to exists or lose combat. Possible threats {combatLog.DamageTakenCount()}!"); + wait.Till(CastingHandler.GCD * 2, + () => bits.Target_Alive() || !bits.Combat()); } private Vector3 GetCorpseLocation(float distance) diff --git a/Core/Goals/TargetPetTargetGoal.cs b/Core/Goals/TargetPetTargetGoal.cs index 32cdee41..a05480d4 100644 --- a/Core/Goals/TargetPetTargetGoal.cs +++ b/Core/Goals/TargetPetTargetGoal.cs @@ -37,6 +37,11 @@ public TargetPetTargetGoal(ConfigurableInput input, AddEffect(GoapKey.hastarget, true); } + public override bool CanRun() + { + return playerReader.PetAlive() && bits.Pet_Defensive(); + } + public override void Update() { input.PressTargetPet();