You can create your own custom disasters using the CustomDisaster
class, provided by RogueLibs. You can configure the disaster's name, description and both of the messages that are displayed at the beginning of the floor. And, of course, you can determine the conditions that the disaster can (or must) happen under, and what happens at the start of and during this disaster. Additionally, you can quickly and easily create a removal mutator that removes your disaster from the pool.
CustomDisaster
classTo make a custom disaster, you need to create a class deriving from CustomDisaster
:
public class MyAwesomeDisaster : CustomDisaster{ /* ... */}
There are 4 methods that you can implement:
public class MyAwesomeDisaster : CustomDisaster{ public override void Start() { /* ... */ } public override void StartAfterNotification() { /* ... */} public override void Finish() { /* ... */ } public override IEnumerator? Updating() { /* ... */ }}
Start
is called when the disaster starts. Finish
is called when the disaster ends. StartAfterNotification
is called after the disaster notification message.
These methods are called in-between levels, so some stuff might not be available at the time they're called.
Updating
returns the updating coroutine for the disaster. It starts after the disaster's notification. It is stopped automatically, when the disaster ends. If your disaster doesn't need updating, you can just return null
.
If you want your disaster to appear only under certain conditions, override the Test
method:
public class MyAwesomeDisaster : CustomDisaster{ public override bool Test() { // for example, if it's a Park level return CurrentDistrict == 2; }}
CurrentDistrict
- index of the current level's district:
CurrentFloor
- index of the current level's floor of the district.
CurrentLevel
- index of the current level.
And, if you want to force your disaster onto a level, override the TestForced
method.
public class MyAwesomeDisaster : CustomDisaster{ public override bool TestForced() { // for example, if there's a Mayor on the level return gc.agentList.Exists(a => a.agentName === VanillaAgents.Mayor); }}
Normally, you can't teleport during disasters, but you can change that by overriding the AllowTeleport
property:
public class MyAwesomeDisaster : CustomDisaster{ public override bool AllowTeleport => true;}
The property is accessed constantly, so you can change the return value with time.
Just call the CreateCustomDisaster
method with your disaster's type as a parameter:
public class MyAwesomeDisaster : CustomDisaster{ [RLSetup] public static void Setup() { RogueLibs.CreateCustomDisaster<MyAwesomeDisaster>(); }}
See more about the RLSetup
attribute here.
You can set your disaster's name and description using WithName
and WithDescription
methods:
public class MyAwesomeDisaster : CustomDisaster{ [RLSetup] public static void Setup() { RogueLibs.CreateCustomDisaster<MyAwesomeDisaster>() .WithName(new CustomNameInfo("My Awesome Disaster")) .WithDescription(new CustomNameInfo("My Awesome Disaster is very cool and does a lot of great stuff, and it's also awesome.")); }}
Plus, you can add two messages (they are displayed at the same time, on two lines):
public class MyAwesomeDisaster : CustomDisaster{ [RLSetup] public static void Setup() { RogueLibs.CreateCustomDisaster<MyAwesomeDisaster>() .WithName(new CustomNameInfo("My Awesome Disaster")) .WithDescription(new CustomNameInfo("My Awesome Disaster is very cool and does a lot of great stuff, and it's also awesome.")) .WithMessage(new CustomNameInfo("My Awesome Disaster!")) .WithMessage(new CustomNameInfo("Watch out for... uh, something.. awesome?!")); }}
See Custom Names for more info.
You can also create a removal mutator automatically:
public class MyAwesomeDisaster : CustomDisaster{ [RLSetup] public static void Setup() { RogueLibs.CreateCustomDisaster<MyAwesomeDisaster>() .WithName(new CustomNameInfo("My Awesome Disaster")) .WithDescription(new CustomNameInfo("My Awesome Disaster is very cool and does a lot of great stuff, and it's also awesome.")) .WithMessage(new CustomNameInfo("My Awesome Disaster!")) .WithMessage(new CustomNameInfo("Watch out for... uh, something.. awesome?!")) .WithRemovalMutator(); }}
A simple disaster that just gives everyone Resurrection after the notification.
using System.Collections;using RogueLibsCore;namespace MyAwesomeMod{ public class NewHealthOrder : CustomDisaster { [RLSetup] public static void Setup() { RogueLibs.CreateCustomDisaster<NewHealthOrder>() .WithName(new CustomNameInfo { English = "New Health Order", }) .WithDescription(new CustomNameInfo { English = "Where is this line used?!", }) .WithMessage(new CustomNameInfo { English = "N.H.O. - New Health Order", }) .WithMessage(new CustomNameInfo { English = "Resurrection for everyone!", }) .WithRemovalMutator(); } public override void Start() { } public override void Finish() { } public override IEnumerator Updating() { foreach (Agent agent in gc.agentList) if (!agent.dead && !agent.electronic && !agent.inhuman) { agent.statusEffects.AddStatusEffect(VanillaEffects.Resurrection, false); } yield break; } }}