Dan

Moderator
So I have it so my big fish will save the date and time. However now it will not save the amount of stones on restart and instead create a random number between 3 and 200. I have tried a lot of things but can not figure it out

My Code

Code:
// total change

using System;
using Server.Network;
using Server.Targeting;

namespace Server.Items
{
    public class BigFish : Item, ICarvable
    {
        private Mobile m_Fisher;
        private DateTime m_CaughtTime = DateTime.UtcNow;  //

        [CommandProperty(AccessLevel.GameMaster)]
        public Mobile Fisher
        {
            get { return m_Fisher; }
            set { m_Fisher = value; InvalidateProperties(); }
        }
        [CommandProperty(AccessLevel.GameMaster)] //
        public DateTime CaughtTime
        {
            get { return m_CaughtTime; }
            set { m_CaughtTime = value; }
        }
        public void Carve(Mobile from, Item item)
        {
            base.ScissorHelper(from, new RawFishSteak(), Math.Max(16, (int)Weight) / 4, false);
        }

        public override int LabelNumber { get { return 1041112; } } // a big fish

        [Constructable]
        public BigFish()
            : base(0x09CC)
        {
            Weight = Utility.RandomMinMax(3, 200);	//TODO: Find correct formula.  max on OSI currently 200, OSI dev says it's not 200 as max, and ~ 1/1,000,000 chance to get highest
            Hue = Utility.RandomBool() ? 0x847 : 0x58C;
            m_CaughtTime = DateTime.UtcNow;  //
        }

        public override void GetProperties(ObjectPropertyList list)
        {
            base.GetProperties(list);

            if (Weight >= 20)
            {
                if (m_Fisher != null)
                    list.Add(1070857, m_Fisher.Name); // Caught by ~1_fisherman~
                list.Add("On " + m_CaughtTime);
                list.Add(1070858, ((int)Weight).ToString()); // ~1_weight~ stones
            }
        }

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

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

            writer.Write((int)2); // version
            writer.Write(m_CaughtTime);
            writer.Write((Mobile)m_Fisher);
        }

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

            int version = reader.ReadInt();

            switch (version)
            {
                case 2:
                    {
                        m_CaughtTime = reader.ReadDateTime();
                        goto case 1;
                    }
                case 1:
                    {
                        m_Fisher = reader.ReadMobile();
                        goto case 0;
                    }
                case 0:
                    {
                        this.Weight = Utility.RandomMinMax(3, 200);
                        break;
                    }
            }
        }
    }
}
 
and ORIG code

Code:
using System;
using Server.Network;
using Server.Targeting;

namespace Server.Items
{
	public class BigFish : Item, ICarvable
	{
		private Mobile m_Fisher;

		[CommandProperty( AccessLevel.GameMaster )]
		public Mobile Fisher
		{
			get{ return m_Fisher; }
			set{ m_Fisher = value; InvalidateProperties(); }
		}

		public void Carve( Mobile from, Item item )
		{
			base.ScissorHelper( from, new RawFishSteak(), Math.Max( 16, (int)Weight ) / 4 , false );
		}

		public override int LabelNumber{ get{ return 1041112; } } // a big fish

		[Constructable]
		public BigFish() : base( 0x09CC )
		{
			Weight = Utility.RandomMinMax( 3, 200 );	//TODO: Find correct formula.  max on OSI currently 200, OSI dev says it's not 200 as max, and ~ 1/1,000,000 chance to get highest
			Hue = Utility.RandomBool() ? 0x847 : 0x58C;
		}

		public override void GetProperties( ObjectPropertyList list )
		{
			base.GetProperties( list );

			if ( Weight >= 20 )
			{
				if ( m_Fisher != null )
					list.Add( 1070857, m_Fisher.Name ); // Caught by ~1_fisherman~

				list.Add( 1070858, ((int)Weight).ToString() ); // ~1_weight~ stones
			}
		}

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

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

			writer.Write( (int) 1 ); // version

			writer.Write( (Mobile) m_Fisher );
		}

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

			int version = reader.ReadInt();

			switch ( version )
			{
				case 1:
				{
					m_Fisher = reader.ReadMobile();
					break;
				}
				case 0:
				{
					Weight = Utility.RandomMinMax( 3, 200 );
					break;
				}
			}
		}
	}
}
 
Of Course!

Code:
using System;
using Server.Network;
using Server.Targeting;

namespace Server.Items
{
    public class BigFish : Item, ICarvable
    {
        private Mobile m_Fisher;
        private DateTime m_CaughtTime = DateTime.UtcNow;  //

        [CommandProperty(AccessLevel.GameMaster)]
        public Mobile Fisher
        {
            get { return m_Fisher; }
            set { m_Fisher = value; InvalidateProperties(); }
        }
        [CommandProperty(AccessLevel.GameMaster)] //
        public DateTime CaughtTime
        {
            get { return m_CaughtTime; }
            set { m_CaughtTime = value; }
        }
        public void Carve(Mobile from, Item item)
        {
            base.ScissorHelper(from, new RawFishSteak(), Math.Max(16, (int)Weight) / 4, false);
        }

        public override int LabelNumber { get { return 1041112; } } // a big fish

        [Constructable]
        public BigFish()
            : base(0x09CC)
        {
            Weight = Utility.RandomMinMax(3, 200);	//TODO: Find correct formula.  max on OSI currently 200, OSI dev says it's not 200 as max, and ~ 1/1,000,000 chance to get highest
            Hue = Utility.RandomBool() ? 0x847 : 0x58C;
            m_CaughtTime = DateTime.UtcNow;  //
        }

        public override void GetProperties(ObjectPropertyList list)
        {
            base.GetProperties(list);

            if (Weight >= 20)
            {
                if (m_Fisher != null)
                    list.Add(1070857, m_Fisher.Name); // Caught by ~1_fisherman~
                list.Add("On " + m_CaughtTime);
                list.Add(1070858, ((int)Weight).ToString()); // ~1_weight~ stones
            }
        }

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

      public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);
            writer.Write((int)3); // version was changed to 3
            writer.Write(m_CaughtTime);
            writer.Write((Mobile)m_Fisher);
            writer.Write((int)Weight); // this time we save the weight last, if we are reading a save file from version 2 or lower than it won't have the weight in it
        }
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();
            switch (version)
            {
                case 3: //we are doing the same thing for v3 as we did in v2, no code changes
                case 2:
                    {
                        m_CaughtTime = reader.ReadDateTime();
                        goto case 1;
                    }
                case 1:
                    {
                        m_Fisher = reader.ReadMobile();
                        goto case 0;
                    }
                case 0:
                    {
                        {
                            Weight = reader.ReadInt(); //save file from version 3 expects the Weight value to be the last value saved.
                        }
                        break;
                    }
            }
        }
	}
}
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back