| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- import { _decorator, Component, Node, Enum, ToggleContainer, Label } from 'cc';
- import { Battle } from '../battle/Battle';
- import { BattleData } from '../battle/BattleData';
- import { Data } from '../core/data/Data';
- import { DataSystem } from '../core/data/DataSystem';
- import { PageView } from '../core/page/PageView';
- import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
- import { WindowSystem } from '../core/ui/window/WindowSystem';
- import { ConfigData } from '../data/ConfigData';
- import { UserData } from '../data/UserData';
- import { FormationData } from '../hero/formation/FormationData';
- import { UserHeroData } from '../hero/UserHeroData';
- import { NoviceGuideData } from './NoviceGuideData';
- const { ccclass, property } = _decorator;
- /**
- * 引导类型
- */
- export enum GuideType {
- Train,//训练
- Formation,//阵位
- Barrack,//兵营
- Recruit,//点将
- HopeHero,//心愿武将
- Marshal//统帅位
- }
- /**新手引导 */
- @ccclass('NoviceGuide')
- export class NoviceGuide extends Component {
- @property({
- type: Enum(GuideType),
- tooltip: "引导类型:\nTrain:训练引导\nFormation:上阵引导\n"
- })
- type: GuideType = GuideType.Train;
- @property({ tooltip: "关卡等级" }) mission: number = 0;
- @property({ type: [Node], tooltip: "新手引导节点集合" }) novices: Array<Node> = [];
- @property({ type: Node, tooltip: "背景节点" }) bgNode: Node;
- @property({ type: Node, tooltip: "背景节点" }) heroUI: Node;
- @property({ type: Node, tooltip: "手型特效节点" }) handNode: Node;
- @property({ type: ToggleContainer, tooltip: "手型特效节点" }) campGroup: ToggleContainer;
- @property({ type: Node, tooltip: "点将台按钮节点" }) recruitNode: Node;
- @property({ type: Label, tooltip: "点将台元宝节点" }) diamondLabel: Label;
- private index = 0;
- private trainConsume;
- private starting = false;
- update() {
- DataSystem.watch(BattleData, 'mission') && this.checkGuide();
- DataSystem.watch(UserData, 'campLv') && this.checkBarrack();
- DataSystem.watch(NoviceGuideData, 'openRecuitWish') && this.checkHopeHero();
- DataSystem.watch(NoviceGuideData, 'changeHero') && this.changeHero();
- DataSystem.watch(NoviceGuideData, 'openBattleResult') && this.checkBarracks();
- DataSystem.watch(NoviceGuideData, 'openMarshal') && this.setMarshal();
- DataSystem.watch(NoviceGuideData, 'openMarshalSkill') && this.setMarshal();
- DataSystem.watch(NoviceGuideData, 'skipBarracks') && (this.type == GuideType.Barrack && this.onClose());
- this.watchFormation(1);
- this.watchFormation(2);
- }
- watchFormation(formationID: number) {
- if (this.starting && DataSystem.watch(FormationData, formationID)) {
- this.starting = false;
- this.next();
- }
- }
- checkBarrack() {
- if (this.type == GuideType.Barrack && this.index != 0) {
- this.onClose();
- }
- }
- /**检测心愿武将引导 */
- checkHopeHero() {
- if (this.type == GuideType.HopeHero) {
- if (localStorage.getItem("NoviceGuideHopeHero" + DataSystem.getData(UserData).account)) {
- this.node.destroy();
- return;
- }
- localStorage.setItem("NoviceGuideHopeHero" + DataSystem.getData(UserData).account, '1');
- this.show();
- }
- }
- changeHero() {
- if (this.type == GuideType.HopeHero) {
- this.next();
- }
- }
- /***
- * 检测兵营引导
- */
- private checkBarracks() {
- if (this.type == GuideType.Barrack) {
- if (localStorage.getItem("NoviceGuideBarracks" + DataSystem.getData(UserData).account)) {
- this.node.destroy();
- return;
- }
- localStorage.setItem("NoviceGuideBarracks" + DataSystem.getData(UserData).account, '1');
- this.show();
- }
- }
- /** 关卡等级检测引导*/
- private checkGuide() {
- if (DataSystem.getData(BattleData).mission != this.mission) {
- return;
- }
- if (localStorage.getItem("NoviceGuide" + DataSystem.getData(UserData).account + this.mission)) {//已远成引导
- this.node.destroy();
- return;
- }
- switch (this.type) {
- case GuideType.Train:
- if (DataSystem.getData(BattleData).mission == this.mission) {
- localStorage.setItem("NoviceGuide" + DataSystem.getData(UserData).account + this.mission, '1');
- this.trainConsume = DataSystem.getData(ConfigData).get('serverConfig').trainConsume;
- if (DataSystem.getData(UserData).money < this.trainConsume) {
- this.node.destroy();
- return;
- }
- }
- break;
- case GuideType.Formation:
- this.starting = true;
- break;
- case GuideType.Recruit:
- this.recruitNode.active = true;
- break;
- case GuideType.Marshal:
- break;
- default: return;
- }
- localStorage.setItem("NoviceGuide" + DataSystem.getData(UserData).account + this.mission, '1');
- WindowSystem.getWindowList().length > 0 ? this.onClose() : this.show();
- }
- /**
- * 阵位
- */
- private setFormation() {
- if (this.heroUI && this.index == 1) {
- this.heroUI.active = true;
- let hero = DataSystem.getData(BattleData).heros.get(1);
- let camp = DataSystem.getData(UserHeroData).get(hero.id).client.camp;
- this.scheduleOnce(() => {
- this.campGroup.toggleItems[parseInt(camp + "") - 1].isChecked = true;
- });
- } else if (this.heroUI && this.index == 2) {
- this.handNode.active = false;
- }
- }
- /**
- * 训练武将
- */
- public onTrain() {
- DataSystem.getData(NoviceGuideData).isTrain = true;
- if (DataSystem.getData(UserData).money < this.trainConsume * 2) {
- this.node.destroy();
- return;
- }
- this.next();
- }
- /**
- * 打开兵营
- */
- private async setBarracks() {
- if (this.index == 1) {
- await WindowSystem.open('prefabs/ui/barracks/barracks', WindowOpenMode.NotCloseAndAdd);
- DataSystem.getData(NoviceGuideData).openBarracks = true;
- }
- }
- /**
- * 打开点将台
- */
- private async setRecruit() {
- this.recruitNode.active = false;
- await WindowSystem.open('prefabs/ui/recruit/recruit', WindowOpenMode.NotCloseAndAdd);
- }
- /**
- * 点击招募
- */
- private onRecruit() {
- DataSystem.getData(NoviceGuideData).isRecruit = true;
- this.onClose();
- }
- /**
- * 打开统帅台
- */
- private async setMarshal() {
- if (this.type == GuideType.Marshal && this.index == 1) {
- this.next();
- }
- }
- /**
- * 更换心愿武将
- */
- private changeHopeHero() {
- DataSystem.getData(NoviceGuideData).isRecuitWish = true;
- this.onClose();
- }
- /**
- * 引导开始
- */
- private show() {
- if (DataSystem.getData(NoviceGuideData).isShow) {
- this.onClose();
- return;
- }
- DataSystem.getData(NoviceGuideData).isShow = true;
- this.bgNode && (this.bgNode.active = true);
- let userData = DataSystem.getData(UserData);
- this.diamondLabel && (this.diamondLabel.string = userData.diamond > 10000 ? (userData.diamond / 1000).toFixed(1) + "k" : userData.diamond + "");
- this.novices[this.index].active = true;
- }
- /**下一步 */
- public async next() {
- this.novices[this.index].active = false;
- if (this.novices[++this.index]) {
- this.type == GuideType.Formation && this.setFormation();
- this.type == GuideType.Barrack && await this.setBarracks();
- this.type == GuideType.Recruit && await this.setRecruit();
- // this.type == GuideType.Marshal && await this.setMarshal();
- this.novices[this.index].active = true;
- } else {
- this.onClose();
- }
- }
- /**
- * 关闭引导
- */
- public onClose() {
- this.recruitNode && (this.recruitNode.active = false);
- this.node.active = false;
- this.node.destroy();
- this.heroUI && this.heroUI.destroy();
- DataSystem.getData(NoviceGuideData).isShow = false;
- }
- }
|