DataManager.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. var XORcipher = require('./XORcipher')
  2. var DataManager = {};
  3. DataManager.unique = null
  4. DataManager.pk = null
  5. DataManager.Skey = null
  6. DataManager.Okey = null
  7. DataManager.callFunc = null
  8. DataManager.target = null
  9. DataManager.playInterval = null
  10. DataManager.start = function (t, e) {
  11. DataManager.callFunc = t,
  12. DataManager.tDataManager = {},
  13. DataManager.unique = null,
  14. DataManager.pk = null,
  15. DataManager.Skey = null,
  16. DataManager.Okey = null,
  17. DataManager.callFunc = null,
  18. DataManager.target = null,
  19. DataManager.playInterval = null,
  20. DataManager.start = function (t, e) {
  21. DataManager.callFunc = t,
  22. DataManager.target = e,
  23. gamen.start(DataManager.startDataComplete)
  24. }
  25. }
  26. DataManager.startDataComplete = function (t, e, i, n, o) {
  27. if (GD.isLogin = t,
  28. GD.isLogin && (GD.sKey = gamen.spkey(n),
  29. GD.oKey = gamen.opkey(o),
  30. GD.unique = XORcipher().xorDecoder(e, GD.sKey),
  31. GD.pk = i,
  32. GD.startTime = Date.now(),
  33. GD.medal = [],
  34. null != gamen.achievement))
  35. for (var s = gamen.achievement.length, r = 0; s > r; ++r) {
  36. var a = XORcipher().xorDecoder(gamen.achievement[r], GD.sKey)
  37. , h = [];
  38. h = a.split("_gamen_"),
  39. GD.medal[r] = [parseInt(h[0]), !1, parseInt(h[1]), h[2], h[3], parseInt(h[5]), h[4]]
  40. }
  41. DataManager.callFunc.call(DataManager.target),
  42. DataManager.playInterval = setInterval(DataManager.promisePlay, .1)
  43. }
  44. DataManager.point = function (t, e) {
  45. if (GD.log(t + " : " + e),
  46. DataManager.otherPoint(t, e),
  47. GD.isLogin) {
  48. t = XORcipher().xorEncoder(t, GD.sKey),
  49. e = XORcipher().xorEncoder(e.toString(), GD.sKey);
  50. var i = Date.now() - GD.startTime
  51. , n = XORcipher().xorEncoder(i.toString(), GD.sKey);
  52. gamen.point(t, e, n)
  53. }
  54. }
  55. DataManager.otherPoint = function (t, e) {
  56. if (GD.isLogin) {
  57. t = XORcipher().xorEncoder(t, GD.oKey),
  58. e = XORcipher().xorEncoder(e.toString(), GD.oKey);
  59. var i = Date.now() - GD.startTime
  60. , n = XORcipher().xorEncoder(i.toString(), GD.oKey);
  61. gamen.otherpoint(t, e, n)
  62. }
  63. }
  64. DataManager.promisePlay = function () {
  65. var t = Date.now() - GD.startTime
  66. , e = XORcipher().xorEncoder(t.toString(), GD.oKey);
  67. gamen.promiseplay(e)
  68. }
  69. DataManager.finish = function (t) {
  70. if (DataManager.playInterval && clearInterval(DataManager.playInterval),
  71. GD.isLogin) {
  72. if (GD.medal.length > 0) {
  73. var e = []
  74. , i = GD.medal.length;
  75. gamen.new_achievement = [];
  76. for (var n = 0; i > n; ++n)
  77. e[n] = GD.medal[n][0] + "_gamen_" + GD.medal[n][2] + "_gamen_" + GD.medal[n][3] + "_gamen_" + GD.medal[n][4] + "_gamen_" + parseInt(GD.medal[n][5]),
  78. gamen.new_achievement[n] = XORcipher().xorEncoder(e[n], GD.sKey)
  79. }
  80. var o = XORcipher().xorEncoder(t.toString(), GD.sKey)
  81. , s = GD.commonOption.gameRestart.bind(GD.commonOption)
  82. , r = XORcipher().xorEncoder(GD.unique, GD.sKey)
  83. , a = XORcipher().xorEncoder(GD.startTime.toString(), GD.sKey)
  84. , h = Date.now()
  85. , l = XORcipher().xorEncoder(h.toString(), this.sKey);
  86. gamen.finish(GD.pk, o, s, r, a, l)
  87. } else
  88. gamen.finish(t, null,GD.commonOption.gameRestart.bind(GD.commonOption))
  89. }
  90. DataManager.addMedal = function (t, e) {
  91. if (GD.isLogin && GD.medal.length > 0) {
  92. for (var i = null, n = 0; n < GD.medal.length; ++n) {
  93. if (t == GD.medal[n][0]) {
  94. i = n,
  95. 0 == GD.medal[i][1] && (null == e && (e = 1),
  96. GD.medal[i][5] += e,
  97. GD.medal[i][2] <= GD.medal[i][5] && (GD.medal[i][1] = !0,
  98. GD.commonOption.setAchievement(i + 1)));
  99. break
  100. }
  101. }
  102. }
  103. }
  104. module.exports = DataManager