Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: add a api for DPSTaken.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Apr 15, 2023
1 parent 613456b commit 3d1f2cc
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
1 change: 0 additions & 1 deletion RotationSolver.Basic/Actions/BaseAction_Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ private bool TargetHostile(float range, bool mustUse, int aoeCount, out BattleCh
return false;
}

//判断一下AOE攻击的时候如果有攻击目标标记目标
if (_action.CastType > 1 && NoAOE)
{
target = null;
Expand Down
1 change: 1 addition & 0 deletions RotationSolver.Basic/Data/ActionEffectSet.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FFXIVClientStructs.FFXIV.Client.Game;
using System.Collections;
using Action = Lumina.Excel.GeneratedSheets.Action;

namespace RotationSolver.Basic.Data;
Expand Down
2 changes: 2 additions & 0 deletions RotationSolver.Basic/Data/ActionRec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
using Action = Lumina.Excel.GeneratedSheets.Action;

public record ActionRec(DateTime UsedTime, Action Action);

public record DamageRec(DateTime ReceiveTime, float Ratio);
26 changes: 26 additions & 0 deletions RotationSolver.Basic/DataCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,23 @@ public static float RatioOfMembersIn2minsBurst
#region Action Record
const int QUEUECAPACITY = 32;
private static Queue<ActionRec> _actions = new Queue<ActionRec>(QUEUECAPACITY);
private static Queue<DamageRec> _damages = new Queue<DamageRec>(QUEUECAPACITY);

public static float DPSTaken
{
get
{
var recs = _damages.Where(r => DateTime.Now - r.ReceiveTime < TimeSpan.FromMilliseconds(5));

if(!recs.Any()) return 0;

var damages = recs.Sum(r => r.Ratio);

var time = recs.Last().ReceiveTime - recs.First().ReceiveTime + TimeSpan.FromMilliseconds(2.5f);

return damages / (float)time.TotalSeconds;
}
}

public static ActionRec[] RecordActions => _actions.Reverse().ToArray();
private static DateTime _timeLastActionUsed = DateTime.Now;
Expand Down Expand Up @@ -292,5 +309,14 @@ public static void AddActionRec(Action act)
_timeLastActionUsed = DateTime.Now;
_actions.Enqueue(new ActionRec(_timeLastActionUsed, act));
}

public static void AddDamageRec(float damageRatio)
{
if (_damages.Count >= QUEUECAPACITY)
{
_damages.Dequeue();
}
_damages.Enqueue(new DamageRec(DateTime.Now, damageRatio));
}
#endregion
}
1 change: 1 addition & 0 deletions RotationSolver/UI/RotationConfigWindow_Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private unsafe void DrawStatus()
ImGui.Text("Fate: " + DataCenter.FateId.ToString());
}
ImGui.Text("TerritoryType: " + DataCenter.TerritoryContentType.ToString());
ImGui.Text("DPSTaken: " + DataCenter.DPSTaken.ToString());

ImGui.Text("Have pet: " + DataCenter.HasPet.ToString());
ImGui.Text("Hostile Near Count: " + DataCenter.NumberOfHostilesInRange.ToString());
Expand Down
14 changes: 13 additions & 1 deletion RotationSolver/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,26 @@ private static unsafe void ReceiveAbilityEffect(uint sourceId, IntPtr sourceChar

private static void ActionFromEnemy(uint sourceId, ActionEffectSet set)
{
//Check Source.
var source = Service.ObjectTable.SearchById(sourceId);
if (source == null) return;
if (source is not BattleChara battle) return;
if (battle is PlayerCharacter) return;
if (battle.SubKind == 9) return; //Friend!
if (Service.ObjectTable.SearchById(battle.ObjectId) is PlayerCharacter) return;

ShowStrEnemy = set.ToString();
var damageRatio = set.TargetEffects
.Where(e => e.Target == Service.Player)
.SelectMany(e => new ActionEffect[]
{
e[0], e[1], e[2], e[3], e[4], e[5], e[6], e[7]
})
.Where(e => e.Type == ActionEffectType.Damage)
.Sum(e => (float)e.Value / Service.Player.MaxHp);

DataCenter.AddDamageRec(damageRatio);

ShowStrEnemy = $"Damage Ratio: {damageRatio}\n{set}";
}

private static void ActionFromSelf(uint sourceId, ActionEffectSet set)
Expand Down

0 comments on commit 3d1f2cc

Please sign in to comment.