2020-09-03 01:47:20 -07:00
|
|
|
/*************************************************************************
|
|
|
|
|
* ModernUO *
|
2023-08-09 09:09:26 -07:00
|
|
|
* Copyright 2019-2023 - ModernUO Development Team *
|
2020-09-03 01:47:20 -07:00
|
|
|
* Email: hi@modernuo.com *
|
|
|
|
|
* File: VirtualCheck.cs *
|
|
|
|
|
* *
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
2023-12-02 13:00:02 -05:00
|
|
|
using ModernUO.Serialization;
|
2020-08-25 18:53:35 -07:00
|
|
|
using Server.Gumps;
|
2024-08-09 19:07:32 -07:00
|
|
|
using System;
|
2020-08-25 18:53:35 -07:00
|
|
|
|
2022-10-10 21:47:08 -07:00
|
|
|
namespace Server.Items;
|
|
|
|
|
|
2023-12-02 13:00:02 -05:00
|
|
|
[SerializationGenerator(0, false)]
|
|
|
|
|
public sealed partial class VirtualCheck : Item
|
2020-08-25 18:53:35 -07:00
|
|
|
{
|
2022-10-10 21:47:08 -07:00
|
|
|
public static bool UseEditGump { get; private set; }
|
2024-08-09 19:07:32 -07:00
|
|
|
public static unsafe delegate*<Mobile, VirtualCheck, IVirtualCheckGump> GumpActivator { get; set; }
|
2021-04-14 01:45:18 -07:00
|
|
|
|
2024-08-09 19:07:32 -07:00
|
|
|
public static unsafe void Configure()
|
2022-10-10 21:47:08 -07:00
|
|
|
{
|
|
|
|
|
UseEditGump = ServerConfiguration.GetSetting("virtualChecks.useEditGump", Core.TOL);
|
2024-08-09 19:07:32 -07:00
|
|
|
|
|
|
|
|
if (UseEditGump && GumpActivator is null)
|
|
|
|
|
{
|
|
|
|
|
throw new NullReferenceException(nameof(GumpActivator));
|
|
|
|
|
}
|
2022-10-10 21:47:08 -07:00
|
|
|
}
|
2020-08-25 18:53:35 -07:00
|
|
|
|
2023-12-02 13:00:02 -05:00
|
|
|
private int _gold;
|
2020-08-25 18:53:35 -07:00
|
|
|
|
2023-12-02 13:00:02 -05:00
|
|
|
private int _plat;
|
2020-08-25 18:53:35 -07:00
|
|
|
|
2022-10-10 21:47:08 -07:00
|
|
|
public VirtualCheck(int plat = 0, int gold = 0) : base(0x14F0)
|
|
|
|
|
{
|
|
|
|
|
Plat = plat;
|
|
|
|
|
Gold = gold;
|
2020-08-25 18:53:35 -07:00
|
|
|
|
2022-10-10 21:47:08 -07:00
|
|
|
Movable = false;
|
|
|
|
|
}
|
2020-08-25 18:53:35 -07:00
|
|
|
|
2022-10-10 21:47:08 -07:00
|
|
|
public override bool IsVirtualItem => true;
|
|
|
|
|
public override bool DisplayWeight => false;
|
|
|
|
|
public override bool DisplayLootType => false;
|
|
|
|
|
public override double DefaultWeight => 0;
|
|
|
|
|
public override string DefaultName => "Offer Of Currency";
|
2020-08-25 18:53:35 -07:00
|
|
|
|
2024-08-09 19:07:32 -07:00
|
|
|
public IVirtualCheckGump Editor { get; private set; }
|
2020-08-25 18:53:35 -07:00
|
|
|
|
2022-10-10 21:47:08 -07:00
|
|
|
[CommandProperty(AccessLevel.Administrator)]
|
|
|
|
|
public int Plat
|
|
|
|
|
{
|
2023-12-02 13:00:02 -05:00
|
|
|
get => _plat;
|
2022-10-10 21:47:08 -07:00
|
|
|
set
|
2020-08-25 18:53:35 -07:00
|
|
|
{
|
2023-12-02 13:00:02 -05:00
|
|
|
_plat = value;
|
2022-10-10 21:47:08 -07:00
|
|
|
InvalidateProperties();
|
2020-08-25 18:53:35 -07:00
|
|
|
}
|
2022-10-10 21:47:08 -07:00
|
|
|
}
|
2020-08-25 18:53:35 -07:00
|
|
|
|
2022-10-10 21:47:08 -07:00
|
|
|
[CommandProperty(AccessLevel.Administrator)]
|
|
|
|
|
public int Gold
|
|
|
|
|
{
|
2023-12-02 13:00:02 -05:00
|
|
|
get => _gold;
|
2022-10-10 21:47:08 -07:00
|
|
|
set
|
2020-08-25 18:53:35 -07:00
|
|
|
{
|
2023-12-02 13:00:02 -05:00
|
|
|
_gold = value;
|
2022-10-10 21:47:08 -07:00
|
|
|
InvalidateProperties();
|
2020-08-25 18:53:35 -07:00
|
|
|
}
|
2022-10-10 21:47:08 -07:00
|
|
|
}
|
2020-08-25 18:53:35 -07:00
|
|
|
|
2022-10-10 21:47:08 -07:00
|
|
|
public override bool IsAccessibleTo(Mobile check)
|
|
|
|
|
{
|
|
|
|
|
var c = GetSecureTradeCont();
|
2020-08-25 18:53:35 -07:00
|
|
|
|
2022-10-10 21:47:08 -07:00
|
|
|
if (check == null || c == null)
|
|
|
|
|
{
|
|
|
|
|
return base.IsAccessibleTo(check);
|
2020-08-25 18:53:35 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-10 21:47:08 -07:00
|
|
|
return c.RootParent == check && IsChildOf(c);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-09 19:07:32 -07:00
|
|
|
public override unsafe void OnDoubleClickSecureTrade(Mobile from)
|
2022-10-10 21:47:08 -07:00
|
|
|
{
|
|
|
|
|
if (UseEditGump && IsAccessibleTo(from))
|
2020-08-25 18:53:35 -07:00
|
|
|
{
|
2022-10-10 21:47:08 -07:00
|
|
|
if (Editor?.Check?.Deleted != false)
|
2020-08-25 18:53:35 -07:00
|
|
|
{
|
2024-08-09 19:07:32 -07:00
|
|
|
Editor = GumpActivator(from, this);
|
2022-10-10 21:47:08 -07:00
|
|
|
Editor.Send();
|
2020-08-25 18:53:35 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-10-10 21:47:08 -07:00
|
|
|
Editor.Refresh(true);
|
2020-08-25 18:53:35 -07:00
|
|
|
}
|
|
|
|
|
}
|
2022-10-10 21:47:08 -07:00
|
|
|
else
|
2020-08-25 18:53:35 -07:00
|
|
|
{
|
2022-10-10 21:47:08 -07:00
|
|
|
if (Editor != null)
|
|
|
|
|
{
|
|
|
|
|
Editor.Close();
|
|
|
|
|
Editor = null;
|
|
|
|
|
}
|
2020-08-25 18:53:35 -07:00
|
|
|
|
2022-10-10 21:47:08 -07:00
|
|
|
base.OnDoubleClickSecureTrade(from);
|
2020-08-25 18:53:35 -07:00
|
|
|
}
|
2022-10-10 21:47:08 -07:00
|
|
|
}
|
2020-08-25 18:53:35 -07:00
|
|
|
|
2022-10-10 21:47:08 -07:00
|
|
|
public override void OnSingleClick(Mobile from)
|
|
|
|
|
{
|
2022-11-29 04:58:12 +01:00
|
|
|
LabelTo(from, $"Offer: {Plat:#,0} platinum, {Gold:#,0} gold");
|
2022-10-10 21:47:08 -07:00
|
|
|
}
|
2020-08-25 18:53:35 -07:00
|
|
|
|
2022-10-10 21:47:08 -07:00
|
|
|
public override void GetProperties(IPropertyList list)
|
|
|
|
|
{
|
|
|
|
|
base.GetProperties(list);
|
2020-08-25 18:53:35 -07:00
|
|
|
|
2022-10-10 21:47:08 -07:00
|
|
|
list.Add(1060738, $"{Plat:#,0} platinum, {Gold:#,0} gold"); // value: ~1_val~
|
|
|
|
|
}
|
2020-08-25 18:53:35 -07:00
|
|
|
|
2022-10-10 21:47:08 -07:00
|
|
|
public void UpdateTrade(Mobile user)
|
|
|
|
|
{
|
|
|
|
|
var c = GetSecureTradeCont();
|
2020-08-25 18:53:35 -07:00
|
|
|
|
2022-10-10 21:47:08 -07:00
|
|
|
if (c?.Trade == null)
|
2020-08-25 18:53:35 -07:00
|
|
|
{
|
2022-10-10 21:47:08 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2020-08-25 18:53:35 -07:00
|
|
|
|
2022-10-10 21:47:08 -07:00
|
|
|
if (user == c.Trade.From.Mobile)
|
|
|
|
|
{
|
|
|
|
|
c.Trade.UpdateFromCurrency();
|
|
|
|
|
}
|
|
|
|
|
else if (user == c.Trade.To.Mobile)
|
|
|
|
|
{
|
|
|
|
|
c.Trade.UpdateToCurrency();
|
2020-08-25 18:53:35 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-10 21:47:08 -07:00
|
|
|
c.ClearChecks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnAfterDelete()
|
|
|
|
|
{
|
|
|
|
|
base.OnAfterDelete();
|
|
|
|
|
|
|
|
|
|
if (Editor != null)
|
2020-08-25 18:53:35 -07:00
|
|
|
{
|
2022-10-10 21:47:08 -07:00
|
|
|
Editor.Close();
|
|
|
|
|
Editor = null;
|
2020-08-25 18:53:35 -07:00
|
|
|
}
|
2022-10-10 21:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
2023-12-02 13:00:02 -05:00
|
|
|
[AfterDeserialization(false)]
|
|
|
|
|
private void AfterDeserialization()
|
2022-10-10 21:47:08 -07:00
|
|
|
{
|
|
|
|
|
Delete();
|
|
|
|
|
}
|
2020-08-25 18:53:35 -07:00
|
|
|
}
|