增加无限体力,以及laf云数据转移

This commit is contained in:
YZ\249929363 2025-07-17 17:19:34 +08:00
parent dbe89a0eea
commit 001aed347b
8 changed files with 1221 additions and 595 deletions

File diff suppressed because it is too large Load Diff

View File

@ -215,14 +215,16 @@ export default class GameManager extends cc.Component {
MiniGameSdk.API.shushu_Init(); MiniGameSdk.API.shushu_Init();
Utils.getUserInfo((data) => { Utils.getUserInfo((data) => {
console.log("登陆成功", data); console.log("登陆成功", data);
if (data.data._id) {
cc.fx.GameConfig.GM_INFO.uid = data.data._id;
cc.fx.StorageMessage.setStorage("uid", data.data._id);
}
if (data.data.outTradeNo.length > 0) { if (data.data.outTradeNo.length > 0) {
console.log("设置补发数据", data.data.outTradeNo); console.log("设置补发数据", data.data.outTradeNo);
cc.fx.GameConfig.GM_INFO.allOutTradeNo = []; cc.fx.GameConfig.GM_INFO.allOutTradeNo = [];
cc.fx.GameConfig.GM_INFO.allOutTradeNo = data.data.outTradeNo; cc.fx.GameConfig.GM_INFO.allOutTradeNo = data.data.outTradeNo;
console.log("______________________________有未发放奖励", cc.fx.GameConfig.GM_INFO.allOutTradeNo); console.log("______________________________有未发放奖励", cc.fx.GameConfig.GM_INFO.allOutTradeNo);
} }
this.load6 = true;
});
let levelInfo = cc.fx.StorageMessage.getStorage("level"); let levelInfo = cc.fx.StorageMessage.getStorage("level");
//旧的读取数据设置数据方法,以强联网为主 //旧的读取数据设置数据方法,以强联网为主
if (levelInfo == undefined || levelInfo == "" || levelInfo == null) { if (levelInfo == undefined || levelInfo == "" || levelInfo == null) {
@ -232,12 +234,13 @@ export default class GameManager extends cc.Component {
else { else {
this.newReadData(); this.newReadData();
} }
console.log("即将读取体力值"); console.log("即将读取体力值");
cc.fx.GameTool.getHealth((data) => { cc.fx.GameTool.getHealth((data) => {
console.log("体力值完成进入游戏"); console.log("体力值完成进入游戏");
this.load5 = true; this.load5 = true;
}); });
});
} }
else { else {
this.load3 = true; this.load3 = true;
@ -297,6 +300,10 @@ export default class GameManager extends cc.Component {
console.error('读取用户数据失败', err) console.error('读取用户数据失败', err)
} }
}) })
//laf云函数
Utils.getUserData((data) => {
})
} }
else { else {
if (openid) if (openid)
@ -525,6 +532,10 @@ export default class GameManager extends cc.Component {
} }
} }
}) })
//laf云函数
Utils.getUserData((data) => {
})
} }
}); });
console.log("服务器也没有金币信息", cc.fx.GameConfig.GM_INFO.coin); console.log("服务器也没有金币信息", cc.fx.GameConfig.GM_INFO.coin);
@ -664,6 +675,10 @@ export default class GameManager extends cc.Component {
} }
} }
}) })
//laf云函数
Utils.getUserData((data) => {
})
} }
setUserData() { setUserData() {

View File

@ -1127,7 +1127,7 @@ export namespace MiniGameSdk {
}, },
// 根据环境变量设置 debug 模式 // 根据环境变量设置 debug 模式
debug: !isProduction, debug: !isProduction,
enableLog: true enableLog: false
}; };
// 创建 TA 实例 // 创建 TA 实例
API._ta = new ThinkingAnalyticsAPI(config); API._ta = new ThinkingAnalyticsAPI(config);

View File

@ -97,10 +97,12 @@ export class GameConfig {
version: number; //版本号 version: number; //版本号
shushu_DistinctId: string; //数数访客ID shushu_DistinctId: string; //数数访客ID
shushu_AccountId: string; //数数账号ID shushu_AccountId: string; //数数账号ID
uid: string;
}; };
//游戏内信息 //游戏内信息
static get Instance() { static get Instance() {
@ -235,7 +237,8 @@ export class GameConfig {
paid_user: false, //是否是付费用户 paid_user: false, //是否是付费用户
version: 1.4, //版本号 version: 1.4, //版本号
shushu_DistinctId: "", //数数访客ID shushu_DistinctId: "", //数数访客ID
shushu_AccountId: "" //数数账号ID shushu_AccountId: "", //数数账号ID
uid: "", //用户和后端唯一id
}; };
// this.setCode(this.getKey("scode")); // this.setCode(this.getKey("scode"));
// this.GM_INFO.level = 0; // this.GM_INFO.level = 0;

View File

@ -331,6 +331,7 @@ export default class Utils {
//#endregion //#endregion
//#region POST请求
/** /**
* POST请求 * POST请求
* *
@ -470,6 +471,273 @@ export default class Utils {
} }
//#region laf云函数 游戏内数据用
//获取用户数据,包含头像昵称注册时间
static getUserData(callBack) {
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 data = {
uid: cc.fx.GameConfig.GM_INFO.uid,
action: 'read',
}
Utils.POST("userData", data, res => {
console.log("获得userData数据:", res);
if (res.code === 1) {
console.log("服务器:获取用户数据成功", res);
if (callBack) callBack(res);
} else {
console.log("服务器:获取用户数据失败", res);
if (callBack) callBack(res);
}
});
}
}
//上传用户信息
static setUserData(data, callBack) {
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,
action: 'save',
userData: data
}
Utils.POST("userData", setData, res => {
console.log("获得userData数据:", res);
if (res.code === 1) {
console.log("服务器:获取用户数据成功", res);
if (callBack) callBack(res);
} else {
console.log("服务器:获取用户数据失败", res);
if (callBack) callBack(res);
}
});
}
}
//获得金币信息
static getUserCoin(callBack) {
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,
action: 'read',
}
Utils.POST("userCoin", setData, res => {
console.log("获得userCoin数据:", res);
if (res.code === 1) {
console.log("服务器:获得金币成功", res);
if (callBack) callBack(res);
} else {
console.log("服务器:获得金币失败", res);
if (callBack) callBack(res);
}
});
}
}
//上传金币信息
static setUserCoin(callBack) {
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,
action: 'save',
coinAmount: cc.fx.GameConfig.GM_INFO.coin
}
Utils.POST("userCoin", setData, res => {
console.log("获得userCoin数据:", res);
if (res.code === 1) {
console.log("服务器:上传金币成功", res);
if (callBack) callBack(res);
} else {
console.log("服务器:上传金币失败", res);
if (callBack) callBack(res);
}
});
}
}
//获得关卡等级信息
static getUserLevel(callBack) {
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,
action: 'read',
}
Utils.POST("userLevel", setData, res => {
console.log("获得userLevel数据:", res);
if (res.code === 1) {
console.log("服务器:获得等级成功", res);
if (callBack) callBack(res);
} else {
console.log("服务器:获得等级失败", res);
if (callBack) callBack(res);
}
});
}
}
//上传关卡等级信息
static setUserLevel(callBack) {
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,
action: 'save',
levelAmount: cc.fx.GameConfig.GM_INFO.level
}
Utils.POST("userLevel", setData, res => {
console.log("获得userLevel数据:", res);
if (res.code === 1) {
console.log("服务器:上传等级成功", res);
if (callBack) callBack(res);
} else {
console.log("服务器:上传等级失败", res);
if (callBack) callBack(res);
}
});
}
}
//获得用户道具信息
static getUserProp(callBack) {
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,
action: 'read',
}
Utils.POST("userProp", setData, res => {
console.log("获得userProp数据:", res);
if (res.code === 1) {
console.log("服务器:获得道具成功", res);
if (callBack) callBack(res);
} else {
console.log("服务器:获得道具失败", res);
if (callBack) callBack(res);
}
});
}
}
//上传道具信息
static setUserProp(propid, amount, callBack) {
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,
action: 'save',
propType: propid,
propData: amount,
}
Utils.POST("userProp", setData, res => {
console.log("获得userProp数据:", res);
if (res.code === 1) {
console.log("服务器:上传道具成功", res);
if (callBack) callBack(res);
} else {
console.log("服务器:上传道具失败", res);
if (callBack) callBack(res);
}
});
}
}
//获得关卡等级信息
static getUserHealth(callBack) {
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,
action: 'read',
}
Utils.POST("userHealth", setData, res => {
console.log("获得userHealth数据:", res);
if (res.code === 1) {
console.log("服务器:获得体力成功", res);
if (callBack) callBack(res);
} else {
console.log("服务器:获得体力失败", res);
if (callBack) callBack(res);
}
});
}
}
//上传关卡等级信息
static setUserHealth(health, callBack) {
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,
action: 'save',
healthAmount: cc.fx.GameConfig.GM_INFO.hp,
}
Utils.POST("userHealth", setData, res => {
console.log("获得userHealth数据:", res);
if (res.code === 1) {
console.log("服务器:上传体力成功", res);
if (callBack) callBack(res);
} else {
console.log("服务器:上传体力失败", res);
if (callBack) callBack(res);
}
});
}
}
// const propName={ // const propName={
//   gold_1: "金币包1", //   gold_1: "金币包1",
//   gold_2: "金币包2", //   gold_2: "金币包2",

View File

@ -419,6 +419,10 @@ var GameTool = {
} }
}) })
//laf云函数
Utils.getUserCoin((data) => {
})
} }
}, },
@ -457,6 +461,10 @@ var GameTool = {
console.error('存储用户数据失败', err) console.error('存储用户数据失败', err)
} }
}) })
//laf云函数
Utils.setUserCoin((data) => {
})
} }
}, },
@ -481,6 +489,10 @@ var GameTool = {
} }
}) })
//laf云函数
Utils.getUserLevel((data) => {
})
} }
}, },
@ -511,6 +523,9 @@ var GameTool = {
} }
if (callback) callback(); if (callback) callback();
}) })
//laf云函数
Utils.getUserHealth((data) => {
})
} }
else { else {
console.log("有存储过体力值:", health); console.log("有存储过体力值:", health);
@ -569,14 +584,24 @@ var GameTool = {
callback(err); callback(err);
} }
}) })
//laf云函数
Utils.getUserHealth((data) => {
})
} }
}, },
//设置用户体力值 有可能加,有可能定时器减 //设置用户体力值 有可能加,有可能定时器减
setUserHealth(health, callback) { setUserHealth(health, callback) {
if (health > 0) {
if (cc.fx.GameConfig.GM_INFO.hp < 5) {
cc.fx.GameConfig.GM_INFO.hp += health; cc.fx.GameConfig.GM_INFO.hp += health;
// if(health < 0) { }
// } }
else {
cc.fx.GameConfig.GM_INFO.hp += health;
}
// else MiniGameSdk.API.showToast("体力值恢复"); // else MiniGameSdk.API.showToast("体力值恢复");
const timestamp = Date.now(); const timestamp = Date.now();
let healthInfo = {} let healthInfo = {}
@ -595,6 +620,7 @@ var GameTool = {
"timestamp": timestamp "timestamp": timestamp
} }
} }
cc.fx.StorageMessage.setStorage("health", healthInfo); cc.fx.StorageMessage.setStorage("health", healthInfo);
MiniGameSdk.API.shushu_SetSuperProperties(null, null); MiniGameSdk.API.shushu_SetSuperProperties(null, null);
//@ts-ignore //@ts-ignore
@ -620,6 +646,10 @@ var GameTool = {
// console.error('存储关卡数据失败', err) // console.error('存储关卡数据失败', err)
} }
}) })
//laf云函数
Utils.setUserHealth(health, (data) => {
})
} }
}, },
@ -712,6 +742,10 @@ var GameTool = {
console.error('存储关卡数据失败', err) console.error('存储关卡数据失败', err)
} }
}) })
//laf云函数
Utils.setUserLevel((data) => {
})
} }
}, },
@ -740,6 +774,11 @@ var GameTool = {
callback(err); callback(err);
} }
}) })
//laf云函数
Utils.getUserProp((data) => {
})
} }
}, },
@ -788,6 +827,9 @@ var GameTool = {
console.error('存储道具数据失败', err) console.error('存储道具数据失败', err)
} }
}) })
Utils.setUserProp(propid, newPropData, (data) => {
})
} }
}, },
@ -829,6 +871,9 @@ var GameTool = {
} }
} }
}) })
Utils.setUserData(userInfo, (data) => {
})
} }
}, },

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -0,0 +1,38 @@
{
"ver": "2.3.7",
"uuid": "34625e3f-02b1-40c4-902a-5d7e0823c3ae",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 137,
"height": 121,
"platformSettings": {},
"subMetas": {
"skylineHealth": {
"ver": "1.0.6",
"uuid": "591a3b58-c345-4c24-84a2-f4faa8acdda1",
"importer": "sprite-frame",
"rawTextureUuid": "34625e3f-02b1-40c4-902a-5d7e0823c3ae",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 137,
"height": 121,
"rawWidth": 137,
"rawHeight": 121,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}