Free");
AddButton(width / 2 - 80, y, c_Contract.Free ? 0xD3 : 0xD2, "Free", new GumpCallback(Free));
AddButton(width / 2 + 60, y, c_Contract.Free ? 0xD3 : 0xD2, "Free", new GumpCallback(Free));
if ( !c_Contract.Free )
{
AddHtml( 0, y+=25, width/2-20, "Per " + c_Contract.PriceTypeShort);
AddTextField( width/2+20, y, 70, 20, 0x480, 0xBBC, "Price", c_Contract.Price.ToString() );
AddButton(width / 2 - 5, y + 3, 0x2716, "Price", new GumpCallback(Price));
AddHtml( 0, y+=20, width, "
Suggest");
AddButton(width / 2 - 70, y + 3, 0x2716, "Suggest", new GumpCallback(SuggestPrice));
AddButton(width / 2 + 60, y + 3, 0x2716, "Suggest", new GumpCallback(SuggestPrice));
}
string helptext = String.Format( " Now you can finalize the contract by including your price per {0}. " +
"Once you finalize, the only way you can modify it is to dump it and start a new contract! By " +
"using the suggest button, a price will automatically be figured based on the following:
", c_Contract.PriceTypeShort );
helptext += String.Format( "Volume: {0}
", c_Contract.CalcVolume() );
helptext += String.Format( "Cost per unit: {0} gold", General.SuggestionFactor );
helptext += "
You may also give this space away for free using the option above.";
AddHtml( 10, y+=35, width-20, 150, helptext, false, true );
y += 150;
AddHtml( 30, y+=20, 80, "Previous");
AddButton( 10, y, 0x15E3, 0x15E7, "Previous", new GumpStateCallback( ChangePage ), (int)c_Page-1 );
if ( c_Contract.Price != 0 )
{
AddHtml( width-70, y, 60, "Finalize");
AddButton( width-30, y, 0x15E1, 0x15E5, "Finalize", new GumpCallback( FinalizeSetup ) );
}
}
protected override void OnClose()
{
c_Contract.ClearPreview();
}
private void SuggestPrice()
{
if ( c_Contract == null )
return;
c_Contract.Price = c_Contract.CalcVolume()*General.SuggestionFactor;
if ( c_Contract.RentByTime == TimeSpan.FromDays( 1 ) )
c_Contract.Price /= 60;
if ( c_Contract.RentByTime == TimeSpan.FromDays( 7 ) )
c_Contract.Price = (int)((double)c_Contract.Price/8.57);
if ( c_Contract.RentByTime == TimeSpan.FromDays( 30 ) )
c_Contract.Price /= 2;
NewGump();
}
private void SuggestLocSec()
{
int price = c_Contract.CalcVolume()*General.SuggestionFactor;
c_Contract.Secures = price/75;
c_Contract.Locks = c_Contract.Secures/2;
c_Contract.FixLocSec();
NewGump();
}
private void Price()
{
c_Contract.Price = GetTextFieldInt("Price");
Owner.SendMessage("Price set!");
NewGump();
}
private void Secures()
{
c_Contract.Secures = GetTextFieldInt("Secures");
Owner.SendMessage("Secures set!");
NewGump();
}
private void Lockdowns()
{
c_Contract.Locks = GetTextFieldInt("Lockdowns");
Owner.SendMessage("Lockdowns set!");
NewGump();
}
private void ChangePage(object obj)
{
if ( c_Contract == null || !(obj is int) )
return;
c_Contract.ClearPreview();
c_Page = (Page)(int)obj;
NewGump();
}
private void EntireHouse()
{
if ( c_Contract == null || c_Contract.ParentHouse == null )
return;
c_Contract.EntireHouse = !c_Contract.EntireHouse;
c_Contract.ClearPreview();
if ( c_Contract.EntireHouse )
{
ArrayList list = new ArrayList();
bool once = false;
foreach (Rectangle3D rect in RUOVersion.RegionArea(c_Contract.ParentHouse.Region))
{
list.Add(new Rectangle2D(new Point2D(rect.Start.X, rect.Start.Y), new Point2D(rect.End.X, rect.End.Y)));
if (once)
continue;
if (rect.Start.Z >= rect.End.Z)
{
c_Contract.MinZ = rect.End.Z;
c_Contract.MaxZ = rect.Start.Z;
}
else
{
c_Contract.MinZ = rect.Start.Z;
c_Contract.MaxZ = rect.End.Z;
}
once = true;
}
c_Contract.Blocks = list;
}
else
{
c_Contract.Blocks.Clear();
c_Contract.MinZ = short.MinValue;
c_Contract.MaxZ = short.MinValue;
}
NewGump();
}
private void SignLocSelect()
{
Owner.Target = new InternalTarget( this, c_Contract, TargetType.SignLoc );
}
private void MinZSelect()
{
Owner.SendMessage( "Target the base floor for your rental area." );
Owner.Target = new InternalTarget( this, c_Contract, TargetType.MinZ );
}
private void MaxZSelect()
{
Owner.SendMessage( "Target the highest floor for your rental area." );
Owner.Target = new InternalTarget( this, c_Contract, TargetType.MaxZ );
}
private void LengthUp()
{
if ( c_Contract == null )
return;
c_Contract.NextPriceType();
if ( c_Contract.RentByTime == TimeSpan.FromDays( 0 ) )
c_Contract.RentByTime = TimeSpan.FromDays( 1 );
NewGump();
}
private void LengthDown()
{
if ( c_Contract == null )
return;
c_Contract.PrevPriceType();
if ( c_Contract.RentByTime == TimeSpan.FromDays( 0 ) )
c_Contract.RentByTime = TimeSpan.FromDays( 30 );
NewGump();
}
private void Free()
{
c_Contract.Free = !c_Contract.Free;
NewGump();
}
private void AddBlock()
{
Owner.SendMessage( "Target the north western corner." );
Owner.Target = new InternalTarget( this, c_Contract, TargetType.BlockOne );
}
private void ClearBlocks()
{
if ( c_Contract == null )
return;
c_Contract.Blocks.Clear();
c_Contract.ClearPreview();
NewGump();
}
private void FinalizeSetup()
{
if ( c_Contract == null )
return;
if ( c_Contract.Price == 0 )
{
Owner.SendMessage( "You can't rent the area for 0 gold!" );
NewGump();
return;
}
c_Contract.Completed = true;
c_Contract.BanLoc = c_Contract.ParentHouse.Region.GoLocation;
if ( c_Contract.EntireHouse )
{
Point3D point = c_Contract.ParentHouse.Sign.Location;
c_Contract.SignLoc = new Point3D( point.X, point.Y, point.Z-5 );
c_Contract.Secures = Core.AOS ? c_Contract.ParentHouse.GetAosMaxSecures() : c_Contract.ParentHouse.MaxSecures;
c_Contract.Locks = Core.AOS ? c_Contract.ParentHouse.GetAosMaxLockdowns() : c_Contract.ParentHouse.MaxLockDowns;
}
Owner.SendMessage( "You have finalized this rental contract. Now find someone to sign it!" );
}
private class InternalTarget : Target
{
private ContractSetupGump c_Gump;
private RentalContract c_Contract;
private TargetType c_Type;
private Point3D c_BoundOne;
public InternalTarget( ContractSetupGump gump, RentalContract contract, TargetType type ) : this( gump, contract, type, Point3D.Zero ){}
public InternalTarget( ContractSetupGump gump, RentalContract contract, TargetType type, Point3D point ) : base( 20, true, TargetFlags.None )
{
c_Gump = gump;
c_Contract = contract;
c_Type = type;
c_BoundOne = point;
}
protected override void OnTarget( Mobile m, object o )
{
IPoint3D point = (IPoint3D)o;
if ( c_Contract == null || c_Contract.ParentHouse == null )
return;
if ( !c_Contract.ParentHouse.Region.Contains( new Point3D( point.X, point.Y, point.Z ) ) )
{
m.SendMessage( "You must target within the home." );
m.Target = new InternalTarget( c_Gump, c_Contract, c_Type, c_BoundOne );
return;
}
switch( c_Type )
{
case TargetType.SignLoc:
c_Contract.SignLoc = new Point3D( point.X, point.Y, point.Z );
c_Contract.ShowSignPreview();
c_Gump.NewGump();
break;
case TargetType.MinZ:
if (!c_Contract.ParentHouse.Region.Contains(new Point3D(point.X, point.Y, point.Z)))
m.SendMessage( "That isn't within your house." );
else if ( c_Contract.HasContractedArea( point.Z ) )
m.SendMessage( "That area is already taken by another rental contract." );
else
{
c_Contract.MinZ = point.Z;
if ( c_Contract.MaxZ < c_Contract.MinZ+19 )
c_Contract.MaxZ = point.Z+19;
}
c_Contract.ShowFloorsPreview(m);
c_Gump.NewGump();
break;
case TargetType.MaxZ:
if ( !c_Contract.ParentHouse.Region.Contains(new Point3D(point.X, point.Y, point.Z)) )
m.SendMessage( "That isn't within your house." );
else if ( c_Contract.HasContractedArea( point.Z ) )
m.SendMessage( "That area is already taken by another rental contract." );
else
{
c_Contract.MaxZ = point.Z+19;
if ( c_Contract.MinZ > c_Contract.MaxZ )
c_Contract.MinZ = point.Z;
}
c_Contract.ShowFloorsPreview(m);
c_Gump.NewGump();
break;
case TargetType.BlockOne:
m.SendMessage( "Now target the south eastern corner." );
m.Target = new InternalTarget( c_Gump, c_Contract, TargetType.BlockTwo, new Point3D( point.X, point.Y, point.Z ) );
break;
case TargetType.BlockTwo:
Rectangle2D rect = TownHouseSetupGump.FixRect( new Rectangle2D( c_BoundOne, new Point3D( point.X+1, point.Y+1, point.Z ) ) );
if ( c_Contract.HasContractedArea( rect, point.Z ) )
m.SendMessage( "That area is already taken by another rental contract." );
else
{
c_Contract.Blocks.Add( rect );
c_Contract.ShowAreaPreview( m );
}
c_Gump.NewGump();
break;
}
}
protected override void OnTargetCancel( Mobile m, TargetCancelType cancelType )
{
c_Gump.NewGump();
}
}
}
}