fix: Moves container enumerables to Item. (#2238)

This commit is contained in:
Kamron Batman 2025-07-24 14:26:35 -07:00 • committed by GitHub
parent 1e2f4b1171
commit c2e44a58f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 87 additions and 67 deletions

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2024 - ModernUO Development Team *
* Copyright 2019-2025 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: Item.cs *
* *
@ -192,7 +192,7 @@ public enum ExpandFlag
Spawner = 0x100
}
public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEntity, IValueLinkListNode<Item>
public partial class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEntity, IValueLinkListNode<Item>
{
private static readonly ILogger logger = LogFactory.GetLogger(typeof(Item));
@ -534,6 +534,8 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
public List<Item> Items => LookupItems() ?? EmptyItems;
public int LookupContainerVersion() => (this as Container)?._version ?? LookupCompactInfo()?.Version ?? 0;
[CommandProperty(AccessLevel.GameMaster)]
public IEntity RootParent
{
@ -1696,11 +1698,11 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
{
if (this is Container cont)
{
return cont.m_Items ?? (cont.m_Items = new List<Item>());
return cont.m_Items ??= new List<Item>();
}
var info = AcquireCompactInfo();
return info.m_Items ?? (info.m_Items = new List<Item>());
return info.m_Items ??= new List<Item>();
}
private void SetFlag(ImplFlag flag, bool value)
@ -2471,15 +2473,6 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
{
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void SetSaveFlag(ref SaveFlag flags, SaveFlag toSet, bool setIf)
{
if (setIf)
{
flags |= toSet;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool GetSaveFlag(SaveFlag flags, SaveFlag toGet) => (flags & toGet) != 0;
@ -3195,9 +3188,13 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
item.Map = m_Map;
var items = AcquireItems();
items.Add(item);
if (this is not Container)
{
AcquireCompactInfo().Version++;
}
if (!item.IsVirtualItem)
{
UpdateTotal(item, TotalType.Gold, item.TotalGold);
@ -3360,6 +3357,11 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
if (items.Remove(item))
{
if (this is not Container)
{
AcquireCompactInfo().Version++;
}
item.SendRemovePacket();
if (!item.IsVirtualItem)
@ -4321,6 +4323,8 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
public int m_TempFlags;
public double m_Weight = -1;
public int Version;
}
[Flags]