| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- import { _decorator, Component, Node, Label, isValid, EventHandler, Color } from 'cc';
- import { DataSystem } from '../../core/data/DataSystem';
- import { Http, HttpResponseCode } from '../../core/net/Http';
- import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode';
- import { WindowSystem } from '../../core/ui/window/WindowSystem';
- import { ConfigData } from '../../data/ConfigData';
- import { HttpErrorCode } from '../../data/HttpErrorCode';
- import { UserData } from '../../data/UserData';
- import { Hero_Client, UserHeroData } from '../../hero/UserHeroData';
- import { MarshalSkillSystem } from '../../marshal/MarshalSkillSystem';
- import { ReportThinking } from '../../ReportThinking';
- import { RecruitData } from '../RecruitData';
- import { RecruitItem } from './RecruitItem';
- import { UpdateRecruit } from './UpdateRecruit';
- const { ccclass, property } = _decorator;
- /**
- * 招募页 单抽与十连抽展示页
- * @author 郑聂华
- */
- @ccclass('RecruitGeneralUI')
- export class RecruitGeneralUI extends Component {
- @property({ type: Label, displayName: '文本_元宝', tooltip: "文本_元宝" }) txtNumDiamond: Label = null;
- @property({ type: Node, displayName: '单抽页', tooltip: "单抽页" }) panelOne: Node = null;
- @property({ type: Node, displayName: '十连抽页', tooltip: "十连抽页" }) panelTen: Node = null;
- @property({ type: Node, displayName: '单_开始页', tooltip: "单_开始页" }) panelOneStart: Node = null;
- @property({ type: Node, displayName: '单_结束页', tooltip: "单_结束页" }) panelOneEnd: Node = null;
- @property({ type: Node, displayName: '返回按钮', tooltip: "返回按钮" }) backNode: Node = null;
- @property({ type: RecruitItem, displayName: '抽奖Item_单', tooltip: "抽奖Item_单" }) recruitItemOne: RecruitItem = null;
- @property({ type: RecruitItem, displayName: '抽奖Item_十', tooltip: "抽奖Item_十" }) recruitItemTens: RecruitItem[] = [];
- @property({ type: Node, displayName: '十_开始页', tooltip: "十_开始页" }) panelTenStart: Node = null;
- @property({ type: Node, displayName: '十_结束页', tooltip: "十_结束页" }) panelTenEnd: Node = null;
- @property({ type: Label, displayName: '文本_单抽元宝消耗', tooltip: "文本_单抽元宝消耗" }) txtCostOne: Label = null;
- @property({ type: Label, displayName: '文本_十连抽元宝消耗', tooltip: "文本_十连抽元宝消耗" }) txtCostTen: Label = null;
- @property({ type: Label, displayName: '文本_单抽倒计时', tooltip: "文本_单抽倒计时" }) txtTimerOne: Label = null;
- @property({ type: EventHandler, displayName: '招募结束回调', tooltip: "招募结束回调" }) recruitBack: EventHandler = null;
- private isCanRecruit: boolean = true;
- private isOpenedOne: boolean = false;
- private isOpenAll: boolean = false;
- private herodatacfg: any;
- private serverConfig: any;
- private paramData: { type: number, data: [{ chip: number, hero: any }] };
- private userData: UserData;
- onLoad() {
- this.serverConfig = DataSystem.getData(ConfigData).get("serverConfig");
- }
- update() {
- DataSystem.watch(UserData, "diamond") && this.updateDiamond();
- }
- private updateDiamond() {
- this.txtNumDiamond.string = this.userData.diamond > 10000 ? (this.userData.diamond / 1000).toFixed(1) + "k" : this.userData.diamond + "";
- this.txtCostOne.string = this.serverConfig.recruit1 + "";
- this.txtCostTen.string = this.serverConfig.recruit10 + "";// * 10 * this.serverConfig.invite_discount + "";
- this.txtCostOne.color = this.userData.diamond < this.serverConfig.recruit1 ? Color.RED : new Color(255, 235, 60, 255);
- this.txtCostTen.color = this.userData.diamond < this.serverConfig.recruit10 ? Color.RED : new Color(255, 235, 60, 255);
- }
- /**
- * 打开页面回调
- *{type:1} 1 单抽 2 十连抽
- */
- private init(param: any) {
- this.herodatacfg = DataSystem.getData(ConfigData).get("general");
- this.paramData = param;
- this.serverConfig = DataSystem.getData(ConfigData).get("serverConfig");
- this.userData = DataSystem.getData(UserData);
- this.updateDiamond();
- this.backNode.active = false;
- this.panelOne.active = param.type == 1;
- this.panelTen.active = param.type == 2;
- param.type == 1 && this.initPanelOne();
- param.type == 2 && this.initPanelTen();
- this.recruitItemOne.recruitEndBack = this.recruitBack;
- for (let t of this.recruitItemTens) { t.recruitEndBack = this.recruitBack; }
- }
- /**单抽初始化*/
- initPanelOne() {
- this.panelTen.active = false;
- this.panelOneStart.active = true;
- this.panelOneEnd.active = false;
- this.recruitItemOne.init(1);
- this.scheduleOnce(this.openRecruitOne, 3);
- }
- /**十连抽抽初始化*/
- initPanelTen() {
- this.panelTenStart.active = true;
- this.panelTenEnd.active = false;
- this.openRecruitTen();
- }
- /**单抽翻牌*/
- async openRecruitOne() {
- if (this.isOpenedOne) return; this.isOpenedOne = true;
- this.unschedule(this.openRecruitOne);
- let tempData = this.paramData.data[0];
- this.recruitItemOne.openDraw(this.herodatacfg[tempData.hero.id], 1, tempData.chip > 0, tempData.chip);
- }
- /**十连抽翻牌*/
- async openRecruitTen() {
- await new Promise<void>(resolve => { setTimeout(() => resolve(), 1000) });
- for (let i = 0; isValid(this.node) && i < this.recruitItemTens.length; i++) {
- if (!this.isOpenAll) {
- let tempData = this.paramData.data[i];
- this.recruitItemTens[i].openDraw(this.herodatacfg[tempData.hero.id], 2, tempData.chip > 0, tempData.chip);
- await new Promise<void>(resolve => { setTimeout(() => resolve(), 300) });
- }
- }
- }
- /**
- * 招募
- * @param recruitType 招募类型 1 单抽 2 十连抽
- */
- private async recruitHero(recruitType: number = 1) {
- this.isCanRecruit = false;
- let result = await this.getComponent(Http).send("/api/recruit/recruit", { num: recruitType == 1 ? 1 : 10 });
- if (result && result.code == HttpResponseCode.Success) {
- this.backNode.active = false;
- let userData = DataSystem.getData(UserData);
- let recruit_diamond = recruitType == 1 ? this.serverConfig.recruit1 : this.serverConfig.recruit10;
- ReportThinking.currency_decrease('diamond', userData.diamond, recruit_diamond, userData.diamond - recruit_diamond, 'recruit');
- if (recruitType == 1) DataSystem.getData(UserData).diamond -= this.serverConfig.recruit1;
- else DataSystem.getData(UserData).diamond -= this.serverConfig.recruit10;
- this.paramData.data = result.data;
- this.isOpenedOne = false;
- if (recruitType == 1) this.initPanelOne(); else this.initPanelTen();
- this.getComponent(UpdateRecruit).addRecruitResults(result.data);
- this.updateUserHeroData(result.data);
- this.isCanRecruit = true;
- }
- else if (result && result.code == HttpErrorCode.NoTimes) {
- recruitType == 1 && WindowSystem.showTips("已达今日单次招募次数上限");
- recruitType == 2 && WindowSystem.showTips("已达今日十连招募次数上限");
- this.isCanRecruit = true;
- } else {
- WindowSystem.showTips("招募失败");
- this.isCanRecruit = true;
- }
- }
- /**更新武将数据*/
- private updateUserHeroData(data: any[]) {
- let userHeroData = DataSystem.getData(UserHeroData);
- //console.log("----Hero: ", data);
- for (let i = 0; i < data.length; i++) {
- if (data[i].chip == 0) {
- userHeroData.addHero(data[i].hero.id);
- ReportThinking.hero_activate(DataSystem.getData(ConfigData).get('general')[data[i].hero.id].name, 'recruit');
- } else {
- userHeroData.addChip(data[i].hero.id, data[i].chip);
- }
- }
- this.updateMarshalSkillNotice();
- }
- /**更新统帅技能数据*/
- private updateMarshalSkillNotice() {
- MarshalSkillSystem.updateNoticeQueue();
- }
- /**招募结束回调*/
- private recruitEndBack() {
- if (this.paramData.type == 1) {
- //await new Promise<void>(resolve => { setTimeout(() => resolve(), 1500) });//计算出的时间
- this.panelOneEnd.active = true; this.panelOneStart.active = false;
- this.backNode.active = true;
- } else {
- let isEnd = true;
- for (let i = 0; i < this.recruitItemTens.length; i++) { !this.recruitItemTens[i].isRecruitEnd && (isEnd = false); }
- if (isEnd) { this.panelTenEnd.active = true; this.panelTenStart.active = false; this.backNode.active = true; };
- }
- }
- /**是否存在兑换元宝次数*/
- private async isHaveExchangeTimes() {
- let result = await this.getComponent(Http).send("/api/recruit/GetExchange");
- if (result && result.code == HttpResponseCode.Success) {
- //return (result.data.freeTimes + result.data.videoTimes) > 0
- return result.data.hadExchangedTimes < Object.keys(result.data.config).length
- }
- return false;
- }
- /**点击开启单抽*/
- private onClickOpenOne() {
- this.openRecruitOne();
- }
- /**点击单抽*/
- private async onClickRecruitOneBtn() {
- if (!this.isCanRecruit) return;
- if (DataSystem.getData(UserData).diamond >= this.serverConfig.recruit1) {
- this.recruitHero(1);
- } else {
- if (await this.isHaveExchangeTimes()) {
- WindowSystem.open("prefabs/ui/recruit/diamondExchange", WindowOpenMode.NotCloseAndAdd, ["6"]);
- } else {
- WindowSystem.showTips("元宝不足");
- }
- }
- }
- /**点击开启全部十连抽*/
- private async onClickOpenTenAll() {
- this.isOpenAll = true; let awaitTime = 1500;
- let isFirst = true, isSameFirst = false, isOpenedLow = false, isOpenedHigh = false;
- for (let i = 0; i < this.recruitItemTens.length; i++) {
- if (!this.recruitItemTens[i].isOpened) {
- let tempData = this.paramData.data[i];
- let heroCfg = this.herodatacfg[tempData.hero.id];
- if (!isOpenedLow) { if (heroCfg.color < 3) { isOpenedLow = true; isSameFirst = true; } }
- if (!isOpenedHigh) { if (heroCfg.color >= 3) { isOpenedHigh = true; isSameFirst = true; } }
- let openParam = { isOpenAll: true, isFirst: isFirst, isSameFirst: isSameFirst };
- this.recruitItemTens[i].openDraw(heroCfg, 2, tempData.chip > 0, tempData.chip, openParam);
- if (heroCfg.color >= 3 && awaitTime == 1500) awaitTime = 3000;
- isFirst = isSameFirst = false;
- }
- }
- this.panelTenStart.active = false;
- }
- /**点击十连抽*/
- private async onClickRecruitTenBtn() {
- if (!this.isCanRecruit) return;
- if (DataSystem.getData(UserData).diamond >= this.serverConfig.recruit10) {
- this.isOpenAll = false;
- for (let t of this.recruitItemTens) {
- t.init();
- }
- this.recruitHero(2);
- } else {
- if (await this.isHaveExchangeTimes()) {
- WindowSystem.open("prefabs/ui/recruit/diamondExchange", WindowOpenMode.NotCloseAndAdd, ["6"]);
- } else {
- WindowSystem.showTips("元宝不足");
- }
- }
- }
- onDestroy() {
- if (DataSystem.getData(RecruitData).recruitResults && DataSystem.getData(RecruitData).recruitResults.length > 0) {
- WindowSystem.open("prefabs/ui/recruit/recruitResult", WindowOpenMode.NotCloseAndAdd);
- }
- }
- }
|