User:MomBun/Sandbox: Difference between revisions

3,491 bytes added ,  03:04, 3 August 2022
adding skeletal example with comments (Thank you Gnarf!)
mNo edit summary
(adding skeletal example with comments (Thank you Gnarf!))
Line 74: Line 74:
== C# Scripting, and Making The Mutation ==
== C# Scripting, and Making The Mutation ==


TO DO: ADD COMMENTS
Here is an example of a mutation that will add udders to your character, editing the title of your character "With Udders" and occasionally moo
<syntaxhighlight lang="csharp">
using System;
using System.Collections.Generic;
using System.Text;


TODO: ADD SKELETAL EXAMPLE
using XRL.Rules;
using XRL.Messages;
using ConsoleLib.Console;


TODO: ??? there has to be info about c# I'll need to add, probably expand upon my comments
// Namespace is a necessity here, and allows the game to find your mutation and add it to the game
namespace XRL.World.Parts.Mutation
{
    // This is also necessary as it allows the game to save info related to your mutation, for further info on this, check out the guide on serialization at [[Modding:Serialization_(Saving/Loading)]]
    [Serializable]
    // This defines the class that you will call in Mutations.XML
    class TEST_Udders : BaseMutation
    {


This is the source code from <code>FlamingHands.cs</code>
        // This sets the description for your mutation
        public override string GetDescription()
        {
            return "You have udders!";
        }
 
        // This sets the description for what exactly your mutation does
        public override string GetLevelText(int Level)
        {
            return  "Occasionally you will moo";
        }
 
        // Caves of Qud uses two different event systems so here is an example of each
 
        // This is how you tell the "Minimal events" system we want to handle a specific type of event.
        // We will listen for GetDisplayNameEvent.
        public override bool WantEvent(int ID, int cascade)
        {
            return base.WantEvent(ID, cascade) || ID == GetDisplayNameEvent.ID;
        }
 
        // Handle the GetDisplayNameEvent
        public override bool HandleEvent(GetDisplayNameEvent e)
        {
            var DescriptionBuilder = e.DB;
            // should show up when you look at anything with the mutation.
            DescriptionBuilder.AddWithClause("udders");
            return true;
        }
 
        // This is how you handle the other style of qud events
 
        // This is a much more effecient registration for this type of event and should be enabled.
        // Tells the event system that all your registrations are handled in your Register(GameObject) method.
        public override bool AllowStaticRegistration()
        {
            return true;
        }
 
        // First we must register the event
        public override void Register(GameObject obj) {
            obj.RegisterPartEvent(this, "EndTurn");
            // Call the base Register method that we overrode.
            base.Register(obj);
        }
 
        // Then we can handle the EndTurn type events here.
        public override bool FireEvent(Event E)
        {
            if (E.ID == "EndTurn")
            {
                // 1 in 100 chance to get "You moo." printed to the message log.
                if (1.in100()) DidX("moo");
            }
            return base.FireEvent(E);
        }
 
        // This is called every time the mutation changes level, and can be used to change things like damage.
        public override bool ChangeLevel(int NewLevel)
        {
            return true;
        }
 
        // These two are called upon when an object gains said mutation and what happens, and is used to add or remove things as necessary
        public override bool Mutate(GameObject PLAYER, int Level)
        {
            return true;
        }
 
        public override bool Unmutate(GameObject PLAYER)
        {
            return true;
        }
    }
}
</syntaxhighlight>
 
TODO: Re-work the huge file of flaminghands.cs to be have comments and explain it , possibly with Gnarf's help if they are okay/free to do so
 
This is the source code from <code>FlamingHands.cs</code> as an example of a more complex mutation.
<syntaxhighlight lang="csharp">
<syntaxhighlight lang="csharp">
using ConsoleLib.Console;
using ConsoleLib.Console;
12

edits