2 using System.Collections.Generic;
9 namespace Loot.Api.Loaders
17 internal static IDictionary<string, Mod> Mods;
18 public static int ModCount => Mods.Count;
22 Mods =
new Dictionary<string, Mod>();
25 internal static void Load()
27 Mods.Add(
Loot.Instance.Name,
Loot.Instance);
30 internal static void Unload()
36 internal static void CheckModLoading(
Mod mod,
string source,
bool invert =
false)
40 throw new NullReferenceException($
"Mod is null in {source}");
43 if (mod.GetType().GetField(
"loading", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(mod) is
bool b)
47 throw new Exception($
"{source} can only be called from Mod.Load or Mod.Autoload");
52 throw new Exception($
"{source} can only be called if mod {mod.Name} is already loaded");
57 internal static bool CheckModRegistered(
Mod mod,
string source,
bool @throw =
true)
59 bool modIsPresent = Mods.ContainsKey(mod.Name);
60 if (modIsPresent &&
@throw)
62 throw new Exception($
"Mod {mod.Name} is already registered in {source}");
73 CheckModLoading(mod,
"RegisterMod");
74 CheckModRegistered(mod,
"RegisterMod");
76 Mods.Add(
new KeyValuePair<string, Mod>(mod.Name, mod));
80 internal static void ProcessMods()
82 foreach (var kvp
in Mods)
84 AddContent(kvp.Value);
93 internal static void AddContent(
Mod mod)
95 CheckModLoading(mod,
"SetupContent", invert:
true);
97 var ordered = Mods.FirstOrDefault(x => x.Key.Equals(mod.Name))
101 .OrderBy(x => x.FullName, StringComparer.InvariantCulture)
102 .Where(t => t.IsClass && !t.IsAbstract && t.GetCustomAttribute<DoNotLoadAttribute>() == null)
105 var rarities = ordered.Where(x => x.IsSubclassOf(typeof(
ModifierRarity)));
106 var modifiers = ordered.Where(x => x.IsSubclassOf(typeof(
Modifier)));
107 var pools = ordered.Where(x => x.IsSubclassOf(typeof(
ModifierPool)));
108 var effects = ordered.Where(x => x.IsSubclassOf(typeof(
ModifierEffect)));
114 foreach (Type type
in rarities)
119 foreach (Type type
in modifiers)
124 foreach (Type type
in pools)
129 foreach (Type type
in effects)
Defines a modifier, which is an unloaded GlobalItem Making it a GlobalItem gives easy access to all h...
static ModifierContent Modifier
A ModifierEffect signifies the effect of a modifier on a player It should house the implementation...
static ModifierPoolContent ModifierPool
Defines the rarity of a modifier
static ModifierRarityContent ModifierRarity
Defines a modifier pool. A modifier pool holds a certain amount of effects in an array It allows to r...
static ModifierEffectContent ModifierEffect
static void RegisterMod(Mod mod)
Registers specified mod, enabling autoloading for that mod
This class holds all Content holders of this mod You can use this to access content loaded into the m...
This class is responsible for loading mods into Even More Modifiers Mods can be registered and trigge...