增加 无限体力部分功能

This commit is contained in:
YZ\249929363 2025-07-18 16:43:00 +08:00
parent 3faeb90acd
commit a8250acd35
5 changed files with 249 additions and 173 deletions

View File

@ -1728,7 +1728,7 @@
"__id__": 28
},
"_children": [],
"_active": true,
"_active": false,
"_components": [
{
"__id__": 36
@ -1889,7 +1889,7 @@
}
],
"_prefab": null,
"_opacity": 255,
"_opacity": 0,
"_color": {
"__type__": "cc.Color",
"r": 109,
@ -2136,7 +2136,7 @@
"__id__": 40
},
"_children": [],
"_active": false,
"_active": true,
"_components": [
{
"__id__": 44
@ -2146,9 +2146,9 @@
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 235,
"b": 10,
"r": 0,
"g": 126,
"b": 81,
"a": 255
},
"_contentSize": {
@ -2205,8 +2205,8 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_string": "00:00",
"_N$string": "00:00",
"_string": "",
"_N$string": "",
"_fontSize": 40,
"_lineHeight": 40,
"_enableWrapText": true,

View File

@ -62,6 +62,7 @@ export default class JiaZai extends cc.Component {
private heathScheduleCallback: Function = null;
@property(cc.Node)
setUi: cc.Node = null;
scheduleCallback2: any;
// LIFE-CYCLE CALLBACKS:
@ -101,16 +102,6 @@ export default class JiaZai extends cc.Component {
return;
}
JiaZai.cachedRewardPrefab = prefab;
// let data = [
// { type: "coin", count: 125294 },
// { type: "coin", count: 7498 },
// { type: "freeze", count: 2 },
// { type: "hammer", count: 2 },
// { type: "magic", count: 2 },
// { type: "infinite_health", count: 1800 * 4 },
// ]
// this.openRewardWindow(data);
this.getOrder();
});
});
@ -158,21 +149,7 @@ export default class JiaZai extends cc.Component {
// //console.log("已经进入Home界面");
// //console.log("金币",cc.fx.GameConfig.GM_INFO.coin);
// //console.log("关卡",cc.fx.GameConfig.GM_INFO.level+1);
if (cc.fx.GameConfig.GM_INFO.userPowerTime != 0) {
let nowTime = Math.floor(Date.now() / 1000);
if (cc.fx.GameConfig.GM_INFO.userPowerTime > nowTime) {
console.log("还有无限体力时间_____________", (cc.fx.GameConfig.GM_INFO.userPowerTime - nowTime));
this.Stamina.getChildByName("skyLine").active = true;
}
else {
this.Stamina.getChildByName("skyLine").active = false;
console.log("无限体力时间已过期");
}
}
else {
this.Stamina.getChildByName("skyLine").active = false;
console.log("没有无限体力时间");
}
this.updatePower();
cc.fx.GameTool.getHealth(null);
// cc.fx.GameConfig.LEVEL_INFO_init(false,0);
setTimeout(() => {
@ -275,10 +252,9 @@ export default class JiaZai extends cc.Component {
this.heathScheduleCallback = null;
}
}
//开始倒计时
//开始倒计时 恢复体力
startTimeCutDown() {
this.scheduleCallback = function () {
if (this.pause) return;
if (cc.fx.GameConfig.GM_INFO.min_Time <= 0) {
this.stopTimeCutDown();
var timeTemp = cc.fx.GameTool.getTimeMargin(cc.fx.GameConfig.GM_INFO.min_Time);
@ -306,13 +282,55 @@ export default class JiaZai extends cc.Component {
}.bind(this);
this.schedule(this.scheduleCallback, 1);
}
// 停止倒计时
// 停止倒计时 恢复体力
stopTimeCutDown() {
if (this.scheduleCallback) {
this.unschedule(this.scheduleCallback);
}
}
startPowerTime() {
this.scheduleCallback2 = function () {
let nowTime = Math.floor(Date.now() / 1000);
if (cc.fx.GameConfig.GM_INFO.userPowerTime < nowTime) {
this.Stamina.getChildByName("skyLine").active = false;
this.Stamina.getChildByName("time").opacity = 255;
this.Stamina.getChildByName("man").active = true;
this.stopPowerTime();
return;
}
else {
this.Stamina.getChildByName("skyLine").active = true;
this.Stamina.getChildByName("time").opacity = 0;
this.Stamina.getChildByName("man").active = false;
}
let time = cc.fx.GameConfig.GM_INFO.userPowerTime - nowTime;
if (time <= 0) {
time = 0;
this.stopTimeCutDown();
var timeTemp = cc.fx.GameTool.getTimeMargin2(time);
// 同步显示
if (this.Stamina && this.Stamina.getChildByName("skyLine").getChildByName("skyTime")) {
this.Stamina.getChildByName("skyLine").getChildByName("skyTime").getComponent(cc.Label).string = timeTemp;
}
}
else {
var timeTemp = cc.fx.GameTool.getTimeMargin2(time);
// 同步显示
if (this.Stamina && this.Stamina.getChildByName("skyLine").getChildByName("skyTime")) {
this.Stamina.getChildByName("skyLine").getChildByName("skyTime").getComponent(cc.Label).string = timeTemp;
}
}
}.bind(this);
this.schedule(this.scheduleCallback2, 1);
}
stopPowerTime() {
if (this.scheduleCallback2) {
this.unschedule(this.scheduleCallback2);
}
}
uploadToCloud(level: number) {
if (typeof wx !== 'undefined') {
//@ts-ignore
@ -350,7 +368,7 @@ export default class JiaZai extends cc.Component {
startGame() {
cc.fx.AudioManager._instance.playEffect("anniu_Big", null);
if (cc.fx.GameConfig.GM_INFO.hp < 1) {
if (cc.fx.GameConfig.GM_INFO.hp < 1 && cc.fx.GameConfig.GM_INFO.userPowerTime == 0) {
MiniGameSdk.API.showToast("体力值不足");
setTimeout(() => {
this.openHeath();
@ -435,6 +453,7 @@ export default class JiaZai extends cc.Component {
this.node.addChild(this.RewardNode);
this.RewardNode.getComponent("RewardWindow").init(data);
}
this.updatePower();
}
// 关闭商店
@ -607,5 +626,30 @@ export default class JiaZai extends cc.Component {
closeLoad() {
this.node.getChildByName("Loading").active = false;
}
updatePower() {
if (cc.fx.GameConfig.GM_INFO.userPowerTime != 0) {
let nowTime = Math.floor(Date.now() / 1000);
if (cc.fx.GameConfig.GM_INFO.userPowerTime > nowTime) {
this.startPowerTime();
console.log("还有无限体力时间_____________", (cc.fx.GameConfig.GM_INFO.userPowerTime - nowTime));
this.Stamina.getChildByName("skyLine").active = true;
this.Stamina.getChildByName("time").opacity = 0;
this.Stamina.getChildByName("man").active = false;
}
else {
this.Stamina.getChildByName("skyLine").active = false;
console.log("无限体力时间已过期");
this.Stamina.getChildByName("time").opacity = 255;
this.Stamina.getChildByName("man").active = true;
}
}
else {
this.Stamina.getChildByName("skyLine").active = false;
this.Stamina.getChildByName("time").opacity = 255;
this.Stamina.getChildByName("man").active = true;
console.log("没有无限体力时间");
}
}
// update (dt) {}
}

View File

@ -1908,9 +1908,9 @@ export default class MapConroler extends cc.Component {
setTimeout(() => {
this.setPropNum();
// this.iceLabel.string = cc.fx.GameConfig.GM_INFO.freezeAmount.toString();
MiniGameSdk.API.showToast("购买冻结时间成功");
// MiniGameSdk.API.showToast("购买冻结时间成功");
let data = [
{ "freeze": 3 },
{ type: "freeze", count: 3 },
]
MapConroler._instance.SceneManager.openRewardWindow(data);
}, 200);
@ -1925,11 +1925,11 @@ export default class MapConroler extends cc.Component {
cc.fx.StorageMessage.setStorage("prop", propInfo);
this.node.parent.parent.parent.getComponent("SceneManager").closePropBuy();
setTimeout(() => {
MiniGameSdk.API.showToast("购买魔法棒成功");
// MiniGameSdk.API.showToast("购买魔法棒成功");
this.setPropNum();
// this.magicLabel.string = cc.fx.GameConfig.GM_INFO.magicAmount.toString();
let data = [
{ "magic": 3 },
{ type: "magic", count: 3 },
]
MapConroler._instance.SceneManager.openRewardWindow(data);
}, 200);
@ -1945,9 +1945,9 @@ export default class MapConroler extends cc.Component {
setTimeout(() => {
this.setPropNum();
// this.hammerLabel.string = cc.fx.GameConfig.GM_INFO.hammerAmount.toString();
MiniGameSdk.API.showToast("购买锤子成功");
// MiniGameSdk.API.showToast("购买锤子成功");
let data = [
{ "hammer": 1 },
{ type: "hammer", count: 1 },
]
MapConroler._instance.SceneManager.openRewardWindow(data);
}, 200);

View File

@ -309,6 +309,27 @@ var GameTool = {
return m + ':' + miao
},
//输入秒,返回需要展示时间格式
getTimeMargin2: (second) => {
// 计算总秒数
let total = Math.floor(second);
// 计算小时数
const hours = Math.floor(total / 3600);
total %= 3600;
// 计算分钟数
const minutes = Math.floor(total / 60);
// 计算剩余秒数
const seconds = total % 60;
// 将小时、分钟和秒转换为两位数的字符串
const hh = String(hours).padStart(2, '0');
const mm = String(minutes).padStart(2, '0');
const ss = String(seconds).padStart(2, '0');
// 若小时数大于 0返回包含小时的完整格式否则只返回分和秒
return hours > 0 ? `${hh}:${mm}:${ss}` : `${mm}:${ss}`;
},
//输入秒,返回需要展示时间格式
getTimeShenNong: (second) => {
second = parseInt(second / 1000 + "");
@ -912,7 +933,7 @@ var GameTool = {
cc.fx.GameTool.changeCoin(1200);
coin = 1200;
price = 600;
MiniGameSdk.API.showToast("充值成功获得1200金币");
// MiniGameSdk.API.showToast("充值成功获得1200金币");
rewardData = [
{ type: "coin", count: coin },
]
@ -921,7 +942,7 @@ var GameTool = {
cc.fx.GameTool.changeCoin(8000);
coin = 8000;
price = 3600;
MiniGameSdk.API.showToast("充值成功获得8000金币");
// MiniGameSdk.API.showToast("充值成功获得8000金币");
rewardData = [
{ type: "coin", count: coin },
]
@ -930,7 +951,7 @@ var GameTool = {
cc.fx.GameTool.changeCoin(16000);
coin = 16000;
price = 6800;
MiniGameSdk.API.showToast("充值成功获得16000金币");
// MiniGameSdk.API.showToast("充值成功获得16000金币");
this.rewardData = [
{ type: "coin", count: coin },
]
@ -939,7 +960,7 @@ var GameTool = {
cc.fx.GameTool.changeCoin(32000);
coin = 32000;
price = 12800;
MiniGameSdk.API.showToast("充值成功获得32000金币");
// MiniGameSdk.API.showToast("充值成功获得32000金币");
rewardData = [
{ type: "coin", count: coin },
]
@ -948,7 +969,7 @@ var GameTool = {
cc.fx.GameTool.changeCoin(100000);
coin = 100000;
price = 32800;
MiniGameSdk.API.showToast("充值成功获得100000金币");
// MiniGameSdk.API.showToast("充值成功获得100000金币");
rewardData = [
{ type: "coin", count: coin },
]
@ -957,7 +978,7 @@ var GameTool = {
cc.fx.GameTool.changeCoin(240000);
coin = 240000;
price = 64800;
MiniGameSdk.API.showToast("充值成功获得240000金币");
// MiniGameSdk.API.showToast("充值成功获得240000金币");
rewardData = [
{ type: "coin", count: coin },
]
@ -966,8 +987,8 @@ var GameTool = {
cc.fx.GameTool.changeCoin(5000);
coin = 5000;
price = 1800;
this.setUserPowerTime(1800);
MiniGameSdk.API.showToast("获得无限体力小组合包");
this.setUserPowerTime(60);
// MiniGameSdk.API.showToast("获得无限体力小组合包");
rewardData = [
{ type: "coin", count: coin },
{ type: "infinite_health", count: 1800 },
@ -985,7 +1006,7 @@ var GameTool = {
}
this.getShopProp(propData, null);
this.setUserPowerTime(3600);
MiniGameSdk.API.showToast("获得无限体力大组合包");
// MiniGameSdk.API.showToast("获得无限体力大组合包");
rewardData = [
{ type: "coin", count: coin },
{ type: "freeze", count: 2 },
@ -1006,7 +1027,7 @@ var GameTool = {
}
this.getShopProp(propData2, null);
this.setUserPowerTime(7200);
MiniGameSdk.API.showToast("获得无限体力超组合包");
// MiniGameSdk.API.showToast("获得无限体力超组合包");
rewardData = [
{ type: "coin", count: coin },
{ type: "freeze", count: 6 },
@ -1020,6 +1041,16 @@ var GameTool = {
if (MapConroler._instance != null)
MapConroler._instance.SceneManager.openRewardWindow(rewardData);
else {
const canvasTemp = cc.find("Canvas"); // 假设 Canvas 节点
if (canvasTemp) {
const JiaZai = canvasTemp.getComponent("JiaZai");
if (JiaZai) {
JiaZai.openRewardWindow(rewardData);
}
}
}
const dataTemp = {
change_reason: "shop",

View File

@ -384,127 +384,128 @@ export default class NewClass extends cc.Component {
type: systemType,
}
cc.fx.GameTool.shushu_Track("init_order", data);
this.openLoad();
//console.log("7.14_____________________", "调用充值接口");
Utils.buyProp(id, count, price, (res) => {
//console.log("获得充值结果", res);
if (res == null) {
MiniGameSdk.API.showToast("充值失败");
this.btn_Touch = true;
const dataFail = {
outTradeNo: Utils.outTradeNo,
price: price,
payment_name: productId,
payment_num: 1,
type: systemType,
fail_reason: "网络异常,没有拉起支付",
}
cc.fx.GameTool.shushu_Track("payment_fail", dataFail);
this.closeLoad();
return;
}
else if (res.err) {
MiniGameSdk.API.showToast("充值失败");
//console.log(res);
this.btn_Touch = true;
let name = "支付拉起失败";
if (res.errCode == -2) {
name = "用户取消充值";
}
const dataFail = {
outTradeNo: Utils.outTradeNo,
price: price,
payment_name: productId,
payment_num: 1,
type: systemType,
fail_reason: name,
}
cc.fx.GameTool.shushu_Track("payment_fail", dataFail);
this.closeLoad();
return;
}
else {
Utils.getPayInfo((data) => {
//console.log("7.14_______________充值成功,准备轮训");
//console.log("获得轮训结果:", data);
this.closeLoad();
if (data.data.pay_state == 1) {
this.btn_Touch = true;
MiniGameSdk.API.showToast("取消充值");
const dataFail2 = {
outTradeNo: Utils.outTradeNo,
price: price,
payment_name: productId,
payment_num: 1,
type: systemType,
fail_reason: "用户取消支付",
}
cc.fx.GameTool.shushu_Track("payment_fail", dataFail2);
}
else if (data.data.pay_state == 2) {
this.btn_Touch = true;
const dataSuccess = {
outTradeNo: Utils.outTradeNo,
price: price,
payment_name: productId,
payment_num: 1,
type: systemType,
}
cc.fx.GameTool.shushu_Track("payment", dataSuccess);
let name = "购买金币道具:" + productId;
MiniGameSdk.API.yinli_Pay(price, Utils.outTradeNo, name)
//console.log("7.14_______________充值成功,轮训成功,准备发货");
Utils.setPayInfo(
(res) => {
//console.log("设置轮训结果:", res);
if (res.code === 1) {
//console.log("7.14_________正式发货");
MiniGameSdk.API.showToast("充值成功");
cc.fx.GameTool.shopBuy(productId);
//console.log("充值成功获得金币");
}
else {
MiniGameSdk.API.showToast("网络异常,充值奖励将在登录后再次发放");
const dataFail4 = {
outTradeNo: Utils.outTradeNo,
price: price,
payment_name: productId,
payment_num: 1,
type: systemType,
fail_reason: "成功付款,但是发货时请求服务器失败,充值成功未发货",
}
cc.fx.GameTool.shushu_Track("payment_fail", dataFail4);
}
NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true);
if (this.node.parent.getComponent("JiaZai"))
this.node.parent.getComponent("JiaZai").updateCoin();
else if (this.node.parent.getComponent("SceneManager")) {
this.node.parent.getComponent("SceneManager").updateCoin();
}
}, null)
}
else {
NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true);
const dataFail3 = {
outTradeNo: Utils.outTradeNo,
price: price,
payment_name: productId,
payment_num: 1,
type: systemType,
fail_reason: "拉起支付后,付款时网络异常付款失败",
}
cc.fx.GameTool.shushu_Track("payment_fail", dataFail3);
this.btn_Touch = true;
if (this.node.parent.getComponent("JiaZai"))
this.node.parent.getComponent("JiaZai").updateCoin();
else if (this.node.parent.getComponent("SceneManager")) {
this.node.parent.getComponent("SceneManager").updateCoin();
}
}
})
}
});
// this.openLoad();
//console.log("7.14_____________________", "调用充值接口");
// Utils.buyProp(id, count, price, (res) => {
// //console.log("获得充值结果", res);
// if (res == null) {
// MiniGameSdk.API.showToast("充值失败");
// this.btn_Touch = true;
// const dataFail = {
// outTradeNo: Utils.outTradeNo,
// price: price,
// payment_name: productId,
// payment_num: 1,
// type: systemType,
// fail_reason: "网络异常,没有拉起支付",
// }
// cc.fx.GameTool.shushu_Track("payment_fail", dataFail);
// this.closeLoad();
// return;
// }
// else if (res.err) {
// MiniGameSdk.API.showToast("充值失败");
// //console.log(res);
// this.btn_Touch = true;
// let name = "支付拉起失败";
// if (res.errCode == -2) {
// name = "用户取消充值";
// }
// const dataFail = {
// outTradeNo: Utils.outTradeNo,
// price: price,
// payment_name: productId,
// payment_num: 1,
// type: systemType,
// fail_reason: name,
// }
// cc.fx.GameTool.shushu_Track("payment_fail", dataFail);
// this.closeLoad();
// return;
// }
// else {
// Utils.getPayInfo((data) => {
// //console.log("7.14_______________充值成功,准备轮训");
// //console.log("获得轮训结果:", data);
// this.closeLoad();
// if (data.data.pay_state == 1) {
// this.btn_Touch = true;
// MiniGameSdk.API.showToast("取消充值");
// const dataFail2 = {
// outTradeNo: Utils.outTradeNo,
// price: price,
// payment_name: productId,
// payment_num: 1,
// type: systemType,
// fail_reason: "用户取消支付",
// }
// cc.fx.GameTool.shushu_Track("payment_fail", dataFail2);
// }
// else if (data.data.pay_state == 2) {
// this.btn_Touch = true;
// const dataSuccess = {
// outTradeNo: Utils.outTradeNo,
// price: price,
// payment_name: productId,
// payment_num: 1,
// type: systemType,
// }
// cc.fx.GameTool.shushu_Track("payment", dataSuccess);
// let name = "购买金币道具:" + productId;
// MiniGameSdk.API.yinli_Pay(price, Utils.outTradeNo, name)
// //console.log("7.14_______________充值成功,轮训成功,准备发货");
// Utils.setPayInfo(
// (res) => {
// //console.log("设置轮训结果:", res);
// if (res.code === 1) {
// //console.log("7.14_________正式发货");
// MiniGameSdk.API.showToast("充值成功");
// cc.fx.GameTool.shopBuy(productId);
// //console.log("充值成功获得金币");
// }
// else {
// MiniGameSdk.API.showToast("网络异常,充值奖励将在登录后再次发放");
// const dataFail4 = {
// outTradeNo: Utils.outTradeNo,
// price: price,
// payment_name: productId,
// payment_num: 1,
// type: systemType,
// fail_reason: "成功付款,但是发货时请求服务器失败,充值成功未发货",
// }
// cc.fx.GameTool.shushu_Track("payment_fail", dataFail4);
// }
// NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true);
// if (this.node.parent.getComponent("JiaZai"))
// this.node.parent.getComponent("JiaZai").updateCoin();
// else if (this.node.parent.getComponent("SceneManager")) {
// this.node.parent.getComponent("SceneManager").updateCoin();
// }
// }, null)
// }
// else {
// NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true);
// const dataFail3 = {
// outTradeNo: Utils.outTradeNo,
// price: price,
// payment_name: productId,
// payment_num: 1,
// type: systemType,
// fail_reason: "拉起支付后,付款时网络异常付款失败",
// }
// cc.fx.GameTool.shushu_Track("payment_fail", dataFail3);
// this.btn_Touch = true;
// if (this.node.parent.getComponent("JiaZai"))
// this.node.parent.getComponent("JiaZai").updateCoin();
// else if (this.node.parent.getComponent("SceneManager")) {
// this.node.parent.getComponent("SceneManager").updateCoin();
// }
// }
// })
// }
// });
}
}