MessManager.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. // import { Event_Name } from "../core/event/event_mgr";
  2. // import EventManager from "../core/event/EventManager";
  3. export default class MessManager {
  4. private static _instance: MessManager;
  5. private constructor() { }
  6. public static getInstance(): MessManager {
  7. if (!MessManager._instance) {
  8. MessManager._instance = new MessManager();
  9. }
  10. return MessManager._instance;
  11. }
  12. //--胜利局数
  13. private winCount = 0;
  14. private winCountMax = 2;
  15. //--单局道具使用次数
  16. private itemCounts = [0, 0, 0];
  17. private itemCountMaxs = [1, 1, 1];
  18. private canRewardCount: number = 0;
  19. public haveReward: boolean = false;
  20. /**
  21. * 本地数据初始化
  22. */
  23. public initData() {
  24. if (CC_DEBUG) {
  25. window["loginData"] = {
  26. userId: 11111,
  27. satoken: "111dTtCi0jk7zsK1mJj6ujrk6YT5DBZ3V6NoMHTarvyJKDDS9GoVbHIf9l4t7SJO3J3ZXK3B23Ve4O8YbwdGp08PoaLscA5S7JkQozeLi7mdYyyj1O3pU7EuRAcktN4e1Zm",
  28. }
  29. }
  30. // window["loginData"] = {
  31. // userId: 133,
  32. // satoken: "dTtCi0jk7zsK1mJj6ujrk6YT5DBZ3V6NoMHTarvyJKDDS9GoVbHIf9l4t7SJO3J3ZXK3B23Ve4O8YbwdGp08PoaLscA5S7JkQozeLi7mdYyyj1O3pU7EuRAcktN4e1Zm",
  33. // }
  34. }
  35. // public initOneGame() {
  36. // this.addPlayCount();
  37. // this.itemCounts = [0, 0, 0];
  38. // }
  39. // public getItmeScore(index: number) {
  40. // if (this.itemCounts[index] == 0) {
  41. // return 10;
  42. // } else if (this.itemCounts[index] == 1) {
  43. // return 50;
  44. // } else {
  45. // return 0;
  46. // }
  47. // }
  48. // public getCanRewardCount(): number {
  49. // return this.canRewardCount;
  50. // }
  51. // public getCanPlay(): boolean {
  52. // return this.winCount < this.winCountMax;
  53. // }
  54. // public getCanUseItem(index: number): boolean {
  55. // return this.itemCounts[index] < this.itemCountMaxs[index];
  56. // }
  57. // public addItemCount(index: number, callBack, callFail = null) {
  58. // if (this.itemCounts[index] == 0) {
  59. // this.changeScore(-10, () => {
  60. // this.itemCounts[index]++;
  61. // callBack && callBack();
  62. // }, () => {
  63. // callFail && callFail();
  64. // });
  65. // } else {
  66. // this.changeScore(-50, () => {
  67. // this.itemCounts[index]++;
  68. // callBack && callBack();
  69. // }, () => {
  70. // callFail && callFail();
  71. // });
  72. // }
  73. // }
  74. // public addWinCount() {
  75. // this.winCount++;
  76. // this.setWinTimes(this.winCount);
  77. // }
  78. public getPlayCount(callBack: Function, callFail: Function = null) {
  79. fetch("https://miniapi.maox.com.cn/api/index/get_login_num", {
  80. method: "POST",
  81. headers: {
  82. "Content-Type": "application/json"
  83. },
  84. body: JSON.stringify({ user_id: window["loginData"].userId })
  85. }).then((response: Response) => {
  86. return response.text()
  87. }).then((value) => {
  88. let valueJson = JSON.parse(value);
  89. if (valueJson["code"] == 1) {
  90. this.canRewardCount = valueJson["data"];
  91. console.log(" this.canRewardCount", this.canRewardCount)
  92. this.haveReward = this.canRewardCount > 0 ? true : false;
  93. callBack && callBack();
  94. } else {
  95. let options = {
  96. title: "hint",
  97. content: "今日已经通关一局,请明日再来!"
  98. }
  99. callFail && callFail();
  100. }
  101. })
  102. }
  103. public addGameCount(callBack: Function, callFail: Function) {
  104. fetch("https://miniapi.maox.com.cn/api/index/add_game_num", {
  105. method: "POST",
  106. headers: {
  107. "Content-Type": "application/json",
  108. },
  109. body: JSON.stringify({ user_id: window["loginData"].userId, "satoken": window["loginData"].satoken })
  110. }).then((response: Response) => {
  111. return response.text()
  112. }).then((value) => {
  113. let valueJson = JSON.parse(value);
  114. if (valueJson["code"] == 1) {
  115. this.canRewardCount--;
  116. callBack && callBack();
  117. } else {
  118. callFail && callFail();
  119. }
  120. })
  121. }
  122. addPlayCount() {
  123. fetch("https://miniapi.maox.com.cn/api/index/counter", {
  124. method: "POST",
  125. headers: {
  126. "Content-Type": "application/json"
  127. },
  128. body: JSON.stringify({ user_id: window["loginData"].userId })
  129. }).then((response: Response) => {
  130. return response.text()
  131. }).then((value) => {
  132. let valueJson = JSON.parse(value);
  133. if (valueJson["code"] == 1) {
  134. } else {
  135. }
  136. })
  137. }
  138. // kongTou() {
  139. // fetch("http://game.jiuqishujie.cn/api/app-order/addUnconditionalAirdropCollectiblesCopy/" + window["loginData"].userId, {
  140. // method: "POST",
  141. // headers: {
  142. // "Content-Type": "application/json",
  143. // "satoken": window["loginData"].satoken
  144. // },
  145. // }).then((response: Response) => {
  146. // return response.text()
  147. // }).then((value) => {
  148. // let valueJson = JSON.parse(value);
  149. // if (valueJson["code"] == 200) {
  150. // } else {
  151. // let options = {
  152. // title: "hint",
  153. // content: valueJson["data"]
  154. // }
  155. // EventManager.Instance.emit(Event_Name.UI_SHOW, options);
  156. // }
  157. // })
  158. // }
  159. changeScore(score, callBack, callFail = null) {
  160. fetch(`http://game.jiuqishujie.cn/api/mall-credits/reduceOrIncreasePoints/${window["loginData"].userId}/${score >= 0 ? 1 : 2}/${Math.abs(score)}`, {
  161. method: "POST",
  162. headers: {
  163. "Content-Type": "application/json",
  164. "satoken": window["loginData"].satoken
  165. },
  166. }).then((response: Response) => {
  167. return response.text()
  168. }).then((value) => {
  169. let valueJson = JSON.parse(value);
  170. if (valueJson["code"] == 200) {
  171. callBack && callBack();
  172. } else {
  173. callFail && callFail();
  174. }
  175. })
  176. }
  177. questServer(score, callBack, callFail = null) {
  178. if (!window["loginData"].userId) {
  179. callBack && callBack();
  180. return
  181. }
  182. if (!window["loginData"].satoken) {
  183. callBack && callBack();
  184. return
  185. }
  186. fetch('https://multiplatform.maox.com.cn/api/a/add_score', {
  187. method: "POST",
  188. headers: {
  189. "Content-Type": "application/json"
  190. },
  191. body: JSON.stringify({
  192. score: score.toString(),
  193. user_id: window["loginData"].userId,
  194. "token": window["loginData"].satoken,
  195. })
  196. }).then((response: Response) => {
  197. return response.text()
  198. }).then((value) => {
  199. let valueJson = JSON.parse(value);
  200. console.error(valueJson);
  201. if (valueJson["code"] == 200) {
  202. callBack && callBack();
  203. } else {
  204. callFail && callFail();
  205. }
  206. })
  207. }
  208. getUserSore(callBack, callFail = null) {
  209. if (!window["loginData"].userId) {
  210. callBack && callBack();
  211. return
  212. }
  213. fetch('https://multiplatform.maox.com.cn/api/a/get_user_today_score', {
  214. method: "POST",
  215. headers: {
  216. "Content-Type": "application/json"
  217. },
  218. body: JSON.stringify({
  219. user_id: window["loginData"].userId,
  220. })
  221. }).then((response: Response) => {
  222. return response.text()
  223. }).then((value) => {
  224. let valueJson = JSON.parse(value);
  225. console.error(valueJson);
  226. if (valueJson["code"] == 1) {
  227. callBack && callBack(valueJson);
  228. } else {
  229. callFail && callFail();
  230. }
  231. })
  232. }
  233. }
  234. export const messManager = MessManager.getInstance();