PlayerSystem.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using System.Collections.Generic;
  2. using System.Text.Json;
  3. using BattleIce;
  4. namespace ET.Server
  5. {
  6. [FriendOf(typeof (WNPlayer))]
  7. [FriendOf(typeof (BattleIceAgentComponent))]
  8. public static class PlayerSystem
  9. {
  10. public class PlayerAwakeSystem: AwakeSystem<WNPlayer, Session, PlayerInfo>
  11. {
  12. /// <summary>
  13. /// 玩家实体创建
  14. /// </summary>
  15. /// <param name="self"></param>
  16. /// <param name="session"></param>
  17. /// <param name="playerInfo"></param>
  18. protected override void Awake(WNPlayer self, Session session, PlayerInfo playerInfo)
  19. {
  20. Log.Info($"创建玩家实体...");
  21. }
  22. }
  23. public class PlayerDestroySystem: DestroySystem<WNPlayer>
  24. {
  25. /// <summary>
  26. /// 玩家实体销毁
  27. /// </summary>
  28. /// <param name="self"></param>
  29. protected override void Destroy(WNPlayer self)
  30. {
  31. Log.Info($"销毁玩家实体...");
  32. }
  33. }
  34. /// <summary>
  35. /// 获取角色id
  36. /// </summary>
  37. /// <param name="self"></param>
  38. /// <returns></returns>
  39. public static long GetId(this WNPlayer self)
  40. {
  41. return self.GetComponent<PlayerDataComponent>().Data.Id;
  42. }
  43. /// <summary>
  44. /// 获取账号id
  45. /// </summary>
  46. /// <param name="self"></param>
  47. /// <returns></returns>
  48. public static long GetUserId(this WNPlayer self)
  49. {
  50. return self.GetComponent<PlayerDataComponent>().Data.UserId;
  51. }
  52. /// <summary>
  53. /// 获取名称
  54. /// </summary>
  55. /// <param name="self"></param>
  56. /// <returns></returns>
  57. public static string GetName(this WNPlayer self)
  58. {
  59. return self.GetComponent<PlayerDataComponent>().Data.Name;
  60. }
  61. /// <summary>
  62. /// 获取性别
  63. /// </summary>
  64. /// <param name="self"></param>
  65. /// <returns></returns>
  66. public static int GetSex(this WNPlayer self)
  67. {
  68. return self.GetComponent<PlayerDataComponent>().Data.Sex;
  69. }
  70. /// <summary>
  71. /// 获取职业
  72. /// </summary>
  73. /// <param name="self"></param>
  74. /// <returns></returns>
  75. public static int GetPro(this WNPlayer self)
  76. {
  77. return self.GetComponent<PlayerDataComponent>().Data.Pro;
  78. }
  79. /// <summary>
  80. /// 获取经验
  81. /// </summary>
  82. /// <param name="self"></param>
  83. /// <returns></returns>
  84. public static long GetExp(this WNPlayer self)
  85. {
  86. return self.GetComponent<PlayerDataComponent>().Data.Exp;
  87. }
  88. /// <summary>
  89. /// 获取等级
  90. /// </summary>
  91. /// <param name="self"></param>
  92. /// <returns></returns>
  93. public static int GetLevel(this WNPlayer self)
  94. {
  95. return self.GetComponent<PlayerDataComponent>().Data.Level;
  96. }
  97. /// <summary>
  98. /// 获取金币
  99. /// </summary>
  100. /// <param name="self"></param>
  101. /// <returns></returns>
  102. public static long GetGold(this WNPlayer self)
  103. {
  104. return self.GetComponent<PlayerDataComponent>().Data.Gold;
  105. }
  106. /// <summary>
  107. /// 获取场景实例id
  108. /// </summary>
  109. /// <param name="self"></param>
  110. /// <returns></returns>
  111. public static long GetMapInstanceId(this WNPlayer self)
  112. {
  113. return self.Map.InstanceId;
  114. }
  115. /** 获取服务器id **/
  116. public static int GetLogicServerId(this WNPlayer self)
  117. {
  118. return self.GetComponent<PlayerDataComponent>().Data.LogicServerId;
  119. }
  120. public static ZoneManagerPrx GetZoneManager(this WNPlayer self)
  121. {
  122. return self.DomainScene().GetComponent<BattleIceAgentComponent>().IceZoneManager;
  123. }
  124. public static XmdsManagerPrx GetXmdsManager(this WNPlayer self)
  125. {
  126. return self.DomainScene().GetComponent<BattleIceAgentComponent>().IceXmdsManager;
  127. }
  128. /** bornData相关初始化 **/
  129. public static void InitBornData(this WNPlayer self)
  130. {
  131. switch (self.BornType)
  132. {
  133. case (int)BORN_TYPE.HISTORY:
  134. self.GetComponent<PlayerTempDataComponent>().MapData.mapId = self.GetComponent<PlayerTempDataComponent>().MapData.historyMapId;
  135. self.GetComponent<PlayerTempDataComponent>().MapData.mapInstanceId =
  136. self.GetComponent<PlayerTempDataComponent>().MapData.historyMapInstanceId;
  137. self.GetComponent<PlayerTempDataComponent>().MapData.x = self.GetComponent<PlayerTempDataComponent>().MapData.historyX;
  138. self.GetComponent<PlayerTempDataComponent>().MapData.y = self.GetComponent<PlayerTempDataComponent>().MapData.historyY;
  139. break;
  140. case (int)BORN_TYPE.BORN:
  141. self.GetComponent<PlayerTempDataComponent>().MapData.mapId = self.GetComponent<PlayerTempDataComponent>().MapData.bornMapId;
  142. self.GetComponent<PlayerTempDataComponent>().MapData.mapInstanceId =
  143. self.GetComponent<PlayerTempDataComponent>().MapData.bornMapInstanceId;
  144. self.GetComponent<PlayerTempDataComponent>().MapData.x = self.GetComponent<PlayerTempDataComponent>().MapData.bornX;
  145. self.GetComponent<PlayerTempDataComponent>().MapData.y = self.GetComponent<PlayerTempDataComponent>().MapData.bornY;
  146. break;
  147. }
  148. }
  149. /** 客户端资源加载完成通知 给客户端推送的数据要在这里 **/
  150. public static void OnReady(this WNPlayer self)
  151. {
  152. self.OnEndEnterScene();
  153. // 登录第一次进场景处理,此次登陆登出期间只处理一次
  154. if (self.ReadyFirst)
  155. {
  156. self.ReadyFirst = false;
  157. }
  158. }
  159. /** 玩家登录事件 **/
  160. public static void OnLogin(this WNPlayer self)
  161. {
  162. self.ReadyFirst = true;
  163. self.DomainScene().GetComponent<GamePlayerComponent>().Add(self.GetId(), self);
  164. }
  165. /** 向客户端推送角色相关数据 **/
  166. public static void OnEndEnterScene(this WNPlayer self)
  167. {
  168. bool ready = self.GetComponent<PlayerTempDataComponent>().MapData.ready;
  169. if (ready)
  170. {
  171. Log.Warning($"$OnEndEnterScene跳过 : playerId={self.GetId()}, 玩家场景:{self.Map.MapId}, 进入场景:" + (self.Map?.MapId ?? -1));
  172. return;
  173. }
  174. self.GetComponent<PlayerTempDataComponent>().MapData.ready = true;
  175. self.GetXmdsManager().playerReady(self.GetId().ToString().Trim());
  176. //PKMode设置为All
  177. self.GetXmdsManager().refreshPlayerPKMode(self.GetId().ToString().Trim(), false, (int)PkModel.All);
  178. //设置为自动战斗
  179. self.GetXmdsManager().autoBattle(self.Map.Id.ToString().Trim(), self.GetId().ToString().Trim(), true);
  180. }
  181. /** 场景中角色需求数据 **/
  182. public static string ToJSON4EnterScene(this WNPlayer self, Map map)
  183. {
  184. var json = new
  185. {
  186. effects = new
  187. {
  188. MaxHP = 99999,
  189. HPPer = 1,
  190. HP = 88888,
  191. Attack = 20,
  192. AttackPer = 100,
  193. MoveSpeed = 5,
  194. },
  195. effectsExt = new { },
  196. // skills = self.ToJson4BattleServerSkillInfos,
  197. skills = new List<SkillInfo>()
  198. {
  199. new SkillInfo
  200. {
  201. id = 90210,
  202. level = 1,
  203. type = 3,
  204. skillTime = 0,
  205. cdTime = 0,
  206. flag = 0
  207. },
  208. new SkillInfo
  209. {
  210. id = 90203,
  211. level = 1,
  212. type = 1,
  213. skillTime = 0,
  214. cdTime = 0,
  215. flag = 0
  216. },
  217. },
  218. tasks = new { },
  219. flags = new { },
  220. playerEntered = false,
  221. avatars = new { },
  222. basic = new
  223. {
  224. name = self.GetName(),
  225. alliesForce = 0,
  226. force = 1,
  227. pro = self.GetPro(),
  228. serverId = ConstGame.GameServerId,
  229. titleId = 0,
  230. level = self.GetLevel(),
  231. vip = 0,
  232. upLevel = 1,
  233. // 无悬赏
  234. beReward = 0,
  235. logicServerId = ConstGame.GameServerId,
  236. sex = self.GetSex(),
  237. uuid = self.GetId().ToString(),
  238. potionAddition = 0
  239. },
  240. connectServerId = "bs-" + ConstGame.GameServerId,
  241. uid = self.GetId().ToString(),
  242. unitTemplateID = 1,
  243. robot = false,
  244. tempData = new
  245. {
  246. //x = this.getPlayerAreaData().bornX,
  247. //y = this.getPlayerAreaData().bornY,
  248. x = 225,
  249. y = 127,
  250. direction = System.MathF.PI / 2,
  251. hp = 100000,
  252. mp = 0,
  253. },
  254. pkInfo = new { mode = 0, value = 0, level = 1, },
  255. //petBase,
  256. addTestPetData = 0,
  257. sceneData = new { allowAutoGuard = 3, },
  258. };
  259. string retjson = JsonSerializer.Serialize(json, new JsonSerializerOptions { IncludeFields = true });
  260. Log.Debug($"{self.GetName()}, enterSceneData:{retjson.ToString()}");
  261. return retjson;
  262. }
  263. }
  264. }