import { JungleRewardConfig } from "./JungleTypes"; /** 将活动奖励配置转换成项目现有道具接口调用。 */ export default class JungleRewardService { public grant(ownerNode: cc.Node, rewards: JungleRewardConfig[]): void { const gameTool = cc.fx && cc.fx.GameTool; rewards.forEach((reward) => { const itemId = this.getItemId(reward); if (gameTool && typeof gameTool.getPassCheckPorp === "function") { if (reward.type === "infinite_health" && reward.count !== 900 && reward.count !== 1800 && reward.count !== 3600 && typeof gameTool.setUserPowerTime === "function") { gameTool.setUserPowerTime(reward.count); } else { gameTool.getPassCheckPorp(itemId, reward.count, false); } } }); const canvas = cc.find("Canvas"); const home = canvas && canvas.getComponent("JiaZai"); if (home) { if (typeof home.updateCoin === "function") { home.updateCoin(); } if (typeof home.updatePower === "function") { home.updatePower(); } } ownerNode.emit("jungle-reward-granted", rewards); } private getItemId(reward: JungleRewardConfig): number { if (typeof reward.itemId === "number") { return reward.itemId; } switch (reward.type) { case "coin": return 1001; case "freeze": return 2001; case "hammer": return 2002; case "magic_wand": return 2003; case "infinite_health": if (reward.count === 900) return 3001; if (reward.count === 1800) return 3002; if (reward.count === 3600) return 3003; return 3001; default: return 1001; } } }