Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon: [1.7.63] - Fix potentially not detecting extra body pulled mobs during combat #659

Merged
merged 2 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Addons/DataToColor/Constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion Addons/DataToColor/DataToColor.toc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 19 additions & 1 deletion Addons/DataToColor/Query.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ local UnitRangedDamage = UnitRangedDamage

local GameMenuFrame = GameMenuFrame

local HasPetUI = HasPetUI

-- bits

local UnitAffectingCombat = UnitAffectingCombat
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion Core/Addon/PlayerReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions Core/AddonComponent/AddonBits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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
Expand Down
107 changes: 54 additions & 53 deletions Core/Goals/CombatGoal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyAction> 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<KeyAction> 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
{
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions Core/Goals/TargetPetTargetGoal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down