Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
ModSupportTunneler.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using Loot.Ext;
5 using Terraria.ModLoader;
6 
7 namespace Loot.ModSupport
8 {
13  internal static class ModSupportTunneler
14  {
15  private static List<ModSupport> _modSupporters;
16 
17  public static T GetModSupport<T>() where T : ModSupport
18  {
19  return (T)_modSupporters?.FirstOrDefault(s => s.GetType() == typeof(T) || s.GetType().IsAssignableFrom(typeof(T)));
20  }
21 
22  public static void Init()
23  {
24  foreach (var modSupporter in GetSupporters())
25  {
26  Mod supportingMod = modSupporter.GetSupportingMod();
27  modSupporter.ModIsLoaded = supportingMod != null && modSupporter.CheckValidity(supportingMod);
28  }
29  }
30 
31  public static void AddServerSupport()
32  {
33  foreach (var modSupporter in GetSupporters())
34  {
35  Mod supportingMod = modSupporter.GetSupportingMod();
36  if (modSupporter.ModIsLoaded)
37  {
38  modSupporter.AddServerSupport(supportingMod);
39  }
40  }
41  }
42 
43  public static void AddClientSupport()
44  {
45  foreach (var modSupporter in GetSupporters())
46  {
47  Mod supportingMod = modSupporter.GetSupportingMod();
48  if (modSupporter.ModIsLoaded)
49  {
50  modSupporter.AddClientSupport(supportingMod);
51  }
52  }
53  }
54 
55  private static IEnumerable<ModSupport> GetSupporters()
56  {
57  return _modSupporters ??
58  (_modSupporters =
59  ReflectUtils.GetLootNonAbstractClasses(t => t.IsSubclassOf(typeof(ModSupport)))
60  .Select(t => (ModSupport)Activator.CreateInstance(t))
61  .ToList());
62  }
63  }
64 }