Modding:Mutations: Difference between revisions
Adding syntax highlighting.
imported>CaptainTechnicality54384 (Created page with "Category:Modding First, include a mutations.xml in your mod that defines a new mutation. Mutations.xml sample, adding a simple mod <?xml version="1.0" encoding="utf-8"...") |
imported>CaptainTechnicality54384 (Adding syntax highlighting.) |
||
Line 3: | Line 3: | ||
Mutations.xml sample, adding a simple mod | Mutations.xml sample, adding a simple mod | ||
<syntaxhighlight lang="xml"> | |||
<?xml version="1.0" encoding="utf-8" ?> | |||
<mutations> | |||
<category Name="Physical"> | |||
<mutation Name="Udder" Cost="1" MaxSelected="1" Class="FreeholdTutorial_Udder" Exclusions="" Code="ea"></mutation> | |||
</category> | |||
</mutations> | |||
</syntaxhighlight> | |||
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) | 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) | ||
Line 15: | Line 17: | ||
Skeletal mutation example. | Skeletal mutation example. | ||
<syntaxhighlight lang="csharp"> | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using XRL.Rules; | |||
using XRL.Messages; | |||
using ConsoleLib.Console; | |||
namespace XRL.World.Parts.Mutation | |||
{ | |||
[Serializable] | [Serializable] | ||
class FreeholdTutorial_Udder : BaseMutation | class FreeholdTutorial_Udder : BaseMutation | ||
Line 81: | Line 84: | ||
} | } | ||
} | } | ||
} | |||
</syntaxhighlight> | |||
Line 88: | Line 91: | ||
Flaming Hands - Full Example .cs | Flaming Hands - Full Example .cs | ||
<syntaxhighlight lang="csharp"> | |||
using System; | |||
using System.Collections.Generic; | |||
using XRL.UI; | |||
using ConsoleLib.Console; | |||
namespace XRL.World.Parts.Mutation | |||
{ | |||
[Serializable] | [Serializable] | ||
class FlamingHands : BaseMutation | class FlamingHands : BaseMutation | ||
Line 347: | Line 351: | ||
} | } | ||
} | } | ||
} | |||
</syntaxhighlight> | |||
Your namespace should be XRL.World.Parts.Mutations, the class should be marked serializeable and derived from BaseMutation. | Your namespace should be XRL.World.Parts.Mutations, the class should be marked serializeable and derived from BaseMutation. | ||
<syntaxhighlight lang="csharp"> | |||
using System; | |||
using System.Collections.Generic; | |||
using XRL.UI; | |||
using ConsoleLib.Console; | |||
namespace XRL.World.Parts.Mutation | |||
{ | |||
[Serializable] | [Serializable] | ||
class FlamingHands : BaseMutation | class FlamingHands : BaseMutation | ||
{ | { | ||
</syntaxhighlight> | |||
GetDescription and GetLevelText are called to generate the descriptive for a given level of the mutation. | GetDescription and GetLevelText are called to generate the descriptive for a given level of the mutation. | ||
<syntaxhighlight lang="csharp"> | |||
public override string GetDescription() | public override string GetDescription() | ||
{ | { | ||
Line 380: | Line 385: | ||
return Ret; | return Ret; | ||
} | } | ||
</syntaxhighlight> | |||
Change level is called any time the mutation changes level. | Change level is called any time the mutation changes level. | ||
<syntaxhighlight lang="csharp"> | |||
public override bool ChangeLevel(int NewLevel) | |||
{ | |||
Physics pPhysics = ParentObject.GetPart("Physics") as Physics; | Physics pPhysics = ParentObject.GetPart("Physics") as Physics; | ||
Line 392: | Line 398: | ||
return base.ChangeLevel(NewLevel); | return base.ChangeLevel(NewLevel); | ||
} | |||
</syntaxhighlight> | |||
Mutate and Unmutate are called on an object when it gains or loses the mutation. | Mutate and Unmutate are called on an object when it gains or loses the mutation. | ||
<syntaxhighlight lang="csharp"> | |||
public override bool Mutate(GameObject GO, int Level) | |||
public override bool Unmutate(GameObject GO) | |||
</syntaxhighlight> | |||
BaseMutation derives from Part, so the typical event registration and handling functions are available | BaseMutation derives from Part, so the typical event registration and handling functions are available | ||
<syntaxhighlight lang="csharp"> | |||
public override void Register(GameObject Object) | |||
public override bool FireEvent(Event E) | |||
</syntaxhighlight> |