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!

Creating a new weapon property.

bazspeed

Sorceror
only changes were at the top of both

Code:
public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );
 
            int version = reader.ReadInt();
 
            switch ( version )
            {
                case 9:
                case 8:
                case 7:
                case 6:
                case 5:

Code:
public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
 
            writer.Write( (int) 9 ); // version
 
            SaveFlag flags = SaveFlag.None;
 
            SetSaveFlag( ref flags, SaveFlag.DamageLevel,        m_DamageLevel != WeaponDamageLevel.Regular );
            SetSaveFlag( ref flags, SaveFlag.AccuracyLevel,        m_AccuracyLevel != WeaponAccuracyLevel.Regular );
            SetSaveFlag( ref flags, SaveFlag.DurabilityLevel,    m_DurabilityLevel != WeaponDurabilityLevel.Regular );
            SetSaveFlag( ref flags, SaveFlag.Quality,            m_Quality != WeaponQuality.Regular );
            SetSaveFlag( ref flags, SaveFlag.Hits,                m_Hits != 0 );
 

Soteric

Knight
As I said you need to increment version. If you have version 9, then you should make it 10. And add case 10 in Deserialize.
 

bazspeed

Sorceror
thnx, at last my inexperience pulled through.

just tested on a weapon, i can add the CritRate but i dont think it adds to the players rate, typeing [showcrit still only shows 3 which is the base.

Any ideas?

BTW, love your claim command Daat. I have it linked to my own game currency.
 

daat99

Moderator
Staff member
You need to modify the critical chance code to check for your new property.

I think there is an easier way to do that without a new property but I'm not sure (can't remember how at the moment).
 

bazspeed

Sorceror
I left this out of the baseweapon.cs, but putting it back in asks me to delete items again.

Code:
public override bool OnEquip( Mobile from )
        {
            {
        //Crit Droth
            if ( CritRate != 0 )
                {
                PlayerMobile pmfrom = from as PlayerMobile;
                pmfrom.Crit += m_CritRate;
                return base.OnEquip( from );
                }
 

daat99

Moderator
Staff member
This code snippet has nothing to do with ser/deser. It's unlikely that you are asked to delete items again just because of that one.
 

bazspeed

Sorceror
No matter how hard I try. I seem to put them all in the right places. It compiles the first time perfect and it seems no problem.

However, when i try and change the Critrate on any item it says its changed it but hasnt.

Then when i reboot server, then says error with items and asks if i want to delete them starting with dagger.

Any suggestions?
 

daat99

Moderator
Staff member
You changed your ser/deser method and you made a mistake.

You need to make sure you read the exact same information you wrote on your world save.
 

daat99

Moderator
Staff member
ser = serialization = writing.
deser = deserialization = reading.
If you write A and then B than you need to read A first and B second.

You didn't.
 

nate85

Sorceror
daat99 is right. When you get a console error saying you have to delete items, that almost always means you are not deserializing things in the same manner/order as you are serializing them.

Adding your "onEquip" function really should not affect those items. You really need to find a way to post your Seralize and Deserialize functions.
 

Vorspire

Knight
Deserializaton errors can also occur if any code running in Deserialize throws an exception (crashes).

I just implemented Critical Hit Chance Increase, Resilience and Faster Ethereal casting properties on Pandora and didn't have to modify the De/Serialize methods of anything other than in AosAttributes (AOS.cs)

If you only want Crit rating on weapons, edit AosWeaponAttributes (AOS.cs) and add your new property there, it will then apply to all weapons without the need for BaseWeapon edits.
 

bazspeed

Sorceror
Thanx Vorspire. That worked perfect.

Next question is, no matter how hard i try i cannot change the number. It shows as 0 all the time even if i place a line in a weapon

WeaponAttributes.Crit = 1;

Or even with the CritDeed I created that adds 5%.

Everything says it does add them, but never does. Any suggestions?
 

bazspeed

Sorceror
In AOS.cs

Under : public enum AosAttribute
{

added
IncreasedKarmaLoss=0x00800000,
Crit=0x10800000

Not sure if that is a good code.

Under

[CommandProperty( AccessLevel.GameMaster )]
public int IncreasedKarmaLoss { get { return this[AosAttribute.IncreasedKarmaLoss]; } set { this[AosAttribute.IncreasedKarmaLoss] = value; } }

I added

[CommandProperty( AccessLevel.GameMaster )]
public int Crit { get { return this[AosAttribute.Crit]; } set { this[AosAttribute.Crit] = value; } }


If I change GameMaster to Owner, does that mean only I can change it?

As a test I created a Crit element in a weapon.

Under the [Constructable]

I added

Attributes.Crit = 1;

I also created a Weapon Enhance Deed

Code:
using System;
using Server.Network;
using Server.Prompts;
using Server.Items;
using Server.Targeting;
using Server.Mobiles;
 
namespace Server.Items
{
    public class CritTarget : Target
    {
        private CritDeed m_Deed;
        private Mobile m_from;
 
        public CritTarget( CritDeed deed ) : base( 1, false, TargetFlags.None )
        {
            m_Deed = deed;
        }
 
        protected override void OnTarget(Mobile from, object target)
        {
            if (m_Deed.Deleted)
                return;
 
            if (target is BaseWeapon)
            {
                BaseWeapon weapon = (BaseWeapon)target;
                int Critadjust = weapon.Attributes.Crit;
 
                if (Critadjust >= 50)
                {
                    from.SendMessage(0x35, "The weapons already at 50% !!!");
                }
                else
                {
                    Critadjust = Critadjust + 5;
 
                    if (Critadjust > 50)
                    {
                        Critadjust = 50;
                        weapon.Attributes.Crit = Critadjust;
                        from.SendMessage( 0x35, "The weapon gets maxed out, 50% Crit obtained.");
                        m_Deed.Delete();
                    }
                    else
                    {
                        weapon.Attributes.Crit = Critadjust;
                        from.SendMessage( 0x35, "The weapon recieves an additional 5% Crit.");
                        m_Deed.Delete();
                    }
                }
            }
            else
            {
                from.SendMessage( 0x35, "This deed only works on weapons.");
            }
        }
    }
 
    public class CritDeed : Item // Create the item class which is derived from the base item class
    {
        [Constructable]
        public CritDeed() : base( 0x14F0 )
        {
            Weight = 1.0;
            Name = "Crit +5% Deed";
            LootType = LootType.Blessed;
            Hue = 1278;
        }
 
        public CritDeed( 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 override bool DisplayLootType{ get{ return false; } }
 
        public override void OnDoubleClick( Mobile from )
        {
            if ( !IsChildOf( from.Backpack ) )
            {
                from.SendMessage( 0x35, "The Deed Must Be In Your Bag To Use It" );
            }
            else
            {
                from.SendMessage( 0x35, "Which weapon do you want to upgrade with Crit ?" );
                from.Target = new CritTarget( this );
            }
        }   
    }
}

Hope this helps

I cannot alter the state of the Crit on any weapon in any way.
 

daat99

Moderator
Staff member
Enum are often used as boolean flags, they can't be used in order to store normal integers though.

If you want to add a new "attribute" than you need to do it like the other attributes.
Try to locate another weapon attribute and see how they are implemented.
 

bazspeed

Sorceror
Its the same as all the other ones

public enum AosAttribute
{
RegenHits=0x00000001,
RegenStam=0x00000002,
RegenMana=0x00000004,
DefendChance=0x00000008,
AttackChance=0x00000010,
BonusStr=0x00000020,
BonusDex=0x00000040,
BonusInt=0x00000080,
BonusHits=0x00000100,
BonusStam=0x00000200,
BonusMana=0x00000400,
WeaponDamage=0x00000800,
WeaponSpeed=0x00001000,
SpellDamage=0x00002000,
CastRecovery=0x00004000,
CastSpeed=0x00008000,
LowerManaCost=0x00010000,
LowerRegCost=0x00020000,
ReflectPhysical=0x00040000,
EnhancePotions=0x00080000,
Luck=0x00100000,
SpellChanneling=0x00200000,
NightSight=0x00400000,
IncreasedKarmaLoss=0x00800000,
Crit=0x10800000
}
 
Top