新定义

This commit is contained in:
bob
2025-07-30 20:35:38 +08:00
parent e612d8fe38
commit 6b113cf32b
18 changed files with 646 additions and 94 deletions

View File

@@ -1,19 +0,0 @@
syntax = "proto3";
package Fantasy.Network.Message;
/// GameAccount实体类
message RoleBaseInfo
{
string NickName = 1;//昵称
string Head = 2;//头像
string Country = 3;//国家
int32 Level = 4;//等级
int32 Exp = 5;//当前等级
}
///角色信息
message RoleInfo
{
RoleBaseInfo BaseInfo = 1;
int64 RoleId = 2; //账号id
}

View File

@@ -0,0 +1,96 @@
syntax = "proto3";
package Fantasy.Network.Message;
/// 角色基础信息
message RoleBaseInfo
{
string NickName = 1; //昵称
string Head = 2; //头像
string Country = 3; //国家
int32 Level = 4; //等级
int32 Exp = 5; //当前等级
}
message KeyValueStringInt64
{
string Key = 1; //键
int64 Value = 2; //值
}
message KeyValueInt64
{
int64 Key = 1; //键
int64 Value = 2; //值
}
message KeyValueString
{
string Key = 1; //键
string Value = 2; //值
}
/// 角色信息
message RoleInfo
{
RoleBaseInfo BaseInfo = 1;
int64 RoleId = 2; //账号id
repeated ItemInfo Items = 3; //身上物品
repeated FishInfo Fishs = 4; //鱼护
repeated ActivityInfo Activities = 5; //活动信息
repeated KeyValueInt64 Currency = 6; //货币信息
repeated KeyValueInt64 Slots = 7; //插槽使用情况
repeated SkillInfo Skills = 8; //技能信息
}
/// VIP信息
message VipInfo
{
int64 OpenTime = 1; //开通时间
int64 ExpirationTime = 2; //到期时间
}
///奖励信息
message AwardInfo
{
int64 ConfigId = 1; //奖励id
int32 Count = 2; //数量
}
///物品信息
message ItemInfo
{
int32 ConfigId = 1; //配置id
int64 Id = 2; //物品id
int32 Count = 3; //数量
int64 ExpirationTime = 4; //失效时间
int64 GetTime = 5; //获得时间
int64 Abrasion = 6; //耐久度
}
///fish信息
message FishInfo
{
int32 ConfigId = 1; //配置id
int64 Id = 2; //物品id
int32 Weight =3; //重量
int64 GetTime = 4; //获得时间
int64 ExpirationTime = 5; //失效时间
}
//活动信息
message ActivityInfo
{
int64 Id = 1; //活动id
int64 StartTime = 2; //开始时间
int64 EndTime = 3; //结束时间
repeated KeyValueStringInt64 Data = 4; //活动数据
}
///技能情况
message SkillInfo
{
int32 ConfigId = 1; //技能配置id
int32 Level = 2; //技能等级
int32 Exp = 3; //技能经验
}

View File

@@ -0,0 +1,14 @@
syntax = "proto3";
package Fantasy.Network.Message;
/// 好友信息
message FriendInfo
{
int64 Id = 1; //好友id
int64 AddTime = 2; //添加时间
string NickName = 3; //昵称
string Head = 4; //头像
int32 Level = 5; //等级
string Country = 6; //国家
int32 OnlineStatus = 7; //在线状态
}

View File

@@ -0,0 +1,13 @@
syntax = "proto3";
package Fantasy.Network.Message;
message MailInfo
{
int64 Id = 1; //邮件id
string Title = 2; //标题
string Content = 3; //内容
int64 SendTime = 4; //发送时间
int32 Type = 5; //邮件类型
repeated AwardInfo Items = 6; //附件列表
bool IsRead = 7; //是否已读
}

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<LangVersion>default</LangVersion>
<TargetFramework>net9.0</TargetFramework>
@@ -28,6 +28,9 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Game\Activity\" />
<Folder Include="Game\Mail\" />
<Folder Include="Game\Skill\" />
<Folder Include="Map\" />
</ItemGroup>

27
Entity/Game/Fish/Fish.cs Normal file
View File

@@ -0,0 +1,27 @@
using Fantasy.Entitas;
using MongoDB.Bson.Serialization.Attributes;
namespace NB.Game;
public class Fish : Entity
{
/// <summary>
/// 配置id
/// </summary>
[BsonElement("cid")] public int ConfigId;
/// <summary>
/// 重量
/// </summary>
[BsonElement("w")] public int Weight;
/// <summary>
/// 获取时间
/// </summary>
[BsonElement("gt")] public long GetTime;
/// <summary>
/// 失效时间
/// </summary>
[BsonElement("et")] public long ExpirationTime;
}

View File

@@ -16,20 +16,15 @@ public class Item : Entity
/// <summary>
/// 拥有的数量
/// </summary>
public int Count;
[BsonElement("c")] public int Count;
/// <summary>
/// 配置id
/// </summary>
public int ConfigId;
[BsonElement("cid")] public int ConfigId;
/// <summary>
/// 是否绑定
/// </summary>
public bool IsBind;
/// <summary>
/// 当前所属的容器
/// </summary>
[BsonIgnore] public Container Container;
}
[BsonElement("ib")] public bool IsBind;
}

View File

@@ -1,16 +0,0 @@
using Fantasy.Entitas;
namespace NB;
public class PlayerInfo : Entity
{
/// <summary>
/// 昵称
/// </summary>
public string NickName;
/// <summary>
/// 头像
/// </summary>
public string Head;
}

View File

@@ -0,0 +1,19 @@
namespace NB;
public class PlayerVip
{
/// <summary>
/// 是否是vip
/// </summary>
public bool IsVip;
/// <summary>
/// 获取时间
/// </summary>
public long GetTime;
/// <summary>
/// 失效时间
/// </summary>
public long ExpirationTime;
}

View File

@@ -6,17 +6,48 @@ namespace NB.Game;
public sealed class Player : Entity
{
public long CreateTime;
public long LoginTime;
[BsonElement("ct")] public long CreateTime;
[BsonElement("lt")] public long LoginTime;
public PlayerBasic Basic = new PlayerBasic();
public PlayerStatistics Statistics = new PlayerStatistics();
public PlayerDayFlags DayFlags = new PlayerDayFlags();
public PlayerVip Vip = new PlayerVip();
/// <summary>
/// 余额
/// </summary>
public int Money;
/// <summary>
/// 金币
/// </summary>
public int Gold;
/// <summary>
/// 其他货币
/// </summary>
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
public Dictionary<int, int> Currency = new();
/// <summary>
/// 插槽
/// </summary>
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
public Dictionary<uint, long> Slots = new Dictionary<uint, long>();
/// <summary>
/// 背包物品
/// </summary>
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
public Dictionary<long, Item> Items = new Dictionary<long, Item>();
/// <summary>
/// 鱼护
/// </summary>
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
public Dictionary<long, Fish> Fishes = new Dictionary<long, Fish>();
[BsonIgnore] public long SessionRunTimeId;

View File

@@ -0,0 +1,318 @@
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>
/// 角色基础信息
/// </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; }
}
[ProtoContract]
public partial class KeyValueStringInt64 : AMessage, IProto
{
public static KeyValueStringInt64 Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<KeyValueStringInt64>();
}
public override void Dispose()
{
Key = default;
Value = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<KeyValueStringInt64>(this);
#endif
}
[ProtoMember(1)]
public string Key { get; set; }
[ProtoMember(2)]
public long Value { get; set; }
}
[ProtoContract]
public partial class KeyValueInt64 : AMessage, IProto
{
public static KeyValueInt64 Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<KeyValueInt64>();
}
public override void Dispose()
{
Key = default;
Value = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<KeyValueInt64>(this);
#endif
}
[ProtoMember(1)]
public long Key { get; set; }
[ProtoMember(2)]
public long Value { get; set; }
}
[ProtoContract]
public partial class KeyValueString : AMessage, IProto
{
public static KeyValueString Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<KeyValueString>();
}
public override void Dispose()
{
Key = default;
Value = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<KeyValueString>(this);
#endif
}
[ProtoMember(1)]
public string Key { get; set; }
[ProtoMember(2)]
public string Value { 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;
Items.Clear();
Fishs.Clear();
Activities.Clear();
Currency.Clear();
Slots.Clear();
Skills.Clear();
#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; }
[ProtoMember(3)]
public List<ItemInfo> Items = new List<ItemInfo>();
[ProtoMember(4)]
public List<FishInfo> Fishs = new List<FishInfo>();
[ProtoMember(5)]
public List<ActivityInfo> Activities = new List<ActivityInfo>();
[ProtoMember(6)]
public List<KeyValueInt64> Currency = new List<KeyValueInt64>();
[ProtoMember(7)]
public List<KeyValueInt64> Slots = new List<KeyValueInt64>();
[ProtoMember(8)]
public List<SkillInfo> Skills = new List<SkillInfo>();
}
/// <summary>
/// VIP信息
/// </summary>
[ProtoContract]
public partial class VipInfo : AMessage, IProto
{
public static VipInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<VipInfo>();
}
public override void Dispose()
{
OpenTime = default;
ExpirationTime = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<VipInfo>(this);
#endif
}
[ProtoMember(1)]
public long OpenTime { get; set; }
[ProtoMember(2)]
public long ExpirationTime { get; set; }
}
/// <summary>
/// 奖励信息
/// </summary>
[ProtoContract]
public partial class AwardInfo : AMessage, IProto
{
public static AwardInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<AwardInfo>();
}
public override void Dispose()
{
ConfigId = default;
Count = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<AwardInfo>(this);
#endif
}
[ProtoMember(1)]
public long ConfigId { get; set; }
[ProtoMember(2)]
public int Count { get; set; }
}
/// <summary>
/// 物品信息
/// </summary>
[ProtoContract]
public partial class ItemInfo : AMessage, IProto
{
public static ItemInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<ItemInfo>();
}
public override void Dispose()
{
ConfigId = default;
Id = default;
Count = default;
ExpirationTime = default;
GetTime = default;
Abrasion = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<ItemInfo>(this);
#endif
}
[ProtoMember(1)]
public int ConfigId { get; set; }
[ProtoMember(2)]
public long Id { get; set; }
[ProtoMember(3)]
public int Count { get; set; }
[ProtoMember(4)]
public long ExpirationTime { get; set; }
[ProtoMember(5)]
public long GetTime { get; set; }
[ProtoMember(6)]
public long Abrasion { get; set; }
}
/// <summary>
/// fish信息
/// </summary>
[ProtoContract]
public partial class FishInfo : AMessage, IProto
{
public static FishInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<FishInfo>();
}
public override void Dispose()
{
ConfigId = default;
Id = default;
Weight = default;
GetTime = default;
ExpirationTime = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<FishInfo>(this);
#endif
}
[ProtoMember(1)]
public int ConfigId { get; set; }
[ProtoMember(2)]
public long Id { get; set; }
[ProtoMember(3)]
public int Weight { get; set; }
[ProtoMember(4)]
public long GetTime { get; set; }
[ProtoMember(5)]
public long ExpirationTime { get; set; }
}
[ProtoContract]
public partial class ActivityInfo : AMessage, IProto
{
public static ActivityInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<ActivityInfo>();
}
public override void Dispose()
{
Id = default;
StartTime = default;
EndTime = default;
Data.Clear();
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<ActivityInfo>(this);
#endif
}
[ProtoMember(1)]
public long Id { get; set; }
[ProtoMember(2)]
public long StartTime { get; set; }
[ProtoMember(3)]
public long EndTime { get; set; }
[ProtoMember(4)]
public List<KeyValueStringInt64> Data = new List<KeyValueStringInt64>();
}
/// <summary>
/// 技能情况
/// </summary>
[ProtoContract]
public partial class SkillInfo : AMessage, IProto
{
public static SkillInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<SkillInfo>();
}
public override void Dispose()
{
ConfigId = default;
Level = default;
Exp = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<SkillInfo>(this);
#endif
}
[ProtoMember(1)]
public int ConfigId { get; set; }
[ProtoMember(2)]
public int Level { get; set; }
[ProtoMember(3)]
public int Exp { get; set; }
}
}

View File

@@ -18,58 +18,41 @@ using Fantasy.Serialize;
namespace Fantasy
{
/// <summary>
/// GameAccount实体类
/// 好友信息
/// </summary>
[ProtoContract]
public partial class RoleBaseInfo : AMessage, IProto
public partial class FriendInfo : AMessage, IProto
{
public static RoleBaseInfo Create(Scene scene)
public static FriendInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<RoleBaseInfo>();
return scene.MessagePoolComponent.Rent<FriendInfo>();
}
public override void Dispose()
{
Id = default;
AddTime = default;
NickName = default;
Head = default;
Country = default;
Level = default;
Exp = default;
Country = default;
OnlineStatus = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<RoleBaseInfo>(this);
GetScene().MessagePoolComponent.Return<FriendInfo>(this);
#endif
}
[ProtoMember(1)]
public string NickName { get; set; }
public long Id { get; set; }
[ProtoMember(2)]
public string Head { get; set; }
public long AddTime { get; set; }
[ProtoMember(3)]
public string Country { get; set; }
public string NickName { get; set; }
[ProtoMember(4)]
public int Level { get; set; }
public string Head { 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; }
public int Level { get; set; }
[ProtoMember(6)]
public string Country { get; set; }
[ProtoMember(7)]
public int OnlineStatus { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
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
{
}

View File

@@ -0,0 +1,55 @@
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
{
[ProtoContract]
public partial class MailInfo : AMessage, IProto
{
public static MailInfo Create(Scene scene)
{
return scene.MessagePoolComponent.Rent<MailInfo>();
}
public override void Dispose()
{
Id = default;
Title = default;
Content = default;
SendTime = default;
Type = default;
Items.Clear();
IsRead = default;
#if FANTASY_NET || FANTASY_UNITY
GetScene().MessagePoolComponent.Return<MailInfo>(this);
#endif
}
[ProtoMember(1)]
public long Id { get; set; }
[ProtoMember(2)]
public string Title { get; set; }
[ProtoMember(3)]
public string Content { get; set; }
[ProtoMember(4)]
public long SendTime { get; set; }
[ProtoMember(5)]
public int Type { get; set; }
[ProtoMember(6)]
public List<AwardInfo> Items = new List<AwardInfo>();
[ProtoMember(7)]
public bool IsRead { get; set; }
}
}

View File

@@ -17,7 +17,7 @@ public class G2Game_EnterRequestHandler : RouteRPC<Scene, G2Game_EnterRequest, G
Log.Debug("收到 G2Game_EnterRequestHandler");
var accountId = request.AccountId;
// 在缓存中检查该账号是否存在
var gameAccountManageComponent = scene.GetComponent<PlayerManageComponent>();
Log.Debug("检查账号是否在缓存中");
@@ -32,16 +32,30 @@ public class G2Game_EnterRequestHandler : RouteRPC<Scene, G2Game_EnterRequest, G
// 如果没有,就要创建一个新的并且保存到数据库。
// 如果不存在,表示这是一个新的账号,需要创建一下这个账号。
account = await PlayerFactory.Create(scene, accountId);
// account.
account.Basic.Level = 99;
account.Basic.NickName = "王麻子";
account.Basic.Country = "cn";
account.Basic.Exp = 999;
account.Basic.Head = "xxx.png";
for (int i = 0; i < 500; i++)
{
var item = Entity.Create<Item>(scene, true, true);
account.Items.Add(item.Id, item);
}
for (int i = 0; i < 500; i++)
{
var item = Entity.Create<Fish>(scene, true, true);
account.Fishes.Add(item.Id, item);
}
// account.Items
account.NeedSave = true;
await account.SaveDataBase();
}
else
{
@@ -68,11 +82,11 @@ public class G2Game_EnterRequestHandler : RouteRPC<Scene, G2Game_EnterRequest, G
return;
}
}
account.LoginTime = TimeHelper.Now;
response.RoleRouteId = account.RuntimeId;
await FTask.CompletedTask;
}
}

View File

@@ -19,8 +19,7 @@ public static class PlayerFactory
{
var gameAccount = Entity.Create<Player>(scene, aId, false, false);
gameAccount.LoginTime = gameAccount.CreateTime = TimeHelper.Now;
var info = gameAccount.AddComponent<PlayerInfo>();
if (isSaveDataBase)
{

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<Nullable>enable</Nullable>
<LangVersion>default</LangVersion>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>