修复抽卡
This commit is contained in:
parent
62fe4d309f
commit
576eb6abf7
|
|
@ -48,7 +48,8 @@ export default class Avatar extends cc.Component {
|
|||
if (data) {
|
||||
this.avatarData = cc.fx.GameTool.getAvatarData(data.headArr);
|
||||
}
|
||||
this.film = data.film;
|
||||
this.film = Number(data.film) || 0;
|
||||
cc.fx.GameConfig.GM_INFO.film = this.film;
|
||||
// console.log("头像信息", this.avatarData);
|
||||
this.avatar = cc.fx.GameConfig.GM_INFO.useravatarIcon;
|
||||
this.avatarKuang = cc.fx.GameConfig.GM_INFO.useravaterkuang;
|
||||
|
|
@ -314,7 +315,6 @@ export default class Avatar extends cc.Component {
|
|||
if (this.avatar.length > 10) {
|
||||
this.content.children[0].getChildByName("select").active = true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
this.changeBtnState("avatar");
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@ export class GameConfig {
|
|||
guide: boolean; //是否有引导
|
||||
url: string; //访问域名
|
||||
coin: number; //用户金币
|
||||
film: number; //头像抽卡代币
|
||||
success: boolean; //用户游戏成功与否
|
||||
matchId: any; //用于埋点上传的ID
|
||||
gameState: boolean; custom: number; //用于测试跳关卡
|
||||
|
|
@ -281,6 +282,7 @@ export class GameConfig {
|
|||
guide: true, //是否有引导
|
||||
url: "https://api.sparkus.cn",//访问域名
|
||||
coin: 0, //用户金币
|
||||
film: 0, //头像抽卡代币(以服务端返回值为准)
|
||||
success: false, //用户游戏成功与否
|
||||
matchId: null, //用于埋点上传的ID
|
||||
gameState: false,
|
||||
|
|
|
|||
|
|
@ -515,6 +515,9 @@ export default class Utils {
|
|||
Utils.POST("userLevel", setData, res => {
|
||||
//console.log("获得userLevel数据:", res);
|
||||
if (res.code === 1) {
|
||||
if (res.data && res.data.film !== undefined) {
|
||||
cc.fx.GameConfig.GM_INFO.film = Number(res.data.film);
|
||||
}
|
||||
//console.log("服务器:获得等级成功", res);
|
||||
if (callBack) callBack(res);
|
||||
} else {
|
||||
|
|
@ -552,6 +555,9 @@ export default class Utils {
|
|||
Utils.POST("userLevel", setData, res => {
|
||||
//console.log("获得userLevel数据:", res);
|
||||
if (res.code === 1) {
|
||||
if (res.data && res.data.film !== undefined) {
|
||||
cc.fx.GameConfig.GM_INFO.film = Number(res.data.film);
|
||||
}
|
||||
//console.log("服务器:上传等级成功", res);
|
||||
if (callBack) callBack(res);
|
||||
} else {
|
||||
|
|
@ -1665,10 +1671,11 @@ export default class Utils {
|
|||
Utils.POST("drawHead", setData, res => {
|
||||
if (res.code === 1) {
|
||||
console.log("正常获取到抽卡结果", res);
|
||||
if (callBack) callBack(res);
|
||||
} else {
|
||||
console.log("获取抽卡失败,失败原因", res);
|
||||
}
|
||||
// 失败也必须回调,否则抽卡页的 Loading 和防重复点击状态无法恢复。
|
||||
if (callBack) callBack(res);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -1754,6 +1761,9 @@ export default class Utils {
|
|||
Utils.POST("getFilm", setData, res => {
|
||||
if (res.code === 1) {
|
||||
console.log("正常获取用户代币", res);
|
||||
if (res.data && res.data.film !== undefined) {
|
||||
cc.fx.GameConfig.GM_INFO.film = Number(res.data.film);
|
||||
}
|
||||
if (callBack) callBack(res);
|
||||
} else {
|
||||
console.log("获取代币失败,失败原因", res);
|
||||
|
|
|
|||
|
|
@ -19,17 +19,25 @@ export default class GachaManager extends cc.Component {
|
|||
avatarData: any = null;
|
||||
own = 0;
|
||||
reward = 0;
|
||||
film = 0;
|
||||
isDrawing = false;
|
||||
|
||||
onLoad() {
|
||||
this.avatarData = [];
|
||||
this.own = 0;
|
||||
this.reward = 0;
|
||||
this.film = 0;
|
||||
this.isDrawing = false;
|
||||
// this.init();
|
||||
}
|
||||
//初始化数据
|
||||
init(data, film) {
|
||||
this.avatarData = [];
|
||||
this.own = 0;
|
||||
const parsedFilm = Number(film);
|
||||
this.film = isNaN(parsedFilm) ? 0 : parsedFilm;
|
||||
// 界面显示和抽卡判断必须使用同一份代币数据。
|
||||
cc.fx.GameConfig.GM_INFO.film = this.film;
|
||||
console.log("222222初始化数据", data);
|
||||
if (data) {
|
||||
this.avatarData = data;
|
||||
|
|
@ -54,17 +62,17 @@ export default class GachaManager extends cc.Component {
|
|||
let cost = this.getCostFilm();
|
||||
botoom.getChildByName("total").getComponent(cc.Label).string = cost.toString();
|
||||
console.log("抽卡所需film", cost);
|
||||
if (film >= cost) {
|
||||
if (this.film >= cost) {
|
||||
botoom.getChildByName("yes").active = true;
|
||||
console.log("有足够film");
|
||||
botoom.getChildByName("yes").getComponent(cc.Label).string = film.toString();
|
||||
botoom.getChildByName("yes").getComponent(cc.Label).string = this.film.toString();
|
||||
}
|
||||
else {
|
||||
console.log("没有足够film");
|
||||
botoom.getChildByName("no").active = true;
|
||||
botoom.getChildByName("no").getComponent(cc.Label).string = film.toString();
|
||||
botoom.getChildByName("no").getComponent(cc.Label).string = this.film.toString();
|
||||
}
|
||||
console.log("拥有film", film);
|
||||
console.log("拥有film", this.film);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -73,6 +81,7 @@ export default class GachaManager extends cc.Component {
|
|||
if (this.own > film.length)
|
||||
this.own = film.length - 1;
|
||||
let count = film[this.own];
|
||||
console.log("抽卡所需film", count);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
|
@ -88,21 +97,25 @@ export default class GachaManager extends cc.Component {
|
|||
}
|
||||
|
||||
playGacha() {
|
||||
if (this.isDrawing) {
|
||||
return;
|
||||
}
|
||||
if (this.own >= 8) {
|
||||
MiniGameSdk.API.showToast("已拥有当期所有头像");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
let cost = this.getCostFilm();
|
||||
if (cc.fx.GameConfig.GM_INFO.film < cost) {
|
||||
MiniGameSdk.API.showToast("代币不足,闯关获取更多代币!");
|
||||
return;
|
||||
}
|
||||
console.log("抽卡所需film", cost, "当前页面film", this.film);
|
||||
}
|
||||
|
||||
// 余额和拥有头像最终以服务端为准,避免本地缓存过期误拦截。
|
||||
this.isDrawing = true;
|
||||
this.openLoad();
|
||||
Utils.getGacha(res => {
|
||||
console.log("抽卡结果", res);
|
||||
this.isDrawing = false;
|
||||
this.closeLoad();
|
||||
if (res.code == 1) {
|
||||
|
||||
console.log("抽卡成功");
|
||||
|
|
@ -121,7 +134,10 @@ export default class GachaManager extends cc.Component {
|
|||
});
|
||||
}
|
||||
else if (res.code == 0) {
|
||||
MiniGameSdk.API.showToast(res.msg);
|
||||
if (res.data && res.data.film !== undefined) {
|
||||
this.init(this.avatarData, res.data.film);
|
||||
}
|
||||
MiniGameSdk.API.showToast(res.msg || "代币不足,闯关获取更多代币!");
|
||||
cc.fx.GameTool.shushu_Track("avatar_gacha", {
|
||||
pool_id: "spring",
|
||||
pull_count: (this.own + 1),
|
||||
|
|
@ -142,7 +158,6 @@ export default class GachaManager extends cc.Component {
|
|||
result: "",
|
||||
});
|
||||
}
|
||||
this.closeLoad();
|
||||
});
|
||||
// let cost = this.getCostFilm();
|
||||
// if (cc.fx.GameConfig.GM_INFO.film >= cost) {
|
||||
|
|
|
|||
|
|
@ -68,12 +68,12 @@ export default async function (ctx: FunctionContext) {
|
|||
// 根据数量获取对应的消耗,数量超过7时取最后一个(120)
|
||||
let filmCost = filmConsumeTable[Math.min(count, 7)];
|
||||
|
||||
// 执行消耗
|
||||
film -= filmCost;
|
||||
|
||||
if (film < 0) {
|
||||
return { code: 0, data: null, msg: "代币不足" }
|
||||
film = Number(film) || 0;
|
||||
if (film < filmCost) {
|
||||
return { code: 0, data: { film: film, cost: filmCost }, msg: "代币不足,闯关获取更多代币!" }
|
||||
}
|
||||
// 检查通过后再扣除,余额始终以服务端数据为准。
|
||||
film -= filmCost;
|
||||
|
||||
let num = Math.floor(Math.random() * total);
|
||||
let list = [];
|
||||
|
|
@ -109,4 +109,3 @@ export default async function (ctx: FunctionContext) {
|
|||
await db.collection(dbname).where({ _id: uid }).update({ headArr: headArr, film: film });
|
||||
return { code: 1, data: { headArr: headArr, reward: list[num2], film: film }, msg: "成功" };
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,10 +89,10 @@ export default async function (ctx: FunctionContext) {
|
|||
// console.log(oldlevelAmount);
|
||||
// console.error("----------------------------------");
|
||||
let ret = await db.collection(dbname).where({ _id: uid }).update({ address: address, film: film, careerAmount: careerAmount, levelTJ: levelTJ, levelAmount: levelAmount, addLevel: add, timestamp: Date.now() });
|
||||
return { code: 1, data: {IP:ip,address:address,rank:rankNum,levelAmount: levelAmount,timestamp: Date.now() }, msg: "用户数据更新成功" }
|
||||
return { code: 1, data: { IP: ip, address: address, rank: rankNum, levelAmount: levelAmount, film: film, timestamp: Date.now() }, msg: "用户数据更新成功" }
|
||||
case 'read':
|
||||
return {
|
||||
code: 1, data: { levelAmount: res1.data?.levelAmount||0, timestamp: res1.data?.timestamp||0 }, msg: "成功"
|
||||
code: 1, data: { levelAmount: res1.data?.levelAmount || 0, film: res1.data?.film ?? res1.data?.levelAmount ?? 0, timestamp: res1.data?.timestamp || 0 }, msg: "成功"
|
||||
}
|
||||
default:
|
||||
return {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user