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
classTo make a custom agent, you need to create a class deriving from CustomAgent
:
public class MyAwesomeAgent : CustomAgent{ /* ... */}
There's only one method that you need to implement - SetupAgent
:
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
:
[AgentCategories(RogueCategories.Guns, RogueCategories.Defense, "MyAwesomeCategory")]public class MyAwesomeAgent : CustomAgent{ /* ... */}
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.
Just call the CreateCustomAgent
method with your agent's type as a parameter:
public class MyAwesomeAgent : CustomAgent{ [RLSetup] public static void Setup() { RogueLibs.CreateCustomAgent<MyAwesomeAgent>(); }}
See more about the RLSetup
attribute here.
You can set your agent's name using WithName
method:
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:
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); }}
See Custom Names, Custom Sprites for more info.
SetupAgent
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 name | Description |
---|---|
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). |
modMeleeSkill | The NPC's melee skill. Aceepts values from 0 to 2. More details in Combat.Start() . |
modGunSkill | The NPC's gun skill. Accepts values from 0 to 2. Affects weapon cooldown and attack range. More details in Combat.CombatCheck() and Combat.SetPersonalCooldown() . |
modToughness | The 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 . |
modVigilant | The NPC's sensitivity to noise. Accepts values from 0 to 2. More details on GoalNoiseReact . |
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.
For spawning agents you needs make body of patch LoadLevel.SetupMore4()
and load patch in patcher:
See more about the patching here.
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 */);}
Use that conditions for avoiding spawn agents on tutorial and homebase levels.
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 */); } }