123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- var XORcipher = require('./XORcipher')
- var DataManager = {};
- DataManager.unique = null
- DataManager.pk = null
- DataManager.Skey = null
- DataManager.Okey = null
- DataManager.callFunc = null
- DataManager.target = null
- DataManager.playInterval = null
- DataManager.start = function (t, e) {
- DataManager.callFunc = t,
- DataManager.tDataManager = {},
- DataManager.unique = null,
- DataManager.pk = null,
- DataManager.Skey = null,
- DataManager.Okey = null,
- DataManager.callFunc = null,
- DataManager.target = null,
- DataManager.playInterval = null,
- DataManager.start = function (t, e) {
- DataManager.callFunc = t,
- DataManager.target = e,
- gamen.start(DataManager.startDataComplete)
- }
- }
- DataManager.startDataComplete = function (t, e, i, n, o) {
- if (GD.isLogin = t,
- GD.isLogin && (GD.sKey = gamen.spkey(n),
- GD.oKey = gamen.opkey(o),
- GD.unique = XORcipher().xorDecoder(e, GD.sKey),
- GD.pk = i,
- GD.startTime = Date.now(),
- GD.medal = [],
- null != gamen.achievement))
- for (var s = gamen.achievement.length, r = 0; s > r; ++r) {
- var a = XORcipher().xorDecoder(gamen.achievement[r], GD.sKey)
- , h = [];
- h = a.split("_gamen_"),
- GD.medal[r] = [parseInt(h[0]), !1, parseInt(h[1]), h[2], h[3], parseInt(h[5]), h[4]]
- }
- DataManager.callFunc.call(DataManager.target),
- DataManager.playInterval = setInterval(DataManager.promisePlay, .1)
- }
- DataManager.point = function (t, e) {
- if (GD.log(t + " : " + e),
- DataManager.otherPoint(t, e),
- GD.isLogin) {
- t = XORcipher().xorEncoder(t, GD.sKey),
- e = XORcipher().xorEncoder(e.toString(), GD.sKey);
- var i = Date.now() - GD.startTime
- , n = XORcipher().xorEncoder(i.toString(), GD.sKey);
- gamen.point(t, e, n)
- }
- }
- DataManager.otherPoint = function (t, e) {
- if (GD.isLogin) {
- t = XORcipher().xorEncoder(t, GD.oKey),
- e = XORcipher().xorEncoder(e.toString(), GD.oKey);
- var i = Date.now() - GD.startTime
- , n = XORcipher().xorEncoder(i.toString(), GD.oKey);
- gamen.otherpoint(t, e, n)
- }
- }
- DataManager.promisePlay = function () {
- var t = Date.now() - GD.startTime
- , e = XORcipher().xorEncoder(t.toString(), GD.oKey);
- gamen.promiseplay(e)
- }
- DataManager.finish = function (t) {
- if (DataManager.playInterval && clearInterval(DataManager.playInterval),
- GD.isLogin) {
- if (GD.medal.length > 0) {
- var e = []
- , i = GD.medal.length;
- gamen.new_achievement = [];
- for (var n = 0; i > n; ++n)
- 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]),
- gamen.new_achievement[n] = XORcipher().xorEncoder(e[n], GD.sKey)
- }
- var o = XORcipher().xorEncoder(t.toString(), GD.sKey)
- , s = GD.commonOption.gameRestart.bind(GD.commonOption)
- , r = XORcipher().xorEncoder(GD.unique, GD.sKey)
- , a = XORcipher().xorEncoder(GD.startTime.toString(), GD.sKey)
- , h = Date.now()
- , l = XORcipher().xorEncoder(h.toString(), this.sKey);
- gamen.finish(GD.pk, o, s, r, a, l)
- } else
- gamen.finish(t, null,GD.commonOption.gameRestart.bind(GD.commonOption))
- }
- DataManager.addMedal = function (t, e) {
- if (GD.isLogin && GD.medal.length > 0) {
- for (var i = null, n = 0; n < GD.medal.length; ++n) {
- if (t == GD.medal[n][0]) {
- i = n,
- 0 == GD.medal[i][1] && (null == e && (e = 1),
- GD.medal[i][5] += e,
- GD.medal[i][2] <= GD.medal[i][5] && (GD.medal[i][1] = !0,
- GD.commonOption.setAchievement(i + 1)));
- break
- }
- }
- }
- }
- module.exports = DataManager
|