RunUO/Scripts/Engines/InnRooms/InnRentalGump.cs

115 lines
4.1 KiB
C#

using System;
using Server;
using Server.Gumps;
using Server.Mobiles;
using Server.Items;
using Server.Network;
namespace Server.Custom.InnRooms
{
public class InnRentalGump : Gump
{
private PlayerMobile m_Player;
public InnRentalGump(PlayerMobile pm) : base(150, 150)
{
m_Player = pm;
AddPage(0);
// Widened the background from 400 to 500
AddBackground(0, 0, 500, 300, 9270);
// Centered the header to match the new 500 width
AddHtml(0, 15, 500, 20, "<CENTER><BASEFONT COLOR=#FFFFFF>Inn Room Rentals</BASEFONT></CENTER>", false, false);
DrawRoomOption(1, "Small Room", InnRoomSize.Small, 60);
DrawRoomOption(2, "Medium Room", InnRoomSize.Medium, 120);
DrawRoomOption(3, "Large Room", InnRoomSize.Large, 180);
}
private void DrawRoomOption(int buttonId, string title, InnRoomSize size, int yPos)
{
int available = InnRoomManager.GetAvailableCount(size);
int cost = InnRoomManager.GetCost(size);
int total = 0;
foreach (RoomDefinition def in InnRoomManager.Rooms)
{
if (def.Size == size)
total++;
}
// Pushed the text to X: 70 to clear the button
AddHtml(70, yPos, 150, 20, $"<BASEFONT COLOR=#FCCA03>{title}</BASEFONT>", false, false);
AddHtml(70, yPos + 20, 200, 20, $"<BASEFONT COLOR=#FFFFFF>Cost: {cost} Gold</BASEFONT>", false, false);
// Pushed the availability count to X: 320 to sit nicely on the right side
AddHtml(320, yPos + 10, 150, 20, $"<BASEFONT COLOR=#FFFFFF>{available} / {total} Available</BASEFONT>", false, false);
if (available > 0)
{
// Kept the button firmly at X: 25
AddButton(25, yPos + 5, 4005, 4007, buttonId, GumpButtonType.Reply, 0);
}
else
{
AddHtml(25, yPos + 5, 20, 20, "<BASEFONT COLOR=#FF0000>X</BASEFONT>", false, false);
}
}
public override void OnResponse(NetState sender, RelayInfo info)
{
if (info.ButtonID == 0 || m_Player == null) return;
InnRoomSize selectedSize = InnRoomSize.Small;
if (info.ButtonID == 2) selectedSize = InnRoomSize.Medium;
if (info.ButtonID == 3) selectedSize = InnRoomSize.Large;
int slot = InnRoomManager.FindFirstOpenSlot(selectedSize);
if (slot == -1)
{
m_Player.SendMessage(33, "Those rooms are currently sold out.");
return;
}
int cost = InnRoomManager.GetCost(selectedSize);
if (Banker.Withdraw(m_Player, cost))
{
RentRoom(selectedSize, slot);
}
else if (m_Player.Backpack != null && m_Player.Backpack.ConsumeTotal(typeof(Gold), cost))
{
RentRoom(selectedSize, slot);
}
else
{
m_Player.SendMessage(33, $"You need {cost} gold in your account or backpack to rent that room.");
}
}
private void RentRoom(InnRoomSize size, int slot)
{
m_Player.LastInnLocation = m_Player.Location;
m_Player.LastInnMap = m_Player.Map;
RoomDefinition roomDef = InnRoomManager.Rooms[slot];
Point3D voidRoomLoc = roomDef.Location;
Map voidRoomMap = roomDef.RoomMap;
InnRoomHouse newHouse = new InnRoomHouse(m_Player);
newHouse.RoomTier = size;
newHouse.RoomIndex = slot;
newHouse.RentExpires = DateTime.UtcNow + TimeSpan.FromDays(7);
newHouse.MoveToWorld(new Point3D(voidRoomLoc.X, voidRoomLoc.Y, voidRoomLoc.Z - 20), voidRoomMap);
m_Player.PlaySound(0x249);
m_Player.SendMessage(68, $"You have rented a {size} room.");
m_Player.MoveToWorld(voidRoomLoc, voidRoomMap);
}
}
}