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 counter for using actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 20, 2023
1 parent c69e3f1 commit 67f6741
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 20 deletions.
10 changes: 9 additions & 1 deletion Resources/HostileCastingArea.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,5 +375,13 @@
32114,
31727,
33018,
7946
7946,
33080,
33087,
33250,
33274,
33275,
33497,
33490,
33494
]
3 changes: 3 additions & 0 deletions Resources/RotationSolverRecord.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ClickingCount": 1
}
32 changes: 28 additions & 4 deletions RotationSolver.Basic/Configuration/OtherConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class OtherConfiguration

public static HashSet<uint> InvincibleStatus = new();

public static RotationSolverRecord RotationSolverRecord = new ();

public static void Init()
{
if (!Directory.Exists(Svc.PluginInterface.ConfigDirectory.FullName))
Expand All @@ -39,6 +41,8 @@ public static void Init()
Task.Run(() => InitOne(ref HostileCastingTank, nameof(HostileCastingTank)));

Task.Run(() => InitOne(ref BeneficialPositions, nameof(BeneficialPositions)));

Task.Run(() => InitOne(ref RotationSolverRecord, nameof(RotationSolverRecord), false));
}

public static void Save()
Expand All @@ -50,6 +54,12 @@ public static void Save()
SaveHostileCastingArea();
SaveHostileCastingTank();
SaveBeneficialPositions();
SaveRotationSolverRecord();
}

public static void SaveRotationSolverRecord()
{
Task.Run(() => Save(RotationSolverRecord, nameof(RotationSolverRecord)));
}

public static void SaveBeneficialPositions()
Expand Down Expand Up @@ -104,10 +114,13 @@ private static void Save<T>(T value, string name)
private static void SavePath<T>(T value, string path)
{
File.WriteAllTextAsync(path,
JsonConvert.SerializeObject(value, Formatting.Indented));
JsonConvert.SerializeObject(value, Formatting.Indented, new JsonSerializerSettings()
{
TypeNameHandling = TypeNameHandling.None,
}));
}

private static void InitOne<T>(ref T value, string name)
private static void InitOne<T>(ref T value, string name, bool download = true)
{
var path = GetFilePath(name);
if (File.Exists(path))
Expand All @@ -121,21 +134,32 @@ private static void InitOne<T>(ref T value, string name)
PluginLog.Warning(ex, $"Failed to load {name}.");
}
}
else
else if(download)
{
try
{
var client = new HttpClient();
var str = client.GetStringAsync($"https://raw.githubusercontent.com/ArchiDog1998/RotationSolver/main/Resources/{name}.json").Result;

File.WriteAllText(path, str);
value = JsonConvert.DeserializeObject<T>(str);
value = JsonConvert.DeserializeObject<T>(str, new JsonSerializerSettings()
{
MissingMemberHandling = MissingMemberHandling.Error,
Error = delegate (object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
{
args.ErrorContext.Handled = true;
}
});
}
catch
{
SavePath(value, path);
}
}
else
{
SavePath(value, path);
}
}
}
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
12 changes: 12 additions & 0 deletions RotationSolver.Basic/Configuration/RotationSolverRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace RotationSolver.Basic.Configuration;

/// <summary>
/// Record something about your using of Rotation Solver.
/// </summary>
public class RotationSolverRecord
{
/// <summary>
/// How many times have rs clicked for you
/// </summary>
public ulong ClickingCount { get; set; } = 0;
}
31 changes: 17 additions & 14 deletions RotationSolver/Commands/RSCommands_Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Dalamud.Logging;
using ECommons.DalamudServices;
using ECommons.GameHelpers;
using RotationSolver.Basic.Configuration;
using RotationSolver.Localization;
using RotationSolver.UI;
using RotationSolver.Updaters;
Expand All @@ -26,7 +27,7 @@ internal static unsafe bool CanDoAnAction(bool isGCD)

//Do not click the button in random time.
if (DateTime.Now - _lastClickTime < TimeSpan.FromMilliseconds(new Random().Next(
(int)(Service.Config.GetValue(Basic.Configuration.PluginConfigFloat.ClickingDelayMin) * 1000), (int)(Service.Config.GetValue(Basic.Configuration.PluginConfigFloat.ClickingDelayMax) * 1000)))) return false;
(int)(Service.Config.GetValue(PluginConfigFloat.ClickingDelayMin) * 1000), (int)(Service.Config.GetValue(PluginConfigFloat.ClickingDelayMax) * 1000)))) return false;
_lastClickTime = DateTime.Now;

if (!isGCD && ActionUpdater.NextAction is IBaseAction act1 && act1.IsRealGCD) return false;
Expand All @@ -37,7 +38,7 @@ internal static unsafe bool CanDoAnAction(bool isGCD)
internal static uint _lastActionID;
public static void DoAction()
{
var wrong = new Random().NextDouble() < Service.Config.GetValue(Basic.Configuration.PluginConfigFloat.MistakeRatio) && ActionUpdater.WrongAction != null;
var wrong = new Random().NextDouble() < Service.Config.GetValue(PluginConfigFloat.MistakeRatio) && ActionUpdater.WrongAction != null;
var nextAction = wrong ? ActionUpdater.WrongAction : ActionUpdater.NextAction;
if (nextAction == null) return;

Expand All @@ -53,27 +54,29 @@ public static void DoAction()
// Svc.Chat.Print($"Will Do {acti}");
#endif

if (Service.Config.GetValue(Basic.Configuration.PluginConfigBool.KeyBoardNoise))
if (Service.Config.GetValue(PluginConfigBool.KeyBoardNoise))
{
PreviewUpdater.PulseActionBar(nextAction.AdjustedID);
}

if (nextAction.Use())
{
OtherConfiguration.RotationSolverRecord.ClickingCount++;

_lastActionID = nextAction.AdjustedID;
_lastUsedTime = DateTime.Now;

if (nextAction is BaseAction act)
{
if (Service.Config.GetValue(Basic.Configuration.PluginConfigBool.KeyBoardNoise))
if (Service.Config.GetValue(PluginConfigBool.KeyBoardNoise))
Task.Run(() => PulseSimulation(nextAction.AdjustedID));

if (act.ShouldEndSpecial) ResetSpecial();
#if DEBUG
//Svc.Chat.Print($"{act}, {act.Target.Name}, {ActionUpdater.AbilityRemainCount}, {ActionUpdater.WeaponElapsed}");
#endif
//Change Target
if (act.Target != null && (Service.Config.GetValue(Basic.Configuration.PluginConfigBool.SwitchTargetFriendly) && !DataCenter.IsManual || ((Svc.Targets.Target?.IsNPCEnemy() ?? true)
if (act.Target != null && (Service.Config.GetValue(PluginConfigBool.SwitchTargetFriendly) && !DataCenter.IsManual || ((Svc.Targets.Target?.IsNPCEnemy() ?? true)
|| Svc.Targets.Target?.GetObjectKind() == Dalamud.Game.ClientState.Objects.Enums.ObjectKind.Treasure)
&& act.Target.IsNPCEnemy()))
{
Expand All @@ -90,12 +93,12 @@ static async void PulseSimulation(uint id)
started = true;
try
{
for (int i = 0; i < new Random().Next(Service.Config.GetValue(Basic.Configuration.PluginConfigInt.KeyBoardNoiseMin),
Service.Config.GetValue(Basic.Configuration.PluginConfigInt.KeyBoardNoiseMax)); i++)
for (int i = 0; i < new Random().Next(Service.Config.GetValue(PluginConfigInt.KeyBoardNoiseMin),
Service.Config.GetValue(PluginConfigInt.KeyBoardNoiseMax)); i++)
{
PreviewUpdater.PulseActionBar(id);
var time = Service.Config.GetValue(Basic.Configuration.PluginConfigFloat.ClickingDelayMin) +
new Random().NextDouble() * (Service.Config.GetValue(Basic.Configuration.PluginConfigFloat.ClickingDelayMax) - Service.Config.GetValue(Basic.Configuration.PluginConfigFloat.ClickingDelayMin));
var time = Service.Config.GetValue(PluginConfigFloat.ClickingDelayMin) +
new Random().NextDouble() * (Service.Config.GetValue(PluginConfigFloat.ClickingDelayMax) - Service.Config.GetValue(PluginConfigFloat.ClickingDelayMin));
await Task.Delay((int)(time * 1000));
}
}
Expand Down Expand Up @@ -131,18 +134,18 @@ internal static void UpdateRotationState()
{
CancelState();
}
else if (Service.Config.GetValue(Basic.Configuration.PluginConfigBool.AutoOffWhenDead)
else if (Service.Config.GetValue(PluginConfigBool.AutoOffWhenDead)
&& Player.Available
&& Player.Object.CurrentHp == 0)
{
CancelState();
}
else if (Service.Config.GetValue(Basic.Configuration.PluginConfigBool.AutoOffCutScene)
else if (Service.Config.GetValue(PluginConfigBool.AutoOffCutScene)
&& Svc.Condition[ConditionFlag.OccupiedInCutSceneEvent])
{
CancelState();
}
else if (Service.Config.GetValue(Basic.Configuration.PluginConfigBool.AutoOffBetweenArea)
else if (Service.Config.GetValue(PluginConfigBool.AutoOffBetweenArea)
&& (
Svc.Condition[ConditionFlag.BetweenAreas]
|| Svc.Condition[ConditionFlag.BetweenAreas51]))
Expand All @@ -156,7 +159,7 @@ internal static void UpdateRotationState()
CancelState();
}
//Auto manual on being attacked by someone.
else if (Service.Config.GetValue(Basic.Configuration.PluginConfigBool.StartOnAttackedBySomeone)
else if (Service.Config.GetValue(PluginConfigBool.StartOnAttackedBySomeone)
&& target != null
&& !target.IsDummy())
{
Expand All @@ -166,7 +169,7 @@ internal static void UpdateRotationState()
}
}
//Auto start at count Down.
else if (Service.Config.GetValue(Basic.Configuration.PluginConfigBool.StartOnCountdown)
else if (Service.Config.GetValue(PluginConfigBool.StartOnCountdown)
&& Service.CountDownTime > 0)
{
_lastCountdownTime = Service.CountDownTime;
Expand Down
4 changes: 3 additions & 1 deletion RotationSolver/Localization/Localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -496,5 +496,7 @@
"ConfigWindow_Basic_IdealClickingTime": "The ideal click time.",
"ConfigWindow_Basic_RealClickingTime": "The real click time.",
"ConfigWindow_Basic_ClickingDuration": "The clicking duration, RS will try to click at this duration.",
"ConfigWindow_Basic_WeaponDelay": "This is the clipping time.\nGCD is over. However, RS forgets to click the next action."
"ConfigWindow_Basic_WeaponDelay": "This is the clipping time.\nGCD is over. However, RS forgets to click the next action.",
"ConfigWindow_About_ClickingCount": "Rotation Solver helped you by clicking actions {0:N0} times.",
"ConfigWindow_About_ClickingTooMuch": "Well, you must be a lazy player!"
}
2 changes: 2 additions & 0 deletions RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -715,4 +715,6 @@ internal partial class Strings
public string ConfigWindow_Basic_RealClickingTime { get; set; } = "The real click time.";
public string ConfigWindow_Basic_ClickingDuration { get; set; } = "The clicking duration, RS will try to click at this duration.";
public string ConfigWindow_Basic_WeaponDelay { get; set; } = "This is the clipping time.\nGCD is over. However, RS forgets to click the next action.";
public string ConfigWindow_About_ClickingCount { get; set; } = "Rotation Solver helped you by clicking actions {0:N0} times.";
public string ConfigWindow_About_ClickingTooMuch { get; set; } = "Well, you must be a lazy player!";
}
23 changes: 23 additions & 0 deletions RotationSolver/UI/RotationConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,29 @@ private static void DrawAbout()
Util.OpenLink("https://discord.gg/4fECHunam9");
}

var clickingCount = OtherConfiguration.RotationSolverRecord.ClickingCount;
if (clickingCount > 0)
{
ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(0.2f, 0.6f, 0.95f, 1));
var countStr = string.Format(LocalizationManager.RightLang.ConfigWindow_About_ClickingCount,
clickingCount);
ImGuiHelper.DrawItemMiddle(() =>
{
ImGui.TextWrapped(countStr);
}, width, ImGui.CalcTextSize(countStr).X);

if (clickingCount >= 100_000)
{
countStr = LocalizationManager.RightLang.ConfigWindow_About_ClickingTooMuch;
ImGuiHelper.DrawItemMiddle(() =>
{
ImGui.TextWrapped(countStr);
}, width, ImGui.CalcTextSize(countStr).X);
}
ImGui.PopStyleColor();
}


_aboutHeaders.Draw();
}

Expand Down

0 comments on commit 67f6741

Please sign in to comment.