Modding:Mutations

Tutorial
First, include a mutations.xml in your mod that defines a new mutation. Mutations.xml sample, adding a simple mod

Then add a new .cs file in your mod that implements the class. Here's a skeletal implementation of the entry above. It must be in the XRL.World.Parts.Mutation namespace and must ultimately descend from BaseMutation. (Though not necessarily directly, if you have a very complex mod)

Skeletal mutation example.

Here's a full decompiled example of the Flaming Hands mutation from the game's source code. (Note that, because it's decompiled, some of the variables have very generic names, like  instead of something more descriptive, like  )

Your namespace should be XRL.World.Parts.Mutations, the class should be marked serializeable and derived from BaseMutation.

GetDescription and GetLevelText are called to generate the descriptive for a given level of the mutation.

Change level is called any time the mutation changes level.

Mutate and Unmutate are called on an object when it gains or loses the mutation.

BaseMutation derives from Part, so the typical event registration and handling functions are available

XML Parameters and Additional Details
You may add the following elements to a tag in Mutations.xml
 * Name
 * Class
 * Cost
 * MaxSelected
 * Constructor (optional)
 * Exclusions (optional)
 * BearerDescription
 * Code

Name
Name of the mutation as it appears in the character creation screen.

Class
The name of the .cs Class object that is used to instantiate your mutation object.

Cost
The mutation costs this many mutation points when a character selects it during the character creation process.

MaxSelected
The maximum number of copies of this mutation that can be selected during character creation.

Currently this is only used for Unstable Mutation and there is some hard-coded special handling of that mutation when it comes to details such as constructing a Build Library code for builds that include Unstable Mutation. It is not clear if this value can be set to more than 1 for a modded mutation without causing some problems.

Constructor
This element should be a string argument (or a comma-delimited string of arguments, if there are more than one) to pass to the mutation's class constructor. All such arguments are received as string parameters in the mutation class constructor. For example, Corrosive Gas Generation and Sleep Gas Generation both use the same mutation class, GasGeneration. However, Mutations.xml passes a different argument to the constructor, which indicates which type of gas should be used.

Mutations.xml

GasGeneration.cs

The GasObject property is set to to "SleepGas" in this case, because that was the value provided in the Constructor element of Mutations.xml.

Theoretically you could create a new mutation that generates any type of gas simply by adding a single tag to a Mutations.xml file. For example, this Mutations.xml file alone would create a new mutation called "Confusion Gas Generation"

Exclusions
The Exclusions parameter defines mutations that should be considered mutually exclusive with this mutation. For example, you can only have one type of back-slot mutation, so the game defines the other three types of back-slot mutations as Exclusions in the Mutations.xml file.

Example from Mutations.xml:

BearerDescription
It appears that this description is used in some of the random generation algorithms for villages and history in the game. For example, if a village reveres mutants with the Multiple Arms mutation, they might use the string defined in Mutations.xml ("the many-armed") to describe them in their praises or monuments.

Code
The Code element value is used when constructing a Build Library code for characters you create.

It is unclear if there is really a "best practice" for codes. Probably one should avoid using the codes used by base game mutations, but conflict with other mods may be inevitable. It would appear that this code can be longer than 2 characters, but that is an untested hypothesis.