Discussion in   Coding Corner   started     10 years ago   August 10, 2013, 11:09:14 AM   by   Keldon

Lets make armor with a double click heal (C#)

Keldon
Offline
223 Posts
Topic :   Lets make armor with a double click heal (C#)
10 years ago  August 10, 2013, 11:09:14 AM

Over the last month I have been exploring the world of programming in C#.  Part of this is doing some play testing on my own private server that I can add scripts to and reboot as needed.  For this I needed to make a piece of armor that gave me everything all in one piece.  That part was simple but my mobs continued to kill me and I had limited ability to gain the health back for rapid testing (I am sure there is a command but I do not know it for server owner healing).


I started off with the declaration of the namespaces I would be using:

Code: [Select]

using System;
using Server;


namespace Server.Items
{
}


After this I decided I wanted to just build upon the leather chest that already existed in the game and override the resists so this one piece of armor would give me 70 in all resists:
Code: [Select]


using System;
using Server;


namespace Server.Items
{

    public class GMTestArmor : LeatherChest
    {
        public override int BasePhysicalResistance{get {return 70;}}
        public override int BaseColdResistance{get {return 70; }}
        public override int BaseFireResistance{get {return 70; }}
        public override int BasePoisonResistance{get {return 70;}}
        public override int BaseEnergyResistance{get {return 70;}}
    }
}


Now we are ready to move on to the constructable portion where we give the item a name so it can be summoned by a GM as well as give this one piece of gear several very over powered attributes:
Code: [Select]


using System;
using Server;


namespace Server.Items
{

    public class GMTestArmor : LeatherChest
    {
        public override int BasePhysicalResistance{get {return 70;}}
        public override int BaseColdResistance{get {return 70; }}
        public override int BaseFireResistance{get {return 70; }}
        public override int BasePoisonResistance{get {return 70;}}
        public override int BaseEnergyResistance{get {return 70;}}


        [Constructable]

        public GMTestArmor()
        {
            Name = "GM Test Armor";


            ArmorAttributes.SelfRepair = 10;
            ArmorAttributes.MageArmor = 1;
            ArmorAttributes.LowerStatReq = 100;
            Attributes.BonusStr = 150;
            Attributes.BonusDex = 150;
            Attributes.BonusInt = 150;
            Attributes.BonusHits = 10000;
            Attributes.BonusStam = 200;
            Attributes.WeaponDamage = 100;
            Attributes.WeaponSpeed = 50;
            Attributes.LowerManaCost = 100;
            Attributes.LowerRegCost = 100;
        }
    }
}


Up to this point making this piece of armor is not much different then Kyn's other tutorials.  Now I am going to add a double click effect.


The goal of this piece of armor is to only need to put on 1 piece of armor if a mob I create kills me as well as have enough hit points to survive a possibly over powered mob (had a mob hit my pet for 4 thousand damage the other day).  This left the huge problem of how am I going to heal 10 thousand hit points quickly.


I looked around a little bit and found what I was looking for in the heal potion scripts.


First we need to declare the DoHeal ability and how much that heal is going to be for.  Here we can declare numbers for a range with a min and max.  I decided to give it a set number of 10 thousand hit points healed:
Code: [Select]


using System;
using Server;


namespace Server.Items
{

    public class GMTestArmor : LeatherChest
    {
        public override int BasePhysicalResistance{get {return 70;}}
        public override int BaseColdResistance{get {return 70; }}
        public override int BaseFireResistance{get {return 70; }}
        public override int BasePoisonResistance{get {return 70;}}
        public override int BaseEnergyResistance{get {return 70;}}


        [Constructable]

        public GMTestArmor()
        {
            Name = "GM Test Armor";


            ArmorAttributes.SelfRepair = 10;
            ArmorAttributes.MageArmor = 1;
            ArmorAttributes.LowerStatReq = 100;
            Attributes.BonusStr = 150;
            Attributes.BonusDex = 150;
            Attributes.BonusInt = 150;
            Attributes.BonusHits = 10000;
            Attributes.BonusStam = 200;
            Attributes.WeaponDamage = 100;
            Attributes.WeaponSpeed = 50;
            Attributes.LowerManaCost = 100;
            Attributes.LowerRegCost = 100;
        }

        public void DoHeal(Mobile from)
        {
            from.Heal(10000);
        }
    }
}


Now that we have declared how much we are going to heal for we will need to determine how this heal is going to be triggered.  I went with double clicking the chest will heal the person who is doing the double clicking for the DoHeal amount as long as you have taken any damage:
Code: [Select]


using System;
using Server;


namespace Server.Items
{

    public class GMTestArmor : LeatherChest
    {
        public override int BasePhysicalResistance{get {return 70;}}
        public override int BaseColdResistance{get {return 70; }}
        public override int BaseFireResistance{get {return 70; }}
        public override int BasePoisonResistance{get {return 70;}}
        public override int BaseEnergyResistance{get {return 70;}}


        [Constructable]

        public GMTestArmor()
        {
            Name = "GM Test Armor";


            ArmorAttributes.SelfRepair = 10;
            ArmorAttributes.MageArmor = 1;
            ArmorAttributes.LowerStatReq = 100;
            Attributes.BonusStr = 150;
            Attributes.BonusDex = 150;
            Attributes.BonusInt = 150;
            Attributes.BonusHits = 10000;
            Attributes.BonusStam = 200;
            Attributes.WeaponDamage = 100;
            Attributes.WeaponSpeed = 50;
            Attributes.LowerManaCost = 100;
            Attributes.LowerRegCost = 100;
        }

        public void DoHeal(Mobile from)
        {
            from.Heal(10000);
        }

        public override void OnDoubleClick(Mobile from)
        {
            if (from.Hits < from.HitsMax)
                DoHeal(from);


        }
    }
}


The only thing left to do is Serialize/Deserialize the script and it is ready to be used.


Code: [Select]

using System;
using Server;


namespace Server.Items
{
    public class GMTestArmor : LeatherChest
    {
        public override int BasePhysicalResistance{get {return 70;}}
        public override int BaseColdResistance{get {return 70; }}
        public override int BaseFireResistance{get {return 70; }}
        public override int BasePoisonResistance{get {return 70;}}
        public override int BaseEnergyResistance{get {return 70;}}


        [Constructable]
        public GMTestArmor()
        {
            Name = "GM Test Armor";


            ArmorAttributes.SelfRepair = 10;
            ArmorAttributes.MageArmor = 1;
            ArmorAttributes.LowerStatReq = 100;
            Attributes.BonusStr = 150;
            Attributes.BonusDex = 150;
            Attributes.BonusInt = 150;
            Attributes.BonusHits = 10000;
            Attributes.BonusStam = 200;
            Attributes.WeaponDamage = 100;
            Attributes.WeaponSpeed = 50;
            Attributes.LowerManaCost = 100;
            Attributes.LowerRegCost = 100;
        }
        public void DoHeal(Mobile from)
        {
            from.Heal(10000);
        }


        public override void OnDoubleClick(Mobile from)
        {
            if (from.Hits < from.HitsMax)
                DoHeal(from);


        }


        public GMTestArmor (Serial serial ) : base ( serial )
{
}


public override void Serialize ( GenericWriter writer)
{
base.Serialize ( writer );


writer.Write ( (int) 0);
}


public override void Deserialize( GenericReader reader )
{
base.Deserialize ( reader );


int version = reader.ReadInt();
}
    }
}


There are some extra optimizations that could be done like error checking for range on the double click and an error message if the players hit points are full.  Basically its been a long day and I might add those later for practice but not today.