修改协议工具
This commit is contained in:
86
Hotfix/Game/Container/ContainerSystem.cs
Normal file
86
Hotfix/Game/Container/ContainerSystem.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
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
|
||||
}
|
||||
6
Hotfix/Game/Handler/ItemFactory.cs
Normal file
6
Hotfix/Game/Handler/ItemFactory.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace NB.Game;
|
||||
|
||||
public class ItemFactory
|
||||
{
|
||||
|
||||
}
|
||||
49
Hotfix/Game/Role/RoleManagerComponentSystem.cs
Normal file
49
Hotfix/Game/Role/RoleManagerComponentSystem.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Fantasy.Entitas.Interface;
|
||||
|
||||
namespace NB;
|
||||
|
||||
public sealed class RoleManagerComponentDestroySystem : DestroySystem<RoleManagerComponent>
|
||||
{
|
||||
protected override void Destroy(RoleManagerComponent self)
|
||||
{
|
||||
foreach (var (_, role) in self.Roles)
|
||||
{
|
||||
role.Dispose();
|
||||
}
|
||||
|
||||
self.Roles.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static class RoleManagerComponentSystem
|
||||
{
|
||||
public static void Add(this RoleManagerComponent self, Role account)
|
||||
{
|
||||
self.Roles.Add(account.Id, account);
|
||||
}
|
||||
|
||||
public static Role Get(this RoleManagerComponent self, long accountId)
|
||||
{
|
||||
return self.Roles.GetValueOrDefault(accountId);
|
||||
}
|
||||
|
||||
public static bool TryGet(this RoleManagerComponent self, long accountId, out Role account)
|
||||
{
|
||||
return self.Roles.TryGetValue(accountId, out account);
|
||||
}
|
||||
|
||||
public static void Remove(this RoleManagerComponent self, long accountId, bool isDispose = true)
|
||||
{
|
||||
if (!self.Roles.Remove(accountId, out var account))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isDispose)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
account.Dispose();
|
||||
}
|
||||
}
|
||||
6
Hotfix/Game/System/ItemManagerComponentSystem.cs
Normal file
6
Hotfix/Game/System/ItemManagerComponentSystem.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace NB.Game.System;
|
||||
|
||||
public class ItemManagerComponentSystem
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user