Commit 59eec3b1 authored by zhangjinzhou's avatar zhangjinzhou

代码暂存

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