Skip to content

Examples

Gotest edited this page May 9, 2021 · 8 revisions

Here is an entire example mod.

Defining And Registering A Primary Attribute

Creating a Primary Attribute Definition is actually quite simple: you simply need to create a definition and register it!

public void Load()  
{
    PrimaryAttributeDefinitionsRegistry.Instance.Register(CustomAttribute = 
              new PrimaryAttributeDefinition("CustomAttribute", 30, new Color(128, 128, 128)));
}

public PrimaryAttributeDefinition CustomAttribute { get; private set; }

It's very important to keep a reference to this attribute somewhere, unless you want to write

Main.player[Main.myPlayer].GetModPlayer<LeveledPlayer>().GetPlayerPrimaryAttribute(PrimaryAttributeDefinitionsRegistry.Instance.Get("CustomAttribute"));

instead of just

CustomAttribute.GetPlayerPrimaryAttribute(Main.player[Main.myPlayer]);
// or
leveledPlayer.GetPlayerPrimaryAttribute(CustomAttribute);

Creating an Ability

Creating an Ability is fairly simple. This is an example ability (FortitudeDefender01):

sealed class FortitudeDefender01 : FortitudeAbility
{
    public FortitudeDefender01() : base(10, 1, 3, 3, false, "fortitude-defender-1")
    {
    }

    public override void PreUpdateMovement(LeveledPlayer player)
    {
        if (player.player.statLife <= player.player.statLifeMax2 * 0.2)
            player.Resistance.Mod += player.Level >= 3 ? player.Level / 3 : 1;
    }
}

The code for FortitudeAbility is:

abstract class FortitudeAbility : Ability
{
    protected FortitudeAbility(int requiredAttributeLevel, int requiredCombinedLevel, int requiredAP, 
                               int iconID, bool passive, string unlocalizedName) :
         base(PrimaryAttributeDefinitionManager.Fortitude, requiredAttributeLevel, requiredCombinedLevel, 
              requiredAP, iconID, passive, unlocalizedName)
    {
    }
}

You then need to add the ability with the AbilityManagerApi class:

AbilityManagerApi.AddAbility(new FortitudeDefender01());

This code needs (as far as our testing goes) in PostSetupContent of your Mod implementing class.

Clone this wiki locally