diff --git a/Config/NetworkProtocol/Inner/InnerMessage.proto b/Config/NetworkProtocol/Inner/InnerMessage.proto index 8470470..8f9b6a3 100644 --- a/Config/NetworkProtocol/Inner/InnerMessage.proto +++ b/Config/NetworkProtocol/Inner/InnerMessage.proto @@ -23,6 +23,17 @@ message Game2G_ExitResponse // IRouteResponse } +///获取玩家基础信息 +message S2G_GetPlayerBasicInfoRequest // IRouteRequest,G2S_GetPlayerBasicInfoResponse +{ + repeated int64 IdList = 1; // 查询列表 +} +///获取玩家基础信息响应 +message G2S_GetPlayerBasicInfoResponse // IRouteResponse +{ + repeated RoleSimpleInfo RoleList = 1; +} + ///通知游戏服角色进入该聊天服 diff --git a/Config/NetworkProtocol/Outer/SocialMessage.proto b/Config/NetworkProtocol/Outer/SocialMessage.proto index 408b6b0..50f9fe1 100644 --- a/Config/NetworkProtocol/Outer/SocialMessage.proto +++ b/Config/NetworkProtocol/Outer/SocialMessage.proto @@ -115,7 +115,7 @@ message S2C_GetChatRecordResponse // ICustomRouteResponse } - +////////////// ******** 工会 *******///////////// message ClubInfo { diff --git a/Config/NetworkProtocol/Outer/data/Account.proto b/Config/NetworkProtocol/Outer/data/Account.proto index b5b710f..88f3808 100644 --- a/Config/NetworkProtocol/Outer/data/Account.proto +++ b/Config/NetworkProtocol/Outer/data/Account.proto @@ -9,6 +9,8 @@ message RoleBaseInfo string Country = 3; //国家 int32 Level = 4; //等级 int32 Exp = 5; //当前等级 + bool Vip = 6; //是否vip + VipInfo VipInfo = 7; //vip信息 } message KeyValueStringInt64 @@ -51,6 +53,7 @@ message RoleSimpleInfo string Head = 3; //头像 string Country = 4; //国家 int32 Level = 5; //等级 + bool Vip = 6; //是否vip } /// VIP信息 diff --git a/Entity/Def/AppConfig.cs b/Entity/Def/AppConfig.cs new file mode 100644 index 0000000..31f9071 --- /dev/null +++ b/Entity/Def/AppConfig.cs @@ -0,0 +1,14 @@ +namespace NB; + +public class AppConfig +{ + /// + /// 缓存过期检测时间间隔,1小时 + /// + public static long CacheCheckIntervalTime = 360000; + + /// + /// 玩家数据定时落地间隔 + /// + public const long PlayerDataAutoSaveTime = 60000; // 600000; +} \ No newline at end of file diff --git a/Entity/Game/Cache/PlayerBasicCache.cs b/Entity/Game/Cache/PlayerBasicCache.cs new file mode 100644 index 0000000..de4aeb5 --- /dev/null +++ b/Entity/Game/Cache/PlayerBasicCache.cs @@ -0,0 +1,42 @@ +using Fantasy.Entitas; +using MongoDB.Bson.Serialization.Attributes; + +namespace NB.Game; + +public class PlayerBasicCache : Entity +{ + /// + /// 昵称 + /// + public string NickName = ""; + + /// + /// 头像 + /// + public string Head = ""; + + /// + /// 国家 + /// + public string Country = ""; + + /// + /// 等级 + /// + public int Level; + + /// + /// 当前经验 + /// + public int Exp; + + /// + /// 是否是vip + /// + public bool IsVip; + + /// + /// 缓存失效时间 + /// + public long ExpirationTime; +} \ No newline at end of file diff --git a/Entity/Game/Cache/PlayerBasicCacheManageComponent.cs b/Entity/Game/Cache/PlayerBasicCacheManageComponent.cs new file mode 100644 index 0000000..0d03837 --- /dev/null +++ b/Entity/Game/Cache/PlayerBasicCacheManageComponent.cs @@ -0,0 +1,8 @@ +using Fantasy.Entitas; + +namespace NB.Game; + +public class PlayerBasicCacheManageComponent : Entity +{ + public readonly Dictionary Players = new(); +} \ No newline at end of file diff --git a/Entity/Game/Player/Child/PlayerBasic.cs b/Entity/Game/Player/Child/PlayerBasic.cs index 71017db..031acb8 100644 --- a/Entity/Game/Player/Child/PlayerBasic.cs +++ b/Entity/Game/Player/Child/PlayerBasic.cs @@ -3,30 +3,30 @@ using MongoDB.Bson.Serialization.Attributes; namespace NB.Game; -public class PlayerBasic : Entity -{ - /// - /// 昵称 - /// - public string NickName; - - /// - /// 头像 - /// - public string Head; - - /// - /// 国家 - /// - public string Country; - - /// - /// 等级 - /// - public int Level; - - /// - /// 当前经验 - /// - public int Exp; -} \ No newline at end of file +// public class PlayerBasic : Entity +// { +// /// +// /// 昵称 +// /// +// public string NickName; +// +// /// +// /// 头像 +// /// +// public string Head; +// +// /// +// /// 国家 +// /// +// public string Country; +// +// /// +// /// 等级 +// /// +// public int Level; +// +// /// +// /// 当前经验 +// /// +// public int Exp; +// } \ No newline at end of file diff --git a/Entity/Game/Player/Child/PlayerVip.cs b/Entity/Game/Player/Child/PlayerVip.cs index 3124a60..7d04659 100644 --- a/Entity/Game/Player/Child/PlayerVip.cs +++ b/Entity/Game/Player/Child/PlayerVip.cs @@ -5,11 +5,6 @@ namespace NB; public class PlayerVip : Entity { - /// - /// 是否是vip - /// - public bool IsVip; - /// /// 获取时间 /// diff --git a/Entity/Game/Player/Player.cs b/Entity/Game/Player/Player.cs index b2d3f97..0d3f9ae 100644 --- a/Entity/Game/Player/Player.cs +++ b/Entity/Game/Player/Player.cs @@ -7,44 +7,69 @@ namespace NB.Game; public sealed class Player : Entity { /// - /// 基础信息 + /// 昵称 /// - public PlayerBasic Basic; + [BsonElement("name")] public string NickName = ""; + + /// + /// 头像 + /// + [BsonElement("head")] public string Head = ""; + + /// + /// 国家 + /// + [BsonElement("ccy")] public string Country = ""; + + /// + /// 等级 + /// + [BsonElement("lv")] public int Level; + + /// + /// 当前经验 + /// + [BsonElement("exp")] public int Exp; + + /// + /// 是否是vip + /// + [BsonElement("vip")] public bool IsVip; /// /// 统计信息 /// - public PlayerStatistics Statistics; + [BsonElement("stat")] public PlayerStatistics Statistics; /// /// 角色vip信息 /// - public PlayerVip Vip; + [BsonElement("vInfo")] public PlayerVip Vip; /// /// 钱包 /// - public PlayerWallet Wallet; + [BsonElement("wallet")] public PlayerWallet Wallet; /// /// 背包 /// - public ItemContainer ItemContainer; + [BsonElement("bag")] public ItemContainer ItemContainer; /// /// 鱼护 /// - public FishContainer FishContainer; + [BsonElement("fish")] public FishContainer FishContainer; /// /// 技能 /// - public SkillContainer SkillContainer; + [BsonElement("skill")] public SkillContainer SkillContainer; /// /// 成就 /// - public AchievementContainer AchievementContainer; + [BsonElement("achievement")] public AchievementContainer AchievementContainer; [BsonIgnore] public long SessionRunTimeId; diff --git a/Entity/Game/Player/PlayerManageComponent.cs b/Entity/Game/Player/PlayerManageComponent.cs index f153818..59905f4 100644 --- a/Entity/Game/Player/PlayerManageComponent.cs +++ b/Entity/Game/Player/PlayerManageComponent.cs @@ -4,11 +4,6 @@ namespace NB.Game; public sealed class PlayerManageComponent : Entity { - /// - /// 10分钟 - /// - public const long AutoSaveTime = 60000; // 600000; - public long AutoSaveTimerId; public readonly Dictionary Players = new(); diff --git a/Entity/Generate/NetworkProtocol/Account.cs b/Entity/Generate/NetworkProtocol/Account.cs index ea3c8f8..aeee4aa 100644 --- a/Entity/Generate/NetworkProtocol/Account.cs +++ b/Entity/Generate/NetworkProtocol/Account.cs @@ -34,6 +34,8 @@ namespace Fantasy Country = default; Level = default; Exp = default; + Vip = default; + VipInfo = default; #if FANTASY_NET || FANTASY_UNITY GetScene().MessagePoolComponent.Return(this); #endif @@ -48,6 +50,10 @@ namespace Fantasy public int Level { get; set; } [ProtoMember(5)] public int Exp { get; set; } + [ProtoMember(6)] + public bool Vip { get; set; } + [ProtoMember(7)] + public VipInfo VipInfo { get; set; } } [ProtoContract] public partial class KeyValueStringInt64 : AMessage, IProto @@ -167,6 +173,7 @@ namespace Fantasy Head = default; Country = default; Level = default; + Vip = default; #if FANTASY_NET || FANTASY_UNITY GetScene().MessagePoolComponent.Return(this); #endif @@ -181,6 +188,8 @@ namespace Fantasy public string Country { get; set; } [ProtoMember(5)] public int Level { get; set; } + [ProtoMember(6)] + public bool Vip { get; set; } } /// /// VIP信息 diff --git a/Entity/Generate/NetworkProtocol/InnerMessage.cs b/Entity/Generate/NetworkProtocol/InnerMessage.cs index f483672..07bdcae 100644 --- a/Entity/Generate/NetworkProtocol/InnerMessage.cs +++ b/Entity/Generate/NetworkProtocol/InnerMessage.cs @@ -109,6 +109,53 @@ namespace Fantasy public uint ErrorCode { get; set; } } /// + /// 获取玩家基础信息 + /// + [ProtoContract] + public partial class S2G_GetPlayerBasicInfoRequest : AMessage, IRouteRequest, IProto + { + public static S2G_GetPlayerBasicInfoRequest Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + IdList.Clear(); +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + [ProtoIgnore] + public G2S_GetPlayerBasicInfoResponse ResponseType { get; set; } + public uint OpCode() { return InnerOpcode.S2G_GetPlayerBasicInfoRequest; } + [ProtoMember(1)] + public List IdList = new List(); + } + /// + /// 获取玩家基础信息响应 + /// + [ProtoContract] + public partial class G2S_GetPlayerBasicInfoResponse : AMessage, IRouteResponse, IProto + { + public static G2S_GetPlayerBasicInfoResponse Create(Scene scene) + { + return scene.MessagePoolComponent.Rent(); + } + public override void Dispose() + { + ErrorCode = default; + RoleList.Clear(); +#if FANTASY_NET || FANTASY_UNITY + GetScene().MessagePoolComponent.Return(this); +#endif + } + public uint OpCode() { return InnerOpcode.G2S_GetPlayerBasicInfoResponse; } + [ProtoMember(1)] + public List RoleList = new List(); + [ProtoMember(2)] + public uint ErrorCode { get; set; } + } + /// /// 通知游戏服角色进入该聊天服 /// [ProtoContract] diff --git a/Entity/Generate/NetworkProtocol/InnerOpcode.cs b/Entity/Generate/NetworkProtocol/InnerOpcode.cs index d4ed182..96c73a4 100644 --- a/Entity/Generate/NetworkProtocol/InnerOpcode.cs +++ b/Entity/Generate/NetworkProtocol/InnerOpcode.cs @@ -6,10 +6,12 @@ namespace Fantasy public const uint Game2G_EnterResponse = 1207969553; public const uint G2Game_ExitRequest = 1073751826; public const uint Game2G_ExitResponse = 1207969554; - public const uint G2S_EnterRequest = 1073751827; - public const uint S2G_EnterResponse = 1207969555; - public const uint G2S_ExitRequest = 1073751828; - public const uint S2G_ExitResponse = 1207969556; + public const uint S2G_GetPlayerBasicInfoRequest = 1073751827; + public const uint G2S_GetPlayerBasicInfoResponse = 1207969555; + public const uint G2S_EnterRequest = 1073751828; + public const uint S2G_EnterResponse = 1207969556; + public const uint G2S_ExitRequest = 1073751829; + public const uint S2G_ExitResponse = 1207969557; public const uint S2G_ChatMessage = 939534097; public const uint Club2Chat_CreateChannel = 939534098; } diff --git a/Entity/Generate/NetworkProtocol/SocialMessage.cs b/Entity/Generate/NetworkProtocol/SocialMessage.cs index 92cd9f7..6a28d8a 100644 --- a/Entity/Generate/NetworkProtocol/SocialMessage.cs +++ b/Entity/Generate/NetworkProtocol/SocialMessage.cs @@ -441,6 +441,9 @@ namespace Fantasy [ProtoMember(2)] public uint ErrorCode { get; set; } } + /// + /// /////////// ******** 工会 *******///////////// + /// [ProtoContract] public partial class ClubInfo : AMessage, IProto { diff --git a/Hotfix/Game/Cache/Handler/CacheHandler.cs b/Hotfix/Game/Cache/Handler/CacheHandler.cs new file mode 100644 index 0000000..f911111 --- /dev/null +++ b/Hotfix/Game/Cache/Handler/CacheHandler.cs @@ -0,0 +1,16 @@ +using Fantasy; + +namespace NB.Game; + +public static class CacheHandler +{ + public static List GetPlayerBasicCacheInfos(List id) + { + + } + + public static RoleSimpleInfo GetPlayerBasicCacheInfos(long id) + { + + } +} \ No newline at end of file diff --git a/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs b/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs index 492c71d..1193168 100644 --- a/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs +++ b/Hotfix/Game/Player/Components/PlayerManageComponentSystem.cs @@ -59,11 +59,11 @@ public static class PlayerManageComponentSystem account = PlayerFactory.Create(scene, accountId); - account.Basic.Level = 99; - account.Basic.NickName = "王麻子"; - account.Basic.Country = "cn"; - account.Basic.Exp = 999; - account.Basic.Head = "xxx.png"; + account.Level = 99; + account.NickName = "王麻子"; + account.Country = "cn"; + account.Exp = 999; + account.Head = "xxx.png"; // for (int i = 0; i < 500; i++) // { diff --git a/Hotfix/Game/Player/Entity/PlayerSystem.cs b/Hotfix/Game/Player/Entity/PlayerSystem.cs index e3dbff5..68dcc1e 100644 --- a/Hotfix/Game/Player/Entity/PlayerSystem.cs +++ b/Hotfix/Game/Player/Entity/PlayerSystem.cs @@ -12,8 +12,13 @@ public sealed class PlayerDestroySystem : DestroySystem { protected override void Destroy(Player self) { - self.Basic.Dispose(); - self.Basic = null; + self.NickName = string.Empty; + self.Level = 0; + self.Exp = 0; + self.Country = string.Empty; + self.IsVip = false; + self.Head = string.Empty; + self.ItemContainer.Dispose(); self.ItemContainer = null; self.FishContainer.Dispose(); diff --git a/Hotfix/Game/Player/Helper/PlayerHelper.cs b/Hotfix/Game/Player/Helper/PlayerHelper.cs index fbd39c2..c370d38 100644 --- a/Hotfix/Game/Player/Helper/PlayerHelper.cs +++ b/Hotfix/Game/Player/Helper/PlayerHelper.cs @@ -12,11 +12,6 @@ public static class PlayerHelper public static void InitializeChildEntity(this Player self) { - if (self.Basic == null) - { - self.Basic = Entity.Create(self.Scene, true, true); - } - if (self.ItemContainer == null) { self.ItemContainer = Entity.Create(self.Scene, true, true); @@ -54,7 +49,7 @@ public static class PlayerHelper public static async FTask Save(this Player self) { self.NeedSave = true; - self.NeedSaveTime = TimeHelper.Now + PlayerManageComponent.AutoSaveTime; + self.NeedSaveTime = TimeHelper.Now + AppConfig.PlayerDataAutoSaveTime; //先立马保存,后续做缓存 await self.Scene.World.DataBase.Save(self); } @@ -171,10 +166,11 @@ public static class PlayerHelper return new RoleSimpleInfo() { RoleId = self.Id, - NickName = self.Basic.NickName, - Head = self.Basic.Head, - Country = self.Basic.Country, - Level = self.Basic.Level + NickName = self.NickName, + Head = self.Head, + Country = self.Country, + Level = self.Level, + Vip = self.IsVip, }; } @@ -187,14 +183,22 @@ public static class PlayerHelper public static RoleBaseInfo GetRoleBaseInfo(this Player self) { - return new RoleBaseInfo() + var ret = new RoleBaseInfo() { - NickName = self.Basic.NickName, - Head = self.Basic.Head, - Country = self.Basic.Country, - Level = self.Basic.Level, - Exp = self.Basic.Exp, + NickName = self.NickName, + Head = self.Head, + Country = self.Country, + Level = self.Level, + Exp = self.Exp, }; + if (self.IsVip) + { + ret.VipInfo = new VipInfo(); + ret.VipInfo.OpenTime = self.Vip.GetTime; + ret.VipInfo.ExpirationTime = self.Vip.ExpirationTime; + } + + return ret; } #endregion diff --git a/Hotfix/OnCreateSceneEvent.cs b/Hotfix/OnCreateSceneEvent.cs index f43ea11..a820d2e 100644 --- a/Hotfix/OnCreateSceneEvent.cs +++ b/Hotfix/OnCreateSceneEvent.cs @@ -4,6 +4,7 @@ using Fantasy.Entitas; using Fantasy.Event; using Fantasy.Helper; using Fantasy.Serialize; +using NB.Game; using ProtoBuf; namespace NB; @@ -28,7 +29,6 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem /// A task representing the asynchronous operation. protected override async FTask Handler(OnCreateScene self) { - // var epoch1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks / 10000; // // { @@ -44,16 +44,16 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem // var time = (uint)((now - epochThisYear) / 1000); // Log.Debug($"time = {time} now = {now} epochThisYear = {epochThisYear}"); // } - + var scene = self.Scene; - + switch (scene.SceneType) { case 6666: { var subSceneTestComponent = scene.AddComponent(); Log.Debug("增加了SubSceneTestComponent"); - scene.EntityComponent.CustomSystem(subSceneTestComponent,CustomSystemType.RunSystem); + scene.EntityComponent.CustomSystem(subSceneTestComponent, CustomSystemType.RunSystem); break; } case SceneType.Addressable: @@ -71,6 +71,23 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem { break; } + case SceneType.Game: + { + // for (int i = 0; i < 100; i++) + // { + // var accountId = scene.EntityIdFactory.Create; + // var account = PlayerFactory.Create(scene, accountId); + // + // account.Level = 99; + // account.NickName = $"测试号{i + 1}"; + // account.Country = "cn"; + // account.Exp = 999; + // account.Head = "xxx.png"; + // await account.Save(); + // } + // + break; + } case SceneType.Gate: { // var tasks = new List(2000); @@ -92,7 +109,7 @@ public sealed class OnCreateSceneEvent : AsyncEventSystem // } // await FTask.WaitAll(tasks); // } - + // 执行自定义系统 var testCustomSystemComponent = scene.AddComponent(); scene.EntityComponent.CustomSystem(testCustomSystemComponent, CustomSystemType.RunSystem);