Commit 59eec3b1 authored by zhangjinzhou's avatar zhangjinzhou

代码暂存

parent 221ae749
...@@ -115,39 +115,65 @@ Page({ ...@@ -115,39 +115,65 @@ 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("普通进入");
} }
let isnewdata = my.getStorageSync({ this.initGame(query);
key: 'jn_' + app.openId + '_new' },
}); //initgame===>
let isnew = isnewdata.data ? 0 : 1; async initGame(query, gamestat = "normal") {
// isnew = 1; let isnew = false;
this.setData({ let tooltime = 0;
isnew: isnew console.log("initGame", query, gamestat);
}); let { end, gl, start, step, toolcd } = query;
if (isnew != 0) { gameatime = Math.floor((Number(end) - Number(start)) / 1000);
my.setStorageSync({ if (gamestat == "normal") {
key: 'jn_' + app.openId + '_new', let isnewdata = my.getStorageSync({
data: 1 key: 'jn_' + app.openId + '_new'
});
let isnew = isnewdata.data ? 0 : 1;
// isnew = 1;
this.setData({
isnew: isnew
}); });
if (isnew != 0) {
my.setStorageSync({
key: 'jn_' + app.openId + '_new',
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,27 +580,31 @@ Page({ ...@@ -545,27 +580,31 @@ Page({
} }
}, },
onShow() { onShow() {
let ntime = Date.now(); let laststat = this.data.laststat;
let hidetime = this.data.hidetime; if (laststat == "normal") {
if (hidetime) { let ntime = Date.now();
let passtime = ntime - hidetime; let hidetime = this.data.hidetime;
let gametime = this.data.gametime; if (hidetime) {
gametime -= passtime / 1000; let passtime = ntime - hidetime;
if (gametime < 0) { let gametime = this.data.gametime;
gametime = 0; gametime -= passtime / 1000;
} if (gametime < 0) {
gametime = 0;
}
let tooltime1 = this.data.tooltime; let tooltime1 = this.data.tooltime;
tooltime1 -= passtime / 1000; tooltime1 -= passtime / 1000;
if (tooltime1 < 0) { if (tooltime1 < 0) {
tooltime1 = 0; tooltime1 = 0;
}
this.setData({
gametime: gametime,
tooltime: tooltime1
})
} }
this.setData({
gametime: gametime,
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,12 +1091,14 @@ Page({ ...@@ -1047,12 +1091,14 @@ Page({
}).catch(res => { }).catch(res => {
commonToast(res && res.message); commonToast(res && res.message);
}); });
const { success, data } = invitedata; if (invitedata) {
if (success) { const { success, data } = invitedata;
if (data && data.length > this.data.invitedata.length) { if (success) {
this.setData({ if (data && data.length > this.data.invitedata.length) {
invitedata: data this.setData({
}); invitedata: data
});
}
} }
} }
}, },
...@@ -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;
let nowTime = await getServerTime().catch(() => { }); lgamedata["toolcd"] = toolcd;
if (!nowTime) { lgamedata["tooltime"] = tooless;
nowTime = Date.now();
}
console.log("nowtime===>",nowTime,endtime,nowTime-endtime);
if (endtime > nowTime) {//继续
this.lastgamereset(lgamedata, nowTime);
} else {//结算
this.lastgameover(lgamedata, nowTime);
}
} else {
console.error("哪里处理问题====》", lgamedata);
}
my.removeStorage({ my.removeStorage({
key:key key: key
}); });
let nowTime = await getServerTime().catch(() => { });
if (!nowTime) {
nowTime = Date.now();
}
if (end > nowTime) {//继续
this.lastgamereset(lgamedata, nowTime);
} else {//结算
this.lastgameover(lgamedata, nowTime);
}
} else {
console.log("start====query", query);
this.initGame(query, "spe");
} }
}, },
//直接结束 //直接结束
...@@ -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,44 +513,67 @@ Page({ ...@@ -510,44 +513,67 @@ 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: () => {
} // }
}); // });
}) // })
console.log("checkLastGameStat======>", 2, lgamedata); // if (lgamedata) {
if (lgamedata) { // const { endtime, overequest } = lgamedata;
const { endtime, overequest } = lgamedata; // //上局结算过了,不用管
//上局结算过了,不用管 // if (!overequest) {
if (!overequest) { // let querystr = "";
let querystr = ""; // let { roomdata, roomnums, tooltime, canwin, step, startime, avatar2, avatar3, avatar4, othername, overequest } = lgamedata;
let { roomdata, roomnums, tooltime, canwin, step, startime, avatar2, avatar3, avatar4, othername, overequest } = lgamedata; // const nowTime = await getServerTime().catch(() => { });
const nowTime = await getServerTime().catch(() => { }); // if (nowTime && endtime > nowTime) {//上局未结束,继续游戏
console.log("checkLastGameStat======>", 3, endtime-nowTime); // querystr += "laststat=go";
console.log("checkLastGameStat======>",4,endtime,nowTime); // } else {//上局结束,未结算,去结算
if (nowTime && endtime > nowTime) {//上局未结束,继续游戏 // querystr = "laststat=over";
querystr += "laststat=go"; // }
} else {//上局结束,未结算,去结算 // my.redirectTo({
querystr = "laststat=over"; // url: '/pages/pagegamemain/pagegamemain?' + querystr
} // });
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();
}
let toolcd = Math.ceil((toolEndTime-toolStartTime)/1000);
let tooless = Math.ceil((toolEndTime-nowTime)/1000);
if(tooless<0){
tooless = 0;
} }
let querystr = "step=" + step + "&start=" + joinGameStartTime +
"&end=" + joinGameEndTime + "&gl=" + winRate + "&toolcd=" + toolcd+"&tooless="+tooless;
if (nowTime && joinGameEndTime > nowTime) {//上局未结束,继续游戏
querystr += "&laststat=go";
} else {//上局结束,未结算,去结算
querystr += "&laststat=over";
}
my.redirectTo({
url: '/pages/pagegamemain/pagegamemain?' + querystr
});
} }
} }
......
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