Skip to content
Guido "Harb edited this page Nov 15, 2019 · 2 revisions

This submodule allows mods to generate their own difficulties and add it to the rulebook.

It exposes one method: AddDifficulty(DifficultyDef). This adds the specified DifficultyDef to the rulebook and allows runs to be started in that difficulty. While this only sets the scalingfactor for the run, it provides an entry point for checking if a run is ran on your difficulty. In order to facilitate this, it returns your DifficultyIndex, so that you can easily check RoR2.Run.instance.selectedDifficulty against it.

The API automatically sorts all difficulties on their scaling coefficient. For the vanilla DifficultyDefs, checkout the RoR2.DifficultyCatalog.

Example

[R2APISubmoduleDependency("DifficultyAPI")]
class DifficultyExample: BaseUnityPlugin
{
    private DifficultyIndex myIndex;
    private void Awake(){
        DifficultyDef myDef = new DifficultyDef(
            1.5f, //This is the scaling factor, and decides how quickly the difficulty ramps up. drizzle is 1, rainstorm=2, monsoon=3.
            "NormalRain",//The name token. consider using AssetPlus.Language to add your tokens.
            "", //The iconpath, You can use a vanilla icon, or with use of AssetAPI/RescourceAPI use your own custom one.
            "Slightly Harder than drizzle, slighty easier than rainstorm",//The description token. consider using AssetPlus.Language to add your tokens.
            new UnityEngine.Color(0.5f,0.1f,0.2f)//The color that appears when hovering over this in the rulebook.
            );
        myIndex = R2API.DifficultyAPI.AddDifficulty(myDef);

        RoR2.Run.onRunStartGlobal += (RoR2.Run run) =>{
            if(run.selectedDifficulty == myIndex){
                R2API.ChatMessage.Send("Normal Rain selected!");
                //Ideally you'd hook your methods here, so you don't need to check in your changes if the current run is selected. 
            }
        };
        RoR2.Run.onRunDestroyGlobal += (RoR2.Run run) =>{
            if(run.selectedDifficulty == myIndex){
                //If you made changes to the game, specifically for your own difficulty, this would be the ideal moment to undo them and return the game to a vanilla state.
            }
        };
    }
}

Full mod based on DifficultyAPI: Diluvian