zerodowned

Moderator
I was just writing a test "system" to try out some ideas.

I then made a test item that shows an int property in the persistence class .
Everything works as expected but I can get the int displayed on the item to update unless I move it. This is usually solved by adding InvalidateProperties; but that isn't working.

I'll post my test scripts later when I can
 
Persistence Save
Code:
#region References
using System.IO;
using System.Linq;
#endregion

namespace Server.Items
{
    public static class GlobalCount
    {
       
        private static string FilePath = Path.Combine("Saves", "GlobalCount", "GlobalCount.bin");
       
        public static int Count{ get; set; }
       
        public static void Configure()
        {
            EventSink.WorldSave += OnSave;
            EventSink.WorldLoad += OnLoad;
        }

        private static void OnSave(WorldSaveEventArgs e)
        {
            Persistence.Serialize
            (
                FilePath,
                writer =>
                {
                    writer.Write(0); // version

                    writer.Write((int)Count);
                }
            );
        }

        private static void OnLoad()
        {
            Persistence.Deserialize
            (
                FilePath,
                reader =>
                {
                    var version = reader.ReadInt();
                   
                    Count = reader.ReadInt();
                   
                }
            );
        }
    }
}

Item
Code:
using System;
using Server;
using Server.Items;

namespace Server.Items
{   
    public class GlobalCountTestItem : Item
    {
        [CommandProperty(AccessLevel.GameMaster)]
        public int CountUpdate
        {
            get { return GlobalCount.Count; }
            set
            {
                // if( CountUpdate != GlobalCount.Count )
                    // CountUpdate = GlobalCount.Count;
                //GlobalCount.Count = value;
                value = GlobalCount.Count;
                //InvalidateProperties();
            }
        }
       
        [Constructable]
        public GlobalCountTestItem() : base( 0xE73 )
        {
        }

        public GlobalCountTestItem( Serial serial ) : base( serial )
        {
        }
       
        public void Update()
        {
            InvalidateProperties();
        }

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

            list.Add( "{0}", CountUpdate );
           
        }

        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
           
            writer.Write((int)CountUpdate);
        }

        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );
           
            CountUpdate = reader.ReadInt();
        }

    }
}
 

Attachments

  • GlobalCount.cs
    833 bytes · Views: 1
  • GlobalCountMobile.cs
    1.8 KB · Views: 0
  • GlobalCountTestItem.cs
    1.1 KB · Views: 1
Well you would need to call the invalidate from the static class, I would make a list and let the items add themself on creation and delete themself when they get deleted. That way you can do a foreach and invalidate
 
i had considered a list but didn't realize that invalidate HAD to be called from the static class.

I would make a list and let the items add themself on creation and delete themself when they get deleted
Perfect, thank you, hadn't considered that
 
Well I am sure there are other ways, but I think the property in your static class would be perfect when you set it. In fact I just wrote code that does similar things :)
 
I remade the economy system script, so that it doesnt rely on the stone really but so that you can see the current multiplier and the total gold on it in its properties.

So all I really saved there was the multiplier
 
so, in the static class I would do this?

Code:
public static int Count
        {
            get{return _Count;}
            set
            {
                _Count = value;
               
                foreach( GlobalCountTestItem item in _List )
                {
                    item.InvalidateProperties();
                }
            }
        }
 
Thank you, got it all working now.

PersistenceSaves are way easier to understand than I first thought
 

Attachments

  • GlobalCountTestItem.cs
    1.2 KB · Views: 4
  • GlobalCountMobile.cs
    1.8 KB · Views: 3
  • GlobalCount.cs
    1.4 KB · Views: 3
I agree, the first time I used them I wasnt sure either, looked at disguise and thought "man thats really easy" :D
 
Back