RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Enums

Rykor

Wanderer
I have read all i can find on enums and there doesn't seem to be much. They look very useful and i would like to figure them out here is what i am trying. I keep getting error missing reference i am not sure how to do that.

Code:
namespace Server.Items
 
{
 
    public enum Sharpness  // i realize a bool would be better but this just example
    {
 
        Sharp,
        Dull
 
    }
 
        private Sharpness mSharp;  // this is the instanced one?
        public Sharpness Sharp  // this one is public in order to change the instanced one?
        {
            get { return mSharp; }
            set { mSharp = value; }
        }
 
        Sharpness Sharp = Sharp.Dull; // this is how i use the enum?
 
}
 

Mortis

Knight
Being this was posted in the tutorial topic. I will attempt to turn it into a tutorial.

Assuming the enums are in the item script.

In Item script add

Code:
        public enum Sharpness  // i realize a bool would be better but this just example
        {
 
            Dull, // You always want the default to be first.
            Sharp
 
    }

Within (best just under the class).
As seen below within the SharpDagger.cs

Code:
        private Sharpness m_Sharp; // this is the instanced one?
 
        [CommandProperty( AccessLevel.Administrator )]
 
        public Sharpness Sharp  // this one is public in order to change the instanced one?
 
        {
 
            get { return m_Sharp; }
 
            set { m_Sharp = value; }
 
        }
In your Method.
Code:
        if ( Sharp != Sharpness.Sharp )
        {
                        //Your code here
        }
or
Code:
        if ( Sharp != Sharpness.Dull )
        {
                        //Your code here
        }
or
Code:
        if ( Sharp == Sharpness.Sharp )
        {
                        //Your code here
        }
or
Code:
        if ( Sharp == Sharpness.Dull )
        {
                        //Your code here
        }

If in PlayerMobile.cs
Add to PlayerMobile.cs
Code:
        private Sharpness m_Sharp; // this is the instanced one?
 
        [CommandProperty( AccessLevel.Administrator )]
 
        public Sharpness Sharp  // this one is public in order to change the instanced one?
 
        {
 
            get { return m_Sharp; }
 
            set { m_Sharp = value; }
 
        }
To reference it from another script in your method.
Code:
        if ( from is PlayerMobile && ((PlayerMobile)from).Sharp != Sharpness.Sharp )
        {
                        //Your code here
        }

or
Code:
        if ( from is PlayerMobile && ((PlayerMobile)from).Sharp != Sharpness.Dull )
        {
                        //Your code here
        }
or
Code:
        if ( from is PlayerMobile && ((PlayerMobile)from).Sharp == Sharpness.Sharp )
        {
                        //Your code here
        }
or
Code:
        if ( from is PlayerMobile && ((PlayerMobile)from).Sharp == Sharpness.Dull )
        {
                        //Your code here
        }

For this one I will post a working script.
If Enums in a script all by them selves. Say Sharp.cs

Add to your item script.
Code:
using Server.Sharp
In your Method.
Code:
if ( Sharp != Sharpness.Sharp )
{
//Your code here
}
or
Code:
if ( Sharp != Sharpness.Dull )
{
//Your code here
}
or
Code:
if ( Sharp == Sharpness.Sharp )
{
//Your code here
}
or
Code:
if ( Sharp == Sharpness.Dull )
{
//Your code here
}

Sharp.cs
Code:
using System;
using Server.Items;
 
namespace Server.Sharp
 
{
 
        public enum Sharpness  // i realize a bool would be better but this just example
        {
 
            Dull, // You always want the default to be first.
            Sharp
 
    }
}

SharpDagger.cs
Code:
using System;
using Server.Network;
using Server.Targeting;
using Server.Items;
using Server.Sharp;
 
namespace Server.Items
{
 
    [FlipableAttribute( 0xF52, 0xF51 )]
    public class SharpDagger : BaseKnife
    {
 
        private Sharpness m_Sharp; // this is the instanced one?
 
        [CommandProperty( AccessLevel.Administrator )]
        public Sharpness Sharp  // this one is public in order to change the instanced one?
        {
            get { return m_Sharp; }
            set { m_Sharp = value; }
        }
 
        public override WeaponAbility PrimaryAbility{ get{ return WeaponAbility.InfectiousStrike; } }
        public override WeaponAbility SecondaryAbility{ get{ return WeaponAbility.ShadowStrike; } }
 
        public override int AosStrengthReq{ get{ return 10; } }
        public override int AosMinDamage{ get{ return 10; } }
        public override int AosMaxDamage{ get{ return 11; } }
        public override int AosSpeed{ get{ return 56; } }
        public override float MlSpeed{ get{ return 2.00f; } }
 
        public override int OldStrengthReq{ get{ return 1; } }
        public override int OldMinDamage{ get{ return 3; } }
        public override int OldMaxDamage{ get{ return 15; } }
        public override int OldSpeed{ get{ return 55; } }
 
        public override int InitMinHits{ get{ return 31; } }
        public override int InitMaxHits{ get{ return 40; } }
 
        public override SkillName DefSkill{ get{ return SkillName.Fencing; } }
        public override WeaponType DefType{ get{ return WeaponType.Piercing; } }
        public override WeaponAnimation DefAnimation{ get{ return WeaponAnimation.Pierce1H; } }
 
        [Constructable]
        public SharpDagger() : base( 0xF52 )
        {
            Weight = 1.0;
        }
                public override void OnDoubleClick(Mobile from)
                {
            if ( Sharp == Sharpness.Dull )
            {
            //Would probably like to make a sharpening stone and have it target it to sharpen.
            Sharp = Sharpness.Sharp;
            }
        }
        public SharpDagger( Serial serial ) : base( serial )
        {
        }
 
        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
 
            writer.Write( (int) 0 ); // version
        }
 
        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );
 
            int version = reader.ReadInt();
        }
    }
}

You would most likely want to Serialize/Deserialize in order to keep the properties of the Item/Mobile. That is another tutorial.
 
Top