Levelable item deed on exceptional items.

Insert Coin

Citizen
Dec 2, 2018
49
5
3
38
Hello guys,just trying to get a levelable item deed working just on exceptional crafted items,but cant do that,need some help.
Here the code im using right now:


Code:
public class LevelItemTarget : Target
    {
        private LevelItemDeed m_Deed;
        private ItemQuality m_Quality; ///
Code:
protected override void OnTarget( Mobile from, object target )
        {
           
            if ( target is BaseWeapon )
            {
       
             Item item = (Item)target;
             XmlLevelItem a = (XmlLevelItem)XmlAttach.FindAttachment(item, typeof(XmlLevelItem));
               
                if ( m_Quality != ItemQuality.Exceptional )
                {
Any ideas?Thank you,i think error is in if ( m_Quality != ItemQuality.Exceptional ),but dont know how to do that correctly.
 

Insert Coin

Citizen
Dec 2, 2018
49
5
3
38
Oh yes sorry,Servuo is loading fine,deed works,but now can do levelable all weapons,including artifacts,i just want crafted items can be levelable.Here the full code.
 

Lokai

Moderator
ServUO Developer
Dec 4, 2014
1,323
234
63
Western New York State
Shard Name
Test Center
Donate
Donate money to this user
OK. Cool. Can you please post the whole script? Unable to tell what's going on with just the snippet. Thanks.
 

Insert Coin

Citizen
Dec 2, 2018
49
5
3
38
Here the full code:

Code:
using System;
using Server.Network;
using Server.Prompts;
using Server.Items;
using Server.Targeting;
using Server;
using Server.Engines.XmlSpawner2;

namespace Server.Items
{
    public class LevelItemTarget : Target
    {
        private LevelItemDeed m_Deed;
        private ItemQuality m_Quality;

        public LevelItemTarget( LevelItemDeed deed ) : base( 1, false, TargetFlags.None )
        {
            m_Deed = deed;
        }

        protected override void OnTarget( Mobile from, object target )
        {
           
            if ( target is BaseWeapon )
            {
       
             Item item = (Item)target;
             XmlLevelItem a = (XmlLevelItem)XmlAttach.FindAttachment(item, typeof(XmlLevelItem));
               
                if ( m_Quality != ItemQuality.Exceptional )
                {
                   
                if ( a != null )
                {
                    from.SendMessage( "That already is levelable!");
                    return;
                }
                else
                {
                    if( item.RootParent != from ) // Make sure its in their pack or they are wearing it
                    {
                        from.SendMessage( "You cannot make that levelable there!" );
                    }
                    else
                    {
                        // mod to attach the XmlPoints attachment automatically to new chars
                        XmlAttach.AttachTo(item, new XmlLevelItem());

                        from.SendMessage( "You magically make the item levelable..." );

                        m_Deed.Delete();
                    }
                }
            }
            }
            else
            {
                from.SendMessage( "You cannot make that levelable" );
            }
        }
    }

    public class LevelItemDeed : Item // Create the item class which is derived from the base item class
    {
        [Constructable]
        public LevelItemDeed() : base( 0x14F0 )
        {
            Weight = 1.0;
            Name = "a levelable item deed";
            LootType = LootType.Blessed;
            Hue = 1171;
        }
        public override void GetProperties(ObjectPropertyList list)
            {
            base.GetProperties(list);
          
            list.Add("Use on a levelable weapon to activate it.");
            }

        public LevelItemDeed( 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 );
            LootType = LootType.Blessed;

            int version = reader.ReadInt();
        }

        public override bool DisplayLootType{ get{ return false; } }

        public override void OnDoubleClick( Mobile from ) // Override double click of the deed to call our target
        {
            if ( !IsChildOf( from.Backpack ) ) // Make sure its in their pack
            {
                 from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
            }
            else
            {
                from.SendMessage("What item would you like to make levelable?"  );
                from.Target = new LevelItemTarget( this ); // Call our target
            }
        }   
    }
}
 

Lokai

Moderator
ServUO Developer
Dec 4, 2014
1,323
234
63
Western New York State
Shard Name
Test Center
Donate
Donate money to this user
Your check for Quality was not actually looking at the target item, nor was it using the correct logic to avoid the inner process. Try this one:

Code:
using System;
using Server.Network;
using Server.Prompts;
using Server.Items;
using Server.Targeting;
using Server;
using Server.Engines.XmlSpawner2;
namespace Server.Items
{
    public class LevelItemTarget : Target
    {
        private LevelItemDeed m_Deed;
        public LevelItemTarget( LevelItemDeed deed ) : base( 1, false, TargetFlags.None )
        {
            m_Deed = deed;
        }
        protected override void OnTarget( Mobile from, object target )
        {
          
            if ( !( target is BaseWeapon ) )
            {
                from.SendMessage( "You cannot make that levelable." );
            }
            else if ( ((BaseWeapon)target).Quality != ItemQuality.Exceptional )
            {
                from.SendMessage( "Only Exceptionally Crafted Items can be made levelable." );
            }
            else
            {
                Item item = (Item)target;
                XmlLevelItem a = (XmlLevelItem)XmlAttach.FindAttachment(item, typeof(XmlLevelItem));
                if ( a != null )
                {
                    from.SendMessage( "That already is levelable!");
                    return;
                }
                else
                {
                    if( item.RootParent != from ) // Make sure its in their pack or they are wearing it
                    {
                        from.SendMessage( "You cannot make that levelable there!" );
                    }
                    else
                    {
                        // mod to attach the XmlPoints attachment automatically to new chars
                        XmlAttach.AttachTo(item, new XmlLevelItem());
                        from.SendMessage( "You magically make the item levelable..." );
                        m_Deed.Delete();
                    }
                }
            }
        }
    }
    public class LevelItemDeed : Item // Create the item class which is derived from the base item class
    {
        [Constructable]
        public LevelItemDeed() : base( 0x14F0 )
        {
            Weight = 1.0;
            Name = "a levelable item deed";
            LootType = LootType.Blessed;
            Hue = 1171;
        }
        public override void GetProperties(ObjectPropertyList list)
            {
            base.GetProperties(list);
        
            list.Add("Use on a levelable weapon to activate it.");
            }
        public LevelItemDeed( 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 );
            LootType = LootType.Blessed;
            int version = reader.ReadInt();
        }
        public override bool DisplayLootType{ get{ return false; } }
        public override void OnDoubleClick( Mobile from ) // Override double click of the deed to call our target
        {
            if ( !IsChildOf( from.Backpack ) ) // Make sure its in their pack
            {
                 from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
            }
            else
            {
                from.SendMessage("What item would you like to make levelable?"  );
                from.Target = new LevelItemTarget( this ); // Call our target
            }
        } 
    }
}
 

Lokai

Moderator
ServUO Developer
Dec 4, 2014
1,323
234
63
Western New York State
Shard Name
Test Center
Donate
Donate money to this user
One more contribution, in case you decide to expand this beyond weapons, I would do it this way:

Code:
        protected override void OnTarget( Mobile from, object target )
        {
            if ( ( target is BaseWeapon ) && ((BaseWeapon)target).Quality != ItemQuality.Exceptional )
            {
                from.SendMessage( "Only Exceptional weapons can be made levelable." );
            }
            else if ( ( target is BaseArmor ) && ((BaseArmor)target).Quality != ItemQuality.Exceptional )
            {
                from.SendMessage( "Only Exceptional armor can be made levelable." );
            }
            else if (( target is BaseWeapon ) || ( target is BaseArmor ) )
            {
                Item item = (Item)target;
                XmlLevelItem a = (XmlLevelItem)XmlAttach.FindAttachment(item, typeof(XmlLevelItem));
                if ( a != null )
                {
                    from.SendMessage( "That already is levelable!");
                    return;
                }
                else
                {
                    if( item.RootParent != from ) // Make sure its in their pack or they are wearing it
                    {
                        from.SendMessage( "You cannot make that levelable there!" );
                    }
                    else
                    {
                        // mod to attach the XmlPoints attachment automatically to new chars
                        XmlAttach.AttachTo(item, new XmlLevelItem());
                        from.SendMessage( "You magically make the item levelable..." );
                        m_Deed.Delete();
                    }
                }
            }
            else
            {
                from.SendMessage( "That item cannot be made levelable!" );
            }
        }