61 lines
2.0 KiB
C#
Executable File
61 lines
2.0 KiB
C#
Executable File
using ET;
|
|
using ET.EventType;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
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)
|
|
{
|
|
User player = self.Get(id);
|
|
if (player == null)
|
|
{
|
|
player = await self.QueryUserByCache(id);
|
|
if (player == null)
|
|
{
|
|
Log.Error($"[ERROR] user == null where id = {id}");
|
|
return null;
|
|
}
|
|
return player;
|
|
}
|
|
return player;
|
|
}
|
|
|
|
private static async ETTask<User> QueryUserByCache(this UserComponent self,long id)
|
|
{
|
|
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 });
|
|
}
|
|
|
|
|
|
}
|
|
}
|