Modding:Mutations: Difference between revisions

Jump to navigation Jump to search
2,757 bytes removed ,  00:33, 17 August 2020
no edit summary
m (add cleanup note)
No edit summary
Line 89: Line 89:
   
   


Here's a full example of the Flaming Hands mutation from the game's source code.
Here's a full decompiled example of the [[Flaming Hands]] mutation from the game's source code.
Flaming Hands - Full Example .cs
<syntaxhighlight lang="csharp">
<syntaxhighlight lang="csharp">
using System;
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading;
using ConsoleLib.Console;
using XRL.Core;
using XRL.Rules;
using XRL.UI;
using XRL.UI;
using ConsoleLib.Console;
 
namespace XRL.World.Parts.Mutation
namespace XRL.World.Parts.Mutation
{
{
    [Serializable]
[Serializable]
    class FlamingHands : BaseMutation
public class FlamingHands : BaseMutation
    {
{
        public FlamingHands()
public override bool GeneratesEquipment()
        {
{
            Name = "FlamingHands";
return true;
            DisplayName = "Flaming Hands";
}
        }
 
public FlamingHands()
        public Guid FlamingHandsActivatedAbilityID = Guid.Empty;
{
        public ActivatedAbilityEntry FlamingHandsActivatedAbility = null;
this.DisplayName = "Flaming Hands";
}
        public override void Register(GameObject Object)
 
        {
public override void Register(GameObject Object)
            Object.RegisterPartEvent(this, "BeginEquip");
{
            Object.RegisterPartEvent(this, "CommandFlamingHands");
Object.RegisterPartEvent(this, "CommandFlamingHands");
            Object.RegisterPartEvent(this, "AIGetOffensiveMutationList");
Object.RegisterPartEvent(this, "AIGetOffensiveMutationList");
        }
base.Register(Object);
}
        public override string GetDescription()
 
        {
public override string GetDescription()
            return "You emit jets of flame from your hands.";
{
        }
return "You emit jets of flame from your hands.";
}
        public override string GetLevelText(int Level)
 
        {
public override string GetLevelText(int Level)
            string Ret = "Emits a 9-square ray of flame in the direction of your choice\n";
{
            Ret += "Cooldown: 10 rounds\n";
return "Emits a 9-square ray of flame in the direction of your choice\n" + "Cooldown: 10 rounds\n" + "Damage: " + this.ComputeDamage(Level) + "\n" + "Cannot wear gloves";
            Ret += "Damage: " + Level + "d6\n";
}
            Ret += "Cannot wear gloves";
 
            return Ret;
public string ComputeDamage(int UseLevel)
        }
{
string text = UseLevel + "d4";
        public void Flame(Cell C, ScreenBuffer Buffer)
if (this.ParentObject != null)
        {
{
            string Damage = Level + "d6";
int partCount = this.ParentObject.GetPart<Body>().GetPartCount(this.BodyPartType);
if (partCount > 0)
            Body pBody = ParentObject.GetPart("Body") as Body;
{
            int nHandCount = pBody.GetPart("Hands").Count-1;
text = text + "+" + partCount;
            if (nHandCount > 0) Damage += "+" + nHandCount.ToString();
}
}
            if (C != null)
else
            {
{
                List<GameObject> Objects = C.GetObjectsInCell();
text += "+1";
}
                foreach (GameObject GO in Objects)
return text;
                {
}
                    if( GO.PhasedMatches( ParentObject ) )
 
                    {
public string ComputeDamage()
                        GO.FireEvent(Event.New("TemperatureChange", "Amount", 310 + (30 * Level), "Owner", ParentObject));
{
                        for (int x = 0; x < 5; x++) GO.ParticleText("&r" + (char)(219 + Rules.Stat.Random(0, 4)), 2.9f, 1);
return this.ComputeDamage(base.Level);
                        for (int x = 0; x < 5; x++) GO.ParticleText("&R" + (char)(219 + Rules.Stat.Random(0, 4)), 2.9f, 1);
}
                        for (int x = 0; x < 5; x++) GO.ParticleText("&W" + (char)(219 + Rules.Stat.Random(0, 4)), 2.9f, 1);
 
                    }
public void Flame(Cell C, ScreenBuffer Buffer, bool doEffect = true)
                }
{
string dice = this.ComputeDamage();
                foreach (GameObject GO in C.GetObjectsWithPart("Combat"))
if (C != null)
                {
{
                    if( GO.PhasedMatches( ParentObject ) )
foreach (GameObject gameObject in C.GetObjectsInCell())
                    {
{
                        Damage Dmg = new Damage(Rules.Stat.Roll(Damage));
if (gameObject.PhaseMatches(this.ParentObject))
                        Dmg.AddAttribute("Fire");
{
                        Dmg.AddAttribute("Heat");
gameObject.TemperatureChange(310 + 25 * base.Level, this.ParentObject, false, false, false, 0, null, null);
if (doEffect)
                        Event eTakeDamage = Event.New("TakeDamage");
{
                        eTakeDamage.AddParameter("Damage", Dmg);
for (int i = 0; i < 5; i++)
                        eTakeDamage.AddParameter("Owner", ParentObject);
{
                        eTakeDamage.AddParameter("Attacker", ParentObject);
gameObject.ParticleText("&r" + ((char)(219 + Stat.Random(0, 4))).ToString(), 2.9f, 1);
                        eTakeDamage.AddParameter("Message", "from %o flames!");
}
for (int j = 0; j < 5; j++)
                        GO.FireEvent(eTakeDamage);
{
                    }
gameObject.ParticleText("&R" + ((char)(219 + Stat.Random(0, 4))).ToString(), 2.9f, 1);
                }
}
            }
for (int k = 0; k < 5; k++)
{
            Buffer.Goto(C.X, C.Y);
gameObject.ParticleText("&W" + ((char)(219 + Stat.Random(0, 4))).ToString(), 2.9f, 1);
            string sColor = "&C";
}
            int r = Rules.Stat.Random(1, 3);
}
            if (r == 1) sColor = "&R";
}
            if (r == 2) sColor = "&r";
}
            if (r == 3) sColor = "&W";
DieRoll cachedDieRoll = dice.GetCachedDieRoll();
foreach (GameObject gameObject2 in C.GetObjectsWithPartReadonly("Combat"))
            r = Rules.Stat.Random(1, 3);
{
            if (r == 1) sColor += "^R";
if (gameObject2.PhaseMatches(this.ParentObject))
            if (r == 2) sColor += "^r";
{
            if (r == 3) sColor += "^W";
Damage damage = new Damage(cachedDieRoll.Resolve());
damage.AddAttribute("Fire");
            if( C.ParentZone == XRL.Core.XRLCore.Core.Game.ZoneManager.ActiveZone )
damage.AddAttribute("Heat");
            {
Event @event = Event.New("TakeDamage", 0, 0, 0);
                r = Rules.Stat.Random(1, 3);
@event.SetParameter("Damage", damage);
                Buffer.Write(sColor + (char)(219 + Rules.Stat.Random(0, 4)));
@event.SetParameter("Owner", this.ParentObject);
                Popup._TextConsole.DrawBuffer(Buffer);
@event.SetParameter("Attacker", this.ParentObject);
                System.Threading.Thread.Sleep(10);
@event.SetParameter("Message", "from %o flames!");
            }
gameObject2.FireEvent(@event);
        }
}
}
        public override bool FireEvent(Event E)
}
        {
if (doEffect)
            if (E.ID == "AIGetOffensiveMutationList")
{
            {
Buffer.Goto(C.X, C.Y);
                int Distance = (int)E.GetParameter("Distance");
string str = "&C";
                GameObject Target = E.GetParameter("Target") as GameObject;
int num = Stat.Random(1, 3);
                List<XRL.World.AI.GoalHandlers.AICommandList> CommandList = (List<XRL.World.AI.GoalHandlers.AICommandList>)E.GetParameter("List");
if (num == 1)
{
                if (FlamingHandsActivatedAbility != null && FlamingHandsActivatedAbility.Cooldown <= 0 && Distance <= 9 && ParentObject.HasLOSTo(Target) ) CommandList.Add(new XRL.World.AI.GoalHandlers.AICommandList("CommandFlamingHands", 1));
str = "&R";
                return true;
}
            }
if (num == 2)
{
            if (E.ID == "CommandFlamingHands")
str = "&r";
            {
}
                ScreenBuffer Buffer = new ScreenBuffer(80, 25);
if (num == 3)
                Core.XRLCore.Core.RenderMapToBuffer(Buffer);
{
str = "&W";
                List<Cell> TargetCell = PickLine(9, AllowVis.Any);
}
                if (TargetCell == null) return true;
int num2 = Stat.Random(1, 3);
                if (TargetCell.Count <= 0) return true;
if (num2 == 1)
{
                if (TargetCell != null)
str += "^R";
                {
}
                    if (TargetCell.Count == 1)
if (num2 == 2)
                    {
{
                        if (ParentObject.IsPlayer())
str += "^r";
                            if (UI.Popup.ShowYesNoCancel("Are you sure you want to target yourself?") != DialogResult.Yes)
}
                            {
if (num2 == 3)
                                return true;
{
                            }
str += "^W";
                    }
}
if (C.ParentZone == XRLCore.Core.Game.ZoneManager.ActiveZone)
                    if( FlamingHandsActivatedAbility != null ) FlamingHandsActivatedAbility.Cooldown = 110;
{
                    ParentObject.FireEvent(Event.New("UseEnergy", "Amount", 1000, "Type", "Physical Mutation"));
Stat.Random(1, 3);
                   
Buffer.Write(str + ((char)(219 + Stat.Random(0, 4))).ToString(), true);
                    for (int x = 0; x < 9 && x < TargetCell.Count; x++)
Popup._TextConsole.DrawBuffer(Buffer, null, false);
                    {
Thread.Sleep(10);
                        if (TargetCell.Count == 1 || TargetCell[x] != ParentObject.pPhysics.CurrentCell)
}
                        Flame(TargetCell[x],Buffer);
}
}
                        foreach( GameObject GO in TargetCell[x].GetObjectsWithPart("Physics") )
 
                        {
public static bool Cast(FlamingHands mutation = null, string level = "5-6")
                            if (GO.pPhysics.Solid)
{
                            {
if (mutation == null)
                                x = 999;
{
                                break;
mutation = new FlamingHands();
                            }
mutation.Level = Stat.Roll(level, null);
                        }
mutation.ParentObject = XRLCore.Core.Game.Player.Body;
                    }
}
                }
ScreenBuffer scrapBuffer = ScreenBuffer.GetScrapBuffer1(true);
            }
XRLCore.Core.RenderMapToBuffer(scrapBuffer);
List<Cell> list = mutation.PickLine(9, AllowVis.Any, null, false, null);
            if (E.ID == "BeginEquip")
if (list == null)
            {
{
                GameObject Equipment = E.GetParameter("Object") as GameObject;
return true;
                string BodyPartName = E.GetParameter("BodyPartName") as string;
}
if (list.Count <= 0)
                if (BodyPartName == "Hands")
{
                {
return true;
                    if (IsPlayer())
}
                    {
if (list != null)
                        UI.Popup.Show("Your flaming hands prevents you from equipping " + Equipment.DisplayName + "!");
{
                    }
if (list.Count == 1 && mutation.ParentObject.IsPlayer() && Popup.ShowYesNoCancel("Are you sure you want to target yourself?") != DialogResult.Yes)
{
                    E.bCancelled = true;
return true;
                    return false;
}
                }
mutation.CooldownMyActivatedAbility(mutation.FlamingHandsActivatedAbilityID, 10, null);
            }
mutation.UseEnergy(1000);
mutation.PlayWorldSound(mutation.Sound, 0.5f, 0f, true, null);
            return true;
int num = 0;
        }
while (num < 9 && num < list.Count)
{
if (list.Count == 1 || list[num] != mutation.ParentObject.pPhysics.CurrentCell)
        int OldFlame = -1;
{
        int OldVapor = -1;
mutation.Flame(list[num], scrapBuffer, true);
}
        public override bool ChangeLevel(int NewLevel)
foreach (GameObject gameObject in list[num].LoopObjectsWithPart("Physics"))
        {
{
            Physics pPhysics = ParentObject.GetPart("Physics") as Physics;
if (gameObject.pPhysics.Solid && gameObject.GetIntProperty("AllowMissiles", 0) == 0)
{
            TemperatureOnHit pTemp = FlamesObject.GetPart("TemperatureOnHit") as TemperatureOnHit;
Forcefield part = gameObject.GetPart<Forcefield>();
            pTemp.Amount =  (Level*2) + "d8";
if (part == null || !part.CanMissilePassFrom(mutation.ParentObject, null))
{
            return base.ChangeLevel(NewLevel);
num = 999;
        }
break;
}
        public override bool Mutate(GameObject GO, int Level)
}
        {
}
            Unmutate(GO);
num++;
}
            ActivatedAbilities pAA = GO.GetPart("ActivatedAbilities") as ActivatedAbilities;
}
            Physics pPhysics = GO.GetPart("Physics") as Physics;
return true;
}
            if (pPhysics != null)
 
            {
public override bool FireEvent(Event E)
                OldFlame = pPhysics.FlameTemperature;
{
                OldVapor = pPhysics.VaporTemperature;
if (E.ID == "AIGetOffensiveMutationList")
            }
{
           
if (E.GetIntParameter("Distance", 0) <= 9 && base.IsMyActivatedAbilityAIUsable(this.FlamingHandsActivatedAbilityID, null) && this.ParentObject.HasLOSTo(E.GetGameObjectParameter("Target"), true, true, null))
            Body pBody = GO.GetPart("Body") as Body;
{
            if (pBody != null)
E.AddAICommand("CommandFlamingHands", 1, null, false);
            {
}
                GO.FireEvent(Event.New("CommandForceUnequipObject", "BodyPartName", "Hands"));
}
                FlamesObject = GameObjectFactory.Factory.CreateObject("Ghostly Flames");
else if (E.ID == "CommandFlamingHands")
                Event eCommandEquipObject = Event.New("CommandEquipObject");
{
                eCommandEquipObject.AddParameter("Object", FlamesObject);
return FlamingHands.Cast(this, "5-6");
                eCommandEquipObject.AddParameter("BodyPartName", "Hands");
}
                GO.FireEvent(eCommandEquipObject);
return true;
            }
}
 
            FlamingHandsActivatedAbilityID = pAA.AddAbility("Flaming Hands", "CommandFlamingHands", "Physical Mutation");
public override bool ChangeLevel(int NewLevel)
            FlamingHandsActivatedAbility = pAA.AbilityByGuid[FlamingHandsActivatedAbilityID];
{
            return true;
if (GameObject.validate(ref this.FlamesObject))
        }
{
this.FlamesObject.GetPart<TemperatureOnHit>().Amount = base.Level * 2 + "d8";
        public GameObject FlamesObject = null;
}
return base.ChangeLevel(NewLevel);
        public override bool Unmutate(GameObject GO)
}
        {
 
            Physics pPhysics = GO.GetPart("Physics") as Physics;
private void AddAbility()
{
            if (pPhysics != null)
this.FlamingHandsActivatedAbilityID = base.AddMyActivatedAbility("Flaming Hands", "CommandFlamingHands", "Physical Mutation", -1, null, "\a", false, false, false, false, false, false, null);
            {
}
                if (OldFlame != -1) pPhysics.FlameTemperature = OldFlame;
 
                if (OldVapor != -1) pPhysics.BrittleTemperature = OldVapor;
public override bool Mutate(GameObject GO, int Level)
                OldFlame = -1;
{
                OldVapor = -1;
this.Unmutate(GO);
if (this.CreateObject)
                pPhysics.Temperature = 25;
{
            }
Body part = GO.GetPart<Body>();
           
if (part != null)
            Body pBody = GO.GetPart("Body") as Body;
{
            if (pBody != null)
BodyPart firstPart = part.GetFirstPart(this.BodyPartType);
            {
if (firstPart != null)
                BodyPart pMainBody = pBody.GetPartByName("Hands");
{
                if( pMainBody != null )
GO.FireEvent(Event.New("CommandForceUnequipObject", "BodyPart", firstPart));
                if (pMainBody.Equipped != null)
this.FlamesObject = GameObject.create("Ghostly Flames");
                {
this.FlamesObject.GetPart<Armor>().WornOn = firstPart.Type;
                    if (pMainBody.Equipped.Blueprint == "Ghostly Flames")
Event @event = Event.New("CommandForceEquipObject", 0, 0, 0);
                    {
@event.SetParameter("Object", this.FlamesObject);
                        pMainBody.Equipped.FireEvent(Event.New("Unequipped", "UnequippingObject", ParentObject, "BodyPart", pMainBody));
@event.SetParameter("BodyPart", firstPart);
                        pMainBody.Unequip();
@event.SetSilent(true);
                    }
GO.FireEvent(@event);
                }
this.AddAbility();
            }
}
}
            if (FlamingHandsActivatedAbilityID != Guid.Empty)
}
            {
else
                ActivatedAbilities pAA = GO.GetPart("ActivatedAbilities") as ActivatedAbilities;
{
                pAA.RemoveAbility(FlamingHandsActivatedAbilityID);
this.AddAbility();
                FlamingHandsActivatedAbilityID = Guid.Empty;
}
            }
this.ChangeLevel(Level);
return base.Mutate(GO, Level);
            return true;
}
        }
 
    }
public override bool Unmutate(GameObject GO)
{
base.CleanUpMutationEquipment(GO, ref this.FlamesObject);
base.RemoveMyActivatedAbility(ref this.FlamingHandsActivatedAbilityID, null);
return base.Unmutate(GO);
}
 
public string BodyPartType = "Hands";
 
public bool CreateObject = true;
 
public string Sound = "burn_crackling";
 
public GameObject FlamesObject;
 
public Guid FlamingHandsActivatedAbilityID = Guid.Empty;
}
}
}
</syntaxhighlight>
</syntaxhighlight>
Line 360: Line 377:
using System;
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading;
using ConsoleLib.Console;
using XRL.Core;
using XRL.Rules;
using XRL.UI;
using XRL.UI;
using ConsoleLib.Console;
 
namespace XRL.World.Parts.Mutation
namespace XRL.World.Parts.Mutation
{
{
    [Serializable]
[Serializable]
    class FlamingHands : BaseMutation
public class FlamingHands : BaseMutation
    {
{
</syntaxhighlight>
</syntaxhighlight>


Line 373: Line 393:
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">
<syntaxhighlight lang="csharp">
        public override string GetDescription()
public override string GetDescription()
        {
{
            return "You emit jets of flame from your hands.";
return "You emit jets of flame from your hands.";
        }
}
 
 
        public override string GetLevelText(int Level)
public override string GetLevelText(int Level)
        {
{
            string Ret = "Emits a 9-square ray of flame in the direction of your choice\n";
return "Emits a 9-square ray of flame in the direction of your choice\n" + "Cooldown: 10 rounds\n" + "Damage: " + this.ComputeDamage(Level) + "\n" + "Cannot wear gloves";
            Ret += "Cooldown: 10 rounds\n";
}
            Ret += "Damage: " + Level + "d6\n";
            Ret += "Cannot wear gloves";
            return Ret;
        }
</syntaxhighlight>
</syntaxhighlight>
   
   
Line 393: Line 409:
public override bool ChangeLevel(int NewLevel)
public override bool ChangeLevel(int NewLevel)
{
{
    Physics pPhysics = ParentObject.GetPart("Physics") as Physics;
if (GameObject.validate(ref this.FlamesObject))
{
    TemperatureOnHit pTemp = FlamesObject.GetPart("TemperatureOnHit") as TemperatureOnHit;
this.FlamesObject.GetPart<TemperatureOnHit>().Amount = base.Level * 2 + "d8";
    pTemp.Amount = (Level*2) + "d8";
}
return base.ChangeLevel(NewLevel);
    return base.ChangeLevel(NewLevel);
}
}
</syntaxhighlight>
</syntaxhighlight>

Navigation menu