| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- import { _decorator, Component, Node, Label, Sprite, SpriteFrame, Skeleton, sp } from 'cc';
- import { RewardVideoSystem } from '../ad/RewardVideoSystem';
- import { DataSystem } from '../core/data/DataSystem';
- import { Http, HttpResponseCode } from '../core/net/Http';
- import { HttpSystem } from '../core/net/HttpSystem';
- import { ResourceLoader } from '../core/resourceManager/ResourceLoader';
- import { Window } from '../core/ui/window/Window';
- import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
- import { WindowSystem } from '../core/ui/window/WindowSystem';
- import { ConfigData } from '../data/ConfigData';
- import { platform } from '../data/jsb/platform';
- import { UserData } from '../data/UserData';
- import { ReportThinking } from '../ReportThinking';
- import { ActivityInfoData } from './ActivityInfoData';
- import { TaskData } from './TaskData';
- const { ccclass, property, requireComponent } = _decorator;
- /***
- * 宝箱奖励领取
- */
- @ccclass('ActivityGift')
- @requireComponent(Http)
- export class ActivityGift extends Component {
- @property({ type: Node, tooltip: "双倍领取" }) doubleNode: Node;
- @property({ type: Node, tooltip: "普通领取" }) singleNode: Node;
- @property({ type: Node, tooltip: "普通领取按钮节点" }) getBtnNode: Node;
- @property({ type: Label, tooltip: "普通领取" }) numLabel: Label;
- @property({ type: Label, tooltip: "视频领取按钮文本" }) btnLabel: Label;
- @property({ type: Sprite, tooltip: "普通领取" }) iconSprite: Sprite;
- @property({ type: sp.Skeleton, tooltip: "宝箱特效" }) boxSkeleton: sp.Skeleton;
- @property({ type: Node, tooltip: "奖励节点" }) giftNode: Node;
- private id: number;
- private data: any;
- private activitys = [];
- private async onOpenHandler(data: { id: number }) {
- this.id = data.id;
- this.data = DataSystem.getData(ConfigData).get('taskActive')[this.id];
- // this.boxSkeleton.animation = 'animantion';
- let openBox = this.boxSkeleton.addAnimation(0, "animation", false);
- openBox && this.boxSkeleton.setTrackCompleteListener(openBox, (e) => {
- this.giftNode.active = true;
- }
- );
- let result = await this.getComponent(Http).send('/api/task/OpenTaskActive', { id: this.id });
- if (result && result.code == HttpResponseCode.Success) {
- this.numLabel.string = result.data.rewardNum + '';
- if (result.data.rewardType == 'bonus') {
- this.iconSprite.spriteFrame = await this.getComponent(ResourceLoader).load<SpriteFrame>('image/icons/icon1/spriteFrame', SpriteFrame);
- } else {
- this.iconSprite.spriteFrame = await this.getComponent(ResourceLoader).load<SpriteFrame>('image/icons/icon4/spriteFrame', SpriteFrame);
- }
- this.activitys = DataSystem.getData(TaskData).activitys;
- let d: ActivityInfoData;
- for (let i = 0; i < this.activitys.length; i++) {
- if (this.activitys[i].id == this.id) {
- d = this.activitys[i];
- break;
- }
- }
- if (this.data.isdouble) {
- if (d.isReceiveSingle) {
- this.scheduleOnce(() => {
- this.doubleNode.active = true;
- }, 2);
- } else {
- this.scheduleOnce(() => {
- this.btnLabel.string = '三倍领取';
- this.doubleNode.active = true;
- }, 2);
- this.scheduleOnce(() => {
- this.singleNode.active = true;
- }, 5);
- }
- } else {
- this.scheduleOnce(() => {
- this.getBtnNode.active = true;
- }, 2);
- }
- }
- }
- private async onDouble() {
- let result = await this.getComponent(Http).send("/api/ad/watchVideoAD");
- if (result && result.code == 0) {
- ReportThinking.ad_init('activeBox_get');
- let adData = await RewardVideoSystem.show();
- if (adData) {//观看视频成功
- this.onGetGift(true, adData.obj);
- } else {//TODO 观看视频失败
- }
- }
- }
- private onSingle() {
- this.onGetGift();
- }
- private async onGetGift(isDouble: boolean = false, adData?: any) {
- let data;
- if (adData) {
- data = { id: this.id, isDouble: isDouble, adData: adData };
- } else {
- data = { id: this.id, isDouble: isDouble };
- }
- let result = await this.getComponent(Http).send('/api/task/ReceiveTaskActive', data);
- if (result && result.code == HttpResponseCode.Success) {
- adData && ReportThinking.ad_end('activeBox_get', result.data.rewardType == 'bonus' ? result.data.rewardNum : 0);
- // rewardType string 奖励类型(bonus是红包币,money是粮草)
- // rewardNum number 奖励数量/
- let type: number = 0;
- if (result.data.rewardType == 'bonus') {
- type = 3;
- } else {
- type = 1;
- }
- for (let i = 0; i < this.activitys.length; i++) {
- if (this.activitys[i].id == this.id) {
- !isDouble && (this.activitys[i].isReceiveSingle = true);
- isDouble && (this.activitys[i].isReceiveDouble = true);
- }
- }
- ReportThinking.activity(this.id, result.data.rewardNum);
- let userData = DataSystem.getData(UserData);
- ReportThinking.currency_increase(result.data.rewardType, userData[result.data.rewardType], result.data.rewardNum, userData[result.data.rewardType] + result.data.rewardNum, 'activebox_get');
- DataSystem.getData(TaskData).getActiveBoxGiftNum++;
- this.getComponent(Window).close();
- WindowSystem.open("prefabs/ui/turntable/prizeFly", WindowOpenMode.NotCloseAndAdd, [{ type: type, num: result.data.rewardNum }]);
- }
- else if (result && result.code == 104) {
- WindowSystem.showTips('活跃度不足');
- }
- else {
- this.getComponent(Window).close();
- }
- }
- }
|