I'm working on an Account Values System similar to ServUO's Points System but I have a few questions.

Is it possible serialize/deserialize an account? How?

This is my first try:

Code:
namespace Customs.Engines
{
    public abstract class AccountValuesSystem
    {
        public static string FilePath = Path.Combine("Saves/Custom/AccountValuesSystem", "Persistence.bin");
    }

    public class AccountValuesEntry
    {
        public Account m_Account { get; set; }
        public double Points { get; set; }

        public AccountValuesEntry(Account acct)
        {
            m_Account = acct;
        }

        public AccountValuesEntry(Account acct, double points)
        {
            m_Account = acct;
            Points = points;
        }

        public override bool Equals(object o)
        {
            if (o == null || !(o is AccountValuesEntry))
            {
                return false;
            }

            return ((AccountValuesEntry)o).m_Account == m_Account;
        }

        public override int GetHashCode()
        {
            if (m_Account != null)
                return m_Account.GetHashCode();

            return base.GetHashCode();
        }

        public virtual void Serialize(GenericWriter writer)
        {
            writer.Write(0);
            //writer.Write(m_Account); // Error Here
            writer.Write(Points);
        }

        public virtual void Deserialize(GenericReader reader)
        {
            int version = reader.ReadInt();
            //m_Account = reader.ReadMobile() as Account;// Error Here
            Points = reader.ReadDouble();
        }
    }
}

Thanks for the help!
 
My problem is here:

public virtual void Serialize(GenericWriter writer)
{
writer.Write(0);
//writer.Write(m_Account); // Error Here
writer.Write(Points);
}
public virtual void Deserialize(GenericReader reader)
{
int version = reader.ReadInt();
//m_Account = reader.ReadMobile() as Account;// Error Here
Points = reader.ReadDouble();
}


The system does not recognize writer and reader code.
 
Writer/Reader not contains overload methods for Account type, you can use account "Username" (m_Account.Username) with string type and check in deserialize if loaded username contains in Accounts.GetAccount(username).
if acc != null you can set m_Account variable.

or you can make your overload read/write method for accounts.
 
Not sure atm, but if there is a ID for the account you should rather take that, since that will probably not change but an account name in theory could change
 
Back