PlayerFactory.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. namespace ET.Server
  2. {
  3. public static class PlayerFactory
  4. {
  5. /// <summary>
  6. /// 创建玩家实体
  7. /// </summary>
  8. /// <param name="session"></param>
  9. /// <param name="playerInfo"></param>
  10. /// <returns></returns>
  11. public static async ETTask<WNPlayer> CreatPlayer(Session session, PlayerInfo playerInfo)
  12. {
  13. WNPlayer player = session.DomainScene().GetComponent<GamePlayerComponent>()
  14. .AddChild<WNPlayer, Session, PlayerInfo>(session, playerInfo);
  15. // 绑定sessionId
  16. player.GameSessionActorId = session.InstanceId;
  17. player.Session = session;
  18. player.BasicProp = CharacterConfigCategory.Instance.Get(playerInfo.Pro);
  19. player.BornType = (int)BORN_TYPE.NORMAL;
  20. player.EnterState = (int)ENTER_STATE.online;
  21. // 玩家基础数据组件
  22. player.AddComponent<PlayerDataComponent, PlayerInfo, WNPlayer>(playerInfo, player);
  23. // 玩家临时数据组件
  24. player.AddComponent<PlayerTempDataComponent, WNPlayer>(player).Init();
  25. // 玩家技能组件
  26. player.AddComponent<PlayerSkillComponent, WNPlayer>(player).Init();
  27. // 玩家货币组件
  28. player.AddComponent<PlayerMoneyComponent, WNPlayer>(player).Init();
  29. // 玩家属性组件
  30. player.AddComponent<PlayerBtlComponent, WNPlayer>(player).Init();
  31. await ETTask.CompletedTask;
  32. return player;
  33. }
  34. }
  35. }