This mod is a framework that allows other mods to very easily handle events generated by the player when attacking with any weapon.
This framework contains:
- Abstract handler classes, which you can inherit to handle all the events related to a weapon.
- Event IDs enumerations, as well as an enumeration for weapon IDs, and a few constants.
This mod's source code is separated in multiple namespaces:
- The
Constantsnamespace, which contains all the enumerations and other constants that are used by the framework, but you could use it in your own mod. - The
Eventsnamespace, which contains the main feeature of the framework: the abstract event handler classes (see Usage). - The
HandlersManagersnamespace, which contains classes used internally by the framework, and you won't ever need to use. - The
Patchesnamespace, which you won't ever need to use, as it only contains classes used to patch the game's methods.
This is an example of a simple handler that prints a message in the modding console whenever the player gains a new indicator with Sarmiento y Centella.
using BlasII.Framework.WeaponEvents.Events;
using BlasII.ModdingAPI;
namespace BlasII.MyOwnMod;
/// <summary>
/// This is an example of how you can use this framework, to display a message
/// in the console everytime the player gains an indicator while wielding
/// Sarmiento y Centella.
/// </summary>
public class MyCustomRapier : RapierHandler
{
/// <summary>
/// This is all the code you need, now simply add the framework in your
/// dependencies, compile your mod and run the game.
/// </summary>
protected override void OnIndicator(int tier)
{
ModLog.Debug($"Indicator gained! Current indicator level: {tier}");
}
}If for example, you are a modder that wants to execute a piece of code before or after a precise handler, you can use something called lazyness.
You can specify the lazyness of your handler class at its declaration like this:
[HandlerLazyness(10)]
public class AHandlerThatIsLazy : RapierHandler
{
// ...
}The higher the value you give to HandlerLazyness, the lazier your handler will
be. A lazy handler will always execute after the handlers that are less
lazy. Negative values are also accepted, this makes your handler less lazy than
others and will execute it before the others.
By default, every handler has a lazyness of 0, and the order of execution of
handlers with the same lazyness cannot be guaranteed.
So if you wished to execute a special piece of code before and after another
handler, consider this example:
using BlasII.Framework.WeaponEvents.Events;
using BlasII.ModdingAPI;
namespace BlasII.AnotherMod;
[HandlerLazyness(-10)]
public class LeastLazyHandler : RapierHandler
{
protected override void OnIndicator(int tier)
{
ModLog.Debug("This will be executed before!");
}
}
[HandlerLazyness(10)]
public class MostLazyHandler : RapierHandler
{
protected override void OnIndicator(int tier)
{
ModLog.Debug("This will be executed after!");
}
}If you then compile this code, and load this mod, and the one of the first example, this is what you will see after gaining your first Sarmiento y Centella indicator:
This will be executed before!
Indicator gained! Current indicator level: 1
This will be executed after!
From there, you should be able to implement most of your features, and also execute some of them before/after the ones of another mod.
If you have any feature request, please open an issue with the feature "request tag".
This is a non-exhaustive list of mods which make use of this framework, and you can take example on: