namespace Aeshnidae.ResonanceAuras;
///
/// Resonance auras: a second aura track beside the luminance ones, bought with
/// Resonance instead of luminance. Each rank adds a small fixed amount to a number
/// ACE already uses in a formula - never new mechanics. Per character, paid from the
/// account bank, and kept in a table of their own so enlightenment cannot reset
/// them (see AuraDb). What each rank does is in Auras; where it takes effect is in
/// Patches.
///
public class Mod : IHarmonyMod
{
public static readonly string Name = typeof(Mod).Assembly.GetName().Name!;
public static readonly string HarmonyId = $"mod.{Name.ToLowerInvariant()}";
public static readonly string ModPath = Path.Combine(ModManager.ModPath, Name);
public static ModContainer? Container => ModManager.GetModContainerByPath(ModPath);
/// Live settings, re-read every time the mod is enabled.
public static Settings Settings { get; private set; } = new();
private static Harmony? _harmony;
private bool _disposed;
public void Initialize()
{
Settings = Settings.Load(ModPath);
AuraDb.Initialize();
// Players already in the world when the mod is enabled (a hot reload) missed
// the login hook; give them their ranks now.
foreach (var player in PlayerManager.GetAllOnline())
{
try
{
Auras.LoadInto(player);
Auras.TellClientOnLogin(player);
}
catch (Exception ex)
{
ModManager.Log($"[{Name}] could not load auras for {player.Name}: {ex.Message}", ModManager.LogLevel.Warn);
}
}
_harmony = new Harmony(HarmonyId);
// Explicit assembly: the parameterless overload walks the stack, and an
// inlined Initialize() makes it resolve to ACE.Server and patch nothing.
_harmony.PatchAllUncategorized(typeof(Mod).Assembly);
var forSale = Settings.Auras.Count(a => a.MaxRanks > 0 && Aura.ByKey(a.Key) is not null);
ModManager.Log($"[{Name}] ready - {forSale} auras for sale, rank n costs {Settings.RankPriceBase:N0} x n Resonance" +
$"{(AuraDb.Ready ? "" : " (storage unavailable, auras disabled)")}");
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (_disposed)
return;
if (disposing)
{
_harmony?.UnpatchAll(HarmonyId);
_harmony = null;
ModManager.Log($"[{Name}] shut down");
}
_disposed = true;
}
}