Collections - ilikegoodfood/CommunityLib GitHub Wiki

Collections

The base game has a variety of features that could be grouped together, such as natural wonders, magic mastery traits, or magical locii, which are not grouped under intermediate classes. This means that whenever any mod wants to check for any, rather than a specific, version of these things, they would have to get references to all types of these things from the base game and from all other mods, and check against all of them.

The Community Library has a number of Collections, with associated Checker Functions in order to overcome this complexity. Both dependent and non-dependent mods can register things as belonging to one or more of these collections, such as Magic Mastery Traits, and the checker function will check if any base-game or modded items in the collection are present.

Checker Function Summary

Magic Mastery Traits

bool checkHasLocus(Location location)

Magic Locus Properties

bool checkKnowsMagic(Person person)

Natural Wonders

bool checkIsNaturalWonder(Location location)

Vampires

bool checkIsVampire(Unit unit)

This section provides detailed instructions for registering items to these collection for both dependent and non-dependent mods.

Magic Mastery Trait Types

The Magic Mastery Trait Types collection contains Traits that grant holders the ability to perform magic. The base game examples are Blood Mastery, Death Mastery, and Geomancy Mastery, and mods have, at time of writting, aslo introduced Curseweaving Mastery (Covens, Curses, and Curios), and Fleshcrafting (Escamrak).

Function Signiture
void registerMagicType(Type type)

A dependent mod can simply call the function, once for each magic mastery trait type.

Code Example (Dependent)
// Inside if-statement or switch-case of "getModKernel" function for "CommunityLib" namespace
    CommunityLib.ModCore comLib = kernel as CommunityLib.ModCore;

    comLib.registerMagicType(typeof(T_Pyromancy));
    // Each magic mastery trait type must be registered separately
    comLib.registerMagicType(typeof(T_Cryomancy));

A non-dependent mod must use reflection to dynamically aquire a reference to the function that is going to be called before it can call the function.

Code Example (Non-Dependent)
// Inside if-statement or switch-case of "getModKernel" function for "CommunityLib" namespace
    // This line dynamically gets a reference to the function that you are about to call (MethodInfo), based on it's name and parameters.
    MethodInfo MI_registerMagicMasteryTraitType = kernel.GetType().GetMethod("registerMagicType", new Type[] { typeof(Type) });

    // The parameters object array contains the parameters that will be passed into the function.
    object[] parameters = new object[] { typeof(T_Pyromancy) };
    // This line calls the function by its MethodInfo, on the class instance kernel", with the parameters "parameters". 
    MI_registerMagicMasteryTraitType.Invoke(kernel, parameters);
    // Each locus type must be registered seperately.
    parameters = new object[] { typeof(T_Cryomancy) };
    MI_registerMagicMasteryTraitType.Invoke(kernel, parameters);

The function will only fail if the Type you passed in is not a subtype of Trait.

Magical Locus Types

The Magical Locus Types collection contains Properties that are local sources of magical power. The only base game example is the Geomantic Locus, and mods have introduced, at time of writting, the Abyssal Locus (Deep Ones Plus), and the Corrupted Locus (Escamrak).

Function Signiture
void registerLocusType(Type type)

A dependent mod can simply call the function, once for each locus type.

Code Example (Dependent)
// Inside if-statement or switch-case of "getModKernel" function for "CommunityLib" namespace
    CommunityLib.ModCore comLib = kernel as CommunityLib.ModCore;

    comLib.registerLocusType(typeof(Pr_AbstractionLocus));
    // Each locus type must be registered separately
    comLib.registerLocusType(typeof(Pr_AnnihilitationLocus));

A non-dependent mod must use reflection to dynamically aquire a reference to the function that is going to be called before it can call the function.

Code Example (Non-Dependent)
// Inside if-statement or switch-case of "getModKernel" function for "CommunityLib" namespace
    // This line dynamically gets a reference to the function that you are about to call (MethodInfo), based on it's name and parameters.
    MethodInfo MI_registerLocusType = kernel.GetType().GetMethod("registerLocusType", new Type[] { typeof(Type) });

    // The parameters object array contains the parameters that will be passed into the function.
    object[] parameters = new object[] { typeof(Pr_AbstractionLocus) };
    // This line calls the function by its MethodInfo, on the class instance kernel", with the parameters "parameters". 
    MI_registerLocusType.Invoke(kernel, parameters);
    // Each vampire type must be registered seperately.
    parameters = new object[] { typeof(Pr_AnnihiliationLocus) };
    MI_registerLocusType.Invoke(kernel, parameters);

The function will only fail if the Type you passed in is not a subtype of Property.

Natural Wonder Types

The Natural Wonder Types collection contains Settlement or Subsettlemnts that define a natural wonder. The base game examples are Brother of Sleep,, Primal Font, and The Entrance.

Function Signiture
void registerNaturalWonderType(Type type)

A dependent mod can simply call the function, once for each natural wonder type.

Code Example (Dependent)
// Inside if-statement or switch-case of "getModKernel" function for "CommunityLib" namespace
    CommunityLib.ModCore comLib = kernel as CommunityLib.ModCore;

    comLib.registerNaturalWonderType(typeof(Sub_TowerOfBabal));
    // Each magic mastery trait type must be registered separately
    comLib.registerNaturalWonderType(typeof(Set_ThePit));

A non-dependent mod must use reflection to dynamically aquire a reference to the function that is going to be called before it can call the function.

Code Example (Non-Dependent)
// Inside if-statement or switch-case of "getModKernel" function for "CommunityLib" namespace
    // This line dynamically gets a reference to the function that you are about to call (MethodInfo), based on it's name and parameters.
    MethodInfo MI_registerNaturalWonderType = kernel.GetType().GetMethod("registerMagicType", new Type[] { typeof(Type) });

    // The parameters object array contains the parameters that will be passed into the function.
    object[] parameters = new object[] { typeof(Sub_owerOfBabal) };
    // This line calls the function by its MethodInfo, on the class instance kernel", with the parameters "parameters". 
    MI_registerNaturalWonderType.Invoke(kernel, parameters);
    // Each locus type must be registered seperately.
    parameters = new object[] { typeof(Set_ThePit) };
    MI_registerNaturalWonderType.Invoke(kernel, parameters);

The function will only fail if the Type you passed in is not a subtype of Settlement or of Subsettlement.

Vampire Types

The Vampire Types collection contains Units that are Vampires. The only base game example is the Vampire (UAEN_Vampire), and mods have introduced, at time of writting, Vampire Noble (Living Characters).

Function Signiture
void registerVampireType(Type type)

A dependent mod can simply call the function, once for each locus type.

Code Example (Dependent)
// Inside if-statement or switch-case of "getModKernel" function for "CommunityLib" namespace
    CommunityLib.ModCore comLib = kernel as CommunityLib.ModCore;

    comLib.registerVampireType(typeof(UAE_DeathMonarch));
    // Each locus type must be registered separately
    comLib.registerVampireType(typeof(UAEN_VampireThrall));

A non-dependent mod must use reflection to dynamically aquire a reference to the function that is going to be called before it can call the function.

Code Example (Non-Dependent)
// Inside if-statement or switch-case of "getModKernel" function for "CommunityLib" namespace
    // This line dynamically gets a reference to the function that you are about to call (MethodInfo), based on it's name and parameters.
    MethodInfo MI_registerVampireType = kernel.GetType().GetMethod("registerVampireType", new Type[] { typeof(Type) });

    // The parameters object array contains the parameters that will be passed into the function.
    object[] parameters = new object[] { typeof(UAE_DeathMonarch) };
    // This line calls the function by its MethodInfo, on the class instance kernel", with the parameters "parameters". 
    MI_registerVampireType.Invoke(kernel, parameters);
    // Each vampire type must be registered seperately.
    parameters = new object[] { typeof(UAEN_VampireThrall) };
    MI_registerVampireType.Invoke(kernel, parameters);

The function will only fail if the Type you passed in is not a subtype of Unit.

⚠️ **GitHub.com Fallback** ⚠️