diff --git a/RotationSolver/Localization/Strings.cs b/RotationSolver/Localization/Strings.cs index f2c78e682..d2547b912 100644 --- a/RotationSolver/Localization/Strings.cs +++ b/RotationSolver/Localization/Strings.cs @@ -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 diff --git a/RotationSolver/RotationHelper.cs b/RotationSolver/RotationHelper.cs index b379529c3..9f77c269f 100644 --- a/RotationSolver/RotationHelper.cs +++ b/RotationSolver/RotationHelper.cs @@ -2,6 +2,7 @@ using RotationSolver.Basic.Rotations; using System.Diagnostics; using System.Numerics; +using System.Reflection; namespace RotationSolver; @@ -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"; } diff --git a/RotationSolver/Updaters/RotationUpdater.cs b/RotationSolver/Updaters/RotationUpdater.cs index e8d8c53a2..56417516d 100644 --- a/RotationSolver/Updaters/RotationUpdater.cs +++ b/RotationSolver/Updaters/RotationUpdater.cs @@ -17,7 +17,7 @@ public record CustomRotationGroup(ClassJobID jobId, ClassJobID[] classJobIds, IC internal static SortedList CustomRotationsDict { get; private set; } = new SortedList(); - internal static string[] AuthorHashes { get; private set; } = new string[0]; + internal static SortedList AuthorHashes { get; private set; } = new SortedList(); static CustomRotationGroup[] _customRotations { get; set; } = new CustomRotationGroup[0]; static readonly string[] _locs = new string[] { "RotationSolver.dll", "RotationSolver.Basic.dll" }; @@ -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() into author - where author != null - select author.Hash).ToArray(); + AuthorHashes = new SortedList( + (from a in assemblies + select (a, a.GetCustomAttribute()) 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 diff --git a/RotationSolver/Updaters/SocialUpdater.cs b/RotationSolver/Updaters/SocialUpdater.cs index cfc1c4932..a8e734fda 100644 --- a/RotationSolver/Updaters/SocialUpdater.cs +++ b/RotationSolver/Updaters/SocialUpdater.cs @@ -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; @@ -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 @@ -114,34 +116,43 @@ internal static async void UpdateSocial() private static async void SayHelloToAuthor() { - var author = DataCenter.AllianceMembers.OfType() - .FirstOrDefault(c => + var authors = DataCenter.AllianceMembers.OfType() #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)]} "); +#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)); } }