GameProxy.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. using LitJson;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace GFGGame
  5. {
  6. public class GameProxy
  7. {
  8. private const string API_GAME = "game";
  9. public static void ReqRoleInfo(long id)
  10. {
  11. Dictionary<string, object> data = JsonUtil.createJsonDic("id", id);
  12. Post(GameProtoId.GET_ROLE_INFO, "roleInfo", data, (GameResult result) =>
  13. {
  14. if (result == null || result.code == 0)
  15. {
  16. if (result != null && result.roleInfo != null)
  17. {
  18. GameController.PreEnterGame(result);
  19. }
  20. else
  21. {
  22. GameController.ShowCreateRole();
  23. }
  24. }
  25. });
  26. }
  27. public static void ReqCreateRole(long id, string name)
  28. {
  29. Dictionary<string, object> data = JsonUtil.createJsonDic("id", id, "name", name);
  30. Post(GameProtoId.CREATE_ROLE, "roleInfo", data, (GameResult result) =>
  31. {
  32. if (result == null || result.code == 0)
  33. {
  34. ViewManager.Hide(ViewName.CREATE_ROLE_VIEW);
  35. GameController.PreEnterGame(result);
  36. if (GameGlobal.isOfflineVisitor)
  37. {
  38. RoleDataManager.roleName = name;
  39. }
  40. if (GameGlobal.skipGuide)
  41. {
  42. GMController.GetAllDressUpItem();
  43. GMController.GetAllCardItem();
  44. ReqUpdateStoryProgress(10, 100, 100010, 10100);
  45. RoleDataManager.lvl = 100;
  46. }
  47. }
  48. });
  49. }
  50. public static void ReqUpdateTreasure()
  51. {
  52. Dictionary<string, object> data = JsonUtil.createJsonDic("id", RoleDataManager.roleId,
  53. "power", RoleDataManager.power,
  54. "gold", RoleDataManager.gold,
  55. "exp", RoleDataManager.exp,
  56. "lvl", RoleDataManager.lvl,
  57. "diaP", RoleDataManager.diaP,
  58. "diaR", RoleDataManager.diaR,
  59. "powerTime", RoleDataManager.powerTime
  60. );
  61. Post(GameProtoId.UPDATE_TREASURE, "roleInfo", data, (GameResult result) =>
  62. {
  63. });
  64. }
  65. public static void ReqUpdateStoryProgress(int chapter, int chapterLvl, int chapterJY, int chapterLvlJY)
  66. {
  67. Dictionary<string, object> data = JsonUtil.createJsonDic("chapter", chapter, "chapterLvl", chapterLvl, "chapterJY", chapterJY, "chapterLvlJY", chapterLvlJY, "id", RoleDataManager.roleId);
  68. Post(GameProtoId.UPDATE_STORY_PROGRESS, "roleInfo", data, (GameResult result) =>
  69. {
  70. StoryDataManager.SetPassData(chapter, chapterLvl);
  71. StoryDataManager.SetPassData(chapterJY, chapterLvlJY);
  72. });
  73. }
  74. public static void ReqGetStoryScoreList()
  75. {
  76. Dictionary<string, object> data = JsonUtil.createJsonDic("id", RoleDataManager.roleId);
  77. Post(GameProtoId.GET_STORY_SCORE_LIST, "roleInfo", data, (GameResult result) =>
  78. {
  79. if (result != null && result.storyScoreList != null)
  80. {
  81. StoryDataManager.InitScoreList(result.storyScoreList);
  82. }
  83. else
  84. {
  85. StoryDataManager.InitScoreList(null);
  86. }
  87. });
  88. }
  89. public static void ReqUpdateStoryScore(string lvlId, int score)
  90. {
  91. Dictionary<string, object> data = JsonUtil.createJsonDic("lvlId", lvlId, "score", score, "roleId", RoleDataManager.roleId);
  92. Post(GameProtoId.UPDATE_STORY_SCORE, "storyScore", data, (GameResult result) =>
  93. {
  94. });
  95. }
  96. public static void ReqGetStoryStarList()
  97. {
  98. Dictionary<string, object> data = JsonUtil.createJsonDic("id", RoleDataManager.roleId);
  99. Post(GameProtoId.GET_STORY_STAR_LIST, "roleInfo", data, (GameResult result) =>
  100. {
  101. if (result != null && result.storyStarList != null)
  102. {
  103. StoryDataManager.InitStarList(result.storyStarList);
  104. }
  105. else
  106. {
  107. StoryDataManager.InitStarList(null);
  108. }
  109. });
  110. }
  111. public static void ReqUpdateStoryStar(int chapterId, int star, string boxStatus)
  112. {
  113. Dictionary<string, object> data = JsonUtil.createJsonDic("chapterId", chapterId, "star", star, "roleId", RoleDataManager.roleId, "boxStatus", boxStatus);
  114. Post(GameProtoId.UPDATE_STORY_STAR, "storyStar", data, (GameResult result) =>
  115. {
  116. });
  117. }
  118. public static void ReqUpdateRoleSuit(CustomSuitData suitSavedData)
  119. {
  120. Dictionary<string, object> data = JsonUtil.createJsonDic("pos", suitSavedData.pos,
  121. "roleId", RoleDataManager.roleId,
  122. "equipIds", ArrayUtil<int>.JoinArrayToString(suitSavedData.equipDatas),
  123. "bg", suitSavedData.bg,
  124. "pic", suitSavedData.pic,
  125. "suitId", suitSavedData.suitId
  126. );
  127. Post(GameProtoId.UPDATE_ROLE_SUIT, "roleSuit", data, (GameResult result) =>
  128. {
  129. });
  130. }
  131. public static void ReqUpdateRoleSuitIndex(int suitIndex)
  132. {
  133. Dictionary<string, object> data = JsonUtil.createJsonDic("suitIndex", suitIndex, "id", RoleDataManager.roleId);
  134. Post(GameProtoId.UPDATE_ROLE_SUIT_INDEX, "roleInfo", data, (GameResult result) =>
  135. {
  136. });
  137. }
  138. public static void ReqUpdateRoleItems(List<RoleItem> itemList)
  139. {
  140. Dictionary<string, object> data = JsonUtil.createJsonDic("roleId", RoleDataManager.roleId, "itemList", itemList);
  141. Post(GameProtoId.UPDATE_ROLE_ITEMS, "roleItemList", data, (GameResult result) =>
  142. {
  143. });
  144. }
  145. public static void ReqUpdateRoleGuide(GuideData guideData)
  146. {
  147. Dictionary<string, object> data = JsonUtil.createJsonDic("guideId", guideData.guideId,
  148. "roleId", RoleDataManager.roleId,
  149. "count", guideData.count
  150. );
  151. Post(GameProtoId.UPDATE_ROLE_GUIDE, "roleGuide", data, (GameResult result) =>
  152. {
  153. });
  154. }
  155. public static void ReqUpdateTime()
  156. {
  157. Dictionary<string, object> data = JsonUtil.createJsonDic("id", RoleDataManager.roleId);
  158. Post(GameProtoId.GET_TIME, "roleInfo", data, (GameResult result) =>
  159. {
  160. if (result != null && result.roleInfo != null)
  161. {
  162. ServerDataManager.SetServerTime(result.roleInfo.serverTime);
  163. AntiAddictionController.CheckOnlineTime(result.roleInfo.onlineTimeSecs, result.roleInfo.onlineDurationSecs, result.roleInfo.onlineDurationSecsDay);
  164. RoleDataManager.rechargeTotalMon = result.roleInfo.rechargeTotalMon;
  165. }
  166. });
  167. }
  168. public static void ReqUpdateRecommendCount(int recommendCount)
  169. {
  170. int day = StoryDataManager.recommendDay;
  171. Dictionary<string, object> data = JsonUtil.createJsonDic("id", RoleDataManager.roleId, "recommendCount", recommendCount, "recommendDay", day);
  172. Post(GameProtoId.UPDATE_RECOMMEND_COUNT, "roleInfo", data, (GameResult result) =>
  173. {
  174. });
  175. }
  176. public static void ReqUpdateRecharge(int money)
  177. {
  178. Dictionary<string, object> data = JsonUtil.createJsonDic("roleId", RoleDataManager.roleId, "money", money);
  179. Post(GameProtoId.UPDATE_RECHARGE_TIME, "roleRecharge", data, (GameResult result) =>
  180. {
  181. if (result != null && result.roleInfo != null)
  182. {
  183. RoleDataManager.rechargeTotal = result.roleInfo.rechargeTotal;
  184. RoleDataManager.rechargeTotalMon = result.roleInfo.rechargeTotalMon;
  185. }
  186. });
  187. }
  188. public static void ReqUpdateSystemSuitBoxStatus(int suitId, int boxStatus, int boxStatusSyn)
  189. {
  190. Dictionary<string, object> data = JsonUtil.createJsonDic("suitId", suitId, "roleId", RoleDataManager.roleId, "boxStatus", boxStatus, "boxStatusSyn", boxStatusSyn);
  191. Post(GameProtoId.UPDATE_SYSTEM_SUIT_BOX_STATUS, "systemSuit", data, (GameResult result) =>
  192. {
  193. });
  194. }
  195. //============================================================
  196. public static void ReqUpdateCardStatus(CardData cardData)
  197. {
  198. int score1 = cardData.scores[ConstDressUpScoreType.SCORE_FENG];
  199. int score2 = cardData.scores[ConstDressUpScoreType.SCORE_HUA];
  200. int score3 = cardData.scores[ConstDressUpScoreType.SCORE_XUE];
  201. int score4 = cardData.scores[ConstDressUpScoreType.SCORE_YUE];
  202. Dictionary<string, object> data = JsonUtil.createJsonDic("roleId", RoleDataManager.roleId, "cardId", cardData.id, "lv", cardData.lv, "exp", cardData.exp, "star", cardData.star, "res", cardData.res, "score1", score1, "score2", score2, "score3", score3, "score4", score4);
  203. Post(GameProtoId.UPDATE_ROLE_CARD, "roleCard", data, (GameResult result) =>
  204. {
  205. EventAgent.DispatchEvent(ConstMessage.CARD_REFRESH);
  206. });
  207. }
  208. //============================================================
  209. private static void Get(string methodName, Action<GameResult> callback)
  210. {
  211. HttpTool.Instance.Get(GameGlobal.gameApiUrl, methodName, (string data) =>
  212. {
  213. ResultHandler(data, callback);
  214. });
  215. }
  216. private static void Post(int protoId, string dataName, object data, Action<GameResult> callback)
  217. {
  218. string postJsonStr = JsonUtil.createJsonStr("typeid", "" + protoId, dataName, data);
  219. HttpTool.Instance.Post(GameGlobal.gameApiUrl, API_GAME, postJsonStr, (string param) =>
  220. {
  221. ResultHandler(param, callback);
  222. });
  223. }
  224. private static void ResultHandler(string data, Action<GameResult> callback)
  225. {
  226. GameResult resultObj = null;
  227. if (!GameGlobal.isOfflineVisitor)
  228. {
  229. resultObj = null;
  230. if (data != null)
  231. {
  232. resultObj = JsonMapper.ToObject<GameResult>(data);
  233. }
  234. if (resultObj != null && resultObj.code != 0)
  235. {
  236. PromptController.Instance.ShowFloatTextPrompt(resultObj.message);
  237. }
  238. }
  239. if (callback != null)
  240. {
  241. callback(resultObj);
  242. }
  243. }
  244. }
  245. }