feat: 领取奖励特效
This commit is contained in:
@@ -42,6 +42,7 @@ export default class PyramidService {
|
||||
this.error = ""; this.lastDraw = null; this.offset = 0;
|
||||
this.settlementTask = null; this.settlementNotices = []; this.loginVersion++;
|
||||
this.journal = cc.fx.StorageMessage.getStorage(this.storageKey()) || {};
|
||||
this.restoreSettlementNotices();
|
||||
// Legacy unpaid orders must not start polling or prevent a fresh purchase.
|
||||
if (this.journal.order) { delete this.journal.order; this.save(); }
|
||||
}
|
||||
@@ -57,11 +58,21 @@ export default class PyramidService {
|
||||
}
|
||||
static now(): number { return Date.now() + this.offset; }
|
||||
static resetLogin(): void {
|
||||
this.ensure(); this.loginVersion++; this.settlementTask = null; this.settlementNotices = [];
|
||||
this.ensure(); this.loginVersion++; this.settlementTask = null; this.restoreSettlementNotices();
|
||||
}
|
||||
private static restoreSettlementNotices(): void {
|
||||
const records = this.journal.settlements || {};
|
||||
this.settlementNotices = Object.keys(records).filter(id => records[id].phase === "ready")
|
||||
.map(id => records[id].notice);
|
||||
}
|
||||
static settlements(): any[] { this.ensure(); return this.settlementNotices.slice(); }
|
||||
static dismissSettlement(noticeId: string): void {
|
||||
this.ensure(); this.settlementNotices = this.settlementNotices.filter(notice => notice.noticeId !== noticeId); this.emit();
|
||||
this.ensure();
|
||||
const record = this.journal.settlements?.[noticeId];
|
||||
if (!record || record.phase !== "ready") return;
|
||||
// Keep a small receipt so a stale read cannot re-open an acknowledged notice.
|
||||
this.journal.settlements[noticeId] = { phase: "dismissed" };
|
||||
this.save(); this.restoreSettlementNotices(); this.emit();
|
||||
}
|
||||
static readSettlements(): Promise<boolean> {
|
||||
this.ensure();
|
||||
@@ -70,14 +81,24 @@ export default class PyramidService {
|
||||
const task = (async () => {
|
||||
try {
|
||||
const data = await this.request("pyramid/api", { action: "settlement_read" });
|
||||
this.ensure();
|
||||
if (generation !== this.generation || loginVersion !== this.loginVersion) return true;
|
||||
const notices = data.notices || [];
|
||||
// Reading only lists unclaimed notices; inventory changes after an explicit claim.
|
||||
for (const notice of notices) {
|
||||
if (!this.settlementNotices.some(existing => existing.noticeId === notice.noticeId)) this.settlementNotices.push(notice);
|
||||
const records = this.journal.settlements || (this.journal.settlements = {});
|
||||
for (const notice of data.notices || []) {
|
||||
if (!records[notice.noticeId]) records[notice.noticeId] = { phase: "pending", notice };
|
||||
}
|
||||
this.emit();
|
||||
return data.status !== "settling";
|
||||
// Persist before delivery: settlement_claim also marks the server notice read.
|
||||
this.save();
|
||||
let delivered = true;
|
||||
for (const id of Object.keys(records)) {
|
||||
if (records[id].phase !== "pending") continue;
|
||||
try { await this.claimSettlement(records[id].notice); }
|
||||
catch (error) { delivered = false; cc.warn("[Pyramid] 自动补发失败,保留记录重试", error); }
|
||||
this.ensure();
|
||||
if (generation !== this.generation || loginVersion !== this.loginVersion) return true;
|
||||
}
|
||||
this.restoreSettlementNotices(); this.emit();
|
||||
return delivered && data.status !== "settling";
|
||||
} catch (error) { cc.warn("[Pyramid] 补发清单查询失败", error); return false; }
|
||||
finally { if (generation === this.generation && loginVersion === this.loginVersion) this.settlementTask = null; }
|
||||
})();
|
||||
@@ -85,11 +106,18 @@ export default class PyramidService {
|
||||
}
|
||||
static async claimSettlement(notice: any): Promise<any> {
|
||||
this.ensure(); const generation = this.generation, loginVersion = this.loginVersion;
|
||||
const records = this.journal.settlements || (this.journal.settlements = {});
|
||||
if (records[notice.noticeId]?.phase === "ready") return records[notice.noticeId].notice;
|
||||
records[notice.noticeId] = { phase: "pending", notice }; this.save();
|
||||
try {
|
||||
const data = await this.request("pyramid/api", { action: "settlement_claim", periodId: notice.periodId, noticeId: notice.noticeId });
|
||||
this.ensure();
|
||||
if (generation !== this.generation || loginVersion !== this.loginVersion) throw new Error("账号已切换,请重新登录");
|
||||
this.applyInventory(data.inventory, data.notice.goods);
|
||||
this.recordCoinTask("settlement:" + notice.noticeId, data.notice.goods);
|
||||
records[notice.noticeId] = data.notice.goods.length
|
||||
? { phase: "ready", notice: data.notice } : { phase: "dismissed" };
|
||||
this.save(); this.restoreSettlementNotices();
|
||||
this.emit();
|
||||
return data.notice;
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user