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

Commit

Permalink
fix: Allow automated say hello to author to execute multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Apr 4, 2023
1 parent 64838d0 commit 772600a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal partial class Strings
public string Commands_InsertAction { get; set; } = "Will use it within {0}s";

public string Commands_InsertActionFailure { get; set; } = "Can not find the action, please check the action name.";
public string Commands_SayHelloToAuthor { get; set; } = "This \"{0}\" is probably one of the authors of the \"Rotation Solver\", so say hello to him!";
public string Commands_SayHelloToAuthor { get; set; } = "({0}) is probably one of the authors of the \"Rotation Solver\", so say hello to him!";

#endregion

Expand Down
7 changes: 5 additions & 2 deletions RotationSolver/RotationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using RotationSolver.Basic.Rotations;
using System.Diagnostics;
using System.Numerics;
using System.Reflection;

namespace RotationSolver;

Expand Down Expand Up @@ -33,11 +34,13 @@ public static Vector4 GetColor(this ICustomRotation rotation)
=> rotation.IsAllowed(out _) ? ImGuiColors.DalamudWhite : ImGuiColors.DalamudViolet;

public static string GetAuthor(this ICustomRotation rotation)
=> rotation.GetType().Assembly.GetAuthor();

public static string GetAuthor(this Assembly assembly)
{
try
{
var assembly = rotation.GetType().Assembly;
return FileVersionInfo.GetVersionInfo(assembly.Location)?.CompanyName
return FileVersionInfo.GetVersionInfo(assembly.Location)?.CompanyName
?? assembly.GetName().Name
?? "Unknown";
}
Expand Down
11 changes: 6 additions & 5 deletions RotationSolver/Updaters/RotationUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public record CustomRotationGroup(ClassJobID jobId, ClassJobID[] classJobIds, IC

internal static SortedList<JobRole, CustomRotationGroup[]> CustomRotationsDict { get; private set; } = new SortedList<JobRole, CustomRotationGroup[]>();

internal static string[] AuthorHashes { get; private set; } = new string[0];
internal static SortedList<string, string> AuthorHashes { get; private set; } = new SortedList<string, string>();
static CustomRotationGroup[] _customRotations { get; set; } = new CustomRotationGroup[0];

static readonly string[] _locs = new string[] { "RotationSolver.dll", "RotationSolver.Basic.dll" };
Expand All @@ -36,10 +36,11 @@ from l in Directory.GetFiles(dir, "*.dll")

PluginLog.Log("Try to load rotations from these assemblies.", assemblies.Select(a => a.FullName));

AuthorHashes = (from a in assemblies
select a.GetCustomAttribute<AuthorHashAttribute>() into author
where author != null
select author.Hash).ToArray();
AuthorHashes = new SortedList<string, string>(
(from a in assemblies
select (a, a.GetCustomAttribute<AuthorHashAttribute>()) into author
where author.Item2 != null
select author).ToDictionary(i => i.Item2.Hash, i => i.a.GetAuthor() + " - " + i.a.GetName().Name));

_customRotations = (
from a in assemblies
Expand Down
37 changes: 24 additions & 13 deletions RotationSolver/Updaters/SocialUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Game.ClientState.Objects.SubKinds;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using FFXIVClientStructs.FFXIV.Client.UI;
using Lumina.Excel.GeneratedSheets;
using RotationSolver.Basic;
using RotationSolver.Basic.Data;
using RotationSolver.Basic.Helpers;
using RotationSolver.Commands;
using RotationSolver.Localization;
Expand Down Expand Up @@ -95,14 +98,13 @@ internal static void Disable()
Service.ClientState.TerritoryChanged -= ClientState_TerritoryChanged;
}

static RandomDelay socialDelay = new RandomDelay(() => (3, 5));
internal static async void UpdateSocial()
{
if (DataCenter.InCombat || DataCenter.PartyMembers.Count() < 2) return;
if (_canSaying && CanSocial)
if (_canSaying && socialDelay.Delay(CanSocial))
{
_canSaying = false;
await Task.Delay(new Random().Next(3000, 5000));

#if DEBUG
Service.ChatGui.Print("Macro now.");
#endif
Expand All @@ -114,34 +116,43 @@ internal static async void UpdateSocial()

private static async void SayHelloToAuthor()
{
var author = DataCenter.AllianceMembers.OfType<PlayerCharacter>()
.FirstOrDefault(c =>
var authors = DataCenter.AllianceMembers.OfType<PlayerCharacter>()
#if DEBUG
#else
c.ObjectId != Service.ClientState.LocalPlayer.ObjectId &&
.Where(c => c.ObjectId != Service.ClientState.LocalPlayer.ObjectId)
#endif
RotationUpdater.AuthorHashes.Contains(EncryptString(c)));
.Select(c =>
{
if (!RotationUpdater.AuthorHashes.TryGetValue(EncryptString(c), out var nameDesc)) nameDesc = string.Empty;
return (c, nameDesc);
})
.Where(p => !string.IsNullOrEmpty(p.nameDesc));

if (author != null)
foreach (var author in authors)
{
while(!author.IsTargetable() && !DataCenter.InCombat)
while (!author.c.IsTargetable() && !DataCenter.InCombat)
{
await Task.Delay(100);
}

#if DEBUG
Service.ChatGui.Print("Author Time");
#else
Service.TargetManager.SetTarget(author);
Service.TargetManager.SetTarget(author.c);
Service.SubmitToChat($"/{_macroToAuthor[new Random().Next(_macroToAuthor.Count)]} <t>");
#endif
var message = new SeString(new PlayerPayload(author.c.Name.TextValue, author.c.HomeWorld.Id)
, new TextPayload(string.Format(LocalizationManager.RightLang.Commands_SayHelloToAuthor, author.nameDesc)));

Service.ChatGui.PrintChat(new Dalamud.Game.Text.XivChatEntry()
{
Message = string.Format(LocalizationManager.RightLang.Commands_SayHelloToAuthor, author.Name),
Message = message,
Type = Dalamud.Game.Text.XivChatType.Notice,
});
UIModule.PlaySound(20, 0, 0, 0);

await Task.Delay(new Random().Next(800, 1200));
Service.TargetManager.SetTarget(null);
#endif
await Task.Delay(new Random().Next(800, 1200));
}
}

Expand Down

0 comments on commit 772600a

Please sign in to comment.