Commit 59eec3b1 authored by zhangjinzhou's avatar zhangjinzhou

代码暂存

parent 221ae749
...@@ -115,17 +115,34 @@ Page({ ...@@ -115,17 +115,34 @@ Page({
hidetime: 0, hidetime: 0,
othername: [], othername: [],
overequest: false, overequest: false,
laststat: ""
}, },
onLoad(query) { onLoad(query) {
// console.log("onLoad========>", app, props); console.log("onLoad========>", query);
if (query && query.laststat) { if (query && query.laststat) {
let laststat = query.laststat; let laststat = query.laststat;
this.setData({
laststat: laststat
});
console.log("laststat=====>", laststat); console.log("laststat=====>", laststat);
this.getLastGame(); this.checkLastGame(query);
return; return;
} else { } else {
this.setData({
laststat: 'normal'
});
console.log("普通进入"); console.log("普通进入");
} }
this.initGame(query);
},
//initgame===>
async initGame(query, gamestat = "normal") {
let isnew = false;
let tooltime = 0;
console.log("initGame", query, gamestat);
let { end, gl, start, step, toolcd } = query;
gameatime = Math.floor((Number(end) - Number(start)) / 1000);
if (gamestat == "normal") {
let isnewdata = my.getStorageSync({ let isnewdata = my.getStorageSync({
key: 'jn_' + app.openId + '_new' key: 'jn_' + app.openId + '_new'
}); });
...@@ -140,14 +157,23 @@ Page({ ...@@ -140,14 +157,23 @@ Page({
data: 1 data: 1
}); });
} }
} else {
tooltime = query.tooless;
let nowTime = await getServerTime().catch(() => { });
if (!nowTime) {
nowTime = Date.now();
}
gameatime = Math.floor((Number(end) - Number(nowTime)) / 1000);
if (gameatime < 0) {
gameatime = 0;
}
}
// console.log("新手", isnew, query);
let { end, gl, start, step, toolcd } = query;
step = Number(step); step = Number(step);
// step = 3;
gameatime = Math.floor((Number(end) - Number(start)) / 1000);
gtoolcd = Number(toolcd); gtoolcd = Number(toolcd);
console.error("道具cd",toolcd,gtoolcd);
let sucgl = Number(gl); let sucgl = Number(gl);
let nranksuc = Math.random(); let nranksuc = Math.random();
let canwin = false; let canwin = false;
...@@ -202,6 +228,7 @@ Page({ ...@@ -202,6 +228,7 @@ Page({
}; };
roomdata.push(idata); roomdata.push(idata);
} }
// console.log("onload=========>",roomnums,roomdata); // console.log("onload=========>",roomnums,roomdata);
this.setData({ this.setData({
avatar1: app.avatar, avatar1: app.avatar,
...@@ -213,24 +240,32 @@ Page({ ...@@ -213,24 +240,32 @@ Page({
canwin: canwin, canwin: canwin,
isfirst: true, isfirst: true,
gametime: gameatime, gametime: gameatime,
tooltime: 0, tooltime: tooltime,
startime: Number(start), startime: Number(start),
endtime: Number(end), endtime: Number(end),
}); });
this.changePashow();
my.__updateWarms = () => { my.__updateWarms = () => {
this.updateActInfo(); this.updateActInfo();
} }
// console.log("my======>",my);
if (gamestat == "normal") {
this.changePashow();
} else {
this.updateActInfo();
this.updateAiInfo()
this.changePageShow1();
this.updateAct();
}
}, },
startGame() { startGame() {
if (this.data.isnew > 0 && this.data.isnew < 7) { if (this.data.isnew > 0 && this.data.isnew < 7) {
return; return;
} }
my.showToast({ // my.showToast({
content: '请不要关闭APP,会导致本局游戏作废', // content: '请不要关闭APP,会导致本局游戏作废',
duration: 4500, // duration: 4500,
}); // });
// console.log("游戏开始逻辑==canwin", this.data.canwin); // console.log("游戏开始逻辑==canwin", this.data.canwin);
let attiontxt1 = "游戏开始啦,共有" + this.data.roomnums + "名玩家加入游戏,快来升温队伍拿奖励吧。"; let attiontxt1 = "游戏开始啦,共有" + this.data.roomnums + "名玩家加入游戏,快来升温队伍拿奖励吧。";
this.addAttionTxt(attiontxt1); this.addAttionTxt(attiontxt1);
...@@ -545,6 +580,8 @@ Page({ ...@@ -545,6 +580,8 @@ Page({
} }
}, },
onShow() { onShow() {
let laststat = this.data.laststat;
if (laststat == "normal") {
let ntime = Date.now(); let ntime = Date.now();
let hidetime = this.data.hidetime; let hidetime = this.data.hidetime;
if (hidetime) { if (hidetime) {
...@@ -566,6 +603,8 @@ Page({ ...@@ -566,6 +603,8 @@ Page({
tooltime: tooltime1 tooltime: tooltime1
}) })
} }
}
let ngametime = this.data.gametime; let ngametime = this.data.gametime;
if ((this.data.isnew > 0 && this.data.isnew < 7) || this.data.show_v != 2 || ngametime <= 0) { if ((this.data.isnew > 0 && this.data.isnew < 7) || this.data.show_v != 2 || ngametime <= 0) {
return; return;
...@@ -680,6 +719,11 @@ Page({ ...@@ -680,6 +719,11 @@ Page({
}, },
//游戏结束 //游戏结束
async gameover() { async gameover() {
let key = 'jn_' + app.openId + '_gamedata';
my.removeStorage({
key: key
});
this.closenordia(); this.closenordia();
// console.log("游戏结束"); // console.log("游戏结束");
let roomnums = this.data.roomnums; let roomnums = this.data.roomnums;
...@@ -699,7 +743,7 @@ Page({ ...@@ -699,7 +743,7 @@ Page({
let step = this.data.step; let step = this.data.step;
app.curGameWars = this.data.roomdata[this.data.myidx - 1].wd; app.curGameWars = this.data.roomdata[this.data.myidx - 1].wd;
const overdata = await API.gameOver({ const { success, data } = await API.gameOver({
isWin: iswin, isWin: iswin,
step: step step: step
}).catch(res => { }).catch(res => {
...@@ -708,7 +752,7 @@ Page({ ...@@ -708,7 +752,7 @@ Page({
this.setData({ this.setData({
overequest: true overequest: true
}); });
const { success, data } = overdata;
if (success) { if (success) {
const { warms, isWin, prize, unLockStep } = data; const { warms, isWin, prize, unLockStep } = data;
// console.log("over", data) // console.log("over", data)
...@@ -787,14 +831,14 @@ Page({ ...@@ -787,14 +831,14 @@ Page({
let tooltime = this.data.tooltime; let tooltime = this.data.tooltime;
if (tooltime <= 0) {//可使用 if (tooltime <= 0) {//可使用
let addwarm = toolwarm; let addwarm = toolwarm;
let tooldata = await API.sendWarmsByCurGame({ const { success, data } = await API.sendWarmsByCurGame({
type: "tool", type: "tool",
warms: addwarm, warms: addwarm,
step: this.data.step step: this.data.step
}).catch(res => { }).catch(res => {
commonToast(res && res.message); commonToast(res && res.message);
}); });
const { success, data } = tooldata;
if (success) { if (success) {
this.updateActInfo(); this.updateActInfo();
this.setData({ this.setData({
...@@ -869,14 +913,14 @@ Page({ ...@@ -869,14 +913,14 @@ Page({
let startime = this.data.startime; let startime = this.data.startime;
let endtime = this.data.endtime; let endtime = this.data.endtime;
let step = this.data.step; let step = this.data.step;
let attiondata = await API.getWarmDetailListByCurGame({ const { success, data } = await API.getWarmDetailListByCurGame({
joinGameStartTime: startime, joinGameStartTime: startime,
joinGameEndTime: endtime, joinGameEndTime: endtime,
step: step step: step
}).catch(res => { }).catch(res => {
commonToast(res && res.message); commonToast(res && res.message);
}) })
const { success, data } = attiondata;
if (success) { if (success) {
const { total, invite, tool, follow, sign, collect, browseGoods } = data; const { total, invite, tool, follow, sign, collect, browseGoods } = data;
let ridx = this.data.myidx; let ridx = this.data.myidx;
...@@ -1047,6 +1091,7 @@ Page({ ...@@ -1047,6 +1091,7 @@ Page({
}).catch(res => { }).catch(res => {
commonToast(res && res.message); commonToast(res && res.message);
}); });
if (invitedata) {
const { success, data } = invitedata; const { success, data } = invitedata;
if (success) { if (success) {
if (data && data.length > this.data.invitedata.length) { if (data && data.length > this.data.invitedata.length) {
...@@ -1055,6 +1100,7 @@ Page({ ...@@ -1055,6 +1100,7 @@ Page({
}); });
} }
} }
}
}, },
//结算返回首页 //结算返回首页
...@@ -1289,8 +1335,7 @@ Page({ ...@@ -1289,8 +1335,7 @@ Page({
FYGE.getRequestAnimationFrame()(loop); FYGE.getRequestAnimationFrame()(loop);
} }
}, },
//用上局游戏继续 async checkLastGame(query) {
async getLastGame() {
let key = 'jn_' + app.openId + '_gamedata'; let key = 'jn_' + app.openId + '_gamedata';
let lgamedata = await new Promise((res, rej) => { let lgamedata = await new Promise((res, rej) => {
my.getStorage({ my.getStorage({
...@@ -1308,27 +1353,28 @@ Page({ ...@@ -1308,27 +1353,28 @@ Page({
}); });
}) })
if (lgamedata) { if (lgamedata) {
let { let { step, start, end, gl, toolcd, tooless } = query;
roomdata, roomnums, tooltime, canwin, step, startime, endtime, avatar2, avatar3, avatar4, othername, overequest lgamedata["step"] = step;
} = lgamedata; lgamedata["startime"] = start;
commonToast("正在连接到上一局"); lgamedata["endtime"] = end;
if (!overequest) { lgamedata["gl"] = gl;
lgamedata["toolcd"] = toolcd;
lgamedata["tooltime"] = tooless;
my.removeStorage({
key: key
});
let nowTime = await getServerTime().catch(() => { }); let nowTime = await getServerTime().catch(() => { });
if (!nowTime) { if (!nowTime) {
nowTime = Date.now(); nowTime = Date.now();
} }
console.log("nowtime===>",nowTime,endtime,nowTime-endtime); if (end > nowTime) {//继续
if (endtime > nowTime) {//继续
this.lastgamereset(lgamedata, nowTime); this.lastgamereset(lgamedata, nowTime);
} else {//结算 } else {//结算
this.lastgameover(lgamedata, nowTime); this.lastgameover(lgamedata, nowTime);
} }
} else { } else {
console.error("哪里处理问题====》", lgamedata); console.log("start====query", query);
} this.initGame(query, "spe");
my.removeStorage({
key:key
});
} }
}, },
//直接结束 //直接结束
...@@ -1337,13 +1383,6 @@ Page({ ...@@ -1337,13 +1383,6 @@ Page({
let { let {
roomdata, roomnums, tooltime, canwin, step, startime, endtime, avatar2, avatar3, avatar4, othername, overequest, hidetime roomdata, roomnums, tooltime, canwin, step, startime, endtime, avatar2, avatar3, avatar4, othername, overequest, hidetime
} = lgamedata; } = lgamedata;
let passtime = Math.floor((nowTime - hidetime) / 1000);
if (passtime > 0) {
tooltime -= passtime;
}
if (tooltime < 0) {
tooltime = 0;
}
this.setData({ this.setData({
avatar1: app.avatar, avatar1: app.avatar,
avatar2: avatar2, avatar2: avatar2,
...@@ -1362,25 +1401,17 @@ Page({ ...@@ -1362,25 +1401,17 @@ Page({
}); });
this.updateActInfo("last"); this.updateActInfo("last");
this.updateAiInfo(); this.updateAiInfo();
console.log("更新ai");
this.changePageShow1(); this.changePageShow1();
console.log("aiwdshow", this.data.roomdata);
this.gameover(); this.gameover();
}, },
//恢复上局游戏 //恢复上局游戏
async lastgamereset(lgamedata, nowTime) { async lastgamereset(lgamedata, nowTime) {
let { let {
roomdata, roomnums, tooltime, canwin, step, startime, endtime, avatar2, avatar3, avatar4, othername, overequest, hidetime roomdata, roomnums, tooltime, canwin, step, startime, endtime, avatar2, avatar3, avatar4, othername, toolcd, overequest, hidetime
} = lgamedata; } = lgamedata;
let passtime = Math.floor((nowTime - hidetime) / 1000);
if (passtime > 0) {
tooltime -= passtime;
}
if (tooltime < 0) {
tooltime = 0;
}
let gameatime = Math.floor((Number(endtime) - Number(nowTime)) / 1000); let gameatime = Math.floor((Number(endtime) - Number(nowTime)) / 1000);
gtoolcd = Number(toolcd);
this.setData({ this.setData({
avatar1: app.avatar, avatar1: app.avatar,
avatar2: avatar2, avatar2: avatar2,
...@@ -1396,7 +1427,11 @@ Page({ ...@@ -1396,7 +1427,11 @@ Page({
showtooltime: this.changeshowtime(tooltime), showtooltime: this.changeshowtime(tooltime),
startime: Number(startime), startime: Number(startime),
endtime: Number(endtime), endtime: Number(endtime),
}) othername: othername,
overequest: overequest,
hidetime: hidetime
});
this.updateActInfo("last"); this.updateActInfo("last");
this.updateAiInfo(); this.updateAiInfo();
this.changePageShow1(); this.changePageShow1();
...@@ -1455,7 +1490,7 @@ Page({ ...@@ -1455,7 +1490,7 @@ Page({
twd = iwd + towarm; twd = iwd + towarm;
} }
} }
this.updateRolewd(i, twd); this.updateRolewd(i + 1, twd);
......
...@@ -262,8 +262,6 @@ Page({ ...@@ -262,8 +262,6 @@ Page({
app.openId = data.openId; app.openId = data.openId;
// app.step = data.inviteStep; // app.step = data.inviteStep;
this.getActivityBaseInfoById(); this.getActivityBaseInfoById();
this.checkLastGameStat();
} }
}, },
/* /*
...@@ -369,6 +367,11 @@ Page({ ...@@ -369,6 +367,11 @@ Page({
this.canOpenGamePage = true; this.canOpenGamePage = true;
this.start = true; this.start = true;
my.hideLoading(); my.hideLoading();
let lastGameInfo = data.lastGameInfo;
lastGameInfo["step"] = data.step;
this.checkLastGameStat(lastGameInfo);
} }
}, },
...@@ -510,45 +513,68 @@ Page({ ...@@ -510,45 +513,68 @@ Page({
} }
}, },
//检测上局的状态 //检测上局的状态
async checkLastGameStat() { async checkLastGameStat(data) {
console.log("checkLastGameStat======>", 1); //纯本地的
let key = 'jn_' + app.openId + '_gamedata'; // let key = 'jn_' + app.openId + '_gamedata';
let lgamedata = await new Promise((res, rej) => { // let lgamedata = await new Promise((res, rej) => {
my.getStorage({ // my.getStorage({
key: key, // key: key,
success: (result) => { // success: (result) => {
console.log("checkLastGameStat======>suc", result); // res(result.data);
res(result.data); // },
}, // fail: () => {
fail: () => { // rej(false);
rej(false); // },
}, // complete: () => {
complete: () => {
// }
// });
// })
// if (lgamedata) {
// const { endtime, overequest } = lgamedata;
// //上局结算过了,不用管
// if (!overequest) {
// let querystr = "";
// let { roomdata, roomnums, tooltime, canwin, step, startime, avatar2, avatar3, avatar4, othername, overequest } = lgamedata;
// const nowTime = await getServerTime().catch(() => { });
// if (nowTime && endtime > nowTime) {//上局未结束,继续游戏
// querystr += "laststat=go";
// } else {//上局结束,未结算,去结算
// querystr = "laststat=over";
// }
// my.redirectTo({
// url: '/pages/pagegamemain/pagegamemain?' + querystr
// });
// }
// }
//服务器的
let { joinGameStartTime, joinGameEndTime, toolStartTime, toolEndTime, winRate, propsCD ,step} = data;
if (joinGameStartTime && joinGameEndTime) {
let nowTime = await getServerTime().catch(() => { });
if(!nowTime){
nowTime = Date.now();
} }
});
})
console.log("checkLastGameStat======>", 2, lgamedata); let toolcd = Math.ceil((toolEndTime-toolStartTime)/1000);
if (lgamedata) { let tooless = Math.ceil((toolEndTime-nowTime)/1000);
const { endtime, overequest } = lgamedata; if(tooless<0){
//上局结算过了,不用管 tooless = 0;
if (!overequest) { }
let querystr = ""; let querystr = "step=" + step + "&start=" + joinGameStartTime +
let { roomdata, roomnums, tooltime, canwin, step, startime, avatar2, avatar3, avatar4, othername, overequest } = lgamedata; "&end=" + joinGameEndTime + "&gl=" + winRate + "&toolcd=" + toolcd+"&tooless="+tooless;
const nowTime = await getServerTime().catch(() => { });
console.log("checkLastGameStat======>", 3, endtime-nowTime); if (nowTime && joinGameEndTime > nowTime) {//上局未结束,继续游戏
console.log("checkLastGameStat======>",4,endtime,nowTime); querystr += "&laststat=go";
if (nowTime && endtime > nowTime) {//上局未结束,继续游戏
querystr += "laststat=go";
} else {//上局结束,未结算,去结算 } else {//上局结束,未结算,去结算
querystr = "laststat=over"; querystr += "&laststat=over";
} }
my.redirectTo({ my.redirectTo({
url: '/pages/pagegamemain/pagegamemain?' + querystr url: '/pages/pagegamemain/pagegamemain?' + querystr
}); });
} }
} }
}
}); });
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment