| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- import { _decorator, Component, Node, Label, sp, Sprite, SpriteFrame, Color, EventHandler } from 'cc';
- import { DataSystem } from '../../core/data/DataSystem';
- import { Http, HttpResponseCode } from '../../core/net/Http';
- import { ResourceLoader } from '../../core/resourceManager/ResourceLoader';
- import { OpenWindow } from '../../core/ui/window/OpenWindow';
- 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 { NoviceGuideData } from '../../guide/NoviceGuideData';
- import { Hero_Client, UserHeroData } from '../../hero/UserHeroData';
- import { MarshalSkillSystem } from '../../marshal/MarshalSkillSystem';
- import { ReportThinking } from '../../ReportThinking';
- import { RecruitData } from '../RecruitData';
- import { UpdateRecruit } from './UpdateRecruit';
- const { ccclass, property } = _decorator;
- /**
- * 招募页(点将台)
- * @author 郑聂华
- */
- @ccclass('RecruitUI')
- export class RecruitUI extends Component {
- @property({ type: ResourceLoader, displayName: "资源加载组件", tooltip: "资源加载组件" }) res: ResourceLoader = null;
- @property({ type: Label, displayName: '文本_元宝', tooltip: "文本_元宝" }) txtDiamond: Label = null;
- @property({ type: Node, displayName: "心愿背景框", tooltip: "心愿背景框" }) wishRect: Node = null;
- @property({ type: Label, displayName: '文本_倍率', tooltip: "文本_倍率" }) txtRate: Label = null;
- @property({ type: Sprite, displayName: '图_心愿武将', tooltip: "图_心愿武将" }) imgWish: Sprite = null;
- @property({ type: Label, displayName: '文本_心愿武将名', tooltip: "文本_心愿武将名" }) txtName: Label = null;
- @property({ type: Sprite, displayName: '图_心愿武将阵营', tooltip: "图_心愿武将阵营" }) imgWishCamp: Sprite = null;
- @property({ type: sp.Skeleton, displayName: 'Spine_光条特效动画', tooltip: "Spine_光条特效动画" }) spineLight: sp.Skeleton = null;
- @property({ type: Label, displayName: '文本_单抽消耗', tooltip: "文本_单抽消耗" }) txtCostOne: Label = null;
- @property({ type: Label, displayName: '文本_十连抽实际消耗', tooltip: "文本_十连抽实际消耗" }) txtCostTen: Label = null;
- @property({ type: Label, displayName: '文本_十连抽原价消耗', tooltip: "文本_十连抽原价消耗" }) txtCostTenOld: Label = null;
- @property({ type: OpenWindow, displayName: '打开界面', tooltip: "打开界面" }) openWnd: OpenWindow = null;
- private serverConfig;
- private recruitData: RecruitData;
- private isCanRecruit: boolean = true;
- private userData: UserData;
- onLoad() {
- this.recruitData = DataSystem.createData(RecruitData);
- let openEventHandler = new EventHandler();
- openEventHandler.target = this.node;
- openEventHandler.component = "RecruitUI";
- openEventHandler.handler = "onRecruitEvent";
- this.openWnd.onClosing.push(openEventHandler);
- }
- start() {
- this.initPanel();
- }
- update() {
- DataSystem.watch(RecruitData, "curWishId") && this.updateWish();
- DataSystem.watch(UserData, "diamond") && this.updateDiamond();
- DataSystem.watch(NoviceGuideData, "isRecruit") && this.recruitHero();
- }
- private async initPanel() {
- this.userData = DataSystem.getData(UserData);
- this.serverConfig = DataSystem.getData(ConfigData).get("serverConfig");
- this.updateDiamond();
- //判断是否有选中的心愿武将
- this.getWishGeneral();
- }
- /**查询心愿武将*/
- private async getWishGeneral() {
- let result = await this.getComponent(Http).send("/api/recruit/getWish");
- if (result && result.code == HttpResponseCode.Success) {
- this.recruitData.curWishId = result.data.heroID;
- this.recruitData.wishHeroRate = result.data.up;
- this.updateWish();
- }
- }
- /**
- * 更新心愿武将信息
- */
- private async updateWish() {
- let heroDataOne;
- if (this.recruitData.curWishId > 0) {
- heroDataOne = DataSystem.getData(ConfigData).get("general")[this.recruitData.curWishId] as Hero_Client;
- this.spineLight.setAnimation(0, "animation", false);
- this.imgWish.spriteFrame = await this.res.load<SpriteFrame>("images/general/texture/head_img/" + heroDataOne.hero_res + "/spriteFrame", SpriteFrame);
- this.imgWishCamp.spriteFrame = await this.res.load<SpriteFrame>("images/general/texture/icon_camp_" + heroDataOne.camp + "/spriteFrame", SpriteFrame);
- }
- this.imgWish.node.active = this.recruitData.curWishId > 0;
- this.wishRect.active = this.recruitData.curWishId <= 0;
- this.txtName.string = this.recruitData.curWishId > 0 ? heroDataOne.name + "" : "指定武将";
- this.txtRate.string = this.recruitData.curWishId > 0 ? DataSystem.getData(RecruitData).wishHeroRate + "倍" : "";
- }
- /**更新货币*/
- private updateDiamond() {
- this.txtDiamond.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);
- this.txtCostTenOld.string = this.serverConfig.recruit1 * 10 + "";
- }
- /**
- * 招募武将
- * @param recruitType 招募类型 1 一次 2 十次
- */
- private async recruitHero(recruitType: number = 1) {
- let param: any = {}; param.type = recruitType == 1 ? 1 : 2;
- let result = await this.getComponent(Http).send("/api/recruit/recruit", { num: recruitType == 1 ? 1 : 10 });
- //console.log("Recruit: ", result);
- if (result && result.code == HttpResponseCode.Success) {
- 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;
- param.data = result.data;//[{chip:0,id:121001}]
- this.openWnd.open(param);
- 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 onRecruitEvent() {
- console.log("Recruit General Opening");
- this.isCanRecruit = true;
- }
- /**更新武将数据*/
- private updateUserHeroData(data: any[]) {
- let userHeroData = DataSystem.getData(UserHeroData);
- 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 async updateMarshalSkillNotice() {
- await MarshalSkillSystem.updateNoticeQueue();
- }
- /**是否存在兑换元宝次数*/
- 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 async onClickDrawOne() {
- if (!this.isCanRecruit) return; this.isCanRecruit = false;
- if (this.userData.diamond >= this.serverConfig.recruit1) {
- this.recruitHero(1);
- } else {
- if (await this.isHaveExchangeTimes()) {
- WindowSystem.open("prefabs/ui/recruit/diamondExchange", WindowOpenMode.NotCloseAndAdd, ["5"]);
- this.isCanRecruit = true;
- } else {
- this.isCanRecruit = true;
- WindowSystem.showTips("元宝不足");
- }
- }
- }
- private async onClickDrawTen() {
- if (!this.isCanRecruit) return; this.isCanRecruit = false;
- if (this.userData.diamond >= this.serverConfig.recruit10) {
- this.recruitHero(2);
- } else {
- if (await this.isHaveExchangeTimes()) {
- WindowSystem.open("prefabs/ui/recruit/diamondExchange", WindowOpenMode.NotCloseAndAdd, ["5"]);
- this.isCanRecruit = true;
- } else {
- this.isCanRecruit = true;
- WindowSystem.showTips("元宝不足");
- }
- }
- }
- }
|