-
Notifications
You must be signed in to change notification settings - Fork 4
Integration & Compatibility
In this section you will know how to make integration with level up mod with your own mod, most of levelup is made with harmony, its highly recomended that you know what it is, in resume harmony is a ingame function patcher to overwrite/change native functions.
Normally you want to make a compatibility with the levelup mod when you need to interact with special functions from levelup, like damage calculation, or your mod explicitly patch some native functions that are not compatible with 2 mods at same time, for example the function ReceiveDamage in Entity class on LevelUP mod overwrite completly this function, and for other mod working on that function the mod will need to make a compatibility patch for that.
A complete example of compatibility with LevelUP is in the RPGDifficulty mod on Overwrite.cs
To check if the LevelUP is present in the server/game context is quitly simple, what you need is just make a foreach in all mods presents in api and check if the "LevelUP" mod exist
public override void Start(ICoreAPI api)
{
bool levelUPCompatibility = false;
api.ModLoader.Mods.Foreach((mod) => { if (mod.FileName == "LevelUP") levelUPCompatibility = true; });
}Adding or removing damage from the level up you need to use the Entity stats to communicate between patches with LevelUP, actually theres 2 options for LevelUP:
- LevelUP_DamageInteraction_Compatibility_ExtendDamageStart_ReceiveDamage, DamageStart
-
This is used to reduce damage or increase BEFORE the LevelUP levels calculation
- LevelUP_DamageInteraction_Compatibility_ExtendDamageFinish_ReceiveDamage, DamageFinish
-
This is used to reduce damage or increase AFTER the LevelUP levels Calculation
// Overwrite Damage Interaction
[HarmonyPrefix]
[HarmonyPatch(typeof(Entity), "ReceiveDamage")]
public static void ReceiveDamage(Entity __instance, DamageSource damageSource, float damage)
{
// In this line we will check if theres is no patches for LevelUP
if (__instance.Stats.GetBlended("LevelUP_DamageInteraction_Compatibility_ExtendDamageFinish_ReceiveDamage") == 0.0f)
{
// In this context no mods have added a compatibility so we can proceed to your calculation
// In this example we are adding 10 damage to the final calculation of LevelUP, also we can use -10 to reduce 10 damage of calculation
__instance.Stats.Set("LevelUP_DamageInteraction_Compatibility_ExtendDamageFinish_ReceiveDamage", "DamageFinish", 10, true);
}
// Otherwises theres already a patch for the LevelUP
else
{
// In this case we get the actual value from other mods
float entityAdditionalDamage = __instance.Stats.GetBlended("LevelUP_DamageInteraction_Compatibility_ExtendDamageFinish_ReceiveDamage");
// Now we are setting again with the old value from other mod plus your value 10
__instance.Stats["LevelUP_DamageInteraction_Compatibility_ExtendDamageFinish_ReceiveDamage"].Set("DamageFinish", entityAdditionalDamage + 10, true);
}
}