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

Commit

Permalink
feat: add a lot of delay.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jan 31, 2023
1 parent e746d62 commit f9dbd57
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 49 deletions.
8 changes: 7 additions & 1 deletion RotationSolver/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class PluginConfiguration : IPluginConfiguration
public float HealthSingleSpell = 0.55f;

public Dictionary<ClassJobID, float> HealthForDyingTanks { get; set; } = new Dictionary<ClassJobID, float>();
public float InterruptibleTime = 0.5f;

public bool InterruptibleMoreCheck = true;
public float SpecialDuration = 3;
public float WeaponInterval = 0.67f;
Expand All @@ -102,12 +102,18 @@ public class PluginConfiguration : IPluginConfiguration
public float DeathDelayMin = 0;
public float DeathDelayMax = 0;

public float WeakenDelayMin = 0;
public float WeakenDelayMax = 0;

public float HostileDelayMin = 0;
public float HostileDelayMax = 0;

public float HealDelayMin = 0;
public float HealDelayMax = 0;

public float InterruptDelayMin = 0.5f;
public float InterruptDelayMax = 1;

public string PositionalErrorText = string.Empty;

public int MoveTargetAngle = 24;
Expand Down
49 changes: 49 additions & 0 deletions RotationSolver/Data/ObjectListDelay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Dalamud.Game.ClientState.Objects.Types;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace RotationSolver.Data;

internal class ObjectListDelay<T> : IEnumerable<T> where T : GameObject
{
IEnumerable<T> _list = new T[0];
Func<(float min, float max)> _getRange;
SortedList<uint, DateTime> _revealTime = new SortedList<uint, DateTime>();
Random _ran = new Random(DateTime.Now.Millisecond);

public ObjectListDelay(Func<(float min, float max)> getRange)
{
_getRange = getRange;
}

public void Delay(IEnumerable<T> originData)
{
var outList= new List<T>(originData.Count());
var revealTime = new SortedList<uint, DateTime>();
var now = DateTime.Now;

foreach (var item in originData)
{
if(!_revealTime.TryGetValue(item.ObjectId, out var time))
{
var range = _getRange();
var delaySecond = range.min + (float)_ran.NextDouble() * (range.max - range.min);
time = now + new TimeSpan(0, 0, 0, 0, (int)(delaySecond * 1000));
}
revealTime.Add(item.ObjectId, time);

if (time > now)
{
outList.Add(item);
}
}

_revealTime = revealTime;
}


public IEnumerator<T> GetEnumerator() => _list.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => _list.GetEnumerator();
}
3 changes: 1 addition & 2 deletions RotationSolver/Helpers/ObjectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ internal static unsafe bool IsTargetable(this GameObject obj)

internal static bool CanInterrupt(this BattleChara b)
{
var baseCheck = b.IsCasting && b.IsCastInterruptible && b.TotalCastTime >= 2
&& b.CurrentCastTime >= Service.Configuration.InterruptibleTime;
var baseCheck = b.IsCasting && b.IsCastInterruptible && b.TotalCastTime >= 2;

if (!baseCheck) return false;
if (!Service.Configuration.InterruptibleMoreCheck) return true;
Expand Down
17 changes: 13 additions & 4 deletions RotationSolver/Localization/Strings_Major.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,23 @@ internal partial class Strings
public string Configwindow_Param_UseOverlayWindow { get; set; } = "Display top overlay";
public string Configwindow_Param_UseOverlayWindowDesc { get; set; } = "This window is currently used to cue the body position in advance.";
public string Configwindow_Param_Basic { get; set; } = "Basic";
public string Configwindow_Param_WeaponDelay { get; set; } = "Set the range of random delay for GCD in second.";
public string Configwindow_Param_DeathDelay { get; set; } = "Set the range of random delay for raising deaths in second.";
public string Configwindow_Param_HostileDelay { get; set; } = "Set the range of random delay for finding hostile targets in second.";

public string Configwindow_Param_WeaponFaster { get; set; } = "Set the time advance of use actions";
public string Configwindow_Param_WeaponInterval { get; set; } = "Set the interval between abilities using";
public string Configwindow_Param_InterruptibleTime { get; set; } = "Set the delay of interrupting";
public string Configwindow_Param_SpecialDuration { get; set; } = "Set the duration of special windows set by commands";
public string Configwindow_Param_AddDotGCDCount { get; set; } = "Set GCD advance of DOT refresh";
public string Configwindow_Param_AutoOffBetweenArea { get; set; } = "Turn off when player is between area.";

public string Configwindow_Param_Delay { get; set; } = "Delay";

public string Configwindow_Param_WeaponDelay { get; set; } = "Set the range of random delay for GCD in second.";
public string Configwindow_Param_DeathDelay { get; set; } = "Set the range of random delay for raising deaths in second.";
public string Configwindow_Param_HostileDelay { get; set; } = "Set the range of random delay for finding hostile targets in second.";
public string Configwindow_Param_InterruptDelay { get; set; } = "Set the range of random delay for interrupting hostile targets in second.";
public string Configwindow_Param_WeakenDelay { get; set; } = "Set the range of random delay for esuna weakens in second.";

public string Configwindow_Param_HealDelay { get; set; } = "Set the range of random delay for healing people in second.";

public string Configwindow_Param_Display { get; set; } = "Display";
public string Configwindow_Param_PoslockCasting { get; set; } = "Lock the movement when casting";
public string Configwindow_Param_PoslockModifier { get; set; } = "Set the modifier key to unlock the movement temporary";
Expand Down Expand Up @@ -151,6 +158,8 @@ internal partial class Strings
public string Configwindow_Param_UseItemDesc { get; set; } = "Use poison, WIP";
public string Configwindow_Param_Conditon { get; set; } = "Condition";
public string Configwindow_Param_StartOnCountdown { get; set; } = "Turn on auto-rotation on countdown";
public string Configwindow_Param_InterruptibleMoreCheck { get; set; } = "Interrupt the action with action type check.";


public string Configwindow_Param_HealOutOfCombat { get; set; } = "Heal party members outside of combat.";

Expand Down
47 changes: 24 additions & 23 deletions RotationSolver/Updaters/TargetUpdater_Friends.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,20 @@ internal static partial class TargetUpdater
internal static IEnumerable<BattleChara> AllianceTanks { get; private set; } = new PlayerCharacter[0];

[EditorBrowsable(EditorBrowsableState.Never)]
internal static IEnumerable<BattleChara> DeathPeopleAll { get; private set; } = new PlayerCharacter[0];
internal static ObjectListDelay<BattleChara> DeathPeopleAll { get; } = new (
()=>(Service.Configuration.DeathDelayMin, Service.Configuration.DeathDelayMax));

[EditorBrowsable(EditorBrowsableState.Never)]
internal static IEnumerable<BattleChara> DeathPeopleParty { get; private set; } = new PlayerCharacter[0];
internal static ObjectListDelay<BattleChara> DeathPeopleParty { get; } = new(
() => (Service.Configuration.DeathDelayMin, Service.Configuration.DeathDelayMax));

[EditorBrowsable(EditorBrowsableState.Never)]
internal static IEnumerable<BattleChara> WeakenPeople { get; private set; } = new PlayerCharacter[0];
internal static ObjectListDelay<BattleChara> WeakenPeople { get; } = new(
() => (Service.Configuration.WeakenDelayMin, Service.Configuration.WeakenDelayMax));

[EditorBrowsable(EditorBrowsableState.Never)]
internal static IEnumerable<BattleChara> DyingPeople { get; private set; } = new PlayerCharacter[0];
internal static ObjectListDelay<BattleChara> DyingPeople { get; } = new(
() => (Service.Configuration.WeakenDelayMin, Service.Configuration.WeakenDelayMax));
/// <summary>
/// 小队成员HP
/// </summary>
Expand Down Expand Up @@ -120,29 +124,28 @@ private unsafe static void UpdateFriends(IEnumerable<BattleChara> allTargets)
PartyHealers = PartyMembers.GetJobCategory(JobRole.Healer);
AllianceTanks = AllianceMembers.GetJobCategory(JobRole.Tank);

DeathPeopleAll = AllianceMembers.GetDeath();
DeathPeopleParty = PartyMembers.GetDeath();
MaintainDeathPeople();
var deathAll = AllianceMembers.GetDeath();
var deathParty = PartyMembers.GetDeath();
MaintainDeathPeople(ref deathAll, ref deathParty);
DeathPeopleAll.Delay(deathAll);
DeathPeopleParty.Delay(deathParty);

WeakenPeople = PartyMembers.Where(p => p.StatusList.Any(status =>
status.GameData.CanDispel && status.RemainingTime > 2));
WeakenPeople.Delay(PartyMembers.Where(p => p.StatusList.Any(status =>
status.GameData.CanDispel && status.RemainingTime > 2)));

DyingPeople = WeakenPeople.Where(p => p.StatusList.Any(StatusHelper.IsDangerous));
DyingPeople.Delay(WeakenPeople.Where(p => p.StatusList.Any(StatusHelper.IsDangerous)));

SayHelloToAuthor();
#endregion

#region Health
PartyMembersHP = PartyMembers.Select(ObjectHelper.GetHealthRatio).Where(r => r > 0);
PartyMembersAverHP = PartyMembersHP.Average();
PartyMembersDifferHP = (float)Math.Sqrt(PartyMembersHP.Average(d => Math.Pow(d - PartyMembersAverHP, 2)));

UpdateCanHeal(Service.ClientState.LocalPlayer);
#endregion
}

private static RandomDelay _healDelay = new RandomDelay(() => (Service.Configuration.HealDelayMin, Service.Configuration.HealDelayMax));

static RandomDelay _healDelay = new RandomDelay(() => (Service.Configuration.HealDelayMin, Service.Configuration.HealDelayMax));

static void UpdateCanHeal(PlayerCharacter player)
{
Expand Down Expand Up @@ -198,33 +201,31 @@ static float GetHealingOfTimeRatio(BattleChara target, params StatusID[] statusI
}

static SortedDictionary<uint, Vector3> _locations = new SortedDictionary<uint, Vector3>();
private static void MaintainDeathPeople()
private static void MaintainDeathPeople(ref IEnumerable<BattleChara> deathAll, ref IEnumerable<BattleChara> deathParty)
{
SortedDictionary<uint, Vector3> locs = new SortedDictionary<uint, Vector3>();
foreach (var item in DeathPeopleAll)
foreach (var item in deathAll)
{
locs[item.ObjectId] = item.Position;
}
foreach (var item in DeathPeopleParty)
foreach (var item in deathParty)
{
locs[item.ObjectId] = item.Position;
}

DeathPeopleAll = FilterForDeath(DeathPeopleAll);
DeathPeopleParty = FilterForDeath(DeathPeopleParty);
deathAll = FilterForDeath(deathAll);
deathParty = FilterForDeath(deathParty);

_locations = locs;
}

private static IEnumerable<BattleChara> FilterForDeath(IEnumerable<BattleChara> battleCharas)
{
return battleCharas.Where(b =>
private static IEnumerable<BattleChara> FilterForDeath(IEnumerable<BattleChara> battleCharas)
=> battleCharas.Where(b =>
{
if (!_locations.TryGetValue(b.ObjectId, out var loc)) return false;

return loc == b.Position;
});
}


/// <summary>
Expand Down
11 changes: 6 additions & 5 deletions RotationSolver/Updaters/TargetUpdater_Hostile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ internal static partial class TargetUpdater
/// <summary>
/// 敌人
/// </summary>
internal static IEnumerable<BattleChara> HostileTargets { get; private set; } = new BattleChara[0];
internal static ObjectListDelay<BattleChara> HostileTargets { get; } = new ObjectListDelay<BattleChara>(
() => (Service.Configuration.HostileDelayMin, Service.Configuration.HostileDelayMax));

internal static IEnumerable<BattleChara> TarOnMeTargets { get; private set; } = new BattleChara[0];

internal static IEnumerable<BattleChara> CanInterruptTargets { get; private set; } = new BattleChara[0];

internal static ObjectListDelay<BattleChara> CanInterruptTargets { get;} = new ObjectListDelay<BattleChara>(
() => (Service.Configuration.InterruptDelayMin, Service.Configuration.InterruptDelayMax));
internal static bool HasHostilesInRange { get; private set; } = false;

internal static bool IsHostileCastingAOE { get; private set; } = false;
Expand Down Expand Up @@ -81,9 +82,9 @@ private unsafe static void UpdateHostileTargets(IEnumerable<BattleChara> allTarg
return b.CanAttack();
});

HostileTargets = GetHostileTargets(allAttackableTargets);
HostileTargets.Delay(GetHostileTargets(allAttackableTargets));

CanInterruptTargets = HostileTargets.Where(ObjectHelper.CanInterrupt);
CanInterruptTargets.Delay(HostileTargets.Where(ObjectHelper.CanInterrupt));

TarOnMeTargets = HostileTargets.Where(tar => tar.TargetObjectId == Service.ClientState.LocalPlayer.ObjectId);

Expand Down
39 changes: 25 additions & 14 deletions RotationSolver/Windows/RotationConfigWindow_Param.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private void DrawParamTab()
if (ImGui.BeginTabBar("Param Items"))
{
DrawParamTabItem(LocalizationManager.RightLang.Configwindow_Param_Basic, DrawParamBasic);
DrawParamTabItem(LocalizationManager.RightLang.Configwindow_Param_Delay, DrawParamDelay);
DrawParamTabItem(LocalizationManager.RightLang.Configwindow_Param_Display, DrawParamDisplay);
DrawParamTabItem(LocalizationManager.RightLang.Configwindow_Param_Action, DrawParamAction);
DrawParamTabItem(LocalizationManager.RightLang.Configwindow_Param_Conditon, DrawParamCondition);
Expand All @@ -56,26 +57,12 @@ private void DrawParamBasic()
ref Service.Configuration.UseOverlayWindow,
LocalizationManager.RightLang.Configwindow_Param_UseOverlayWindowDesc);

DrawRangedFloat(LocalizationManager.RightLang.Configwindow_Param_WeaponDelay,
ref Service.Configuration.WeaponDelayMin, ref Service.Configuration.WeaponDelayMax);

DrawRangedFloat(LocalizationManager.RightLang.Configwindow_Param_DeathDelay,
ref Service.Configuration.DeathDelayMin, ref Service.Configuration.DeathDelayMax);

DrawRangedFloat(LocalizationManager.RightLang.Configwindow_Param_HostileDelay,
ref Service.Configuration.HostileDelayMin, ref Service.Configuration.HostileDelayMax);

DrawFloatNumber(LocalizationManager.RightLang.Configwindow_Param_WeaponFaster,
ref Service.Configuration.WeaponFaster, max: 0.1f);

DrawFloatNumber(LocalizationManager.RightLang.Configwindow_Param_WeaponInterval,
ref Service.Configuration.WeaponInterval, min: 0.5f, max: 0.7f);

DrawFloatNumber(LocalizationManager.RightLang.Configwindow_Param_InterruptibleTime,
ref Service.Configuration.InterruptibleTime, min: 0, max: 2);

// Service.Configuraton.InterruptibleMoreCheck

DrawFloatNumber(LocalizationManager.RightLang.Configwindow_Param_SpecialDuration,
ref Service.Configuration.SpecialDuration, speed: 0.02f, min: 1, max: 20);

Expand All @@ -86,6 +73,27 @@ private void DrawParamBasic()
ref Service.Configuration.AutoOffBetweenArea);
}

private void DrawParamDelay()
{
DrawRangedFloat(LocalizationManager.RightLang.Configwindow_Param_WeaponDelay,
ref Service.Configuration.WeaponDelayMin, ref Service.Configuration.WeaponDelayMax, max: 1);

DrawRangedFloat(LocalizationManager.RightLang.Configwindow_Param_HostileDelay,
ref Service.Configuration.HostileDelayMin, ref Service.Configuration.HostileDelayMax);

DrawRangedFloat(LocalizationManager.RightLang.Configwindow_Param_InterruptDelay,
ref Service.Configuration.InterruptDelayMin, ref Service.Configuration.InterruptDelayMin);

DrawRangedFloat(LocalizationManager.RightLang.Configwindow_Param_DeathDelay,
ref Service.Configuration.DeathDelayMin, ref Service.Configuration.DeathDelayMax);

DrawRangedFloat(LocalizationManager.RightLang.Configwindow_Param_WeakenDelay,
ref Service.Configuration.WeakenDelayMin, ref Service.Configuration.WeakenDelayMax);

DrawRangedFloat(LocalizationManager.RightLang.Configwindow_Param_HealDelay,
ref Service.Configuration.HealDelayMin, ref Service.Configuration.HealDelayMax);
}

private void DrawParamDisplay()
{
var useOverlayWindow = Service.Configuration.UseOverlayWindow;
Expand Down Expand Up @@ -251,6 +259,9 @@ private void DrawParamAction()

private void DrawParamCondition()
{
DrawCheckBox(LocalizationManager.RightLang.Configwindow_Param_InterruptibleMoreCheck,
ref Service.Configuration.InterruptibleMoreCheck);

DrawCheckBox(LocalizationManager.RightLang.Configwindow_Param_StartOnCountdown,
ref Service.Configuration.StartOnCountdown);

Expand Down

0 comments on commit f9dbd57

Please sign in to comment.