Commit 91de5434 authored by zhangjinzhou's avatar zhangjinzhou

代码暂存

parent 982b741e
{
"enableLegacyRemoteDebug": true
}
\ No newline at end of file
......@@ -14,7 +14,8 @@ const {
const {
commonToast,
navigateToOutside,
getSystemInfo
getSystemInfo,
getServerTime
} = tbcc.tb;
let updateact = 1;//请求
let gameatime = 100;//活动倒计时,100,
......@@ -106,7 +107,6 @@ Page({
inviteshowdata: {
},
avatar1: "",
avatar2: "",
avatar3: "",
......@@ -114,9 +114,18 @@ Page({
canwin: false,
hidetime: 0,
othername: [],
overequest: false,
},
onLoad(query) {
// console.log("onLoad========>", app, props);
if (query && query.laststat) {
let laststat = query.laststat;
console.log("laststat=====>", laststat);
this.getLastGame();
return;
} else {
console.log("普通进入");
}
let isnewdata = my.getStorageSync({
key: 'jn_' + app.openId + '_new'
});
......@@ -138,6 +147,7 @@ Page({
// 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;
......@@ -563,17 +573,54 @@ Page({
this.updateActInfo();
},
onHide() {
//房间数据
let roomdata = this.data.roomdata;
let roomnums = this.data.roomnums;
let tooltime = this.data.tooltime;
let canwin = this.data.canwin;
let step = this.data.step;
let startime = this.data.startime;
let endtime = this.data.endtime;
let avatar2 = this.data.avatar2;
let avatar3 = this.data.avatar3;
let avatar4 = this.data.avatar4;
let othername = this.data.othername;
let overequest = this.data.overequest;
let ntime = Date.now();
my.setStorage({
key: 'jn_' + app.openId + '_gamedata',
data: {
roomdata: roomdata,
roomnums: roomnums,
tooltime: tooltime,
canwin: canwin,
step: step,
startime: startime,
endtime: endtime,
avatar2,
avatar3,
avatar4,
othername: othername,
overequest: overequest,
hidetime: ntime,
}
})
this.setData({
hidetime: ntime
});
},
//更新活动信息
//30s刷新一次邀请人列表,新增温度,结束前5s再请求一次,onshow请求一次
async updateActInfo() {
async updateActInfo(gamestat = "now") {
// console.log("updateActInfo=======>");
clearTimeout(updateact);
await this.updateAttionList();
await this.updateAttionList(gamestat);
await this.getInviteListByCurGame();
let lesstime = this.data.gametime * 1000;
let chatime = 30000;
......@@ -658,6 +705,9 @@ Page({
}).catch(res => {
commonToast(res && res.message);
})
this.setData({
overequest: true
});
const { success, data } = overdata;
if (success) {
const { warms, isWin, prize, unLockStep } = data;
......@@ -814,7 +864,7 @@ Page({
return showm + ":" + shows;
},
//更新attionlist,玩家相关
async updateAttionList() {
async updateAttionList(gamestat = "now") {
// console.log("更新玩家++温度值");
let startime = this.data.startime;
let endtime = this.data.endtime;
......@@ -834,6 +884,9 @@ Page({
if (total > nwd) {
this.updateRolewd(ridx, total);
}
if (gamestat == "last") {
return;
}
//使用道具的单独来
if (tool) {
let txt2 = this.solveAttionTxt(tool, this.data.ltool, "tool");
......@@ -1147,7 +1200,7 @@ Page({
let addy = 50;
let step = this.data.step;
var con = stage.addChild(new FYGE.Container())
con.y=stage.viewRect.y;
con.y = stage.viewRect.y;
stage.addEventListener(FYGE.Event.INIT_STAGE, () => {
SvgaParser.loadSvga(
paple1,
......@@ -1235,6 +1288,179 @@ Page({
stage.flush();
FYGE.getRequestAnimationFrame()(loop);
}
},
//用上局游戏继续
async getLastGame() {
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: () => {
}
});
})
if (lgamedata) {
let {
roomdata, roomnums, tooltime, canwin, step, startime, endtime, avatar2, avatar3, avatar4, othername, overequest
} = lgamedata;
commonToast("正在连接到上一局");
if (!overequest) {
let nowTime = await getServerTime().catch(() => { });
if (!nowTime) {
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({
key:key
});
}
},
//直接结束
async lastgameover(lgamedata, nowTime) {
console.log("直接结束========》");
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,
avatar3: avatar3,
avatar4: avatar4,
step: step,
roomnums: roomnums,
roomdata: roomdata,
canwin: canwin,
gametime: 0,
gametimeshow: this.changeshowtime(0),
tooltime: tooltime,
showtooltime: this.changeshowtime(tooltime),
startime: Number(startime),
endtime: Number(endtime),
});
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
} = 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);
this.setData({
avatar1: app.avatar,
avatar2: avatar2,
avatar3: avatar3,
avatar4: avatar4,
step: step,
roomnums: roomnums,
roomdata: roomdata,
canwin: canwin,
gametime: gameatime,
gametimeshow: this.changeshowtime(gameatime),
tooltime: tooltime,
showtooltime: this.changeshowtime(tooltime),
startime: Number(startime),
endtime: Number(endtime),
})
this.updateActInfo("last");
this.updateAiInfo();
this.changePageShow1();
this.updateAct();
},
async changePageShow1() {
await new Promise((res) => {
this.setData({
show_v: 1
});
setTimeout(() => {
this.setData({
show_v: 2
});
res();
}, 1000);
})
},
//上局游戏直接设置新的
updateAiInfo() {
let canwin = this.data.canwin;
let roomnums = this.data.roomnums - 1;
let roomdata = this.data.roomdata;
let myidx = this.data.myidx - 1;
let mywd = roomdata[myidx].wd;
if (mywd == 0) {
canwin = false;
}
let havechao = false;
for (let i = 0; i < roomdata.length; i++) {
if (i != myidx) {
let idata = this.data.roomdata[i];
let iwd = idata.wd;
let twd = iwd;
if (canwin) {//玩家胜利
if (iwd < mywd) {
twd = Math.floor(Math.random() * (mywd - iwd)) + iwd;
}
} else {//机器胜利
let doup = false;
let towarm = towarm = Math.round(Math.random() * 3) * invitewarm;
if (iwd > mywd) {//可不处理
havechao = true;
doup = Math.random() < 0.2;
} else {
if (havechao) {//可不处理
doup = Math.random() < 0.5;
} else {
doup = true
towarm = Math.ceil(mywd - iwd + towarm);
havechao = true;
}
}
if (doup && towarm > 0) {
twd = iwd + towarm;
}
}
this.updateRolewd(i, twd);
}
}
}
});
\ No newline at end of file
......@@ -262,6 +262,8 @@ Page({
app.openId = data.openId;
// app.step = data.inviteStep;
this.getActivityBaseInfoById();
this.checkLastGameStat();
}
},
/*
......@@ -278,7 +280,7 @@ Page({
}) || {};
if (success) {
const nowTime = await getServerTime().catch(() => {});
const nowTime = await getServerTime().catch(() => { });
if (nowTime && data.startTime > nowTime) {
my.hideLoading();
my.showToast({
......@@ -373,7 +375,7 @@ Page({
canOpenGamePage: false,
/**进入游戏页面 */
async openGamePage() {
if(!this.start){
if (!this.start) {
commonToast("活动已结束")
return;
}
......@@ -421,12 +423,11 @@ Page({
const {
item
} = e.target.dataset;
if(!this.start&&item=='inviteList')
{
if (!this.start && item == 'inviteList') {
commonToast("活动已结束")
return;
}
if (!this.start&&item!='rule') return;
if (!this.start && item != 'rule') return;
this.setData({
modalStatus: modalType[item] || 0
});
......@@ -507,6 +508,47 @@ Page({
} else {
this.openInviteSuccessModal();
}
},
//检测上局的状态
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: () => {
}
});
})
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";
} else {//上局结束,未结算,去结算
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