From 61d20b572997816fea69a9de0b57a1e541b9c6bf Mon Sep 17 00:00:00 2001 From: BobSong <605277374@qq.com> Date: Mon, 1 Sep 2025 23:57:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=92=93=E7=BB=84=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=8D=8F=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NetworkProtocol/Outer/RoomMessage.proto | 2 +- .../Outer/data/CommonProtoData.proto | 7 +- .../Outer/data/MapProtoData.proto | 23 +--- Entity/Game/Item/ItemContainer.cs | 23 ++-- Entity/Game/Player/Player.cs | 12 +- .../NetworkProtocol/CommonProtoData.cs | 26 +++++ .../Generate/NetworkProtocol/MapProtoData.cs | 66 +---------- .../Generate/NetworkProtocol/RoomMessage.cs | 2 +- .../C2Game_GetRoleInfoRequestHandler.cs | 2 + Hotfix/Game/Item/Helper/ItemFactory.cs | 23 +++- Hotfix/Game/Item/ItemContainerSystem.cs | 107 ++++++++++++++---- Hotfix/Game/Item/ItemSystem.cs | 13 ++- .../Components/PlayerManageComponentSystem.cs | 5 +- Hotfix/Game/Player/Entity/PlayerSystem.cs | 55 ++++++++- Hotfix/Game/Player/Helper/PlayerHelper.cs | 18 ++- Main/Properties/launchSettings.json | 2 +- 16 files changed, 240 insertions(+), 146 deletions(-) diff --git a/Config/NetworkProtocol/Outer/RoomMessage.proto b/Config/NetworkProtocol/Outer/RoomMessage.proto index dfbfc29..a066192 100644 --- a/Config/NetworkProtocol/Outer/RoomMessage.proto +++ b/Config/NetworkProtocol/Outer/RoomMessage.proto @@ -54,7 +54,7 @@ message Map2C_RoleGearStateNotify // ICustomRouteMessage,MapRoute message Map2C_RoleGearChangeNotify // ICustomRouteMessage,MapRoute { int64 Id = 1; - UnitGearInfo Gears = 2; //钓组数据 + GearInfo Gears = 2; //钓组数据 } ///玩家位置变化 diff --git a/Config/NetworkProtocol/Outer/data/CommonProtoData.proto b/Config/NetworkProtocol/Outer/data/CommonProtoData.proto index 560d243..41a1b03 100644 --- a/Config/NetworkProtocol/Outer/data/CommonProtoData.proto +++ b/Config/NetworkProtocol/Outer/data/CommonProtoData.proto @@ -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; //钓组配件 } \ No newline at end of file diff --git a/Config/NetworkProtocol/Outer/data/MapProtoData.proto b/Config/NetworkProtocol/Outer/data/MapProtoData.proto index 94739cd..d99c696 100644 --- a/Config/NetworkProtocol/Outer/data/MapProtoData.proto +++ b/Config/NetworkProtocol/Outer/data/MapProtoData.proto @@ -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; //属性信息 } diff --git a/Entity/Game/Item/ItemContainer.cs b/Entity/Game/Item/ItemContainer.cs index b0713e7..9754a1a 100644 --- a/Entity/Game/Item/ItemContainer.cs +++ b/Entity/Game/Item/ItemContainer.cs @@ -19,14 +19,19 @@ public sealed class ItemContainer : Entity [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] public Dictionary Items = new Dictionary(); + /// + /// 钓组信息 + /// + [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] + public Dictionary> FishingRig = new Dictionary>(); - /// - /// 按物品id分组 - /// - [BsonIgnore] public readonly OneToManyList ItemsByConfigId = new OneToManyListPool(); - - /// - /// 容器内按物品类型分组 - /// - [BsonIgnore] public readonly OneToManyList ItemsByType = new OneToManyListPool(); + // /// + // /// 按物品id分组 + // /// + // [BsonIgnore] public readonly OneToManyList ItemsByConfigId = new OneToManyListPool(); + // + // /// + // /// 容器内按物品类型分组 + // /// + // [BsonIgnore] public readonly OneToManyList ItemsByType = new OneToManyListPool(); } \ No newline at end of file diff --git a/Entity/Game/Player/Player.cs b/Entity/Game/Player/Player.cs index 72b7b8a..73f88ba 100644 --- a/Entity/Game/Player/Player.cs +++ b/Entity/Game/Player/Player.cs @@ -49,32 +49,32 @@ public sealed class Player : Entity /// /// 角色vip信息 /// - [BsonElement("vInfo")] public PlayerVip? Vip; + [BsonElement("vInfo")] public PlayerVip Vip; /// /// 钱包 /// - [BsonElement("wallet")] public PlayerWallet? Wallet; + [BsonElement("wallet")] public PlayerWallet Wallet; /// /// 背包 /// - [BsonElement("bag")] public ItemContainer? ItemContainer; + [BsonElement("bag")] public ItemContainer ItemContainer; /// /// 鱼护 /// - [BsonElement("fish")] public FishContainer? FishContainer; + [BsonElement("fish")] public FishContainer FishContainer; /// /// 技能 /// - [BsonElement("skill")] public SkillContainer? SkillContainer; + [BsonElement("skill")] public SkillContainer SkillContainer; /// /// 成就 /// - [BsonElement("achievement")] public AchievementContainer? AchievementContainer; + [BsonElement("achievement")] public AchievementContainer AchievementContainer; /// /// 是否是vip diff --git a/Entity/Generate/NetworkProtocol/CommonProtoData.cs b/Entity/Generate/NetworkProtocol/CommonProtoData.cs index 81573e1..58800c1 100644 --- a/Entity/Generate/NetworkProtocol/CommonProtoData.cs +++ b/Entity/Generate/NetworkProtocol/CommonProtoData.cs @@ -155,6 +155,7 @@ namespace Fantasy Currency.Clear(); Slots.Clear(); Skills.Clear(); + Gears.Clear(); MapId = default; #if FANTASY_NET || FANTASY_UNITY GetScene().MessagePoolComponent.Return(this); @@ -177,6 +178,8 @@ namespace Fantasy [ProtoMember(8)] public List Skills = new List(); [ProtoMember(9)] + public List Gears = new List(); + [ProtoMember(10)] public int MapId { get; set; } } /// @@ -382,4 +385,27 @@ namespace Fantasy [ProtoMember(3)] public int Exp { get; set; } } + /// + /// 玩家当前使用钓组信息 + /// + [ProtoContract] + public partial class GearInfo : AMessage, IProto + { + public static GearInfo Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + Rod = default; + Rigs.Clear(); +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoMember(1)] + public long Rod { get; set; } + [ProtoMember(2)] + public List Rigs = new List(); + } } diff --git a/Entity/Generate/NetworkProtocol/MapProtoData.cs b/Entity/Generate/NetworkProtocol/MapProtoData.cs index d361b08..3206a8c 100644 --- a/Entity/Generate/NetworkProtocol/MapProtoData.cs +++ b/Entity/Generate/NetworkProtocol/MapProtoData.cs @@ -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(); - } - public override void Dispose() - { - Id = default; - ConfigId = default; -#if FANTASY_NET || FANTASY_UNITY - GetScene().MessagePoolComponent.Return(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(); - } - 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(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)] diff --git a/Entity/Generate/NetworkProtocol/RoomMessage.cs b/Entity/Generate/NetworkProtocol/RoomMessage.cs index e54e478..f4c6b52 100644 --- a/Entity/Generate/NetworkProtocol/RoomMessage.cs +++ b/Entity/Generate/NetworkProtocol/RoomMessage.cs @@ -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; } } /// /// 玩家位置变化 diff --git a/Hotfix/Game/Handler/C2Game_GetRoleInfoRequestHandler.cs b/Hotfix/Game/Handler/C2Game_GetRoleInfoRequestHandler.cs index 0ac7054..1d782db 100644 --- a/Hotfix/Game/Handler/C2Game_GetRoleInfoRequestHandler.cs +++ b/Hotfix/Game/Handler/C2Game_GetRoleInfoRequestHandler.cs @@ -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 + /// + /// + /// + /// + /// + public static Item Create(Scene scene, int configId, int count = 1) + { + var item = Entity.Create(scene, true, true); + item.ConfigId = configId; + item.Count = count; + return item; + } } \ No newline at end of file diff --git a/Hotfix/Game/Item/ItemContainerSystem.cs b/Hotfix/Game/Item/ItemContainerSystem.cs index 97ea7e4..a592668 100644 --- a/Hotfix/Game/Item/ItemContainerSystem.cs +++ b/Hotfix/Game/Item/ItemContainerSystem.cs @@ -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 } self.Items.Clear(); - self.ItemsByConfigId.Clear(); - self.ItemsByType.Clear(); + // self.ItemsByConfigId.Clear(); + // self.ItemsByType.Clear(); } } @@ -30,7 +31,7 @@ public static class ItemContainerSystem /// /// /// - 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 /// /// /// - /// - public static void GetItemByConfigId(this ItemContainer self, uint configId, List items) + /// + 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(); } - /// - /// 通过类型获取物品 - /// - /// - /// - /// - public static void GetItemByType(this ItemContainer self, ItemType type, List items) + // /// + // /// 通过配置id获取物品 + // /// + // /// + // /// + // /// + // public static void GetItemByConfigId(this ItemContainer self, uint configId, List items) + // { + // if (!self.ItemsByConfigId.TryGetValue(configId, out var itemList)) + // { + // return; + // } + // + // items.AddRange(itemList); + // } + + // /// + // /// 通过类型获取物品 + // /// + // /// + // /// + // /// + // public static void GetItemByType(this ItemContainer self, ItemType type, List 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 GetItemInfos(this ItemContainer self) + { + List ret = new List(); + foreach (var (_, item) in self.Items) { - return; + ret.Add(item.ToItemInfo()); } - items.AddRange(itemList); + return ret; + } + + public static List GetGearInfos(this ItemContainer self) + { + List ret = new List(); + + foreach (var (rod, rigs) in self.FishingRig) + { + GearInfo gearInfo = new GearInfo(); + gearInfo.Rod = rod; + gearInfo.Rigs.AddRange(rigs); + ret.Add(gearInfo); + } + + return ret; } #endregion diff --git a/Hotfix/Game/Item/ItemSystem.cs b/Hotfix/Game/Item/ItemSystem.cs index d3ae38a..abcc141 100644 --- a/Hotfix/Game/Item/ItemSystem.cs +++ b/Hotfix/Game/Item/ItemSystem.cs @@ -18,14 +18,16 @@ public class ItemDestroySystem : DestroySystem 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; } + } \ No newline at end of file diff --git a/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs b/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs index ed6c976..f88a4f0 100644 --- a/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs +++ b/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs @@ -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 + + } \ No newline at end of file diff --git a/Hotfix/Game/Player/Entity/PlayerSystem.cs b/Hotfix/Game/Player/Entity/PlayerSystem.cs index 37b6be1..a5f1b36 100644 --- a/Hotfix/Game/Player/Entity/PlayerSystem.cs +++ b/Hotfix/Game/Player/Entity/PlayerSystem.cs @@ -17,7 +17,7 @@ public sealed class PlayerDestroySystem : DestroySystem 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 public static class PlayerSystem { - + #region 测试数据 + + public static void SetTestData(this Player player) + { + List addItemConfigs = new List() + { + 100001, 100002, 100003, + 200001, + 300001, 300002, 300003, + 400001, + 500001, 500002, + 600001, 600002, 600003, 600004, + 700001, + 800001 + }; + Dictionary> rigDic = new Dictionary>() + { + { 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(); + 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 } \ No newline at end of file diff --git a/Hotfix/Game/Player/Helper/PlayerHelper.cs b/Hotfix/Game/Player/Helper/PlayerHelper.cs index 23e0d24..43e47ec 100644 --- a/Hotfix/Game/Player/Helper/PlayerHelper.cs +++ b/Hotfix/Game/Player/Helper/PlayerHelper.cs @@ -12,11 +12,11 @@ public static class PlayerHelper public static void InitializeChildEntity(this Player self) { - if (self.Vip == null) { self.Vip = Entity.Create(self.Scene, true, true); } + if (self.Wallet == null) { self.Wallet = Entity.Create(self.Scene, true, true); @@ -31,12 +31,12 @@ public static class PlayerHelper { self.FishContainer = Entity.Create(self.Scene, true, true); } - + if (self.SkillContainer == null) { self.SkillContainer = Entity.Create(self.Scene, true, true); } - + if (self.AchievementContainer == null) { self.AchievementContainer = Entity.Create(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; } diff --git a/Main/Properties/launchSettings.json b/Main/Properties/launchSettings.json index 90a0233..c31a6c9 100644 --- a/Main/Properties/launchSettings.json +++ b/Main/Properties/launchSettings.json @@ -3,7 +3,7 @@ "profiles": { "Main": { "commandName": "Project", - "workingDirectory": "$(OutputPath)", +// "workingDirectory": "$(OutputPath)", "environmentVariables": {}, "commandLineArgs": "--m Develop" }