PlayerSystem.cs 9.5 KB

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