| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import { _decorator, Component, Node, ProgressBar, EventTouch, UIOpacity, Sprite, SpriteFrame } from 'cc';
- import { Http } from '../../core/net/Http';
- import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
- 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('TaskActive')
- export class TaskActive extends Component {
- @property({ type: ProgressBar, tooltip: "活跃度进度条" }) activeProgress: ProgressBar;
- @property({ type: [Node], tooltip: "宝箱节点集合" }) cubeNodes: Array<Node> = [];
- // @property({ type: [Node], tooltip: "星星节点集合" }) starNodes: Array<Node> = [];
- @property({ tooltip: "网络请求对象", type: Http }) http: Http;
- private data: any;
- public async setData(active: any) {
- this.data = active;
- this.activeProgress.progress = this.data.value / 100;
- let starCount = Math.floor(this.data.value / 20);
- for (let i = 0; i < starCount; i++) {
- // this.starNodes[i].active = true;
- (this.cubeNodes[i] && this.cubeNodes[i].getComponent(UIOpacity)) && (this.cubeNodes[i].getComponent(UIOpacity).opacity = 255);
- }
- for (let i = 0; i < 4; i++) {
- if (this.data["box" + i]) {
- this.cubeNodes[i].getComponent(Sprite).spriteFrame = await ResourcesUtils.load("Images/TaskWindow/task_cube_open/spriteFrame", SpriteFrame, this.node);
- this.cubeNodes[i].getComponent(UIOpacity).opacity = 150;
- }
- }
- }
- public async onCubeClick(e: EventTouch, num: string) {
- let touchNum = parseInt(num)
- if (!this.data["box" + num] && touchNum < Math.floor(this.data.value / 20)) {
- if (touchNum < 4) {
- let result = await this.http.send("/api/task/activeBoxReceive", { index: num, adData: g.adData });
- if (result.code == 0) {
- this.cubeNodes[num].getComponent(Sprite).spriteFrame = await ResourcesUtils.load("Images/TaskWindow/task_cube_open/spriteFrame", SpriteFrame, this.node);
- this.cubeNodes[num].getComponent(UIOpacity).opacity = 150;
- if (result.data.diamond > 0) {
- platform.reportThinking("diamond_increase", JSON.stringify({ previous_number: g.userData.diamond, increase_number: result.data.diamond, current_number: g.userData.diamond + result.data.diamond, reasons: "activeBoxReceive" }));
- WindowManager.open("Prefabs/GetWindow", WindowOpenMode.NotCloseAndAdd, [{ count: result.data.diamond, type: GetType.Diamond, needBezierEffect: true }], this.node.parent.parent);
- } else {
- 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: "activeBoxReceive" }));
- WindowManager.open("Prefabs/GetWindow", WindowOpenMode.NotCloseAndAdd, [{ count: result.data.bonus, type: GetType.RedBag, needBezierEffect: true }], this.node.parent.parent);
- }
- } else if (result.code == HttpErrorCode.VideoADCD) {
- WindowManager.showTips("请求频繁,请稍后再试");
- }
- } else {
- let result = await this.http.send("/api/ad/watchVideoAD");
- if (result.code == 0) {
- //播放视频
- platform.reportThinking("ad_init", JSON.stringify({ ad_id: "task_active", 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 async onVideoOver() {
- let result = await this.http.send("/api/task/activeBoxReceive", { index: 4, adData: g.adData });
- if (result.code == 0) {
- platform.reportThinking("ad_end", JSON.stringify({ ad_id: "task_active", ad_time: Utils.formatDate(new Date()), id: g.userData.id, role_name: g.userData.nickName, level: g.userData.getLevel(), award: result.data.bonus }));
- 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: "activeBoxReceive" }));
- WindowManager.open("Prefabs/GetWindow", WindowOpenMode.NotCloseAndAdd, [{ count: result.data.bonus, type: GetType.RedBag, needBezierEffect: true }], this.node.parent.parent);
- } else if (result.code == HttpErrorCode.VideoADCD) {
- WindowManager.showTips("请求频繁,请稍后再试");
- }
- }
- }
|