All pastes #625471 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-07-18 23:18 UTC
rendered paste body
using System;
using Server.IN.Logging;
using Server.Items;
using Server.Network;

namespace Server.Gumps
{
	public class RewardGump : Gump
	{
		public enum Buttons
		{
			colorCodeEntry,
			upButton,
			downButton,
			applyButton,
			okButton,
			nameEntry
		}

		private SkillInfo m_Skill;
		private int m_CurrentHue;
		private string m_Name;

		private int[] m_StaffColors = new int[]{ 0x001, 0x493, 0x77a, 0x79b, 0x7a5, 0x7ab, 0x9ad, 0xa8e, 0xa8f, 0xa97, 0xb92, 0xb94, 0xb96 };

		public RewardGump( SkillInfo skill, int currentHue, string name ) : base( 100, 100 )
		{
			this.m_Skill = skill;
			this.m_CurrentHue = currentHue;
			this.m_Name = name;

			this.Closable = true;
			this.Disposable = true;
			this.Dragable = true;
			this.Resizable = false;
			this.AddPage( 0 );
			this.AddBackground( 100, 100, 200, 227, 9200 );
			this.AddLabel( 128, 112, 0, GetSkillTitle() );
			this.AddTextEntry( 137, 188, 62, 19, 0, (int)Buttons.colorCodeEntry, Convert.ToString( this.m_CurrentHue ) );
			this.AddLabel( 115, 146, 0, @"Congrats, Enter a color code." );
			this.AddButton( 115, 180, 250, 250, (int)Buttons.upButton, GumpButtonType.Reply, 0 );
			this.AddButton( 114, 201, 252, 252, (int)Buttons.downButton, GumpButtonType.Reply, 0 );
			this.AddButton( 133, 298, 239, 248, (int)Buttons.applyButton, GumpButtonType.Reply, 0 );
			this.AddItem( 215, 185, this.GetItemId(), this.m_CurrentHue );
			this.AddLabel( 114, 233, 0, @"Enter an acceptable name." );
			this.AddTextEntry( 120, 266, 153, 20, 0, (int)Buttons.nameEntry, this.m_Name );
			this.AddButton( 207, 297, 247, 248, (int)Buttons.okButton, GumpButtonType.Reply, 0 );
		}

		private int GetItemId()
		{
			int itemId = -1;

			switch( this.m_Skill.SkillID )
			{
				case 0: // alchemy
					itemId = 0xE9B;
					break;
				case 7: // Blacksmithy
					itemId = 0x13E3;
					break;
				case 8: // Bowcraft/fletching
					itemId = 0x13B1;
					break;
				case 11: // Carpentry
					itemId = 0xF44;
					break;
				case 23: // Inscription
					itemId = 0xFC0;
					break;
				case 25: // Magery
					itemId = 0xE3B;
					break;
				case 34: // Tailoring
					itemId = 0xFAB;
					break;
				case 35: // Animal Taming
					itemId = 0xE82;
					break;
			}

			return itemId;
		}

		private string GetSkillTitle()
		{
			string Title = null;

			switch( this.m_Skill.SkillID )
			{
				case 0: // alchemy
					Title = "GM Alchemy Reward";
					break;
				case 7: // Blacksmithy
					Title = "GM Blacksmith Reward";
					break;
				case 8: // Bowcraft/fletching
					Title = "GM Bowcraft Reward";
					break;
				case 11: // Carpentry
					Title = "GM Carpentry Reward";
					break;
				case 23: // Inscription
					Title = "GM Inscription Reward";
					break;
				case 25: // Magery
					Title = "GM Magery Reward";
					break;
				case 34: // Tailoring
					Title = "GM Tailoring Reward";
					break;
				case 35: // Animal Taming
					Title = "GM Animal Taming Reward";
					break;
			}

			return Title;
		}

		public override void OnResponse( NetState sender, RelayInfo info )
		{
			try
			{
				string hue = info.GetTextEntry( (int)Buttons.colorCodeEntry ).Text;

				if( hue.StartsWith( "0x" ) )
					this.m_CurrentHue = Convert.ToInt32( hue, 16 );
				else
					this.m_CurrentHue = Convert.ToInt32( hue );

				for( int i = 0; i < m_StaffColors.Length; i++ )
					if( this.m_CurrentHue == m_StaffColors[i] )
					{
						sender.Mobile.SendMessage( "Invalid Hue Selected:  That is a staff only color" );
						sender.Mobile.SendGump( new RewardGump( this.m_Skill, ++this.m_CurrentHue, this.m_Name ) );
						return;
					}
			}
			catch
			{
				sender.Mobile.SendMessage( "Invalid Hue Selected:  Enter as an integer or hex number (0x)" );
				sender.Mobile.SendGump( new RewardGump( this.m_Skill, 0, this.m_Name ) );
				return;
			}

			this.m_Name = info.GetTextEntry( (int)Buttons.nameEntry ).Text;

			switch( info.ButtonID )
			{
				case (int)Buttons.upButton:
				{
					sender.Mobile.SendGump( new RewardGump( this.m_Skill, ++this.m_CurrentHue, this.m_Name ) );
					break;
				}
				case (int)Buttons.downButton:
				{
					sender.Mobile.SendGump( new RewardGump( this.m_Skill, --this.m_CurrentHue, this.m_Name ) );
					break;
				}
				case (int)Buttons.applyButton:
				{
					sender.Mobile.SendGump( new RewardGump( this.m_Skill, this.m_CurrentHue, this.m_Name ) );
					break;
				}
				case (int)Buttons.okButton:
				{
					Process( sender.Mobile );
					sender.Mobile.CloseGump( typeof( RewardGump ) );
					break;
				}
				default:
				{
					sender.Mobile.SendGump( new RewardGump( this.m_Skill, this.m_CurrentHue, this.m_Name ) );
					break;
				}
			}
		}

		private void Process( Mobile from )
		{
			Item rewardItem;

			switch( this.m_Skill.SkillID )
			{
				case 0: // alchemy
					rewardItem = new MortarPestle();
					break;
				case 7: // Blacksmithy
					rewardItem = new GMSmithHammer();
					break;
				case 8: // Bowcraft/fletching
					rewardItem = new Bow();
					break;
				case 11: // Carpentry
					rewardItem = new Hatchet();
					break;
				case 23: // Inscription
					rewardItem = new ScribesPen();
					break;
				case 25: // Magery
					rewardItem = new Spellbook();
					( rewardItem as Spellbook ).Content = ulong.MaxValue;
					break;
				case 34: // Tailoring
					rewardItem = new RewardDyeTub();
					break;
				case 35: // Animal Taming
					rewardItem = new ShepherdsCrook();
					break;
				default:
					return;
			}

			rewardItem.Hue = this.m_CurrentHue;
			rewardItem.LootType = LootType.Blessed;

			if( this.m_Name != "" )
				rewardItem.Name = this.m_Name;

			if( rewardItem is DyeTub )
			{
				RewardDyeTub tub = (RewardDyeTub)rewardItem;
				tub.DyedHue = rewardItem.Hue;
                tub.Owner = from;

			}
			else if( rewardItem is GMSmithHammer )
			{
				GMSmithHammer hammer = (GMSmithHammer)rewardItem;
				hammer.Owner = from;
			}

			from.AddToBackpack( rewardItem );

			// Log
			RewardLogging.WriteLine( from, this.m_Skill, this.m_Name, this.m_CurrentHue );
		}
	}
}