PlayerSystem.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 = 10,
  192. AttackPer = 100,
  193. },
  194. effectsExt = new { },
  195. // skills = self.ToJson4BattleServerSkillInfos,
  196. skills = new List<SkillInfo>()
  197. {
  198. new SkillInfo
  199. {
  200. id = 90210,
  201. level = 1,
  202. type = 3,
  203. skillTime = 0,
  204. cdTime = 0,
  205. flag = 0
  206. },
  207. new SkillInfo
  208. {
  209. id = 90203,
  210. level = 1,
  211. type = 1,
  212. skillTime = 0,
  213. cdTime = 0,
  214. flag = 0
  215. },
  216. },
  217. tasks = new { },
  218. flags = new { },
  219. playerEntered = false,
  220. avatars = new { },
  221. basic = new
  222. {
  223. name = self.GetName(),
  224. alliesForce = 0,
  225. force = 1,
  226. pro = self.GetPro(),
  227. serverId = ConstGame.GameServerId,
  228. titleId = 0,
  229. level = self.GetLevel(),
  230. vip = 0,
  231. upLevel = 1,
  232. beReward = 0,
  233. logicServerId = ConstGame.GameServerId,
  234. sex = self.GetSex(),
  235. uuid = self.GetId().ToString(),
  236. potionAddition = 0
  237. },
  238. connectServerId = "bs-" + ConstGame.GameServerId,
  239. uid = self.GetId().ToString(),
  240. unitTemplateID = 1,
  241. robot = false,
  242. tempData = new
  243. {
  244. //x = this.getPlayerAreaData().bornX,
  245. //y = this.getPlayerAreaData().bornY,
  246. x = 0,
  247. y = 30,
  248. direction = 0f,
  249. hp = 100000,
  250. mp = 0,
  251. },
  252. pkInfo = new { mode = 0, value = 0, level = 1, },
  253. //petBase,
  254. addTestPetData = 0,
  255. sceneData = new { allowAutoGuard = 3, },
  256. };
  257. string retjson = JsonSerializer.Serialize(json, new JsonSerializerOptions { IncludeFields = true });
  258. Log.Debug($"{self.GetName()}, enterSceneData:{retjson.ToString()}");
  259. return retjson;
  260. }
  261. }
  262. }