/**********************************************************
RunUO AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Jul-26-2011 09:17:43pm
Filepath: scripts\_custom\events and scenarios\Easter 2011\EggStatue.cs
Lines of code: 103

Description: 

***********************************************************/


using System;
using System.Collections;
using System.Collections.Generic;
using Server;
using Server.Items;
using Server.Mobiles;

namespace Server.Items
{

	public class EggStatue : Item
	{
		//Hashtable eggRecords = new Hashtable();
		//Hashtable eggPrizes = new Hashtable();
		
		Dictionary<int, int> eggRecords = new Dictionary<int, int>();
		Dictionary<int, int> eggPrizes = new Dictionary<int, int>();

		
		//Hashtable eggPrizes = new Hashtable();
		//Hashtable prizeSlot = (Hashtable)eggPrizes[columnName];
		//return hColumn.ContainsKey(codeValue);
		
		[Constructable]
		public EggStatue() : base(0x35FD)
		{
		Hue = 1153;
		Movable=false;
		}
		
		public override void OnDoubleClick( Mobile from )
		{
		if(!from.InRange(this,1))return;
		
		int whiteAmt=0, goldAmt=0;
		int points;
		
		whiteAmt = from.Backpack.GetAmount(typeof(WhiteEgg));
		goldAmt = from.Backpack.GetAmount(typeof(GoldenEgg));
		if(whiteAmt<=0 && goldAmt<=0) {
			from.SendMessage(200, "You have {0} points. Bring your Easter eggs here and double click the statue",((eggRecords.ContainsKey(from.Serial)) ? eggRecords[from.Serial] : 0));
			return;
		}
	
		Modify();
		points = whiteAmt + (goldAmt * 5);
		
		//if we made it here, we have all the components, so we can consume them		
		
		from.Backpack.ConsumeTotal(typeof(WhiteEgg),whiteAmt );
		from.Backpack.ConsumeTotal(typeof(GoldenEgg),goldAmt );

		
		if (eggRecords.ContainsKey(from.Serial))
			eggRecords[from.Serial] = (int)eggRecords[from.Serial] + points;
		else {
			eggRecords.Add(from.Serial, points);
			eggPrizes.Add(from.Serial, 10);
		}
		
		if (eggPrizes.ContainsKey(from.Serial)) {
			//Console.WriteLine("EggPrize value: " + eggPrizes[from.Serial]);
			if((int)eggRecords[from.Serial] >= 10 && (int)eggPrizes[from.Serial] <= 10) {
				eggPrizes[from.Serial] = 25;
				from.SendMessage(200, "You have been given an Easter Basket as thanks");
				from.AddToBackpack(new EasterBasket());
			}
			
			for (int i = 1; i < 40; i++) {
				if((int)eggRecords[from.Serial] >= (i*25) && (int)eggPrizes[from.Serial] <= (i*25)) {
					from.SendMessage(200, "A reward and some gold have been placed in your pack");                            
					from.AddToBackpack(new randomartydeed());
					from.AddToBackpack(new BankCheck(250000));
					eggPrizes[from.Serial] = (i+1)*25;
				}
			}
		}
		else {
			from.SendMessage(33, "Egg Prize Error");
		}
		
		from.SendMessage(200, "You turn in your eggs, you now have " + eggRecords[from.Serial] + " points");
		}		
		
		
		public EggStatue( Serial serial ) : base( serial )
		{
		}
		
		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );
			writer.Write( (int) 0 );
			
			
			//write eggRecords:
			
			writer.Write((int)eggRecords.Count); 
			
			foreach(KeyValuePair<int, int> kvp in eggRecords)
			{	
				writer.Write((int)kvp.Key);
				writer.Write((int)kvp.Value);
			}
			
			
			//write eggPrizes:
			
			writer.Write((int)eggPrizes.Count); 	
			
			foreach(KeyValuePair<int, int> kvp in eggPrizes)
			{
				writer.Write((int)kvp.Key);
				writer.Write((int)kvp.Value);
			}
			
			
		}
		
		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );
			int version = reader.ReadInt();			
			
			int tmpcount, tmpkey,tmpval; //temp vars for reading eggRecords and eggPrizes			
			
			//read eggRecords:
			tmpcount = reader.ReadInt();		
			for(int i=0;i<tmpcount;i++)
			{
				tmpkey = reader.ReadInt();
				tmpval = reader.ReadInt();
				
				if (eggRecords.ContainsKey(tmpkey)) eggRecords[tmpkey] = tmpval;
				else eggRecords.Add(tmpkey, tmpval);
			}
			
			//read eggPrizes:	
			tmpcount = reader.ReadInt();			
			for(int i=0;i<tmpcount;i++)
			{
				tmpkey = reader.ReadInt();
				tmpval = reader.ReadInt();
				
				if (eggPrizes.ContainsKey(tmpkey)) eggPrizes[tmpkey] = tmpval;
				else eggPrizes.Add(tmpkey, tmpval);
			}
			
		}
	}
}