Modding:Mutations: Difference between revisions

363 bytes added ,  15:54, 23 May 2019
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
<?xml version="1.0" encoding="utf-8" ?>
<syntaxhighlight lang="xml">
<mutations>
<?xml version="1.0" encoding="utf-8" ?>
  <category Name="Physical">
<mutations>
    <mutation Name="Udder" Cost="1" MaxSelected="1" Class="FreeholdTutorial_Udder" Exclusions="" Code="ea"></mutation>
  <category Name="Physical">
  </category>
    <mutation Name="Udder" Cost="1" MaxSelected="1" Class="FreeholdTutorial_Udder" Exclusions="" Code="ea"></mutation>
</mutations>
</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.
using System;
<syntaxhighlight lang="csharp">
using System.Collections.Generic;
using System;
using System.Text;
using System.Collections.Generic;
using System.Text;
   
   
using XRL.Rules;
using XRL.Rules;
using XRL.Messages;
using XRL.Messages;
using ConsoleLib.Console;
using ConsoleLib.Console;
   
   
namespace XRL.World.Parts.Mutation
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
using System;
<syntaxhighlight lang="csharp">
using System.Collections.Generic;
using System;
using XRL.UI;
using System.Collections.Generic;
using ConsoleLib.Console;
using XRL.UI;
using ConsoleLib.Console;
   
   
namespace XRL.World.Parts.Mutation
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.


using System;
<syntaxhighlight lang="csharp">
using System.Collections.Generic;
using System;
using XRL.UI;
using System.Collections.Generic;
using ConsoleLib.Console;
using XRL.UI;
using ConsoleLib.Console;
   
   
namespace XRL.World.Parts.Mutation
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.
public override bool ChangeLevel(int NewLevel)
<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.
public override bool Mutate(GameObject GO, int Level)
<syntaxhighlight lang="csharp">
public override bool Mutate(GameObject GO, int Level)
    
    
public override bool Unmutate(GameObject GO)
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


public override void Register(GameObject Object)
<syntaxhighlight lang="csharp">
public override void Register(GameObject Object)
   
   
public override bool FireEvent(Event E)
public override bool FireEvent(Event E)
</syntaxhighlight>