修改钓组相关协议
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Network.Interface;
|
||||
using NB.Map;
|
||||
|
||||
@@ -12,6 +13,7 @@ public class C2Game_GetRoleInfoRequestHandler : RouteRPC<Player, C2Game_GetRoleI
|
||||
{
|
||||
response.RoomId = 0;
|
||||
response.RoleInfo = entity.GetRoleInfo();
|
||||
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,23 @@
|
||||
namespace NB.Game;
|
||||
using Fantasy;
|
||||
using Fantasy.Entitas;
|
||||
using NB.Map;
|
||||
|
||||
public class ItemFactory
|
||||
namespace NB.Game;
|
||||
|
||||
public static class ItemFactory
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个新的Player
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="configId"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
public static Item Create(Scene scene, int configId, int count = 1)
|
||||
{
|
||||
var item = Entity.Create<Item>(scene, true, true);
|
||||
item.ConfigId = configId;
|
||||
item.Count = count;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Fantasy.Entitas.Interface;
|
||||
using Fantasy;
|
||||
using Fantasy.Entitas.Interface;
|
||||
|
||||
namespace NB.Game;
|
||||
|
||||
@@ -14,8 +15,8 @@ public sealed class ItemContainerDestroySystem : DestroySystem<ItemContainer>
|
||||
}
|
||||
|
||||
self.Items.Clear();
|
||||
self.ItemsByConfigId.Clear();
|
||||
self.ItemsByType.Clear();
|
||||
// self.ItemsByConfigId.Clear();
|
||||
// self.ItemsByType.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +31,7 @@ public static class ItemContainerSystem
|
||||
/// <param name="id"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
public static bool GetItemById(this ItemContainer self, uint id, out Item item)
|
||||
public static bool GetItemById(this ItemContainer self, long id, out Item? item)
|
||||
{
|
||||
return self.Items.TryGetValue(id, out item);
|
||||
}
|
||||
@@ -40,31 +41,99 @@ public static class ItemContainerSystem
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <param name="configId"></param>
|
||||
/// <param name="items"></param>
|
||||
public static void GetItemByConfigId(this ItemContainer self, uint configId, List<Item> items)
|
||||
/// <param name="item"></param>
|
||||
public static bool GetFistItemByConfigId(this ItemContainer self, int configId, out Item? item)
|
||||
{
|
||||
if (!self.ItemsByConfigId.TryGetValue(configId, out var itemList))
|
||||
foreach (var (_, it) in self.Items)
|
||||
{
|
||||
return;
|
||||
if (it.ConfigId == configId)
|
||||
{
|
||||
item = it;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
items.AddRange(itemList);
|
||||
item = null;
|
||||
return false;
|
||||
// if (!self.ItemsByConfigId.TryGetValue(configId, out var itemList))
|
||||
// {
|
||||
// item = null;
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// item = itemList.First();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过类型获取物品
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="items"></param>
|
||||
public static void GetItemByType(this ItemContainer self, ItemType type, List<Item> items)
|
||||
// /// <summary>
|
||||
// /// 通过配置id获取物品
|
||||
// /// </summary>
|
||||
// /// <param name="self"></param>
|
||||
// /// <param name="configId"></param>
|
||||
// /// <param name="items"></param>
|
||||
// public static void GetItemByConfigId(this ItemContainer 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 ItemContainer self, ItemType type, List<Item> items)
|
||||
// {
|
||||
// if (!self.ItemsByType.TryGetValue((uint)type, out var itemList))
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// items.AddRange(itemList);
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Add
|
||||
|
||||
public static void Add(this ItemContainer self, int configId, int count)
|
||||
{
|
||||
if (!self.ItemsByType.TryGetValue((uint)type, out var itemList))
|
||||
var item = ItemFactory.Create(self.Scene, configId, count);
|
||||
self.Items.Add(item.Id, item);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 结构转换
|
||||
|
||||
public static List<ItemInfo> GetItemInfos(this ItemContainer self)
|
||||
{
|
||||
List<ItemInfo> ret = new List<ItemInfo>();
|
||||
foreach (var (_, item) in self.Items)
|
||||
{
|
||||
return;
|
||||
ret.Add(item.ToItemInfo());
|
||||
}
|
||||
|
||||
items.AddRange(itemList);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static List<GearInfo> GetGearInfos(this ItemContainer self)
|
||||
{
|
||||
List<GearInfo> ret = new List<GearInfo>();
|
||||
|
||||
foreach (var (rod, rigs) in self.FishingRig)
|
||||
{
|
||||
GearInfo gearInfo = new GearInfo();
|
||||
gearInfo.Rod = rod;
|
||||
gearInfo.Rigs.AddRange(rigs);
|
||||
ret.Add(gearInfo);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -18,14 +18,16 @@ public class ItemDestroySystem : DestroySystem<Item>
|
||||
|
||||
public static class ItemSystem
|
||||
{
|
||||
public static ItemInfo ToItemInfo(this Item item)
|
||||
public static ItemInfo ToItemInfo(this Item self)
|
||||
{
|
||||
return new ItemInfo()
|
||||
{
|
||||
ConfigId = item.ConfigId,
|
||||
Id = item.Id,
|
||||
Count = item.Count,
|
||||
// ExpirationTime = item.IsBind;
|
||||
Id = self.Id,
|
||||
ConfigId = self.Count,
|
||||
Count = self.Count,
|
||||
ExpirationTime = self.ExpirationTime,
|
||||
GetTime = self.GetTime,
|
||||
Abrasion = self.Abrasion
|
||||
};
|
||||
}
|
||||
|
||||
@@ -59,4 +61,5 @@ public static class ItemSystem
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -103,7 +103,8 @@ public static class PlayerManageComponentSystem
|
||||
}
|
||||
|
||||
// account.Statistics.LoginTime = TimeHelper.Now;
|
||||
|
||||
account.SetTestData();
|
||||
|
||||
await account.Save();
|
||||
|
||||
return account;
|
||||
@@ -170,4 +171,6 @@ public static class PlayerManageComponentSystem
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public sealed class PlayerDestroySystem : DestroySystem<Player>
|
||||
self.Exp = 0;
|
||||
self.Country = string.Empty;
|
||||
self.Head = string.Empty;
|
||||
|
||||
|
||||
// self.ItemContainer.Dispose();
|
||||
// self.ItemContainer = null;
|
||||
// self.FishContainer.Dispose();
|
||||
@@ -35,5 +35,56 @@ public sealed class PlayerDestroySystem : DestroySystem<Player>
|
||||
|
||||
public static class PlayerSystem
|
||||
{
|
||||
|
||||
#region 测试数据
|
||||
|
||||
public static void SetTestData(this Player player)
|
||||
{
|
||||
List<int> addItemConfigs = new List<int>()
|
||||
{
|
||||
100001, 100002, 100003,
|
||||
200001,
|
||||
300001, 300002, 300003,
|
||||
400001,
|
||||
500001, 500002,
|
||||
600001, 600002, 600003, 600004,
|
||||
700001,
|
||||
800001
|
||||
};
|
||||
Dictionary<int, List<int>> rigDic = new Dictionary<int, List<int>>()
|
||||
{
|
||||
{ 100001, [300001, 400001, 500002, 700001, 800001] },
|
||||
{ 100002, [200001, 300001, 400001, 500002, 700001, 800001] },
|
||||
{ 100003, [200001, 400001, 600001] }
|
||||
};
|
||||
//添加测试数据
|
||||
if (player.ItemContainer != null && player.ItemContainer.Items.Count < 1)
|
||||
{
|
||||
foreach (var configId in addItemConfigs)
|
||||
{
|
||||
player.ItemContainer.Add(configId, 1);
|
||||
}
|
||||
|
||||
foreach (var (rod, list) in rigDic)
|
||||
{
|
||||
if (player.ItemContainer.GetFistItemByConfigId(rod, out var item) && item != null)
|
||||
{
|
||||
var childs = new List<long>();
|
||||
foreach (var i in list)
|
||||
{
|
||||
if (player.ItemContainer.GetFistItemByConfigId(i, out var itemChild) && itemChild != null)
|
||||
{
|
||||
childs.Add(itemChild.Id);
|
||||
}
|
||||
}
|
||||
|
||||
player.ItemContainer.FishingRig[item.Id] = childs;
|
||||
}
|
||||
}
|
||||
|
||||
// player.ItemContainer.FishingRig
|
||||
}
|
||||
// if(player.gr)
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -12,11 +12,11 @@ public static class PlayerHelper
|
||||
|
||||
public static void InitializeChildEntity(this Player self)
|
||||
{
|
||||
|
||||
if (self.Vip == null)
|
||||
{
|
||||
self.Vip = Entity.Create<PlayerVip>(self.Scene, true, true);
|
||||
}
|
||||
|
||||
if (self.Wallet == null)
|
||||
{
|
||||
self.Wallet = Entity.Create<PlayerWallet>(self.Scene, true, true);
|
||||
@@ -31,12 +31,12 @@ public static class PlayerHelper
|
||||
{
|
||||
self.FishContainer = Entity.Create<FishContainer>(self.Scene, true, true);
|
||||
}
|
||||
|
||||
|
||||
if (self.SkillContainer == null)
|
||||
{
|
||||
self.SkillContainer = Entity.Create<SkillContainer>(self.Scene, true, true);
|
||||
}
|
||||
|
||||
|
||||
if (self.AchievementContainer == null)
|
||||
{
|
||||
self.AchievementContainer = Entity.Create<AchievementContainer>(self.Scene, true, true);
|
||||
@@ -80,6 +80,12 @@ public static class PlayerHelper
|
||||
}
|
||||
|
||||
account.Deserialize(scene);
|
||||
account.ItemContainer.Deserialize(scene);
|
||||
foreach (var (_, item) in account.ItemContainer.Items)
|
||||
{
|
||||
item.Deserialize(scene);
|
||||
}
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
@@ -149,9 +155,9 @@ public static class PlayerHelper
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 结构转换
|
||||
|
||||
|
||||
public static RoleSimpleInfo GetRoleSimpleInfo(this Player self)
|
||||
{
|
||||
return new RoleSimpleInfo()
|
||||
@@ -169,6 +175,8 @@ public static class PlayerHelper
|
||||
{
|
||||
var info = new RoleInfo();
|
||||
info.BaseInfo = GetRoleBaseInfo(self);
|
||||
info.Items = self.ItemContainer.GetItemInfos();
|
||||
info.Gears = self.ItemContainer.GetGearInfos();
|
||||
info.RoleId = self.RouteId;
|
||||
return info;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user