Files
2026-06-19 00:00:16 -04:00

148 lines
5.0 KiB
C#
Executable File

using System;
using System.Collections.Generic;
using Server;
using Server.Items;
using Server.Mobiles;
using Server.ContextMenus;
namespace Server.CustomSystems
{
[Flipable(0x9A8, 0x9A9)]
public class RoyalMintBox : Container
{
public override int DefaultMaxWeight => 400;
public override int DefaultGumpID => 0x4B;
[Constructable]
public RoyalMintBox() : base(0x9A8)
{
Name = "Royal Mint Processing Box";
Hue = 2713;
Movable = true;
Weight = 15.0;
}
public RoyalMintBox(Serial serial) : base(serial)
{
}
public override void OnDoubleClick(Mobile from)
{
// Allow use if:
// ✔ In backpack
// ✔ In bank box
// ✔ Secured/locked down in house
// ✔ Any container the player can access
if (!IsChildOf(from.Backpack) && !IsAccessibleTo(from))
{
from.SendLocalizedMessage(501640); // You cannot reach that.
return;
}
base.OnDoubleClick(from);
from.SendMessage(0x59, "Place your Heritage Sovereign notes inside, and select 'Activate' from the context menu to consolidate your vouchers.");
}
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list)
{
base.GetContextMenuEntries(from, list);
if (from.Alive && (IsChildOf(from.Backpack) || IsAccessibleTo(from)))
list.Add(new ProcessNotesEntry(from, this));
}
private class ProcessNotesEntry : ContextMenuEntry
{
private readonly Mobile m_From;
private readonly RoyalMintBox m_Box;
public ProcessNotesEntry(Mobile from, RoyalMintBox box)
: base(3006170, 2) // -1 to force use of ToString()
{
m_From = from;
m_Box = box;
Color = 0x7FFF;
}
public override string ToString()
{
return "Consolidate your Notes";
}
public override void OnClick()
{
if (m_Box.Deleted || !m_From.Alive)
return;
// Allow processing if:
// ✔ In backpack
// ✔ In bank box
// ✔ Secured/locked down in house
// ✔ Any accessible container
if (!m_Box.IsChildOf(m_From.Backpack) && !m_Box.IsAccessibleTo(m_From))
{
m_From.SendMessage(0x22, "You cannot reach the mint box to process vouchers.");
return;
}
List<HeritageSovereign> notes = new List<HeritageSovereign>();
int total = 0;
foreach (Item item in m_Box.Items)
{
if (item is HeritageSovereign sovereign)
{
total += sovereign.Amount;
notes.Add(sovereign);
}
}
if (total == 0)
{
m_From.SendMessage(0x22, "There are no sovereign vouchers inside the mint box to process.");
return;
}
foreach (HeritageSovereign s in notes)
s.Delete();
m_From.PlaySound(0x2E6);
Effects.SendLocationParticles(
EffectItem.Create(m_From.Location, m_From.Map, EffectItem.DefaultDuration),
0x376A, 9, 32, 2713, 0, 5022, 0
);
int remaining = total;
int tier100 = remaining / 100; remaining %= 100;
int tier50 = remaining / 50; remaining %= 50;
int tier10 = remaining / 10; remaining %= 10;
int tier5 = remaining / 5; remaining %= 5;
if (tier100 > 0) m_Box.DropItem(new HeritageSovereign(tier100 * 100));
if (tier50 > 0) m_Box.DropItem(new HeritageSovereign(tier50 * 50));
if (tier10 > 0) m_Box.DropItem(new HeritageSovereign(tier10 * 10));
if (tier5 > 0) m_Box.DropItem(new HeritageSovereign(tier5 * 5));
if (remaining > 0)
m_Box.DropItem(new HeritageSovereign(remaining));
m_From.SendMessage(0x42, $"Mint complete! Consolidated a total value of {total} Sovereigns into optimized vouchers.");
}
}
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();
}
}
}