86 lines
2.1 KiB
C#
86 lines
2.1 KiB
C#
using Fantasy.Entitas.Interface;
|
|
|
|
namespace NB.Game;
|
|
|
|
public sealed class ContainerDestroySystem : DestroySystem<Container>
|
|
{
|
|
protected override void Destroy(Container self)
|
|
{
|
|
self.CellCount = 0;
|
|
self.CellCountMax = 0;
|
|
self.CurrentCellCount = 0;
|
|
|
|
foreach (var (_, item) in self.Items)
|
|
{
|
|
item.Dispose();
|
|
}
|
|
|
|
self.Items.Clear();
|
|
self.ItemsByCell.Clear();
|
|
self.ItemsByConfigId.Clear();
|
|
self.ItemsByType.Clear();
|
|
}
|
|
}
|
|
|
|
public static class ContainerSystem
|
|
{
|
|
#region Get
|
|
|
|
/// <summary>
|
|
/// 通过唯一id获取
|
|
/// </summary>
|
|
/// <param name="self"></param>
|
|
/// <param name="id"></param>
|
|
/// <param name="item"></param>
|
|
/// <returns></returns>
|
|
public static bool GetItemById(this Container self, uint id, out Item item)
|
|
{
|
|
return self.Items.TryGetValue(id, out item);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过格子位置获取物品
|
|
/// </summary>
|
|
/// <param name="self"></param>
|
|
/// <param name="cell"></param>
|
|
/// <param name="item"></param>
|
|
/// <returns></returns>
|
|
public static bool GetItemByCell(this Container self, uint cell, out Item item)
|
|
{
|
|
return self.ItemsByCell.TryGetValue(cell, out item);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过配置id获取物品
|
|
/// </summary>
|
|
/// <param name="self"></param>
|
|
/// <param name="configId"></param>
|
|
/// <param name="items"></param>
|
|
public static void GetItemByConfigId(this Container self, uint configId, List<Item> items)
|
|
{
|
|
if (!self.ItemsByConfigId.TryGetValue(configId, out var itemList))
|
|
{
|
|
return;
|
|
}
|
|
|
|
items.AddRange(itemList);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过类型获取物品
|
|
/// </summary>
|
|
/// <param name="self"></param>
|
|
/// <param name="type"></param>
|
|
/// <param name="items"></param>
|
|
public static void GetItemByType(this Container self, ItemType type, List<Item> items)
|
|
{
|
|
if (!self.ItemsByType.TryGetValue((uint)type, out var itemList))
|
|
{
|
|
return;
|
|
}
|
|
|
|
items.AddRange(itemList);
|
|
}
|
|
|
|
#endregion
|
|
} |