PlayerSystem.cs 10 KB

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