锦标赛是有时限的竞技活动,共享一份初始 payload 与一份排行榜。
Cocos 封装同时暴露 FRVR 锦标赛(服务器后端、可移植)与平台锦标赛(宿主渠道原生,例如 Facebook Instant 的锦标赛面)。
const tournamentId = await FRVRSDK.instance.createTournament(
{ gameMode: 'classic' }, // payload —— 每个参赛者都会拿到这份
{
title: 'Weekly Challenge',
sortOrder: 'HIGHER_IS_BETTER', // 计时挑战用 'LOWER_IS_BETTER'
endTime: Date.now() + 7 * 24 * 3600 * 1000,
},
);
await FRVRSDK.instance.postTournamentScore(tournamentId, 1000);
const tournament = await FRVRSDK.instance.getTournamentById(tournamentId);
const myEntry = await FRVRSDK.instance.getMyTournamentEntry(tournamentId);
const mine = await FRVRSDK.instance.getMyTournaments();
部分渠道(尤其是 Facebook Instant)有原生锦标赛流程,会出现在宿主 UI 中。如果支持,优先用平台锦标赛 —— 平台会额外给你导量。
if (FRVRSDK.instance.isPlatformTournamentsSupported()) {
const current = await FRVRSDK.instance.getCurrentPlatformTournament();
const active = await FRVRSDK.instance.getActivePlatformTournaments();
await FRVRSDK.instance.joinPlatformTournament(tournamentId);
await FRVRSDK.instance.leavePlatformTournament();
await FRVRSDK.instance.sharePlatformTournament(score, payload);
}
sharePlatformTournament 会把一次锦标赛结果发到渠道的 feed / 分享面 —— 在一局结束时调用,带动传播。
async onRunEnded(score: number) {
if (FRVRSDK.instance.isPlatformTournamentsSupported()) {
const current = await FRVRSDK.instance.getCurrentPlatformTournament();
if (current) {
await FRVRSDK.instance.sharePlatformTournament(score, {});
return;
}
}
// 兜底:如果玩家在某个 FRVR 锦标赛里,就上报到当前的那个
const mine = await FRVRSDK.instance.getMyTournaments();
const active = mine.find(t => !t.ended);
if (active) await FRVRSDK.instance.postTournamentScore(active.id, score);
}