缓存模块

This commit is contained in:
bob
2025-08-15 18:12:04 +08:00
parent d5689258fc
commit 34b25273a7
19 changed files with 275 additions and 79 deletions

14
Entity/Def/AppConfig.cs Normal file
View File

@@ -0,0 +1,14 @@
namespace NB;
public class AppConfig
{
/// <summary>
/// 缓存过期检测时间间隔,1小时
/// </summary>
public static long CacheCheckIntervalTime = 360000;
/// <summary>
/// 玩家数据定时落地间隔
/// </summary>
public const long PlayerDataAutoSaveTime = 60000; // 600000;
}

View File

@@ -0,0 +1,42 @@
using Fantasy.Entitas;
using MongoDB.Bson.Serialization.Attributes;
namespace NB.Game;
public class PlayerBasicCache : Entity
{
/// <summary>
/// 昵称
/// </summary>
public string NickName = "";
/// <summary>
/// 头像
/// </summary>
public string Head = "";
/// <summary>
/// 国家
/// </summary>
public string Country = "";
/// <summary>
/// 等级
/// </summary>
public int Level;
/// <summary>
/// 当前经验
/// </summary>
public int Exp;
/// <summary>
/// 是否是vip
/// </summary>
public bool IsVip;
/// <summary>
/// 缓存失效时间
/// </summary>
public long ExpirationTime;
}

View File

@@ -0,0 +1,8 @@
using Fantasy.Entitas;
namespace NB.Game;
public class PlayerBasicCacheManageComponent : Entity
{
public readonly Dictionary<long, PlayerBasicCache> Players = new();
}

View File

@@ -3,30 +3,30 @@ using MongoDB.Bson.Serialization.Attributes;
namespace NB.Game;
public class PlayerBasic : Entity
{
/// <summary>
/// 昵称
/// </summary>
public string NickName;
/// <summary>
/// 头像
/// </summary>
public string Head;
/// <summary>
/// 国家
/// </summary>
public string Country;
/// <summary>
/// 等级
/// </summary>
public int Level;
/// <summary>
/// 当前经验
/// </summary>
public int Exp;
}
// public class PlayerBasic : Entity
// {
// /// <summary>
// /// 昵称
// /// </summary>
// public string NickName;
//
// /// <summary>
// /// 头像
// /// </summary>
// public string Head;
//
// /// <summary>
// /// 国家
// /// </summary>
// public string Country;
//
// /// <summary>
// /// 等级
// /// </summary>
// public int Level;
//
// /// <summary>
// /// 当前经验
// /// </summary>
// public int Exp;
// }

View File

@@ -5,11 +5,6 @@ namespace NB;
public class PlayerVip : Entity
{
/// <summary>
/// 是否是vip
/// </summary>
public bool IsVip;
/// <summary>
/// 获取时间
/// </summary>

View File

@@ -7,44 +7,69 @@ namespace NB.Game;
public sealed class Player : Entity
{
/// <summary>
/// 基础信息
/// 昵称
/// </summary>
public PlayerBasic Basic;
[BsonElement("name")] public string NickName = "";
/// <summary>
/// 头像
/// </summary>
[BsonElement("head")] public string Head = "";
/// <summary>
/// 国家
/// </summary>
[BsonElement("ccy")] public string Country = "";
/// <summary>
/// 等级
/// </summary>
[BsonElement("lv")] public int Level;
/// <summary>
/// 当前经验
/// </summary>
[BsonElement("exp")] public int Exp;
/// <summary>
/// 是否是vip
/// </summary>
[BsonElement("vip")] public bool IsVip;
/// <summary>
/// 统计信息
/// </summary>
public PlayerStatistics Statistics;
[BsonElement("stat")] public PlayerStatistics Statistics;
/// <summary>
/// 角色vip信息
/// </summary>
public PlayerVip Vip;
[BsonElement("vInfo")] public PlayerVip Vip;
/// <summary>
/// 钱包
/// </summary>
public PlayerWallet Wallet;
[BsonElement("wallet")] public PlayerWallet Wallet;
/// <summary>
/// 背包
/// </summary>
public ItemContainer ItemContainer;
[BsonElement("bag")] public ItemContainer ItemContainer;
/// <summary>
/// 鱼护
/// </summary>
public FishContainer FishContainer;
[BsonElement("fish")] public FishContainer FishContainer;
/// <summary>
/// 技能
/// </summary>
public SkillContainer SkillContainer;
[BsonElement("skill")] public SkillContainer SkillContainer;
/// <summary>
/// 成就
/// </summary>
public AchievementContainer AchievementContainer;
[BsonElement("achievement")] public AchievementContainer AchievementContainer;
[BsonIgnore] public long SessionRunTimeId;

View File

@@ -4,11 +4,6 @@ namespace NB.Game;
public sealed class PlayerManageComponent : Entity
{
/// <summary>
/// 10分钟
/// </summary>
public const long AutoSaveTime = 60000; // 600000;
public long AutoSaveTimerId;
public readonly Dictionary<long, Player> Players = new();

View File

@@ -34,6 +34,8 @@ namespace Fantasy
Country = default;
Level = default;
Exp = default;
Vip = default;
VipInfo = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<RoleBaseInfo>(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<RoleSimpleInfo>(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; }
}
/// <summary>
/// VIP信息

View File

@@ -109,6 +109,53 @@ namespace Fantasy
public uint ErrorCode { get; set; }
}
/// <summary>
/// 获取玩家基础信息
/// </summary>
[ProtoContract]
public partial class S2G_GetPlayerBasicInfoRequest : AMessage, IRouteRequest, IProto
{
public static S2G_GetPlayerBasicInfoRequest Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<S2G_GetPlayerBasicInfoRequest>();
}
public override void Dispose()
{
IdList.Clear();
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<S2G_GetPlayerBasicInfoRequest>(this);
#endif
}
[ProtoIgnore]
public G2S_GetPlayerBasicInfoResponse ResponseType { get; set; }
public uint OpCode() { return InnerOpcode.S2G_GetPlayerBasicInfoRequest; }
[ProtoMember(1)]
public List<long> IdList = new List<long>();
}
/// <summary>
/// 获取玩家基础信息响应
/// </summary>
[ProtoContract]
public partial class G2S_GetPlayerBasicInfoResponse : AMessage, IRouteResponse, IProto
{
public static G2S_GetPlayerBasicInfoResponse Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<G2S_GetPlayerBasicInfoResponse>();
}
public override void Dispose()
{
ErrorCode = default;
RoleList.Clear();
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<G2S_GetPlayerBasicInfoResponse>(this);
#endif
}
public uint OpCode() { return InnerOpcode.G2S_GetPlayerBasicInfoResponse; }
[ProtoMember(1)]
public List<RoleSimpleInfo> RoleList = new List<RoleSimpleInfo>();
[ProtoMember(2)]
public uint ErrorCode { get; set; }
}
/// <summary>
/// 通知游戏服角色进入该聊天服
/// </summary>
[ProtoContract]

View File

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

View File

@@ -441,6 +441,9 @@ namespace Fantasy
[ProtoMember(2)]
public uint ErrorCode { get; set; }
}
/// <summary>
/// /////////// ******** 工会 *******/////////////
/// </summary>
[ProtoContract]
public partial class ClubInfo : AMessage, IProto
{