RogueLibs' logo

Creating a Custom Agent

RogueLibs provides classes and methods to create custom agents. All custom agents derive from the CustomAgent class, which provides all of the basic agent functionality. Custom agents are initialized and integrated into the game using the RogueLibs.CreateCustomAgent<TAgent>() method.

CustomAgent class

To make a custom agent, you need to create a class deriving from CustomAgent:

/MyAwesomeProject/MyAwesomeAgent.cs
public class MyAwesomeAgent : CustomAgent{    /* ... */}

There's only one method that you need to implement - SetupAgent:

/MyAwesomeProject/MyAwesomeAgent.cs
public class MyAwesomeAgent : CustomAgent{    public override void SetupAgent()    {        Agent.SetStrength(1);        Agent.SetEndurance(1);        Agent.SetAccuracy(1);        Agent.SetSpeed(1);        Agent.statusEffects.AddTrait("TheLaw");        Agent.modMeleeSkill = 0;        Agent.modGunSkill = 1;        Agent.modToughness = 1;        Agent.modVigilant = 0;    }}

This method is called only once, when the agent is created. See more info later on this page.

You should add categories using the AgentCategories attribute instead of adding them in SetupAgent:

/MyAwesomeProject/MyAwesomeAgent.cs
[AgentCategories(RogueCategories.Guns, RogueCategories.Defense, "MyAwesomeCategory")]public class MyAwesomeAgent : CustomAgent{    /* ... */}
Pro-tip: String consts

Use static types with string consts, like RogueCategories. This way you won't make a typo. Typos can be critical sometimes, since neither the game nor RogueLibs track all existing agent categories.

Initialization

Just call the CreateCustomAgent method with your agent's type as a parameter:

/MyAwesomeProject/MyAwesomeAgent.cs
public class MyAwesomeAgent : CustomAgent{    [RLSetup]    public static void Setup()    {        RogueLibs.CreateCustomAgent<MyAwesomeAgent>();    }}
note

See more about the RLSetup attribute here.

You can set your agent's name using WithName method:

/MyAwesomeProject/MyAwesomeAgent.cs
public class MyAwesomeAgent : CustomAgent{    [RLSetup]    public static void Setup()    {        RogueLibs.CreateCustomAgent<MyAwesomeAgent>()            .WithName(new CustomNameInfo("My Awesome Agent"));    }}

You can set your agent's sprites using WithHeadSprite and WithBodySprite methods:

/MyAwesomeProject/MyAwesomeAgent.cs
public class MyAwesomeAgent : CustomAgent{    [RLSetup]    public static void Setup()    {        RogueLibs.CreateCustomAgent<MyAwesomeAgent>()            .WithName(new CustomNameInfo("My Awesome Agent"))            .WithHeadSprite(Properties.Resources.MyAwesomeAgentHead)            .WithBodySprite(Properties.Resources.MyAwesomeAgentBody);    }}
info

See Custom Names, Custom Sprites for more info.

Implementing SetupAgent

Work-In-Progress

There's a lot of fields that determine agents' properties and behaviour. If you get info about some fields, ping Dzhake or T.B.B in the #🔧|modding.

Member nameDescription
SetEndurance()The Endurance stat. Common range: from 0 to 3 (Endurance 1 to 4 respectively). Determines the agent's max health. Formula: Max health = (80 + enduranceStat * 20) / 3.
SetStrength()The Strength stat. Common range: from 0 to 3 (Strength 1 to 4 respectively). Determines the damage of the agent's melee attacks. Formula: Damage = (weaponDamage * 1 + strengthStat) / 3.
SetAccuracy()The Firearms stat. Common range: from 0 to 3 (Firearms 1 to 4 respectively). Determines the damage of the agent's ranged attacks. Formula: Damage = (accuracyStat * 0.6 + moreAccuracy) / 5.
SetSpeed()The Speed stat. Common range: from 0 to 3 (Speed 1 to 4 respectively). Determines the agent's movement speed. Formula: Max speed = 1750 + speedStat * 250. (the actual physical speed is 1/100 of that number).
modMeleeSkillThe NPC's melee skill. Aceepts values from 0 to 2. More details in Combat.Start().
modGunSkillThe NPC's gun skill. Accepts values from 0 to 2. Affects weapon cooldown and attack range. More details in Combat.CombatCheck() and Combat.SetPersonalCooldown().
modToughnessThe NPC's "toughness". Accepts values from 0 to 2. Determines how much danger an agent can be exposed to, before getting scared and fleeing. More details in BrainUpdate.
modVigilantThe NPC's sensitivity to noise. Accepts values from 0 to 2. More details on GoalNoiseReact.
caution

Do not edit Agent.agentName - that is the internal agent name, that's used by SoR and RL. Editing it may break some stuff. If you need to change the agent's displayed name, use Agent.agentRealName instead.

Spawning agent

For spawning agents you needs make body of patch LoadLevel.SetupMore4() and load patch in patcher:

note

See more about the patching here.

/MyAwesomeProject/MyAwesomePlugin.cs
public void Awake(){    RoguePatcher patcher = new RoguePatcher(this);    patcher.Postfix(typeof(LoadLevel), nameof(LoadLevel.SetupMore4));}public static void LoadLevel_SetupMore4(LoadLevel __instance, ref GameController ___gc){    ___gc.SpawnAgent<MyAwesomeAgent>(/* my awesome position */);}
Pro-tip: Avoiding tutorial and homebase spawning

Use that conditions for avoiding spawn agents on tutorial and homebase levels.

/MyAwesomeProject/MyAwesomePlugin.cs
public void Awake(){    RoguePatcher patcher = new RoguePatcher(this);    patcher.Postfix(typeof(LoadLevel), nameof(LoadLevel.SetupMore4));}public static void LoadLevel_SetupMore4(LoadLevel __instance, ref GameController ___gc){    if (___gc.levelType != "HomeBase" && ___gc.levelType != "Tutorial")    {        ___gc.SpawnAgent<MyAwesomeAgent>(/* my awesome position */);    }        }