增加公共变量

This commit is contained in:
YZ\249929363 2025-07-18 15:59:08 +08:00
parent 00ec26b4d2
commit 3faeb90acd
8 changed files with 301 additions and 166 deletions

View File

@ -162,12 +162,15 @@ export default class JiaZai extends cc.Component {
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("没有无限体力时间");
}
cc.fx.GameTool.getHealth(null);
@ -558,6 +561,9 @@ export default class JiaZai extends cc.Component {
else if (order.itemid == "gold_4") { coinTemp = 32000; }
else if (order.itemid == "gold_5") { coinTemp = 100000; }
else if (order.itemid == "gold_6") { coinTemp = 240000; }
else if (order.itemid == "unlimited_health_bundle_1") { coinTemp = 5000; }
else if (order.itemid == "unlimited_health_bundle_2") { coinTemp = 12000; }
else if (order.itemid == "unlimited_health_bundle_3") { coinTemp = 30000; }
let title = "充值补发奖励金币:" + coinTemp;
MiniGameSdk.API.showToast(title);
cc.fx.GameTool.shopBuy(productId);

View File

@ -125,6 +125,8 @@ export default class MapConroler extends cc.Component {
topDoors: any; //上门
bottomDoors: any; //下门
leftDoors: any;
powerState: boolean = false; //
SceneManager: any;
// mapInfo: number[][] = [];
@ -157,6 +159,7 @@ export default class MapConroler extends cc.Component {
this.reviewState = false;
this.homeCanTouch = true;
this.againCanTouch = true;
this.powerState = false;
this.new_mode = 0;
this.count_Time = 0;
this.add_Time = 0;
@ -168,6 +171,18 @@ export default class MapConroler extends cc.Component {
this.setPropNum();
// cc.game.addPersistRootNode(this.node);
MapConroler._instance = this;
const canvasTemp = cc.find("Canvas"); // 假设 Canvas 节点
if (canvasTemp) {
const SceneManager = canvasTemp.getComponent("SceneManager");
if (SceneManager) {
MapConroler._instance.SceneManager = SceneManager
} else {
console.log("SceneManager 组件未找到");
}
} else {
console.log("SceneManager 节点未找到");
}
}
start() {
@ -278,8 +293,12 @@ export default class MapConroler extends cc.Component {
startUpdate() {
if (this.gameStart == false) {
this.gameStart = true;
cc.fx.GameTool.setUserHealth(-1, (data) => {
})
let power = cc.fx.GameTool.getUserPowerTime();
if (!power) {
cc.fx.GameTool.setUserHealth(-1, (data) => {
})
}
this.powerState = power;
this.count_Time = Date.now();
//发送数数事件——进入关卡
console.log("准备进入下一关,发送下一关进入");
@ -1423,8 +1442,11 @@ export default class MapConroler extends cc.Component {
this.gameWin = true;
if (cc.fx.GameConfig.GM_INFO.hp < 5) {
console.log("恢复一点体力", cc.fx.GameConfig.GM_INFO.level);
cc.fx.GameTool.setUserHealth(1, (data) => {
})
if (!this.powerState) {
cc.fx.GameTool.setUserHealth(1, (data) => {
})
}
this.powerState = false;
}
this.stopTimeCutDown();
// console.log("即将上报成功________________________:",this.add_Time);
@ -1616,6 +1638,10 @@ export default class MapConroler extends cc.Component {
homeBtn() {
// alert("游戏失败");
if (this.powerState) {
this.returnHome();
return;
}
cc.fx.AudioManager._instance.playEffect("anniu_Big", null);
if (!this.homeCanTouch) return;
this.homeCanTouch = false;
@ -1632,12 +1658,6 @@ export default class MapConroler extends cc.Component {
result: "fail"
}
cc.fx.GameTool.shushu_Track("finish_stage", data);
// if (this.gameStart == true) {
// cc.fx.GameTool.setUserHealth(-1, (data) => {
// })
// }
// this.node.parent.parent.parent.destroy();
}
uploadToCloud(level: number) {
if (typeof wx !== 'undefined') {
@ -1865,6 +1885,7 @@ export default class MapConroler extends cc.Component {
}
handleBuySuccess(data) {
this.node.parent.parent.parent.getComponent("SceneManager").resetBtn();
this.updateCoin();
this.pause = false;
@ -1888,6 +1909,10 @@ export default class MapConroler extends cc.Component {
this.setPropNum();
// this.iceLabel.string = cc.fx.GameConfig.GM_INFO.freezeAmount.toString();
MiniGameSdk.API.showToast("购买冻结时间成功");
let data = [
{ "freeze": 3 },
]
MapConroler._instance.SceneManager.openRewardWindow(data);
}, 200);
@ -1903,6 +1928,10 @@ export default class MapConroler extends cc.Component {
MiniGameSdk.API.showToast("购买魔法棒成功");
this.setPropNum();
// this.magicLabel.string = cc.fx.GameConfig.GM_INFO.magicAmount.toString();
let data = [
{ "magic": 3 },
]
MapConroler._instance.SceneManager.openRewardWindow(data);
}, 200);
}
@ -1917,6 +1946,10 @@ export default class MapConroler extends cc.Component {
this.setPropNum();
// this.hammerLabel.string = cc.fx.GameConfig.GM_INFO.hammerAmount.toString();
MiniGameSdk.API.showToast("购买锤子成功");
let data = [
{ "hammer": 1 },
]
MapConroler._instance.SceneManager.openRewardWindow(data);
}, 200);
}

View File

@ -14,11 +14,17 @@ const { ccclass, property } = cc._decorator;
@ccclass
export default class SceneManager extends cc.Component {
// 缓存 shop 预制体
private static cachedShopPrefab: cc.Prefab | null = null;
// 缓存 shop 节点
private shopNode: cc.Node | null = null;
// 缓存 reward 预制体
private static cachedRewardPrefab: cc.Prefab | null = null;
// 缓存 reward 奖励窗口 节点
private RewardNode: cc.Node | null = null;
@property(cc.Label)
label: cc.Label = null;
@ -83,6 +89,13 @@ export default class SceneManager extends cc.Component {
}
SceneManager.cachedShopPrefab = prefab;
});
bundle.load('prefab/RewardWindow', cc.Prefab, (err: Error, prefab: cc.Prefab) => {
if (err) {
cc.error(err.message || err);
return;
}
SceneManager.cachedRewardPrefab = prefab;
});
});
}
setTimeout(() => {
@ -192,8 +205,6 @@ export default class SceneManager extends cc.Component {
this.closePause();
if (MapConroler._instance.gameStart == true) {
MiniGameSdk.API.showToast("体力值减少");
// cc.fx.GameTool.setUserHealth(-1, (data) => {
// })
if (MapConroler._instance.count_Time) {
let overTime = Date.now();
let count_Time = overTime - MapConroler._instance.count_Time;
@ -363,6 +374,29 @@ export default class SceneManager extends cc.Component {
this.node.getChildByName("Game").getChildByName("propWindow").active = false;
}
openRewardWindow(data) {
console.log("_____________________打開獎勵弹窗");
if (!SceneManager.cachedRewardPrefab) {
cc.error('Reward prefab is not loaded yet.');
return;
}
if (!this.RewardNode) {
// 第一次使用,创建节点
this.RewardNode = cc.instantiate(SceneManager.cachedRewardPrefab);
this.node.addChild(this.RewardNode);
this.RewardNode.zIndex = 99;
this.RewardNode.getComponent("Reward").init(data);
}
else {
this.RewardNode.destroy();
this.RewardNode = null;
this.RewardNode = cc.instantiate(SceneManager.cachedRewardPrefab);
this.node.addChild(this.RewardNode);
this.RewardNode.zIndex = 99;
this.RewardNode.getComponent("RewardWindow").init(data);
}
}
update(dt) {
}

View File

@ -98,13 +98,15 @@ export class GameConfig {
shushu_DistinctId: string; //数数访客ID
shushu_AccountId: string; //数数账号ID
uid: string; //用户和后端唯一id
userPowerTime: number;
userPowerTime: number; //用户体力恢复时间
freezeFirst: boolean; hammerFirst: boolean; magicAFirst: boolean;
};
//游戏内信息
static get Instance() {
@ -242,6 +244,9 @@ export class GameConfig {
shushu_AccountId: "", //数数账号ID
uid: "", //用户和后端唯一id
userPowerTime: 0, //用户体力恢复时间
freezeFirst: false,
hammerFirst: false,
magicAFirst: false,
};
// this.setCode(this.getKey("scode"));
// this.GM_INFO.level = 0;

View File

@ -1,4 +1,5 @@
import MapConroler from "../../Map";
import Freeze from "../../prop/Freeze";
import SceneManager from "../../SceneManager";
import { MiniGameSdk } from "../../Sdk/MiniGameSdk";
@ -904,49 +905,73 @@ var GameTool = {
let price = 0;
let getCoin = 0;
var rewardData = null;
switch (productId) {
case "gold_1":
cc.fx.GameTool.changeCoin(1200);
coin = 1200;
price = 600;
MiniGameSdk.API.showToast("充值成功获得1200金币");
rewardData = [
{ type: "coin", count: coin },
]
break;
case "gold_2":
cc.fx.GameTool.changeCoin(8000);
coin = 8000;
price = 3600;
MiniGameSdk.API.showToast("充值成功获得8000金币");
rewardData = [
{ type: "coin", count: coin },
]
break;
case "gold_3":
cc.fx.GameTool.changeCoin(16000);
coin = 16000;
price = 6800;
MiniGameSdk.API.showToast("充值成功获得16000金币");
this.rewardData = [
{ type: "coin", count: coin },
]
break;
case "gold_4":
cc.fx.GameTool.changeCoin(32000);
coin = 32000;
price = 12800;
MiniGameSdk.API.showToast("充值成功获得32000金币");
rewardData = [
{ type: "coin", count: coin },
]
break;
case "gold_5":
cc.fx.GameTool.changeCoin(100000);
coin = 100000;
price = 32800;
MiniGameSdk.API.showToast("充值成功获得100000金币");
rewardData = [
{ type: "coin", count: coin },
]
break;
case "gold_6":
cc.fx.GameTool.changeCoin(240000);
coin = 240000;
price = 64800;
MiniGameSdk.API.showToast("充值成功获得240000金币");
rewardData = [
{ type: "coin", count: coin },
]
break;
case "unlimited_health_bundle_1":
cc.fx.GameTool.changeCoin(5000);
coin = 5000;
price = 1800;
this.setUserPowerTime(60);
this.setUserPowerTime(1800);
MiniGameSdk.API.showToast("获得无限体力小组合包");
rewardData = [
{ type: "coin", count: coin },
{ type: "infinite_health", count: 1800 },
]
break;
case "unlimited_health_bundle_2":
cc.fx.GameTool.changeCoin(12000);
@ -959,8 +984,15 @@ var GameTool = {
"price": price
}
this.getShopProp(propData, null);
this.setUserPowerTime(120);
this.setUserPowerTime(3600);
MiniGameSdk.API.showToast("获得无限体力大组合包");
rewardData = [
{ type: "coin", count: coin },
{ type: "freeze", count: 2 },
{ type: "hammer", count: 2 },
{ type: "magic", count: 2 },
{ type: "infinite_health", count: 3600 },
]
break;
case "unlimited_health_bundle_3":
cc.fx.GameTool.changeCoin(30000);
@ -973,10 +1005,22 @@ var GameTool = {
"price": price
}
this.getShopProp(propData2, null);
this.setUserPowerTime(180);
this.setUserPowerTime(7200);
MiniGameSdk.API.showToast("获得无限体力超组合包");
rewardData = [
{ type: "coin", count: coin },
{ type: "freeze", count: 6 },
{ type: "hammer", count: 6 },
{ type: "magic", count: 6 },
{ type: "infinite_health", count: 7200 },
]
break;
}
if (MapConroler._instance != null)
MapConroler._instance.SceneManager.openRewardWindow(rewardData);
const dataTemp = {
change_reason: "shop",
id: "1001",
@ -1243,7 +1287,25 @@ var GameTool = {
console.log("购买无限体力同步:", data);
})
}
},
getUserPowerTime() {
if (cc.fx.GameConfig.GM_INFO.userPowerTime > 0) {
let nowTime = Math.floor(Date.now() / 1000);
if (nowTime >= cc.fx.GameConfig.GM_INFO.userPowerTime) {
cc.fx.GameConfig.GM_INFO.userPowerTime = 0;
cc.fx.StorageMessage.setStorage("userPowerTime", 0);
Utils.setUserPowerTime(0, (data) => {
console.log("购买无限体力同步:", data);
})
return false;
} else {
return true;
}
}
else {
return false;
}
}
};

View File

@ -37,19 +37,19 @@ export default class setUi extends cc.Component {
this.musicState = cc.fx.GameConfig.GM_INFO.musicOpen;
this.effectState = cc.fx.GameConfig.GM_INFO.effectOpen;
this.vibrateState = cc.fx.GameConfig.GM_INFO.vibrateOpen;
if(this.musicState == true) {
if (this.musicState == true) {
this.music.children[0].active = true;
}else {
} else {
this.music.children[1].active = true;
}
if(this.effectState == true) {
if (this.effectState == true) {
this.effect.children[0].active = true;
}else {
} else {
this.effect.children[1].active = true;
}
if(this.vibrateState == true) {
if (this.vibrateState == true) {
this.vibrate.children[0].active = true;
}else {
} else {
this.vibrate.children[1].active = true;
}
}
@ -64,8 +64,8 @@ export default class setUi extends cc.Component {
cc.fx.GameConfig.GM_INFO.musicOpen = this.musicState;
this.setMusicConfig();
this.music.children[0].active = false;
this.music.children[1].active = true;
this.music.children[0].active = false;
this.music.children[1].active = true;
//如果音乐关闭了,则停止音乐
cc.fx.AudioManager._instance.stopMusic();
}
@ -102,7 +102,7 @@ export default class setUi extends cc.Component {
this.setMusicConfig();
this.effect.children[0].active = true;
this.effect.children[1].active = false;
}
}
@ -122,42 +122,42 @@ export default class setUi extends cc.Component {
this.setMusicConfig();
this.vibrate.children[0].active = true;
this.vibrate.children[1].active = false;
}
}
syncToggleState() {
}
//退出游戏
clickExit() {
if(MapConroler._instance.gameStart == true) {
if (MapConroler._instance.gameStart == true && MapConroler._instance.powerState == false) {
this.exit.active = true;
}
else{
else {
MapConroler._instance.returnHome();
}
}
//取消
cancelExit() {
this.exit.active = false;
// 获取场景中的 pause 组件
// const pauseTs = cc.find("Canvas");
// if (pauseTs) {
// const pause = pauseTs.getComponent(SceneManager);
// if (pause) {
// pause.closePause();
// } else {
// console.warn("pause 组件未找到");
// }
// } else {
// console.warn("pause 节点未找到");
// }
// 获取场景中的 pause 组件
// const pauseTs = cc.find("Canvas");
// if (pauseTs) {
// const pause = pauseTs.getComponent(SceneManager);
// if (pause) {
// pause.closePause();
// } else {
// console.warn("pause 组件未找到");
// }
// } else {
// console.warn("pause 节点未找到");
// }
}
//关闭ui
closeUi() {
cc.fx.AudioManager._instance.playEffect("anniu_little", null);
cc.fx.AudioManager._instance.playEffect("anniu_little", null);
this.node.active = false;
}

View File

@ -934,7 +934,7 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-37.185,
-31.807,
-125.613,
0,
0,

View File

@ -376,9 +376,6 @@ export default class NewClass extends cc.Component {
});
}
else {
console.log("上品ID", productId);
MiniGameSdk.API.showToast(productId);
cc.fx.GameTool.shopBuy(productId);
const data = {
outTradeNo: Utils.outTradeNo,
price: price,
@ -389,127 +386,125 @@ export default class NewClass extends cc.Component {
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();
// }
// }
// })
// }
// });
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();
}
}
})
}
});
}
}