ServUO Version
Publish Unknown
Ultima Expansion
None
This is the Advanced training Dummy script. For some odd reason the east facing dummy doesn't animate correctly. It gets stuck and does odd stuff. I Think the issue is with this portion of the script. can someone brake this portion of code down and tell me what all the numbers mean?

dummy east:
        public void UpdateItemID()
        {
            int baseItemID = (ItemID / 2) * 2;
            ItemID = baseItemID + (Swinging ? 1 : 0);      
        }

this is the full script

advanced dummy:
using System;
using Server;

namespace Server.Items
{
    public class MetalArmorTrainingDummyEast : AddonComponent
    {
        private double m_MinSkill;
        private double m_MaxSkill;

        private Timer m_Timer;

        [CommandProperty( AccessLevel.GameMaster )]
        public double MinSkill
        {
            get{ return m_MinSkill; }
            set{ m_MinSkill = value; }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public double MaxSkill
        {
            get{ return m_MaxSkill; }
            set{ m_MaxSkill = value; }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public bool Swinging
        {
            get{ return ( m_Timer != null ); }
        }

        [Constructable]
        public MetalArmorTrainingDummyEast() : this( 0x16E3 )
        {
        }

        [Constructable]
        public MetalArmorTrainingDummyEast( int itemID ) : base( itemID )
        {
            m_MinSkill = -25.0;
            m_MaxSkill = +25.0;
        }

        public void UpdateItemID()
        {
            int baseItemID = (ItemID / 2) * 2;
            ItemID = baseItemID + (Swinging ? 1 : 0);      
        }

        public void BeginSwing()
        {
            if ( m_Timer != null )
                m_Timer.Stop();

            m_Timer = new InternalTimer( this );
            m_Timer.Start();
        }

        public void EndSwing()
        {
            if ( m_Timer != null )
                m_Timer.Stop();

            m_Timer = null;

            UpdateItemID();
        }

        public void OnHit()
        {
            UpdateItemID();
            Effects.PlaySound( GetWorldLocation(), Map, Utility.RandomList( 0x3A4, 0x3A6, 0x3A9, 0x3AE, 0x3B4, 0x3B6 ) );
        }

        public void Use( Mobile from, BaseWeapon weapon )
        {
            BeginSwing();

            from.Direction = from.GetDirectionTo( GetWorldLocation() );
            weapon.PlaySwingAnimation( from );

            from.CheckSkill( weapon.Skill, m_MinSkill, m_MaxSkill );
        }

        public override void OnDoubleClick( Mobile from )
        {
            BaseWeapon weapon = from.Weapon as BaseWeapon;

            if ( weapon is BaseRanged )
                SendLocalizedMessageTo( from, 501822 ); // You can't practice ranged weapons on this.
            else if ( weapon == null || !from.InRange( GetWorldLocation(), weapon.MaxRange ) )
                SendLocalizedMessageTo( from, 501816 ); // You are too far away to do that.
            else if ( Swinging )
                SendLocalizedMessageTo( from, 501815 ); // You have to wait until it stops swinging.
            else if ( from.Skills[weapon.Skill].Base >= m_MaxSkill )
                SendLocalizedMessageTo( from, 501828 ); // Your skill cannot improve any further by simply practicing with a dummy.
            else if ( from.Mounted )
                SendLocalizedMessageTo( from, 501829 ); // You can't practice on this while on a mount.
            else
                Use( from, weapon );
        }

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

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

            writer.Write( (int) 0 );

            writer.Write( m_MinSkill );
            writer.Write( m_MaxSkill );
        }

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

            int version = reader.ReadInt();

            switch ( version )
            {
                case 0:
                {
                    m_MinSkill = reader.ReadDouble();
                    m_MaxSkill = reader.ReadDouble();

                    if ( m_MinSkill == 0.0 && m_MaxSkill == 100.0 )
                    {
                        m_MinSkill = -100.0;
                        m_MaxSkill = +100.0;
                    }

                    break;
                }
            }

            UpdateItemID();
        }

        private class InternalTimer : Timer
        {
            private MetalArmorTrainingDummyEast m_Dummy;
            private bool m_Delay = true;

            public InternalTimer( MetalArmorTrainingDummyEast dummy ) : base( TimeSpan.FromSeconds( 0.25 ), TimeSpan.FromSeconds( 2.75 ) )
            {
                m_Dummy = dummy;
                Priority = TimerPriority.FiftyMS;
            }

            protected override void OnTick()
            {
                if ( m_Delay )
                    m_Dummy.OnHit();
                else
                    m_Dummy.EndSwing();

                m_Delay = !m_Delay;
            }
        }
    }

    public class MetalArmorTrainingDummyEastAddon : BaseAddon
    {
        public override BaseAddonDeed Deed{ get{ return new MetalArmorTrainingDummyEastDeed(); } }

        [Constructable]
        public MetalArmorTrainingDummyEastAddon()
        {
            AddComponent( new MetalArmorTrainingDummyEast( 0x16E3 ), 0, 0, 0 );
            AddComponent(new AddonComponent(0x16EE), 0, 0, 0);
            AddComponent(new AddonComponent(0x16ED), -1, 1, 0);
            AddComponent(new AddonComponent(0x16EC), 0, 1, 0);
            AddComponent(new AddonComponent(0x16EA), 1, 1, 0);
            AddComponent(new AddonComponent(0x16F1), -1, -1, 0);
            AddComponent(new AddonComponent(0x16F0), 0, -1, 0);
            AddComponent(new AddonComponent(0x16EF), 1, -1, 0);          
        }

        public MetalArmorTrainingDummyEastAddon( 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();
        }
    }

    public class MetalArmorTrainingDummyEastDeed : BaseAddonDeed
    {
        public override BaseAddon Addon{ get{ return new MetalArmorTrainingDummyEastAddon(); } }

        [Constructable]
        public MetalArmorTrainingDummyEastDeed()
        {
            Name = "Metal Armor Training Dummy East";          
        }

        public MetalArmorTrainingDummyEastDeed( Serial serial ) : base( serial )
        {
            Name = "Metal Armor Training Dummy East";          
        }

        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();
        }
    }
}
 
Back