fix: Codegens house/vendors (#1767)
### Summary - Cleans up ShardPoller - Breaks up player vendor file - Codegens houses/vendors
This commit is contained in:
parent
8fd04ac5aa
commit
fb8563aa60
20 changed files with 4801 additions and 4858 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
using ModernUO.Serialization;
|
||||
|
||||
namespace Server.Mobiles;
|
||||
|
||||
[SerializationGenerator(0)]
|
||||
public partial class PlayerVendorPlaceholder : Item
|
||||
{
|
||||
private readonly Timer _timer;
|
||||
|
||||
[SerializableField(0, setter: "private")]
|
||||
[SerializedCommandProperty(AccessLevel.GameMaster)]
|
||||
private PlayerVendor _vendor;
|
||||
|
||||
public PlayerVendorPlaceholder(PlayerVendor vendor) : base(0x1F28)
|
||||
{
|
||||
Hue = 0x672;
|
||||
Movable = false;
|
||||
|
||||
_vendor = vendor;
|
||||
|
||||
_timer = Timer.DelayCall(TimeSpan.FromMinutes(2.0), Delete);
|
||||
}
|
||||
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
if (Vendor != null)
|
||||
{
|
||||
list.Add(1062498, Vendor.Name); // reserved for vendor ~1_NAME~
|
||||
}
|
||||
}
|
||||
|
||||
public void RestartTimer()
|
||||
{
|
||||
_timer.Stop();
|
||||
_timer.Start();
|
||||
}
|
||||
|
||||
public override void OnDelete()
|
||||
{
|
||||
if (Vendor?.Deleted == false)
|
||||
{
|
||||
Vendor.MoveToWorld(Location, Map);
|
||||
Vendor.Placeholder = null;
|
||||
}
|
||||
}
|
||||
|
||||
[AfterDeserialization(false)]
|
||||
private void AfterDeserialization() => Delete();
|
||||
}
|
||||
188
Projects/UOContent/Mobiles/Vendors/VendorBackpack.cs
Normal file
188
Projects/UOContent/Mobiles/Vendors/VendorBackpack.cs
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
using System.Collections.Generic;
|
||||
using ModernUO.Serialization;
|
||||
using Server.ContextMenus;
|
||||
using Server.Engines.BulkOrders;
|
||||
using Server.Ethics;
|
||||
using Server.Items;
|
||||
using Server.Multis;
|
||||
using Server.Targeting;
|
||||
|
||||
namespace Server.Mobiles;
|
||||
|
||||
[SerializationGenerator(0, false)]
|
||||
public partial class VendorBackpack : Backpack
|
||||
{
|
||||
public VendorBackpack()
|
||||
{
|
||||
Layer = Layer.Backpack;
|
||||
Weight = 1.0;
|
||||
}
|
||||
|
||||
public override int DefaultMaxWeight => 0;
|
||||
|
||||
public override bool CheckHold(Mobile m, Item item, bool message, bool checkItems, int plusItems, int plusWeight)
|
||||
{
|
||||
if (!base.CheckHold(m, item, message, checkItems, plusItems, plusWeight))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Ethic.IsImbued(item, true))
|
||||
{
|
||||
if (message)
|
||||
{
|
||||
m.SendMessage("Imbued items may not be sold here.");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!BaseHouse.NewVendorSystem && Parent is PlayerVendor vendor)
|
||||
{
|
||||
var house = vendor.House;
|
||||
|
||||
if (house?.IsAosRules == true && !house.CheckAosStorage(1 + item.TotalItems + plusItems))
|
||||
{
|
||||
if (message)
|
||||
{
|
||||
m.SendLocalizedMessage(1061839); // This action would exceed the secure storage limit of the house.
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool IsAccessibleTo(Mobile m) => true;
|
||||
|
||||
public override bool CheckItemUse(Mobile from, Item item)
|
||||
{
|
||||
if (!base.CheckItemUse(from, item))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (item is Container or BulkOrderBook)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
from.SendLocalizedMessage(500447); // That is not accessible.
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool CheckTarget(Mobile from, Target targ, object targeted) =>
|
||||
base.CheckTarget(from, targ, targeted) &&
|
||||
(from.AccessLevel >= AccessLevel.GameMaster ||
|
||||
targ.GetType().IsDefined(typeof(PlayerVendorTargetAttribute), false));
|
||||
|
||||
public override void GetChildContextMenuEntries(Mobile from, List<ContextMenuEntry> list, Item item)
|
||||
{
|
||||
base.GetChildContextMenuEntries(from, list, item);
|
||||
|
||||
if (RootParent is not PlayerVendor pv || pv.IsOwner(from))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var vi = pv.GetVendorItem(item);
|
||||
|
||||
if (vi != null)
|
||||
{
|
||||
list.Add(new BuyEntry(item));
|
||||
}
|
||||
}
|
||||
|
||||
public override void GetChildNameProperties(IPropertyList list, Item item)
|
||||
{
|
||||
base.GetChildNameProperties(list, item);
|
||||
|
||||
var pv = RootParent as PlayerVendor;
|
||||
|
||||
var vi = pv?.GetVendorItem(item);
|
||||
|
||||
if (vi == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!vi.IsForSale)
|
||||
{
|
||||
list.Add(1043307); // Price: Not for sale.
|
||||
}
|
||||
else if (vi.IsForFree)
|
||||
{
|
||||
list.Add(1043306); // Price: FREE!
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(1043304, vi.FormattedPrice); // Price: ~1_COST~
|
||||
}
|
||||
}
|
||||
|
||||
public override void GetChildProperties(IPropertyList list, Item item)
|
||||
{
|
||||
base.GetChildProperties(list, item);
|
||||
|
||||
var pv = RootParent as PlayerVendor;
|
||||
|
||||
var vi = pv?.GetVendorItem(item);
|
||||
|
||||
if (vi?.Description?.Length > 0)
|
||||
{
|
||||
list.Add(1043305, vi.Description); // <br>Seller's Description:<br>"~1_DESC~"
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSingleClickContained(Mobile from, Item item)
|
||||
{
|
||||
if (RootParent is PlayerVendor vendor)
|
||||
{
|
||||
var vi = vendor.GetVendorItem(item);
|
||||
|
||||
if (vi != null)
|
||||
{
|
||||
if (!vi.IsForSale)
|
||||
{
|
||||
item.LabelTo(from, 1043307); // Price: Not for sale.
|
||||
}
|
||||
else if (vi.IsForFree)
|
||||
{
|
||||
item.LabelTo(from, 1043306); // Price: FREE!
|
||||
}
|
||||
else
|
||||
{
|
||||
item.LabelTo(from, 1043304, vi.FormattedPrice); // Price: ~1_COST~
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(vi.Description))
|
||||
{
|
||||
item.LabelTo(from, $"Description: {vi.Description}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
base.OnSingleClickContained(from, item);
|
||||
}
|
||||
|
||||
private class BuyEntry : ContextMenuEntry
|
||||
{
|
||||
private readonly Item m_Item;
|
||||
|
||||
public BuyEntry(Item item) : base(6103) => m_Item = item;
|
||||
|
||||
public override bool NonLocalUse => true;
|
||||
|
||||
public override void OnClick()
|
||||
{
|
||||
if (m_Item.Deleted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerVendor.TryToBuy(m_Item, Owner.From);
|
||||
}
|
||||
}
|
||||
}
|
||||
64
Projects/UOContent/Mobiles/Vendors/VendorItem.cs
Normal file
64
Projects/UOContent/Mobiles/Vendors/VendorItem.cs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using ModernUO.Serialization;
|
||||
|
||||
namespace Server.Mobiles;
|
||||
|
||||
[SerializationGenerator(0, false)]
|
||||
public partial class VendorItem
|
||||
{
|
||||
[SerializableField(0)]
|
||||
private Item _item;
|
||||
|
||||
[SerializableField(1)]
|
||||
private int _price;
|
||||
|
||||
[SerializableField(3)]
|
||||
private DateTime _created;
|
||||
|
||||
public VendorItem()
|
||||
{
|
||||
}
|
||||
|
||||
public VendorItem(Item item, int price, string description, DateTime created)
|
||||
{
|
||||
_item = item;
|
||||
_price = price;
|
||||
_description = description ?? "";
|
||||
_created = created;
|
||||
Valid = true;
|
||||
}
|
||||
|
||||
public string FormattedPrice =>
|
||||
Core.ML ? Price.ToString("N0", CultureInfo.GetCultureInfo("en-US")) : Price.ToString();
|
||||
|
||||
[SerializableProperty(2)]
|
||||
public string Description
|
||||
{
|
||||
get => _description;
|
||||
set
|
||||
{
|
||||
_description = value ?? "";
|
||||
|
||||
if (Valid)
|
||||
{
|
||||
Item.InvalidateProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsForSale => Price >= 0;
|
||||
public bool IsForFree => Price == 0;
|
||||
public bool Valid { get; private set; }
|
||||
|
||||
public void Invalidate() => Valid = false;
|
||||
|
||||
[AfterDeserialization]
|
||||
private void AfterDeserialization()
|
||||
{
|
||||
if (_price > 100000000)
|
||||
{
|
||||
_price = 100000000;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue