| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import { _decorator, Component, Node } 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';
- const { ccclass, property } = _decorator;
- @ccclass('ADUnlockFarmWindow')
- export class ADUnlockFarmWindow extends Component {
- @property({ type: Http, tooltip: "HTTP请求对象" })
- public http: Http = null;
- private unlockList = [];
- async onClickButton() {
- let result = await this.http.send("/api/ad/watchVideoAD");
- if (result.code == 0) {
- platform.reportThinking("ad_init", JSON.stringify({ ad_id: "buy_field", 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("视频准备中,请稍后再试");
- }
- }
- public onParams(id: number): void {
- this.unlockList = [id];
- // if (id <= 31005) {
- // this.unlockList = [31003, 31004, 31005];
- // } else {
- // this.unlockList = [31006, 31007, 31008];
- // }
- }
- async onVideoOver() {
- let result = await this.http.send("/api/product/unlock", { buildList: this.unlockList, adData: g.adData });
- if (result.code == 0) {
- platform.reportThinking("ad_end", JSON.stringify({ ad_id: "buy_field", ad_time: Utils.formatDate(new Date()), id: g.userData.id, role_name: g.userData.nickName, level: g.userData.getLevel() }))
- for (let i = 0; i < this.unlockList.length; i++) {
- g.gameData.setBuildData(this.unlockList[i], 0);
- WindowManager.close();
- }
- } else if (result.code == HttpErrorCode.VideoADCD) {
- WindowManager.showTips("请求频繁,请稍后再试");
- }
- }
- }
|