diff --git a/Dalamud/Fools/FoolsManager.cs b/Dalamud/Fools/FoolsManager.cs index 73c3e0694..b8660876d 100644 --- a/Dalamud/Fools/FoolsManager.cs +++ b/Dalamud/Fools/FoolsManager.cs @@ -33,6 +33,7 @@ internal class FoolsManager : IDisposable, IServiceType new("Test Fool Plugin", "TestFoolPlugin", "this is a test", "NotNite", typeof(TestFoolPlugin)), new("Pixel Imperfect", "PixelImperfectPlugin", "Whoops... we messed up the math on that one.", "Halpo", typeof(PixelImperfectPlugin)), + new("DailyLifeDuty", "DailyLifeDutyPlugin", "Easily Track Daily and Weekly tasks... in real life", "MidoriKami", typeof(DailyLifeDutyPlugin)), }; } diff --git a/Dalamud/Fools/Helper/Chat.cs b/Dalamud/Fools/Helper/Chat.cs new file mode 100644 index 000000000..54e0803c6 --- /dev/null +++ b/Dalamud/Fools/Helper/Chat.cs @@ -0,0 +1,32 @@ +using Dalamud.Game.Gui; +using Dalamud.Game.Text.SeStringHandling; +using Dalamud.Game.Text.SeStringHandling.Payloads; + +namespace Dalamud.Fools.Helper; + +// Copied from KamiLib's Chat +// https://github.com/MidoriKami/KamiLib/blob/master/ChatCommands/Chat.cs +internal static class Chat +{ + public static void Print(string pluginName, string tag, string message) => Service.Get().Print(GetBaseString(pluginName, tag, message).BuiltString); + + private static SeStringBuilder GetBaseString(string pluginName, string tag, string message, DalamudLinkPayload? payload = null) + { + if (payload is null) + { + return new SeStringBuilder() + .AddUiForeground($"[{pluginName}] ", 45) + .AddUiForeground($"[{tag}] ", 62) + .AddText(message); + } + else + { + return new SeStringBuilder() + .AddUiForeground($"[{pluginName}] ", 45) + .AddUiForeground($"[{tag}] ", 62) + .Add(payload) + .AddUiForeground(message, 35) + .Add(RawPayload.LinkTerminator); + } + } +} diff --git a/Dalamud/Fools/Plugins/DailyLifeDutyPlugin.cs b/Dalamud/Fools/Plugins/DailyLifeDutyPlugin.cs new file mode 100644 index 000000000..35ea47a99 --- /dev/null +++ b/Dalamud/Fools/Plugins/DailyLifeDutyPlugin.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +using Dalamud.Fools.Helper; +using Dalamud.Game; + +namespace Dalamud.Fools.Plugins; + +public class DailyLifeDutyPlugin : IFoolsPlugin +{ + private const string PluginName = "DailyLifeDuty"; + + private static readonly List Duties = new[] + { + new Duty("Dishes", i => $"{i} dishes to be cleaned"), + new Duty("Taxes", _ => "Taxes need to be filed"), + new Duty("Pets", i => $"{i} dogs waiting to be pet"), + new Duty("Garbage", i => $"{i} garbage bags to be put out"), + }.ToList(); + + private long lastMessage; + + public DailyLifeDutyPlugin() + { + Service.Get().Update += this.OnUpdate; + this.EmitDutyReminder(); + } + + public void Dispose() + { + Service.Get().Update -= this.OnUpdate; + } + + private void OnUpdate(Framework framework) + { + if (DateTimeOffset.UtcNow.ToUnixTimeSeconds() - this.lastMessage > 60 * 5) + { + this.EmitDutyReminder(); + } + } + + private void EmitDutyReminder() + { + var duty = Duties[Random.Shared.Next(Duties.Count)]; + Chat.Print(PluginName, duty.Tag, duty.Message(Random.Shared.Next(20))); + this.lastMessage = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); + } + + private class Duty + { + public Duty(string tag, Func message) + { + this.Tag = tag; + this.Message = message; + } + + internal string Tag { get; init; } + + internal Func Message { get; init; } + } +}