修改钓组相关协议

This commit is contained in:
2025-09-01 23:57:34 +08:00
parent 7cdad80c7a
commit 61d20b5729
16 changed files with 240 additions and 146 deletions

View File

@@ -54,7 +54,7 @@ message Map2C_RoleGearStateNotify // ICustomRouteMessage,MapRoute
message Map2C_RoleGearChangeNotify // ICustomRouteMessage,MapRoute
{
int64 Id = 1;
UnitGearInfo Gears = 2; //钓组数据
GearInfo Gears = 2; //钓组数据
}
///玩家位置变化

View File

@@ -120,10 +120,5 @@ message SkillInfo
message GearInfo
{
int64 Rod = 1;
int64 Line = 2;
int64 Bobber = 3;
int64 Hook = 4;
int64 Bait = 5;
int64 Weight = 6;
int64 Reel = 7;
repeated int64 Rigs = 2; //钓组配件
}

View File

@@ -1,24 +1,3 @@
message UnitGearItemInfo
{
int64 Id = 1; //唯一id
int32 ConfigId = 2; //配置id
}
message UnitGearInfo
{
UnitGearItemInfo Rod = 1;
UnitGearItemInfo Reel = 2;
UnitGearItemInfo Bobber = 3;
UnitGearItemInfo Hook = 4;
UnitGearItemInfo Bait = 5;
UnitGearItemInfo Lure = 6;
UnitGearItemInfo Weight = 7;
UnitGearItemInfo Line = 8;
UnitGearItemInfo Leader = 9;
UnitGearItemInfo Feeder = 10;
}
message Vector3Info
{
float x = 1;
@@ -53,7 +32,7 @@ message MapUnitInfo
RoleSimpleInfo RoleInfo = 2; //基础信息
MapUnitPositionInfo Location = 3; //位置信息
UnitStateInfo State = 4; //状态信息
UnitGearInfo Gears = 5; //钓组数据
GearInfo Gears = 5; //钓组数据
UnitFishingInfo FishingInfo = 6; //钓鱼状态信息
repeated KeyValueInt32 KV = 7; //属性信息
}

View File

@@ -19,14 +19,19 @@ public sealed class ItemContainer : Entity
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
public Dictionary<long, Item> Items = new Dictionary<long, Item>();
/// <summary>
/// 钓组信息
/// </summary>
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
public Dictionary<long, List<long>> FishingRig = new Dictionary<long, List<long>>();
/// <summary>
/// 按物品id分组
/// </summary>
[BsonIgnore] public readonly OneToManyList<uint, Item> ItemsByConfigId = new OneToManyListPool<uint, Item>();
/// <summary>
/// 容器内按物品类型分组
/// </summary>
[BsonIgnore] public readonly OneToManyList<uint, Item> ItemsByType = new OneToManyListPool<uint, Item>();
// /// <summary>
// /// 按物品id分组
// /// </summary>
// [BsonIgnore] public readonly OneToManyList<int, Item> ItemsByConfigId = new OneToManyListPool<int, Item>();
//
// /// <summary>
// /// 容器内按物品类型分组
// /// </summary>
// [BsonIgnore] public readonly OneToManyList<uint, Item> ItemsByType = new OneToManyListPool<uint, Item>();
}

View File

@@ -49,32 +49,32 @@ public sealed class Player : Entity
/// <summary>
/// 角色vip信息
/// </summary>
[BsonElement("vInfo")] public PlayerVip? Vip;
[BsonElement("vInfo")] public PlayerVip Vip;
/// <summary>
/// 钱包
/// </summary>
[BsonElement("wallet")] public PlayerWallet? Wallet;
[BsonElement("wallet")] public PlayerWallet Wallet;
/// <summary>
/// 背包
/// </summary>
[BsonElement("bag")] public ItemContainer? ItemContainer;
[BsonElement("bag")] public ItemContainer ItemContainer;
/// <summary>
/// 鱼护
/// </summary>
[BsonElement("fish")] public FishContainer? FishContainer;
[BsonElement("fish")] public FishContainer FishContainer;
/// <summary>
/// 技能
/// </summary>
[BsonElement("skill")] public SkillContainer? SkillContainer;
[BsonElement("skill")] public SkillContainer SkillContainer;
/// <summary>
/// 成就
/// </summary>
[BsonElement("achievement")] public AchievementContainer? AchievementContainer;
[BsonElement("achievement")] public AchievementContainer AchievementContainer;
/// <summary>
/// 是否是vip

View File

@@ -155,6 +155,7 @@ namespace Fantasy
Currency.Clear();
Slots.Clear();
Skills.Clear();
Gears.Clear();
MapId = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<RoleInfo>(this);
@@ -177,6 +178,8 @@ namespace Fantasy
[ProtoMember(8)]
public List<SkillInfo> Skills = new List<SkillInfo>();
[ProtoMember(9)]
public List<GearInfo> Gears = new List<GearInfo>();
[ProtoMember(10)]
public int MapId { get; set; }
}
/// <summary>
@@ -382,4 +385,27 @@ namespace Fantasy
[ProtoMember(3)]
public int Exp { get; set; }
}
/// <summary>
/// 玩家当前使用钓组信息
/// </summary>
[ProtoContract]
public partial class GearInfo : AMessage, IProto
{
public static GearInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<GearInfo>();
}
public override void Dispose()
{
Rod = default;
Rigs.Clear();
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<GearInfo>(this);
#endif
}
[ProtoMember(1)]
public long Rod { get; set; }
[ProtoMember(2)]
public List<long> Rigs = new List<long>();
}
}

View File

@@ -17,70 +17,6 @@ using Fantasy.Serialize;
namespace Fantasy
{
[ProtoContract]
public partial class UnitGearItemInfo : AMessage, IProto
{
public static UnitGearItemInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<UnitGearItemInfo>();
}
public override void Dispose()
{
Id = default;
ConfigId = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<UnitGearItemInfo>(this);
#endif
}
[ProtoMember(1)]
public long Id { get; set; }
[ProtoMember(2)]
public int ConfigId { get; set; }
}
[ProtoContract]
public partial class UnitGearInfo : AMessage, IProto
{
public static UnitGearInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<UnitGearInfo>();
}
public override void Dispose()
{
Rod = default;
Reel = default;
Bobber = default;
Hook = default;
Bait = default;
Lure = default;
Weight = default;
Line = default;
Leader = default;
Feeder = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<UnitGearInfo>(this);
#endif
}
[ProtoMember(1)]
public UnitGearItemInfo Rod { get; set; }
[ProtoMember(2)]
public UnitGearItemInfo Reel { get; set; }
[ProtoMember(3)]
public UnitGearItemInfo Bobber { get; set; }
[ProtoMember(4)]
public UnitGearItemInfo Hook { get; set; }
[ProtoMember(5)]
public UnitGearItemInfo Bait { get; set; }
[ProtoMember(6)]
public UnitGearItemInfo Lure { get; set; }
[ProtoMember(7)]
public UnitGearItemInfo Weight { get; set; }
[ProtoMember(8)]
public UnitGearItemInfo Line { get; set; }
[ProtoMember(9)]
public UnitGearItemInfo Leader { get; set; }
[ProtoMember(10)]
public UnitGearItemInfo Feeder { get; set; }
}
[ProtoContract]
public partial class Vector3Info : AMessage, IProto
{
@@ -205,7 +141,7 @@ namespace Fantasy
[ProtoMember(4)]
public UnitStateInfo State { get; set; }
[ProtoMember(5)]
public UnitGearInfo Gears { get; set; }
public GearInfo Gears { get; set; }
[ProtoMember(6)]
public UnitFishingInfo FishingInfo { get; set; }
[ProtoMember(7)]

View File

@@ -211,7 +211,7 @@ namespace Fantasy
[ProtoMember(1)]
public long Id { get; set; }
[ProtoMember(2)]
public UnitGearInfo Gears { get; set; }
public GearInfo Gears { get; set; }
}
/// <summary>
/// 玩家位置变化

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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;
}

View File

@@ -3,7 +3,7 @@
"profiles": {
"Main": {
"commandName": "Project",
"workingDirectory": "$(OutputPath)",
// "workingDirectory": "$(OutputPath)",
"environmentVariables": {},
"commandLineArgs": "--m Develop"
}