feat: tier starter packs using daily payment factors

This commit is contained in:
COMPUTER\EDY
2026-09-30 18:45:13 +08:00
parent 44901f1e50
commit 60f8fc4047
28 changed files with 1038 additions and 302 deletions
@@ -581,6 +581,9 @@ export class GameConfig {
starter_packTime: number; // 新手礼包截止时间,秒
starterPackServerOffset: number; // 服务端时间与本地时间差,毫秒
starterPackPurchased: boolean;
starterPackRound: number;
starterPackOffer: any;
starterPackAutoShownRound: number;
starterPackLastShownAt: number; // 最近一次实际弹出时间,毫秒
starterPackReactivatedDeadline: number; // 本次会话已确认的新周期截止时间,毫秒
wxFriend: boolean; //微信好友信息授权
@@ -796,6 +799,9 @@ export class GameConfig {
starter_packTime: 0, // 新手礼包截止时间
starterPackServerOffset: 0,
starterPackPurchased: false,
starterPackRound: 0,
starterPackOffer: null,
starterPackAutoShownRound: 0,
starterPackLastShownAt: 0,
starterPackReactivatedDeadline: 0,
wxFriend: false, //微信好友信息授权
+16 -3
View File
@@ -1,5 +1,6 @@
/** Purchases and login compensation use the same client-owned reward. */
export function starterPackReward() {
/** Use the order's offer for delivery; missing snapshots retain legacy rewards. */
export function starterPackReward(offer?: any) {
if (offer?.reward) return { ...offer.reward };
return { coin: 3000, hammer: 3, freeze: 3, magic_wand: 3, infinite_health: 30 * 60 };
}
@@ -21,6 +22,17 @@ export function starterPackTimeText(seconds: number): string {
export function applyStarterPackStatus(data: any): void {
const info = cc.fx.GameConfig.GM_INFO;
const expiry = Number(data.starter_pack) || 0;
const round = Number(data.starterPackRound || data.starterPackOffer?.round) || 0;
if (round && round < (info.starterPackRound || 0)) return;
if (round > (info.starterPackRound || 0)) {
info.starterPackPurchased = false;
info.starterPackReactivatedDeadline = 0;
info.starterPackRound = round;
}
if (data.starterPackOffer && (!info.starterPackOffer || round > Number(info.starterPackOffer.round))) {
info.starterPackOffer = data.starterPackOffer;
}
info.starterPackAutoShownRound = Math.max(info.starterPackAutoShownRound || 0, Number(data.starterPackAutoShownRound) || 0);
if (data.reactivated) info.starterPackReactivatedDeadline = Math.max(info.starterPackReactivatedDeadline || 0, expiry);
// An activity read started before reactivation may arrive after its response.
info.starter_packTime = Math.max(expiry, info.starterPackReactivatedDeadline || 0) / 1000;
@@ -37,7 +49,8 @@ export function starterPackDay(): string {
}
export function starterPackPopupKey(): string {
return 'Starter_pack_' + cc.fx.GameConfig.GM_INFO.uid;
const info = cc.fx.GameConfig.GM_INFO;
return 'Starter_pack_' + info.uid + '_' + (info.starterPackRound || info.starter_packTime);
}
export function starterPackFailureKey(): string {
+11 -6
View File
@@ -95,7 +95,8 @@ export default class Utils {
//#region 道具直购接口
/**道具直购接口*/
static buyProp(id, count, price, systemType, productId, callBack, passEnd?: string) {
static buyProp(id, count, price, systemType, productId, callBack, passEnd?: string, starterPackRound?: number) {
if (!/^starter_pack(?:_[2-5])?$/.test(productId)) cc.fx.GameTool.starterPackQueuedReason = "purchase";
let postName = "wx/orderPaySig";
if (systemType == "ios") {
postName = "wx/iosorderPaySig";
@@ -103,7 +104,8 @@ export default class Utils {
console.log("请求uid:" + Utils.uid, "请求id:" + id, "请求数量:" + count, "请求价格:" + price, "请求链接:" + postName);
Utils.POST(postName, {
uid: Utils.uid, itemid: id, itemCount: count, itemPrice: price,
...(passEnd ? { passVersion: 2, passEnd } : {})
...(passEnd ? { passVersion: 2, passEnd } : {}),
...(starterPackRound ? { starterPackRound } : {})
}, res => {
if (res.code == 1) {
Utils.outTradeNo = res.data.outTradeNo;
@@ -247,6 +249,7 @@ export default class Utils {
//#region ios支付
/**跳转客服,ios支付*/
static GoKEFu(iosPayInfo, callBack) {
if (!/^starter_pack(?:_[2-5])?$/.test(iosPayInfo.payment_name)) cc.fx.GameTool.starterPackQueuedReason = "purchase";
console.log("创建新的订单,清空老订单");
var order = `wcx_` + Math.round(Math.random() * 10 ** 13) + Date.now();
if (iosPayInfo.payment_name == "month_Card") {
@@ -257,7 +260,7 @@ export default class Utils {
cc.fx.GameConfig.GM_INFO.iosReviveOrder = null;
cc.fx.GameConfig.GM_INFO.iosReviveOrder = order;
}
else if (iosPayInfo.payment_name == "starter_pack") {
else if (/^starter_pack(?:_[2-5])?$/.test(iosPayInfo.payment_name)) {
cc.fx.GameConfig.GM_INFO.iosStarterOrder = null;
cc.fx.GameConfig.GM_INFO.iosStarterOrder = order;
}
@@ -280,6 +283,7 @@ export default class Utils {
count: iosPayInfo.payment_count,
price: iosPayInfo.price,//价格单位是分
...(iosPayInfo.passEnd ? { passEnd: iosPayInfo.passEnd, passVersion: 2 } : {}),
...(iosPayInfo.starterPackRound ? { starterPackRound: iosPayInfo.starterPackRound } : {}),
}
const shushu_data = {
outTradeNo: order,
@@ -1177,9 +1181,9 @@ export default class Utils {
}, callBack);
}
static markStarterPackShown(expiry: number) {
static markStarterPackShown(expiry: number, automatic: boolean = false) {
Utils.POST("limitedTimeEvent", {
uid: cc.fx.GameConfig.GM_INFO.uid, event: "starter_pack", action: "shown", expiry,
uid: cc.fx.GameConfig.GM_INFO.uid, event: "starter_pack", action: "shown", expiry, automatic,
}, () => { });
}
@@ -1210,7 +1214,7 @@ export default class Utils {
}
}
//触发新手礼包事件
static setStarter_pack(callBack) {
static setStarter_pack(callBack, reason?: string) {
//@ts-ignore
if ((typeof wx !== 'undefined' && wx !== null) || (typeof tt !== 'undefined' && tt !== null)) {
let uid = cc.fx.StorageMessage.getStorage("uid");
@@ -1222,6 +1226,7 @@ export default class Utils {
uid: cc.fx.GameConfig.GM_INFO.uid,
action: 'save',
event: "starter_pack",
reason, level: cc.fx.GameConfig.GM_INFO.level,
}
Utils.POST("limitedTimeEvent", setData, res => {
console.log("触发新手礼包事件:", res);
+55 -19
View File
@@ -7,9 +7,10 @@ import { MiniGameSdk } from "../../Sdk/MiniGameSdk";
import Utils from "../Pay/Utils";
import { getNewShopProduct } from "../Config/ShopCatalog";
import BlockAssetManager from "./BlockAssetManager";
import HomePopupQueue from "../../../home_popup_queue/HomePopupQueue";
import {
starterPackReward, applyStarterPackStatus, starterPackRemaining, starterPackNow,
starterPackDay, starterPackPopupKey, starterPackFailureKey, starterPackRecordResult
starterPackPopupKey, starterPackFailureKey, starterPackRecordResult
} from "../Config/StarterPack";
//@ts-ignore
//最大工具类 各种公共方法,以及处理上传,获取后端接口数据
@@ -801,6 +802,7 @@ var GameTool = {
if (callback) {
callback(data);
}
if (data?.code === 1) this.tryReactivateStarterPack("resources");
})
}
},
@@ -886,6 +888,7 @@ var GameTool = {
cc.fx.GameTool.shushu_Track("shop_buy", buyData);
callback();
this.tryReactivateStarterPack("purchase");
}
},
@@ -1000,6 +1003,7 @@ var GameTool = {
//商城购买
shopBuy(productId, compensate, orderContext: any = null) {
if (/^starter_pack_[2-5]$/.test(productId) && !orderContext?.starterPackOffer?.reward) return false;
const newProduct = getNewShopProduct(productId);
const newOrderKey = newProduct && orderContext?.outTradeNo
? "ShopBGranted_" + cc.fx.GameConfig.GM_INFO.uid + "_" + orderContext.outTradeNo : "";
@@ -1007,7 +1011,7 @@ var GameTool = {
const rebornOrderKey = /^reborn_Gift(?:_[2-5])?$/.test(productId) && orderContext?.outTradeNo
? "RebornGiftGranted_" + cc.fx.GameConfig.GM_INFO.uid + "_" + orderContext.outTradeNo : "";
if (rebornOrderKey && cc.fx.StorageMessage.getStorage(rebornOrderKey)) return false;
const starterOrderKey = productId === "starter_pack" && orderContext?.outTradeNo
const starterOrderKey = /^starter_pack(?:_[2-5])?$/.test(productId) && orderContext?.outTradeNo
? "StarterPackGranted_" + cc.fx.GameConfig.GM_INFO.uid + "_" + orderContext.outTradeNo : "";
if (starterOrderKey && cc.fx.StorageMessage.getStorage(starterOrderKey)) return;
let coin = 0;
@@ -1295,16 +1299,20 @@ var GameTool = {
if (rebornOrderKey) cc.fx.StorageMessage.setStorage(rebornOrderKey, true);
if (orderContext?.onRebornGiftGranted) orderContext.onRebornGiftGranted();
break;
case "starter_pack": {
const reward = starterPackReward();
case "starter_pack":
case "starter_pack_2":
case "starter_pack_3":
case "starter_pack_4":
case "starter_pack_5": {
const reward = starterPackReward(orderContext?.starterPackOffer);
coin = reward.coin;
price = 300;
price = orderContext?.starterPackOffer?.priceFen || 300;
cc.fx.GameTool.changeCoin(coin);
this.getShopProp({
freeze: reward.freeze, hammer: reward.hammer,
magic_wand: reward.magic_wand, price
}, compensate);
this.setUserPowerTime(reward.infinite_health, "starter_pack", compensate);
this.setUserPowerTime(reward.infinite_health, productId, compensate);
rewardData = [
{ type: "coin", count: coin },
{ type: "freeze", count: reward.freeze },
@@ -1312,7 +1320,9 @@ var GameTool = {
{ type: "magic", count: reward.magic_wand },
{ type: "infinite_health", count: reward.infinite_health },
];
cc.fx.GameConfig.GM_INFO.starterPackPurchased = true;
if ((Number(orderContext?.starterPackBuyRound) || 1) === (cc.fx.GameConfig.GM_INFO.starterPackRound || 1)) {
cc.fx.GameConfig.GM_INFO.starterPackPurchased = true;
}
if (starterOrderKey) cc.fx.StorageMessage.setStorage(starterOrderKey, true);
break;
}
@@ -1352,6 +1362,7 @@ var GameTool = {
}
cc.fx.GameTool.shushu_Track("shop_buy", buyData);
MiniGameSdk.API.shushu_SetSuperProperties(null, true);
if (!compensate && !/^starter_pack(?:_[2-5])?$/.test(productId)) this.tryReactivateStarterPack("purchase");
},
getPassCheckPorp(porpId, num, compensate, getType?) {
@@ -1883,13 +1894,16 @@ var GameTool = {
let dateStr = cc.fx.StorageMessage.getStorage("starter_pack");
},
recordStarterPackShown() {
recordStarterPackShown(automatic: boolean = false) {
const info = cc.fx.GameConfig.GM_INFO;
if (starterPackRemaining() <= 0) return;
info.starterPackLastShownAt = starterPackNow();
cc.fx.StorageMessage.setStorage("StarterPackLastShown_" + info.uid, info.starterPackLastShownAt);
cc.fx.StorageMessage.setStorage(starterPackPopupKey(), starterPackDay());
Utils.markStarterPackShown(Math.round(info.starter_packTime * 1000));
if (automatic) {
info.starterPackAutoShownRound = info.starterPackRound;
cc.fx.StorageMessage.setStorage(starterPackPopupKey(), true);
}
Utils.markStarterPackShown(Math.round(info.starter_packTime * 1000), automatic);
},
recordStarterPackLevelResult(won: boolean) {
@@ -1900,21 +1914,45 @@ var GameTool = {
tryReactivateStarterPack(reason: string) {
const info = cc.fx.GameConfig.GM_INFO;
if (!info.uid || info.level < 15 || !info.canIos || info.starterPackPurchased
|| !(info.starter_packTime > 0) || starterPackRemaining() > 0) return;
if (!info.uid || info.level < 15 || !info.canIos || starterPackRemaining() > 0) return;
if (reason === "resources") {
reason = this.starterPackQueuedReason || (Number.isFinite(info.coin) && info.coin < 500 ? "low_coin"
: info.hp === 0 && Number.isFinite(info.userPowerTime) && info.userPowerTime <= starterPackNow() / 1000 ? "low_health"
: [info.freezeAmount, info.hammerAmount, info.magicAmount].every(value => Number.isFinite(value) && value >= 0 && value <= 3) ? "low_props"
: Number(cc.fx.StorageMessage.getStorage(starterPackFailureKey())) >= 4 ? "four_failures" : "");
}
if (!reason) return;
if (["shop", "level_purchase", "purchase"].includes(this.starterPackQueuedReason)) reason = this.starterPackQueuedReason;
if (reason === "low_coin" && !(info.coin < 500)) return;
const expiry = info.starter_packTime * 1000;
if (expiry > 0 && starterPackNow() < Math.floor((expiry + 8 * 3600000) / 86400000) * 86400000 - 8 * 3600000 + 2 * 86400000) return;
const canvas = cc.find("Canvas");
const home = canvas && canvas.getComponent(JiaZai);
const shop = canvas && canvas.getChildByName("shop");
if (canvas?.getChildByName("Loading")?.activeInHierarchy || shop?.getChildByName("Loading")?.activeInHierarchy) {
this.starterPackQueuedReason = reason;
return;
}
if (cc.fx.GameConfig.isGameplayEntryPreparing() || (!home && !shop?.activeInHierarchy)) {
this.starterPackQueuedReason = reason;
return;
}
if (home && (["RewardNode", "getcard", "monthlyCardNode", "actionpNode", "winStreakNode", "passCheckNode", "passIntroNode", "jungleTreasureNode"]
.some(key => home[key]?.activeInHierarchy)
|| ["zhuanchang", "Transfer", "CloudRisePanel"].some(name => canvas.getChildByName(name)?.activeInHierarchy))) {
this.starterPackQueuedReason = reason;
HomePopupQueue.get(canvas).enqueue("starterPackActivation", 40, done => { this.tryReactivateStarterPack(reason); done(); });
return;
}
if (this.starterPackReactivationUid === info.uid) {
if (reason !== "low_coin") this.starterPackQueuedReason = reason;
return;
}
const lastShown = Math.max(info.starterPackLastShownAt || 0,
Number(cc.fx.StorageMessage.getStorage("StarterPackLastShown_" + info.uid)) || 0);
if (lastShown > 0 && starterPackNow() - lastShown <= 48 * 3600000) return;
const uid = info.uid;
this.starterPackReactivationUid = uid;
this.starterPackQueuedReason = "";
Utils.reactivateStarter_pack(reason, Number(cc.fx.StorageMessage.getStorage(starterPackFailureKey())) || 0,
lastShown, res => {
0, res => {
const queued = this.starterPackReactivationUid === uid ? this.starterPackQueuedReason : "";
if (this.starterPackReactivationUid === uid) {
this.starterPackReactivationUid = "";
@@ -1926,10 +1964,8 @@ var GameTool = {
if (queued) this.tryReactivateStarterPack(queued);
return;
}
const canvas = cc.find("Canvas");
const home = canvas && canvas.getComponent(JiaZai);
if (home) {
home.onStarterPackReactivated();
home.onStarterPackReactivated(!["shop", "level_purchase", "purchase"].includes(reason));
}
});
},