Skip to content

Commit

Permalink
Merge pull request #239 from FFXIV-CombatReborn/breaking-shit
Browse files Browse the repository at this point in the history
Add condition flags to HasPet check
  • Loading branch information
NostraThomas99 authored Jul 17, 2024
2 parents a92356a + 7576248 commit 348eed7
Showing 1 changed file with 44 additions and 32 deletions.
76 changes: 44 additions & 32 deletions RotationSolver.Basic/DataCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public static IBattleChara[] AllHostileTargets
if (b.CurrentHp <= 1) return false;

if (!b.IsTargetable) return false;

if (b.StatusList.Any(StatusHelper.IsInvincible)) return false;
return true;
}).ToArray();
Expand All @@ -327,7 +327,7 @@ public static IBattleChara? DeathTarget
{
var deathAll = AllianceMembers.GetDeath();
var deathParty = PartyMembers.GetDeath();

if (deathParty.Any())
{
var deathT = deathParty.GetJobCategory(JobRole.Tank);
Expand Down Expand Up @@ -358,19 +358,20 @@ public static IBattleChara? DeathTarget
}

return null;

}
}

public static IBattleChara? DispelTarget
{
get
{
var weakenPeople = DataCenter.PartyMembers.Where(o => o is IBattleChara b && b.StatusList.Any(StatusHelper.CanDispel));
var dyingPeople = weakenPeople.Where(o => o is IBattleChara b && b.StatusList.Any(StatusHelper.IsDangerous));
var weakenPeople =
DataCenter.PartyMembers.Where(o => o is IBattleChara b && b.StatusList.Any(StatusHelper.CanDispel));
var dyingPeople =
weakenPeople.Where(o => o is IBattleChara b && b.StatusList.Any(StatusHelper.IsDangerous));

return dyingPeople.OrderBy(ObjectHelper.DistanceToPlayer).FirstOrDefault()
?? weakenPeople.OrderBy(ObjectHelper.DistanceToPlayer).FirstOrDefault();
?? weakenPeople.OrderBy(ObjectHelper.DistanceToPlayer).FirstOrDefault();
}
}

Expand Down Expand Up @@ -400,25 +401,27 @@ public static ulong[] TreasureCharas
public static int NumberOfHostilesInMaxRange => AllHostileTargets.Count(o => o.DistanceToPlayer() <= 25);
public static int NumberOfAllHostilesInRange => AllHostileTargets.Count(o => o.DistanceToPlayer() <= JobRange);
public static int NumberOfAllHostilesInMaxRange => AllHostileTargets.Count(o => o.DistanceToPlayer() <= 25);

public static bool MobsTime => AllHostileTargets.Count(o => o.DistanceToPlayer() <= JobRange && o.CanSee())
>= Service.Config.AutoDefenseNumber;

public static bool AreHostilesCastingKnockback => AllHostileTargets.Any(IsHostileCastingKnockback);

public static float JobRange
{
get
{
float radius = 25;
if (!Player.Available) return radius;

switch (DataCenter.Role)
{
case JobRole.Tank:
case JobRole.Melee:
radius = 3;
break;
}

return radius;
}
}
Expand All @@ -428,7 +431,7 @@ public static float AverageTimeToKill
get
{
var validTimes = AllHostileTargets.Select(b => b.GetTimeToKill()).Where(v => !float.IsNaN(v)).ToList();
return validTimes.Any() ? validTimes.Average() : 0;
return validTimes.Any() ? validTimes.Average() : 0;
}
}

Expand All @@ -444,19 +447,28 @@ public static bool HasPet
{
var mayPet = AllTargets.OfType<IBattleNpc>().Where(npc => npc.OwnerId == Player.Object.GameObjectId);
var hasPet = mayPet.Any(npc => npc.BattleNpcKind == BattleNpcSubKind.Pet);
if (hasPet)
if (hasPet ||
Svc.Condition[ConditionFlag.Mounted] ||
Svc.Condition[ConditionFlag.Mounted2] ||
Svc.Condition[ConditionFlag.BetweenAreas] ||
Svc.Condition[ConditionFlag.BetweenAreas51] ||
Svc.Condition[ConditionFlag.BeingMoved] ||
Svc.Condition[ConditionFlag.WatchingCutscene] ||
Svc.Condition[ConditionFlag.OccupiedInEvent] ||
Svc.Condition[ConditionFlag.Occupied33] ||
Svc.Condition[ConditionFlag.OccupiedInCutSceneEvent] ||
Svc.Condition[ConditionFlag.Jumping61])
{
_petLastSeen = DateTime.Now;
return true;
}
else if (!hasPet && _petLastSeen.AddSeconds(3) < DateTime.Now)

if (!hasPet && _petLastSeen.AddSeconds(3) < DateTime.Now)
{
return false;
}
else
{
return true;
}

return true;
}
}

Expand All @@ -468,8 +480,9 @@ public static bool HasPet

public static Dictionary<ulong, float> RefinedHP => PartyMembers
.ToDictionary(p => p.GameObjectId, GetPartyMemberHPRatio);

private static Dictionary<ulong, uint> _lastHp = [];

private static float GetPartyMemberHPRatio(IBattleChara member)
{
if (member == null) return 0;
Expand All @@ -490,15 +503,20 @@ private static float GetPartyMemberHPRatio(IBattleChara member)
DataCenter.HealHP.Remove(member.GameObjectId);
return (float)member.CurrentHp / member.MaxHp;
}

return Math.Min(1, (hp + rightHp) / (float)member.MaxHp);
}

return (float)member.CurrentHp / member.MaxHp;
}

public static IEnumerable<float> PartyMembersHP => RefinedHP.Values.Where(r => r > 0);
public static float PartyMembersMinHP => PartyMembersHP.Any() ? PartyMembersHP.Min() : 0;
public static float PartyMembersAverHP => PartyMembersHP.Any() ? PartyMembersHP.Average() : 0;
public static float PartyMembersDifferHP => PartyMembersHP.Any() ? (float)Math.Sqrt(PartyMembersHP.Average(d => Math.Pow(d - PartyMembersAverHP, 2))) : 0;

public static float PartyMembersDifferHP => PartyMembersHP.Any()
? (float)Math.Sqrt(PartyMembersHP.Average(d => Math.Pow(d - PartyMembersAverHP, 2)))
: 0;

public static bool HPNotFull => PartyMembersMinHP < 1;

Expand Down Expand Up @@ -605,8 +623,8 @@ internal static void AddDamageRec(float damageRatio)
#endregion

internal static SortedList<string, string> AuthorHashes { get; set; } = [];
private static bool IsCastingTankVfx()

private static bool IsCastingTankVfx()
{
return IsCastingVfx(s =>
{
Expand All @@ -617,6 +635,7 @@ private static bool IsCastingTankVfx()
return true;
});
}

private static bool IsCastingAreaVfx()
{
return IsCastingVfx(s => s.Path.StartsWith("vfx/lockon/eff/coshare"));
Expand All @@ -637,7 +656,6 @@ private static bool IsCastingVfx(Func<VfxNewData, bool> isVfx)
}
catch
{

}

return false;
Expand All @@ -648,24 +666,19 @@ private static bool IsHostileCastingTank(IBattleChara h)
return IsHostileCastingBase(h, (act) =>
{
return OtherConfiguration.HostileCastingTank.Contains(act.RowId)
|| h.CastTargetObjectId == h.TargetObjectId;
|| h.CastTargetObjectId == h.TargetObjectId;
});
}

private static bool IsHostileCastingArea(IBattleChara h)
{
return IsHostileCastingBase(h, (act) =>
{
return OtherConfiguration.HostileCastingArea.Contains(act.RowId);
});
return IsHostileCastingBase(h, (act) => { return OtherConfiguration.HostileCastingArea.Contains(act.RowId); });
}

public static bool IsHostileCastingKnockback(IBattleChara h)
{
return IsHostileCastingBase(h, (act) =>
{
return OtherConfiguration.HostileCastingKnockback.Contains(act.RowId);
});
return IsHostileCastingBase(h,
(act) => { return OtherConfiguration.HostileCastingKnockback.Contains(act.RowId); });
}

private static bool IsHostileCastingBase(IBattleChara h, Func<Action, bool> check)
Expand All @@ -677,11 +690,10 @@ private static bool IsHostileCastingBase(IBattleChara h, Func<Action, bool> chec
var t = last - DataCenter.DefaultGCDTotal;

if (!(h.TotalCastTime > 2.5 &&
t > 0 && t < DataCenter.GCDTime(2))) return false;
t > 0 && t < DataCenter.GCDTime(2))) return false;

var action = Service.GetSheet<Action>().GetRow(h.CastActionId);
if (action == null) return false;
return check?.Invoke(action) ?? false;
}

}
}

0 comments on commit 348eed7

Please sign in to comment.