using System;
using System.IO;

public class DealerMaid
{
	public Maid Maid
	{
		get
		{
			return this.m_DealerMaid;
		}
	}

	private void Init(bool is_active)
	{
		if (this.m_DealerMaid)
		{
			return;
		}
		int num = (!is_active) ? GameMain.Instance.CharacterMgr.GetStockMaidCount() : GameMain.Instance.CharacterMgr.GetMaidCount();
		for (int i = 0; i < num; i++)
		{
			Maid maid;
			if (is_active)
			{
				maid = GameMain.Instance.CharacterMgr.GetMaid(i);
			}
			else
			{
				maid = GameMain.Instance.CharacterMgr.GetStockMaid(i);
			}
			if (maid)
			{
				bool flag = maid.status.personal.uniqueName == "Muku" && maid.status.mainChara;
				if (flag)
				{
					this.m_DealerMaid = maid;
					if (is_active)
					{
						this.m_ActiveNo = maid.ActiveSlotNo;
						this.m_StockNo = -1;
					}
					else
					{
						this.m_ActiveNo = -1;
						this.m_StockNo = i;
					}
					break;
				}
			}
		}
	}

	public void Init()
	{
		if (this.m_DealerMaid)
		{
			this.SetDealerMaid(this.m_DealerMaid);
		}
		else
		{
			this.Init(true);
			this.Init(false);
		}
	}

	public void SetDealerMaid(Maid maid)
	{
		this.m_DealerMaid = maid;
		this.m_ActiveNo = maid.ActiveSlotNo;
		if (this.m_ActiveNo >= 0)
		{
			this.m_StockNo = -1;
		}
		else
		{
			for (int i = 0; i < GameMain.Instance.CharacterMgr.GetStockMaidCount(); i++)
			{
				if (maid == GameMain.Instance.CharacterMgr.GetStockMaid(i))
				{
					this.m_StockNo = i;
					break;
				}
			}
		}
	}

	public void Serialize(BinaryWriter bw)
	{
		this.Init();
		bw.Write(this.m_ActiveNo);
		bw.Write(this.m_StockNo);
	}

	public void Deserialize(BinaryReader br)
	{
		this.m_ActiveNo = br.ReadInt32();
		this.m_StockNo = br.ReadInt32();
		this.m_DealerMaid = null;
		if (this.m_ActiveNo >= 0)
		{
			this.m_DealerMaid = GameMain.Instance.CharacterMgr.GetMaid(this.m_ActiveNo);
		}
		else if (this.m_StockNo >= 0)
		{
			this.m_DealerMaid = GameMain.Instance.CharacterMgr.GetStockMaid(this.m_StockNo);
		}
		this.Init();
	}

	private int m_ActiveNo = -1;

	private int m_StockNo = -1;

	private Maid m_DealerMaid;
}
