85 lines
3.2 KiB
C#
85 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace ET
|
|
{
|
|
public class UnitHelper
|
|
{
|
|
public static async ETTask<Unit> Query(Entity domain, long id)
|
|
{
|
|
try
|
|
{
|
|
Unit unit = EntityFactory.CreateWithId<Unit>(domain, id);
|
|
PlayerData data = await DBComponent.Instance.Query<PlayerData>(id);
|
|
unit.AddComponent(data);
|
|
Character character = await DBComponent.Instance.Query<Character>(id);
|
|
unit.AddComponent(character);
|
|
NumericComponent num = await DBComponent.Instance.Query<NumericComponent>(id);
|
|
unit.AddComponent(num);
|
|
UnitSkillComponent unitSkill = await DBComponent.Instance.Query<UnitSkillComponent>(id);
|
|
unit.AddComponent(unitSkill);
|
|
//!玩家设置
|
|
UserSetting setting = await DBComponent.Instance.Query<UserSetting>(id);
|
|
unit.AddComponent(setting);
|
|
//!任务
|
|
UnitTask unitTask = await DBComponent.Instance.Query<UnitTask>(id);
|
|
unit.AddComponent(unitTask);
|
|
//!背包
|
|
Bag bag = await DBComponent.Instance.Query<Bag>(id);
|
|
unit.AddComponent(bag);
|
|
UnitScene unitScene = await DBComponent.Instance.Query<UnitScene>(id);
|
|
unit.AddComponent(unitScene);
|
|
StarSoulBag starSoulBag = await DBComponent.Instance.Query<StarSoulBag>(id);
|
|
unit.AddComponent(starSoulBag);
|
|
Pet pet = await DBComponent.Instance.Query<Pet>(id);
|
|
unit.AddComponent(pet);
|
|
unit.AddComponent<Combat>();
|
|
|
|
return unit;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
return null;
|
|
}
|
|
public static async ETTask Save<T>(Unit unit) where T : Entity
|
|
{
|
|
Entity entity = unit.GetComponent<T>();
|
|
await SaveComponenet(entity);
|
|
}
|
|
public static async ETTask SaveComponenet<T>(T t) where T : Entity
|
|
{
|
|
await DBComponent.Instance.Save(t);
|
|
}
|
|
//public static async ETVoid Save(Team team)
|
|
//{
|
|
// if (team.MemberCount > 1)
|
|
// {
|
|
// List<Entity> list = new List<Entity>();
|
|
// list.AddRange(team.GetUnits());
|
|
// await DBComponent.Instance.Save(list[0].As<Unit>().TeamLeaderId, list);
|
|
// }
|
|
//}
|
|
/// <summary>
|
|
/// 设置位置信息以及人物信息
|
|
/// </summary>
|
|
/// <param name="unit"></param>
|
|
/// <param name="unitInfo"></param>
|
|
/// <param name="pvpUnitCharacter"></param>
|
|
public static void SetUnitInfo(Unit unit, UnitPosInfo unitInfo)
|
|
{
|
|
UnitScene unitScene = unit.GetComponent<UnitScene>();
|
|
if (unitScene == null)
|
|
{
|
|
Log.Error($"unitScene == null where id = {unit.Id}");
|
|
return;
|
|
}
|
|
unitInfo.X = unitScene.X;
|
|
unitInfo.Y = unitScene.Y;
|
|
unitInfo.YAngle = unitScene.YAngle;
|
|
}
|
|
}
|
|
}
|