CTT/Server/Hotfix/Game/System/User/UserComponentSystem.cs

61 lines
2.0 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using ET;
using ET.EventType;
using System;
using System.Collections.Generic;
using System.Text;
2021-06-29 11:28:15 +08:00
using System.Threading.Tasks;
2021-04-08 20:09:59 +08:00
namespace ET
{
public class UserComponentAwakeSystem : AwakeSystem<UserComponent>
{
public override void Awake(UserComponent self)
{
self.Awake();
}
}
public static class UserComponentSystem
{
/// <summary>
/// 查询缓存或数据库
/// </summary>
/// <param name="self"></param>
/// <param name="id"></param>
/// <returns></returns>
public static async ETTask<User> Query(this UserComponent self, long id)
{
2021-04-11 19:50:39 +08:00
User player = self.Get(id);
2021-04-08 20:09:59 +08:00
if (player == null)
{
2021-06-29 11:28:15 +08:00
player = await self.QueryUserByCache(id);
2021-04-08 20:09:59 +08:00
if (player == null)
{
Log.Error($"[ERROR] user == null where id = {id}");
return null;
}
return player;
}
return player;
}
2021-06-29 11:28:15 +08:00
private static async ETTask<User> QueryUserByCache(this UserComponent self,long id)
2021-04-08 20:09:59 +08:00
{
2021-06-29 11:28:15 +08:00
long mapInstanceId = StartSceneConfigCategory.Instance.GetBySceneName(self.DomainZone(), SceneType.UserCache.ToString()).SceneId;
U2M_GetComponent getComponent= (U2M_GetComponent) await MessageHelper.CallActor(mapInstanceId, new M2U_GetComponent() { UserId = id, type = nameof (User) });
if (getComponent.component == null) return null;
User user = getComponent.component as User;
return user;
}
public static void Save(this UserComponent self, User player)
{
long mapInstanceId = StartSceneConfigCategory.Instance.GetBySceneName(self.DomainZone(), SceneType.UserCache.ToString()).SceneId;
MessageHelper.SendActor(mapInstanceId, new M2U_WriteComponent() { Id = player.Id, type = nameof (User), component =player });
2021-04-08 20:09:59 +08:00
}
}
}