servuo/Scripts/Services/UltimaStore/PlayerProfile.cs
VitaNex fecdcd5f08 + Ultima Store optimizations and housekeeping.
+ Add config file for Ultima Store.
+ Add config file parsing support for Types and Delegates.
+ Add support for delayed state timers with callbacks up to 4 parameters.
+ Add Utility.WriteConsoleColor overload for string formatting.
2018-08-03 17:41:20 +01:00

79 lines
No EOL
1.8 KiB
C#

using System.Collections.Generic;
namespace Server.Engines.UOStore
{
public class PlayerProfile
{
public const StoreCategory DefaultCategory = StoreCategory.Featured;
public const SortBy DefaultSortBy = SortBy.Newest;
public Dictionary<StoreEntry, int> Cart { get; private set; }
public Mobile Player { get; private set; }
public StoreCategory Category { get; set; }
public SortBy SortBy { get; set; }
public PlayerProfile(Mobile m)
{
Cart = new Dictionary<StoreEntry, int>();
Player = m;
Category = DefaultCategory;
SortBy = DefaultSortBy;
}
public PlayerProfile(GenericReader reader)
{
Cart = new Dictionary<StoreEntry, int>();
Deserialize(reader);
}
public void AddToCart(StoreEntry entry, int amount)
{
if (Cart.Count < Configuration.CartCapacity)
{
Cart[entry] = amount;
}
}
public void RemoveFromCart(StoreEntry entry)
{
Cart.Remove(entry);
}
public void SetCartAmount(StoreEntry entry, int amount)
{
if (amount > 0)
{
AddToCart(entry, amount);
}
else
{
RemoveFromCart(entry);
}
}
public void Serialize(GenericWriter writer)
{
writer.Write(0);
writer.Write(Player);
writer.Write((int)Category);
writer.Write((int)SortBy);
}
public void Deserialize(GenericReader reader)
{
reader.ReadInt();
Player = reader.ReadMobile();
Category = (StoreCategory)reader.ReadInt();
SortBy = (SortBy)reader.ReadInt();
}
}
}