import { _decorator, Component, EventTouch, Label, find } from 'cc'; import { Http } from '../../core/net/Http'; import { OpenWindow } from '../../core/ui/window/OpenWindow'; import { WindowManager } from '../../core/ui/window/WindowManager'; import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode'; import { Utils } from '../../core/utils/Utils'; import { g } from '../../Data/g'; import { HttpErrorCode } from '../../Data/HttpErrorCode'; import { platform } from '../../Data/platform'; import { GetType } from '../GetWindow/GetType'; const { ccclass, property } = _decorator; @ccclass('HarvestWindow') export class HarvestWindow extends Component { @property({ tooltip: "网络请求对象", type: Http }) http: Http; private buildID: number; private cb: Function; private mult: number; public onParams(buildID: number, cb: Function): void { this.buildID = buildID; this.cb = cb; } public async onButton(e: EventTouch, mult: number) { this.mult = mult; if (mult == 1) { let result = await this.http.send("/api/ad/watchVideoAD"); if (result.code == 0) { let key = this.getThankingKey(this.buildID); platform.reportThinking("ad_init", JSON.stringify({ ad_id: key, ad_time: Utils.formatDate(new Date()), id: g.userData.id, role_name: g.userData.nickName, level: g.userData.getLevel() })); //播放视频 let adData = await g.showRewardVideo(); if (adData) { this.onVideoOver(); } else { //视频观看失败 WindowManager.showTips("视频观看时间不足"); } } else if (result.code == 106) { WindowManager.showTips("今日视频次数已用完,请明日再继续"); } else if (result.code == HttpErrorCode.VideoADCD) { WindowManager.showTips("请求频繁,请稍后再试"); } else { WindowManager.showTips("视频准备中,请稍后再试"); } return; } else { this.onVideoOver(); } } public async onVideoOver() { let result = await this.http.send("/api/product/harvest", { buildID: this.buildID, multiple: this.mult, adData: g.adData }); if (result.code == 0) { this.upThanking(result.data.bonus); g.gameData.rankScore += result.data.addScore; this.cb(this.mult); this.cb = null; WindowManager.close(); platform.reportThinking("envelope_increase", JSON.stringify({ previous_number: g.userData.bonus, increase_number: result.data.bonus, current_number: g.userData.bonus + result.data.bonus, reasons: "harvest" })); WindowManager.open("Prefabs/GetWindow", WindowOpenMode.CloseAndCover, [{ count: result.data.bonus, type: GetType.RedBag, needBezierEffect: true }, { count: result.data.exp, type: GetType.exp, needBezierEffect: false }]); } else if (result.code == HttpErrorCode.VideoADCD) { WindowManager.showTips("请求频繁,请稍后再试"); } } private upThanking(award: number): void { if (this.mult == 1) { let key = this.getThankingKey(this.buildID); platform.reportThinking("ad_end", JSON.stringify({ ad_id: key, ad_time: Utils.formatDate(new Date()), id: g.userData.id, role_name: g.userData.nickName, level: g.userData.getLevel(), award: award })) } else { let data = g.gameData.getProductingList(this.buildID)[0]; if (this.buildID >= 31000 && this.buildID <= 31017) { platform.reportThinking("harvest", JSON.stringify({ field_name: this.buildID, id: g.userData.id, level: g.userData.getLevel(), role_name: g.userData.nickName, harvest_time: Utils.formatDate(new Date()), award_no: award, plant_name: data.productID })); } else { let key = ""; switch (this.buildID) { case 30001: key = "chick"; break; case 30002: key = "cow"; break; case 30003: key = "pig"; break; case 30004: key = "corn"; break; case 30005: key = "milk"; break; case 30006: key = "sugar"; break; case 30007: key = "cake"; break; case 30008: key = "fastfood"; break; case 30009: key = "noodle"; break; } platform.reportThinking("harvest", JSON.stringify({ field_name: key, id: g.userData.id, level: g.userData.getLevel(), role_name: g.userData.nickName, harvest_time: Utils.formatDate(new Date()), award_no: award, plant_name: data.productID })); } } } public getThankingKey(id: number): string { if (id >= 31000 && id <= 31017) { return "harvest_field"; } else { switch (id) { case 30001: return "harvest_chick"; case 30002: return "harvest_cow"; case 30003: return "harvest_pig"; case 30004: return "harvest_corn"; case 30005: return "harvest_milk"; case 30006: return "harvest_sugar"; case 30007: return "harvest_cake"; case 30008: return "harvest_fastfood"; case 30009: return "harvest_noodle"; } } return } onDestroy() { this.cb = null; } }