Files
The-Forging/Scripts/Custom/royalmintofficial.cs
T

276 lines
8.1 KiB
C#
Raw Normal View History

2026-06-19 00:00:16 -04:00
using System;
using System.Collections.Generic;
using Server;
using Server.Items;
using Server.Mobiles;
using Server.Gumps;
using Server.Network;
using Server.Accounting;
namespace Server.CustomSystems
{
public class RoyalMintOfficial : BaseCreature
{
[Constructable]
public RoyalMintOfficial()
: base(AIType.AI_Vendor, FightMode.None, 10, 1, 0.2, 0.4)
{
2026-07-07 13:40:15 -04:00
Name = "Royal Mint Official";
Title = "the Sovereign Clerk";
Body = 0x190;
Hue = 33770;
AddItem(new Robe(2713));
AddItem(new Sandals(1150));
AddItem(new GoldBracelet());
}
2026-06-19 00:00:16 -04:00
public RoyalMintOfficial(Serial serial) : base(serial)
{
}
public override bool IsInvulnerable => true;
public override void OnDoubleClick(Mobile from)
{
if (!from.InRange(Location, 3))
{
from.SendMessage("You must be closer to speak with the Royal Mint Official.");
return;
}
from.CloseGump(typeof(RoyalMintGump));
from.SendGump(new RoyalMintGump(from, this));
}
// ============================================================
// ACCOUNT SOVEREIGN STORAGE (ServUO 54)
// ============================================================
public static int GetAccountSovereigns(Mobile from)
{
if (from?.Account == null)
return 0;
return ((Account)from.Account).Sovereigns;
}
public static void SetAccountSovereigns(Mobile from, int amount)
{
if (from?.Account == null)
return;
((Account)from.Account).Sovereigns = amount;
}
public static void AddAccountSovereigns(Mobile from, int amount)
{
if (from?.Account == null)
return;
((Account)from.Account).Sovereigns += amount;
}
// ============================================================
// PAYMENT LOGIC (NOTES FIRST, THEN ACCOUNT)
// ============================================================
public static bool TrySpendSovereigns(Mobile from, int cost)
{
if (from == null)
return false;
Container pack = from.Backpack;
int noteTotal = 0;
List<HeritageSovereign> notes = new List<HeritageSovereign>();
if (pack != null)
{
foreach (Item item in pack.Items)
{
if (item is HeritageSovereign s)
{
noteTotal += s.Amount;
notes.Add(s);
}
}
}
int accountSov = GetAccountSovereigns(from);
int combined = noteTotal + accountSov;
if (combined < cost)
return false;
int remaining = cost;
// Spend notes first
foreach (HeritageSovereign s in notes)
{
if (remaining <= 0)
break;
if (s.Amount <= remaining)
{
remaining -= s.Amount;
s.Delete();
}
else
{
s.Amount -= remaining;
remaining = 0;
}
}
// Spend remainder from account
if (remaining > 0)
SetAccountSovereigns(from, accountSov - remaining);
return true;
}
// ============================================================
// CONSOLIDATION LOGIC
// ============================================================
public void ConsolidateNotes(Mobile from)
{
Container pack = from.Backpack;
if (pack == null)
{
from.SendMessage("You have no backpack.");
return;
}
List<HeritageSovereign> notes = new List<HeritageSovereign>();
int total = 0;
foreach (Item item in pack.Items)
{
if (item is HeritageSovereign s)
{
total += s.Amount;
notes.Add(s);
}
}
if (total == 0)
{
from.SendMessage("You have no Sovereign notes to consolidate.");
return;
}
foreach (HeritageSovereign s in notes)
s.Delete();
AddAccountSovereigns(from, total);
from.PlaySound(0x2E6);
from.SendMessage($"The Royal Mint has deposited {total} Sovereigns into your account.");
}
// ============================================================
// PURCHASE MINT BOX
// ============================================================
public void PurchaseMintBox(Mobile from)
{
if (!TrySpendSovereigns(from, 5000))
{
from.SendMessage("You do not have 5000 Sovereigns.");
return;
}
from.Backpack.DropItem(new RoyalMintBox());
from.PlaySound(0x2E6);
from.SendMessage("You have purchased a Royal Mint Processing Box.");
}
// ============================================================
// SERIALIZATION
// ============================================================
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(0);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
}
}
// ============================================================
// GUMP UI (INCLUDED)
// ============================================================
public class RoyalMintGump : Gump
{
private readonly Mobile m_From;
private readonly RoyalMintOfficial m_NPC;
public RoyalMintGump(Mobile from, RoyalMintOfficial npc)
: base(50, 50)
{
m_From = from;
m_NPC = npc;
Closable = true;
Dragable = true;
AddPage(0);
AddBackground(0, 0, 350, 260, 9270);
AddLabel(110, 20, 1152, "Royal Mint Services");
int account = RoyalMintOfficial.GetAccountSovereigns(from);
int notes = CountNotes(from);
AddLabel(40, 55, 0x34, $"Account Sovereigns: {account}");
AddLabel(40, 75, 0x34, $"Backpack Notes: {notes}");
AddButton(40, 110, 4005, 4007, 1, GumpButtonType.Reply, 0);
AddLabel(80, 110, 0x34, "Consolidate Your Notes");
AddButton(40, 160, 4005, 4007, 2, GumpButtonType.Reply, 0);
AddLabel(80, 160, 0x34, "Purchase Mint Box (5000)");
AddButton(40, 210, 4017, 4019, 0, GumpButtonType.Reply, 0);
AddLabel(80, 210, 0x34, "Close");
}
private int CountNotes(Mobile from)
{
int total = 0;
if (from.Backpack != null)
{
foreach (Item item in from.Backpack.Items)
{
if (item is HeritageSovereign s)
total += s.Amount;
}
}
return total;
}
public override void OnResponse(NetState sender, RelayInfo info)
{
switch (info.ButtonID)
{
case 1:
m_NPC.ConsolidateNotes(m_From);
break;
case 2:
m_NPC.PurchaseMintBox(m_From);
break;
}
}
}
}