using System;
using System.Collections;
using System.IO;
using Server;
using Server.Items;
using Server.Misc;
using Server.Gumps;
using Server.Mobiles;
using Server.Network;
namespace Server.Mobiles
{
public class TokenExchanger : Mobile
{
private bool b_Active = true;
private int i_ExchangeRate = 20; //20 token for 1 gold
private int i_CoinLimit = 10000; //Limit of gold returned or tokens given before a check is used
[CommandProperty( AccessLevel.GameMaster )]
public int ExchangeRate
{
get{ return i_ExchangeRate; }
set{ i_ExchangeRate = value; InvalidateProperties(); }
}
[CommandProperty( AccessLevel.GameMaster )]
public bool Active
{
get { return b_Active; }
set { b_Active = value; }
}
[CommandProperty( AccessLevel.GameMaster )]
public int CoinLimit
{
get{ return i_CoinLimit; }
set{ i_CoinLimit = value; InvalidateProperties(); }
}
[Constructable]
public TokenExchanger()
{
Body = 400;
Name = "Token Exchanger:";
Title = "Exchange Rate is " + ExchangeRate + " to 1";
Hue = Utility.RandomSkinHue();
Blessed = true;
Direction = (Direction)3;
InitStats( 100, 25, 100 );
AddItem( new LongPants( Utility.RandomNeutralHue() ) );
AddItem( new FancyShirt( Utility.RandomNeutralHue() ) );
AddItem( new Boots( Utility.RandomNeutralHue() ) );
AddItem( new Cloak( Utility.RandomNeutralHue() ) );
AddItem( new BodySash( Utility.RandomNeutralHue() ) );
Container pack = new Backpack();
pack.Movable = false;
AddItem( pack );
}
public override bool OnDragDrop( Mobile m, Item t )
{
if ( b_Active )
{
if ( t is Tokens )
{
int i_Amount = t.Amount;
int i_Gold = i_Amount / i_ExchangeRate;
int i_Tokens = i_Gold * i_ExchangeRate;
m.SendGump( new TokenExchangerGump( m, i_ExchangeRate, i_Tokens, i_Amount, i_CoinLimit ) );
return true;
}
else if (t is TokenCheck )
{
int i_Amount = ((TokenCheck)t).Worth;
int i_Gold = i_Amount / i_ExchangeRate;
int i_Tokens = i_Gold * i_ExchangeRate;
m.SendGump( new TokenExchangerGump( m, i_ExchangeRate, i_Tokens, i_Amount, i_CoinLimit ) );
return true;
}
else
{
m.SendMessage( "This isn't tokens!" );
return false;
}
}
else
{
m.SendMessage( "The Exchanger is not active now. Please try again later" );
return false;
}
}
//Admin Gump
public override void OnDoubleClick( Mobile from )
{
if ( from.AccessLevel > AccessLevel.Counselor )
{
from.SendGump( new TokenExchangerAdminGump( this, this.Active, this.CoinLimit, this.ExchangeRate ) );
}
}
public TokenExchanger( Serial serial ) : base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
writer.Write( b_Active );
writer.Write( i_ExchangeRate );
writer.Write( i_CoinLimit );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
b_Active = reader.ReadBool();
i_ExchangeRate = reader.ReadInt();
i_CoinLimit = reader.ReadInt();
}
}
}
namespace Server.Gumps
{
public class TokenExchangerGump : Gump
{
private Mobile m_From;
private int i_Tokens;
private int i_ExchangeRate;
private int i_Gold;
private int i_Amount;
private int i_CoinLimit;
public TokenExchangerGump(Mobile from, int ExchangeRate, int tokens, int amount, int coinlimit): base( 100, 100 )
{
i_Amount = amount;
m_From = from;
i_Tokens = tokens;
i_ExchangeRate = ExchangeRate;
i_CoinLimit = coinlimit;
int gold = i_Tokens / i_ExchangeRate;
from.SendMessage("You are wanting to exchange {0} token pieces", tokens );
Closable=false;
Disposable=true;
Dragable=true;
Resizable=false;
AddPage(0);
AddBackground(0, 0, 280, 130, 5054); //Grey Background 129
AddImageTiled(13, 15, 253, 21, 3604); //Top Dark Blue Box
AddLabel(17, 15, 1153, "The current Exchange rate is " + ExchangeRate + " to 1");
AddLabel(16, 50, 1153, tokens + " token for " + gold +" Gold" );
AddImageTiled(43, 70, 145, 21, 3604); //Bottom Dark Blue Box
AddLabel(53, 69, 1153, "Is this agreeable?");
AddImageTiled(43, 89, 145, 21, 3004); //White Yes/No Box
AddButton(53, 93, 1209, 1210, 1, GumpButtonType.Reply, 0); //Yes Button
AddLabel(77, 90, 0, "Yes");
AddButton(132, 93, 1209, 1210, 2, GumpButtonType.Reply, 0); //No Button
AddLabel(152, 90, 0, "No");
AddImageTiled(43, 70, 1, 41, 2624); //Outlining - Verticle - Left
AddImageTiled(43, 70, 144, 1, 2624); //Outlining - Horizontal - Top
AddImageTiled(188, 70, 1, 41, 2624); //Outlining - Verticle - Right
AddImageTiled(44, 89, 144, 1, 2624); //Outlining - Horizontal - Middle
AddImageTiled(115, 89, 1, 22, 2624); //Outlining - Verticle - Middle
AddImageTiled(44, 110, 144, 1, 2624); //Outlining - Horizontal - Bottom
}
public override void OnResponse( NetState state, RelayInfo info )
{
Mobile m_From = state.Mobile;
Container c = m_From.Backpack;
int i_Gold = i_Tokens / i_ExchangeRate;
switch ( info.ButtonID )
{
case 1: //Yes
{
if ( c != null )
{
if ( i_Gold > i_CoinLimit || i_Gold > 60000 )
{
m_From.AddToBackpack( new BankCheck( i_Gold ) ); //gold Exchanged
if ( ( i_Amount - i_Gold ) > 0)
{
m_From.AddToBackpack( new Tokens( i_Amount - i_Tokens ) ); //return Remainder of tokens
}
}
else
{
m_From.AddToBackpack( new Gold( i_Gold ) ); //Tokens Exchanged
if ( ( i_Amount - i_Tokens ) > 0)
{
m_From.AddToBackpack( new Tokens( i_Amount - i_Tokens ) ); //return Remainder of tokens
}
}
}
break;
}
case 2: //No
{
if ( c != null )
{
if ( i_Amount > i_CoinLimit || i_Amount > 60000)
{
m_From.AddToBackpack( new TokenCheck( i_Amount ) ); //return Remainder of tokens
}
else
{
m_From.AddToBackpack( new Tokens( i_Amount ) ); //Return ALL gold
}
}
break;
}
}
}
}
public class TokenExchangerAdminGump : Gump
{
private TokenExchanger Exchanger;
public TokenExchangerAdminGump(TokenExchanger m_exchanger, bool Active, int CoinLimit, int ExchangeRate): base( 100, 100 )
{
Exchanger = m_exchanger;
Closable=true;
Disposable=true;
Dragable=true;
Resizable=false;
AddPage(0);
AddBackground(0, 0, 300, 129, 5054); //Grey Background
AddLabel(82, 4, 1153, "Token Exchanger Admin");
AddImageTiled(8, 32, 279, 87, 3604); //Dark Blue Box
//Active
AddLabel(27, 39, 1153, "Active");
AddImageTiled(20, 69, 59, 20, 3004); //White Active Box
AddTextEntry( 25, 69, 53, 20, 0, 90, Active.ToString() );
//Coin Limit
AddLabel(114, 39, 1153, "Coin Limit");
AddImageTiled(118, 69, 59, 20, 3004); //White Coin Limit Box
AddTextEntry( 123, 69, 53, 20, 0, 91, CoinLimit.ToString() );
//Exchange Rate
AddLabel(232, 39, 1153, "Rate");
AddImageTiled(216, 69, 59, 20, 3004); //White Exchange Rate Box
AddTextEntry( 221, 69, 53, 20, 0, 92, ExchangeRate.ToString() );
AddButton(260, 100, 1209, 1210, 93, GumpButtonType.Reply, 0); //Apply Button
AddLabel(222, 95, 1153, "Apply");
}
public override void OnResponse( NetState state, RelayInfo info )
{
Mobile m_From = state.Mobile;
if ( Exchanger.Deleted )
return;
switch ( info.ButtonID )
{
case 93: //Apply
{
try
{
TextRelay t_active = info.GetTextEntry( 90 );
Exchanger.Active = Convert.ToBoolean (t_active.Text);
TextRelay t_coinlimit = info.GetTextEntry( 91 );
Exchanger.CoinLimit = Convert.ToInt32(t_coinlimit.Text);
TextRelay t_exchangerate = info.GetTextEntry( 92 );
Exchanger.ExchangeRate = Convert.ToInt32(t_exchangerate.Text);
Exchanger.Title = "Exchange Rate is " + Exchanger.ExchangeRate + " to 1";
break;
}
catch{break;}
}
}
}
}
}