兑换码功能

This commit is contained in:
huanghaipeng 2025-12-23 16:57:46 +08:00
parent 9fe73bcce6
commit b80d12a4a4
18 changed files with 3875 additions and 1571 deletions

File diff suppressed because it is too large Load Diff

View File

@ -48,6 +48,7 @@ export default class JiaZai extends cc.Component {
private static cachedPassCheckPrefab: cc.Prefab | null = null; private static cachedPassCheckPrefab: cc.Prefab | null = null;
private passCheckNode: cc.Node | null = null; private passCheckNode: cc.Node | null = null;
@property(cc.EditBox) @property(cc.EditBox)
custom: cc.EditBox = null; custom: cc.EditBox = null;
@ -83,6 +84,9 @@ export default class JiaZai extends cc.Component {
private heathScheduleCallback: Function = null; private heathScheduleCallback: Function = null;
@property(cc.Node) @property(cc.Node)
setUi: cc.Node = null; setUi: cc.Node = null;
@property(cc.Prefab)
reddemCodeNode: cc.Prefab = null;
scheduleCallback2: any; scheduleCallback2: any;
scheduleCallback3: any; scheduleCallback3: any;
private isFirstLaunch: boolean = true; // 添加首次启动标志 private isFirstLaunch: boolean = true; // 添加首次启动标志
@ -434,18 +438,18 @@ export default class JiaZai extends cc.Component {
let xinshouNode = this.Stamina.parent.getChildByName("xinshou"); let xinshouNode = this.Stamina.parent.getChildByName("xinshou");
if (xinshouNode) { if (xinshouNode) {
xinshouNode.y = -815; xinshouNode.y = -994;
// 强制刷新节点的变换 // 强制刷新节点的变换
xinshouNode.setPosition(xinshouNode.x, -815); xinshouNode.setPosition(xinshouNode.x, -994);
} }
} else { } else {
let top = this.node.getChildByName("Load").getChildByName("Top"); let top = this.node.getChildByName("Load").getChildByName("Top");
// top.getChildByName("passBtn").active = false; // top.getChildByName("passBtn").active = false;
let xinshouNode = this.Stamina.parent.getChildByName("xinshou"); let xinshouNode = this.Stamina.parent.getChildByName("xinshou");
if (xinshouNode) { if (xinshouNode) {
xinshouNode.y = -627; xinshouNode.y = -806;
// 强制刷新节点的变换 // 强制刷新节点的变换
xinshouNode.setPosition(xinshouNode.x, -627); xinshouNode.setPosition(xinshouNode.x, -806);
} }
}; };
if (cc.fx.GameConfig.GM_INFO.level >= 17) { if (cc.fx.GameConfig.GM_INFO.level >= 17) {
@ -2780,7 +2784,11 @@ export default class JiaZai extends cc.Component {
// 2. 指定动画时间回到顶部 // 2. 指定动画时间回到顶部
careerList.backTop(time); // 0.5秒动画 careerList.backTop(time); // 0.5秒动画
} }
openRedeemCode() {
let reddemCodeNode = cc.instantiate(this.reddemCodeNode);
this.node.addChild(reddemCodeNode);
}
update(dt) { update(dt) {
if (this.newbieGift && this.monthlyCardNode) { if (this.newbieGift && this.monthlyCardNode) {
if (this.monthlyCardNode.active == true) { if (this.monthlyCardNode.active == true) {

106
assets/Script/RedeemCode.ts Normal file
View File

@ -0,0 +1,106 @@
import Utils from "./module/Pay/Utils";
import { MiniGameSdk } from "./Sdk/MiniGameSdk";
const { ccclass, property } = cc._decorator;
@ccclass
export default class RedeemCode extends cc.Component {
@property(cc.Button)
onBtn: cc.Button = null;
@property(cc.EditBox)
editBoxCode: cc.EditBox = null;
start() {
}
onConfirm() {
const account = this.editBoxCode ? this.editBoxCode.string.trim() : "";
// 判断用户输入的值是否为空
if (!account) {
console.log("兑换码不能为空");
return;
}
// 如果不为空,发送给服务器
console.log("发送兑换码到服务器:", account);
// let res = { code: 1, data: { reward: { 1001: 1000, 2001: 1, 2002: 1, 2003: 1 } } }
Utils.getRedeemInfo((res) => {
if (res.code === 1) {
let rewards = res.data.reward;
const rewardData = [];
const canvasTemp = cc.find("Canvas");
let JiaZai = null;
if (canvasTemp) {
JiaZai = canvasTemp.getComponent("JiaZai");
}
for (let itemId in rewards) {
let itemNum = rewards[itemId];
cc.fx.GameTool.getPassCheckPorp(parseInt(itemId), itemNum, false, true);
let typeStr = '';
let finalItemNum = itemNum;
switch (parseInt(itemId)) {
case 1001: // 金币
typeStr = 'coin';
break;
case 2001: // 冰冻道具
typeStr = 'freeze';
break;
case 2002: // 锤子道具
typeStr = 'hammer';
break;
case 2003: // 魔棒道具
typeStr = 'magic';
break;
case 3001: // 无限体力 900秒
typeStr = 'infinite_health';
finalItemNum = 900;
break;
case 3002: // 无限体力 1800秒
typeStr = 'infinite_health';
finalItemNum = 1800;
break;
case 3003: // 无限体力 3600秒
typeStr = 'infinite_health';
finalItemNum = 3600;
break;
default:
typeStr = 'infinite_health'; // 默认类型
finalItemNum = itemNum * 900;
break;
}
// let itemIdType = this.getItemIdType(itemId, itemNum);
rewardData.push({ type: typeStr, count: finalItemNum });
}
// 领取物品弹窗
console.log("rewardData", rewardData)
if (JiaZai && rewardData.length > 0) {
JiaZai.openRewardWindow(rewardData);
}
JiaZai.updateCoin();
const data = {
code: account,
}
cc.fx.GameTool.shushu_Track("redeem", data);
setTimeout(() => {
this.onClose();
}, 1000);
} else {
MiniGameSdk.API.showToast(res.msg);
}
}, account)
}
onClose() {
this.node.destroy();
}
// update (dt) {}
}

View File

@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "2afca3a6-10f3-4ee2-9c17-4bdbcc2dbf54",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@ -1492,5 +1492,25 @@ export default class Utils {
}) })
} }
} }
static getRedeemInfo(callBack, cdk) {
//@ts-ignore
if (typeof wx !== 'undefined' && wx !== null) {
let uid = cc.fx.StorageMessage.getStorage("uid");
//旧的读取数据设置数据方法,以强联网为主
if (uid != undefined && uid != "" && uid != null) {
cc.fx.GameConfig.GM_INFO.uid = uid;
}
let setData = {
uid: cc.fx.GameConfig.GM_INFO.uid,
cdk: cdk,
}
Utils.POST("redeem", setData, res => {
if (res.code === 1) {
if (callBack) callBack(res);
} else {
if (callBack) callBack(res);
}
});
}
}
} }

View File

@ -1159,7 +1159,7 @@ var GameTool = {
MiniGameSdk.API.shushu_SetSuperProperties(null, true); MiniGameSdk.API.shushu_SetSuperProperties(null, true);
}, },
getPassCheckPorp(porpId, num, compensate) { getPassCheckPorp(porpId, num, compensate, getType?) {
console.log("getPassCheckPorp道具:", typeof porpId, "數量:", typeof num) console.log("getPassCheckPorp道具:", typeof porpId, "數量:", typeof num)
let propNumber = 0; let propNumber = 0;
switch (porpId) { switch (porpId) {
@ -1197,8 +1197,12 @@ var GameTool = {
break; break;
} }
let isGetType = "battlepass";
if (getType) {
isGetType = "redeem_code";
}
const dataTemp = { const dataTemp = {
change_reason: "battlepass", change_reason: isGetType,
id: porpId, id: porpId,
num: num, num: num,
compensate: compensate compensate: compensate
@ -1362,6 +1366,11 @@ var GameTool = {
} }
console.log("位置信息___________location", eventData); console.log("位置信息___________location", eventData);
break; break;
case "redeem":
eventData = {
code: data.code,
}
break;
} }
if (name == "stage_help") { if (name == "stage_help") {
console.log("准备上报完成", data); console.log("准备上报完成", data);

BIN
assets/UI/UI/pop/dhm_bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

View File

@ -0,0 +1,38 @@
{
"ver": "2.3.7",
"uuid": "86c8803d-77fb-4ba1-9042-cc197202fe96",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 1000,
"height": 591,
"platformSettings": {},
"subMetas": {
"dhm_bg": {
"ver": "1.0.6",
"uuid": "21679da3-bae7-43e1-8e0a-66c35b87b0c0",
"importer": "sprite-frame",
"rawTextureUuid": "86c8803d-77fb-4ba1-9042-cc197202fe96",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0.5,
"trimX": 1,
"trimY": 0,
"width": 998,
"height": 590,
"rawWidth": 1000,
"rawHeight": 591,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@ -0,0 +1,38 @@
{
"ver": "2.3.7",
"uuid": "9c5a1f3d-1fad-4b65-bc44-5ef99756cf9e",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 556,
"height": 164,
"platformSettings": {},
"subMetas": {
"dhm_dh_btn": {
"ver": "1.0.6",
"uuid": "d4d237b2-15e7-4e74-bfe9-463edbdef0c3",
"importer": "sprite-frame",
"rawTextureUuid": "9c5a1f3d-1fad-4b65-bc44-5ef99756cf9e",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 556,
"height": 164,
"rawWidth": 556,
"rawHeight": 164,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

BIN
assets/UI/UI/pop/dhm_eb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

View File

@ -0,0 +1,38 @@
{
"ver": "2.3.7",
"uuid": "9d7689a0-5261-43ab-91f8-bf1f48520a39",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 788,
"height": 136,
"platformSettings": {},
"subMetas": {
"dhm_eb": {
"ver": "1.0.6",
"uuid": "d2e3330d-1c9a-48b3-9564-5b9674d50e0c",
"importer": "sprite-frame",
"rawTextureUuid": "9d7689a0-5261-43ab-91f8-bf1f48520a39",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 788,
"height": 136,
"rawWidth": 788,
"rawHeight": 136,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1,38 @@
{
"ver": "2.3.7",
"uuid": "e5fb7612-5bda-4832-8254-7a834cf61e80",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 191,
"height": 65,
"platformSettings": {},
"subMetas": {
"dhm_label": {
"ver": "1.0.6",
"uuid": "4451b1fc-ac66-4870-a67d-47934f3d0eee",
"importer": "sprite-frame",
"rawTextureUuid": "e5fb7612-5bda-4832-8254-7a834cf61e80",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 191,
"height": 65,
"rawWidth": 191,
"rawHeight": 65,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

BIN
assets/UI/UI/redeem_btn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

@ -0,0 +1,38 @@
{
"ver": "2.3.7",
"uuid": "a6f0760e-21c7-4d49-85e1-f470c2a9edc1",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 149,
"height": 155,
"platformSettings": {},
"subMetas": {
"redeem_btn": {
"ver": "1.0.6",
"uuid": "ef951790-b6fb-40d1-a77b-f9f353d8d302",
"importer": "sprite-frame",
"rawTextureUuid": "a6f0760e-21c7-4d49-85e1-f470c2a9edc1",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 149,
"height": 155,
"rawWidth": 149,
"rawHeight": 155,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,9 @@
{
"ver": "1.3.2",
"uuid": "6a50bdb2-898b-4336-856c-4204041bf07f",
"importer": "prefab",
"optimizationPolicy": "AUTO",
"asyncLoadAssets": false,
"readonly": false,
"subMetas": {}
}