新增角色相关信息

This commit is contained in:
2025-07-28 23:45:46 +08:00
parent be33e12b35
commit 09bbae66d2
68 changed files with 452 additions and 662 deletions

View File

@@ -28,7 +28,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Gate\" />
<Folder Include="Map\" />
</ItemGroup>

View File

@@ -5,8 +5,7 @@ namespace NB;
/// <summary>
/// 角色基础数据
/// </summary>
[RoleCom]
public class RoleBasic : Entity
public class PlayerBasic
{
/// <summary>
/// 昵称

View File

@@ -5,7 +5,6 @@ namespace NB;
/// <summary>
/// 角色状态标志量
/// </summary>
[RoleCom]
public class RoleDayFlags : Entity
public class PlayerDayFlags
{
}

View File

@@ -5,8 +5,7 @@ namespace NB;
/// <summary>
/// 角色统计数据
/// </summary>
[RoleCom]
public class RoleStatistics : Entity
public class PlayerStatistics
{
/// <summary>
/// 登录次数

View File

@@ -0,0 +1,30 @@
using Fantasy.Entitas;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson.Serialization.Options;
namespace NB.Game;
public sealed class Player : Entity
{
public long CreateTime;
public long LoginTime;
public PlayerBasic Basic = new PlayerBasic();
public PlayerStatistics Statistics = new PlayerStatistics();
public PlayerDayFlags DayFlags = new PlayerDayFlags();
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
public Dictionary<int, int> Currency = new();
[BsonIgnore] public long SessionRunTimeId;
/// <summary>
/// 需要保存数据库
/// </summary>
[BsonIgnore] public bool NeedSave;
/// <summary>
/// 最后保存时间
/// </summary>
[BsonIgnore] public long LastSaveTime;
}

View File

@@ -0,0 +1,8 @@
using Fantasy.Entitas;
namespace NB.Game;
public class PlayerAutoSaveComponent : Entity
{
}

View File

@@ -1,6 +1,6 @@
using Fantasy.Entitas;
namespace NB.Gate;
namespace NB.Game;
public sealed class PlayerManageComponent : Entity
{

View File

@@ -1,15 +0,0 @@
using Fantasy.Entitas;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson.Serialization.Options;
namespace NB;
/// <summary>
/// 角色货币数据
/// </summary>
[RoleCom]
public class RoleCurrency : Entity
{
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
public Dictionary<int, int> dic = new();
}

View File

@@ -1,8 +0,0 @@
using Fantasy.Entitas;
namespace NB;
public sealed class Role : Entity
{
}

View File

@@ -1,10 +0,0 @@
using CommandLine;
namespace NB;
/// <summary>
/// 挂这个 玩家Unit创建时会自动添加此组件
/// </summary>
public class RoleComAttribute : BaseAttribute
{
}

View File

@@ -1,11 +0,0 @@
using Fantasy.Entitas;
namespace NB;
public class RoleManagerComponent : Entity
{
/// <summary>
/// 游戏列表
/// </summary>
public readonly Dictionary<long, Role> Roles = new();
}

View File

@@ -1,13 +0,0 @@
using Fantasy.Entitas;
using MongoDB.Bson.Serialization.Attributes;
namespace NB.Gate;
public sealed class Player : Entity
{
public long CreateTime;
public long LoginTime;
[BsonIgnore]
public long SessionRunTimeId;
}

View File

@@ -1,15 +0,0 @@
using Fantasy.Entitas;
namespace NB.Gate;
public sealed class PlayerFlagComponent : Entity
{
public bool Kick { get; set; }
public long AccountID;
// 有一种可能当在Account在其他地方被销毁
// 这时候因为这个Account是会回收到池子中所以这个引用还是有效的
// 那这时候就会出现这个引用的Account可能是其他用户的了。
public EntityReference<Player> Player;
}

View File

@@ -0,0 +1,10 @@
using Fantasy.Entitas;
namespace NB.Gate;
public sealed class SessionPlayerComponent : Entity
{
public bool Kick { get; set; }
public long AccountID;
}

View File

@@ -15,6 +15,53 @@ using Fantasy.Serialize;
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
#pragma warning disable CS8618
namespace NBC
namespace Fantasy
{
/// <summary>
/// 通知游戏服角色进入该游戏服
/// </summary>
[ProtoContract]
public partial class G2Game_EnterRequest : AMessage, IRouteRequest, IProto
{
public static G2Game_EnterRequest Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<G2Game_EnterRequest>();
}
public override void Dispose()
{
AccountId = default;
GateRouteId = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<G2Game_EnterRequest>(this);
#endif
}
[ProtoIgnore]
public Game2G_EnterResponse ResponseType { get; set; }
public uint OpCode() { return InnerOpcode.G2Game_EnterRequest; }
[ProtoMember(1)]
public long AccountId { get; set; }
[ProtoMember(2)]
public long GateRouteId { get; set; }
}
[ProtoContract]
public partial class Game2G_EnterResponse : AMessage, IRouteResponse, IProto
{
public static Game2G_EnterResponse Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<Game2G_EnterResponse>();
}
public override void Dispose()
{
ErrorCode = default;
RoleRouteId = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<Game2G_EnterResponse>(this);
#endif
}
public uint OpCode() { return InnerOpcode.Game2G_EnterResponse; }
[ProtoMember(1)]
public long RoleRouteId { get; set; }
[ProtoMember(2)]
public uint ErrorCode { get; set; }
}
}

View File

@@ -2,5 +2,7 @@ namespace Fantasy
{
public static partial class InnerOpcode
{
public const uint G2Game_EnterRequest = 1073751825;
public const uint Game2G_EnterResponse = 1207969553;
}
}

View File

@@ -0,0 +1,75 @@
using ProtoBuf;
using System.Collections.Generic;
using MongoDB.Bson.Serialization.Attributes;
using Fantasy;
using Fantasy.Network.Interface;
using Fantasy.Serialize;
// ReSharper disable InconsistentNaming
// ReSharper disable RedundantUsingDirective
// ReSharper disable RedundantOverriddenMember
// ReSharper disable PartialTypeWithSinglePart
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable CheckNamespace
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
#pragma warning disable CS8618
namespace Fantasy
{
/// <summary>
/// GameAccount实体类
/// </summary>
[ProtoContract]
public partial class RoleBaseInfo : AMessage, IProto
{
public static RoleBaseInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<RoleBaseInfo>();
}
public override void Dispose()
{
NickName = default;
Head = default;
Country = default;
Level = default;
Exp = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<RoleBaseInfo>(this);
#endif
}
[ProtoMember(1)]
public string NickName { get; set; }
[ProtoMember(2)]
public string Head { get; set; }
[ProtoMember(3)]
public string Country { get; set; }
[ProtoMember(4)]
public int Level { get; set; }
[ProtoMember(5)]
public int Exp { get; set; }
}
/// <summary>
/// 角色信息
/// </summary>
[ProtoContract]
public partial class RoleInfo : AMessage, IProto
{
public static RoleInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<RoleInfo>();
}
public override void Dispose()
{
BaseInfo = default;
RoleId = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<RoleInfo>(this);
#endif
}
[ProtoMember(1)]
public RoleBaseInfo BaseInfo { get; set; }
[ProtoMember(2)]
public long RoleId { get; set; }
}
}

View File

@@ -15,7 +15,7 @@ using Fantasy.Serialize;
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
#pragma warning disable CS8618
namespace NBC
namespace Fantasy
{
[ProtoContract]
public partial class C2A_LoginRequest : AMessage, IRequest, IProto
@@ -149,45 +149,47 @@ namespace NBC
[ProtoMember(2)]
public long LoginTime { get; set; }
}
/// <summary>
/// 拿到当前账号的信息
/// </summary>
[ProtoContract]
public partial class C2G_GetAccountInfoRequest : AMessage, IRequest, IProto
public partial class C2Game_GetRoleInfoRequest : AMessage, ICustomRouteRequest, IProto
{
public static C2G_GetAccountInfoRequest Create(Scene scene)
public static C2Game_GetRoleInfoRequest Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<C2G_GetAccountInfoRequest>();
return scene.MessagePoolComponent.Rent<C2Game_GetRoleInfoRequest>();
}
public override void Dispose()
{
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<C2G_GetAccountInfoRequest>(this);
GetScene().MessagePoolComponent.Return<C2Game_GetRoleInfoRequest>(this);
#endif
}
[ProtoIgnore]
public G2C_GetAccountInfoResponse ResponseType { get; set; }
public uint OpCode() { return OuterOpcode.C2G_GetAccountInfoRequest; }
public Game2C_GetRoleInfoResponse ResponseType { get; set; }
public uint OpCode() { return OuterOpcode.C2Game_GetRoleInfoRequest; }
[ProtoIgnore]
public int RouteType => Fantasy.RouteType.GameRoute;
}
[ProtoContract]
public partial class G2C_GetAccountInfoResponse : AMessage, IResponse, IProto
public partial class Game2C_GetRoleInfoResponse : AMessage, ICustomRouteResponse, IProto
{
public static G2C_GetAccountInfoResponse Create(Scene scene)
public static Game2C_GetRoleInfoResponse Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<G2C_GetAccountInfoResponse>();
return scene.MessagePoolComponent.Rent<Game2C_GetRoleInfoResponse>();
}
public override void Dispose()
{
ErrorCode = default;
GameAccountInfo = default;
Name = default;
RoleId = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<G2C_GetAccountInfoResponse>(this);
GetScene().MessagePoolComponent.Return<Game2C_GetRoleInfoResponse>(this);
#endif
}
public uint OpCode() { return OuterOpcode.G2C_GetAccountInfoResponse; }
public uint OpCode() { return OuterOpcode.Game2C_GetRoleInfoResponse; }
[ProtoMember(1)]
public GameAccountInfo GameAccountInfo { get; set; }
public string Name { get; set; }
[ProtoMember(2)]
public string RoleId { get; set; }
[ProtoMember(3)]
public uint ErrorCode { get; set; }
}
}

View File

@@ -7,7 +7,7 @@ namespace Fantasy
public const uint C2G_LoginRequest = 268445458;
public const uint G2C_LoginResponse = 402663186;
public const uint G2C_RepeatLogin = 134227729;
public const uint C2G_GetAccountInfoRequest = 268445459;
public const uint G2C_GetAccountInfoResponse = 402663187;
public const uint C2Game_GetRoleInfoRequest = 2281711377;
public const uint Game2C_GetRoleInfoResponse = 2415929105;
}
}

View File

@@ -5,5 +5,6 @@ namespace Fantasy
{
public const int GateRoute = 1001; // Gate
public const int ChatRoute = 1002; // Chat
public const int GameRoute = 1003; // Game
}
}