NoviceGuide.ts 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import { _decorator, Component, Node, Enum, ToggleContainer, Label } from 'cc';
  2. import { Battle } from '../battle/Battle';
  3. import { BattleData } from '../battle/BattleData';
  4. import { Data } from '../core/data/Data';
  5. import { DataSystem } from '../core/data/DataSystem';
  6. import { PageView } from '../core/page/PageView';
  7. import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
  8. import { WindowSystem } from '../core/ui/window/WindowSystem';
  9. import { ConfigData } from '../data/ConfigData';
  10. import { UserData } from '../data/UserData';
  11. import { FormationData } from '../hero/formation/FormationData';
  12. import { UserHeroData } from '../hero/UserHeroData';
  13. import { NoviceGuideData } from './NoviceGuideData';
  14. const { ccclass, property } = _decorator;
  15. /**
  16. * 引导类型
  17. */
  18. export enum GuideType {
  19. Train,//训练
  20. Formation,//阵位
  21. Barrack,//兵营
  22. Recruit,//点将
  23. HopeHero,//心愿武将
  24. Marshal//统帅位
  25. }
  26. /**新手引导 */
  27. @ccclass('NoviceGuide')
  28. export class NoviceGuide extends Component {
  29. @property({
  30. type: Enum(GuideType),
  31. tooltip: "引导类型:\nTrain:训练引导\nFormation:上阵引导\n"
  32. })
  33. type: GuideType = GuideType.Train;
  34. @property({ tooltip: "关卡等级" }) mission: number = 0;
  35. @property({ type: [Node], tooltip: "新手引导节点集合" }) novices: Array<Node> = [];
  36. @property({ type: Node, tooltip: "背景节点" }) bgNode: Node;
  37. @property({ type: Node, tooltip: "背景节点" }) heroUI: Node;
  38. @property({ type: Node, tooltip: "手型特效节点" }) handNode: Node;
  39. @property({ type: ToggleContainer, tooltip: "手型特效节点" }) campGroup: ToggleContainer;
  40. @property({ type: Node, tooltip: "点将台按钮节点" }) recruitNode: Node;
  41. @property({ type: Label, tooltip: "点将台元宝节点" }) diamondLabel: Label;
  42. private index = 0;
  43. private trainConsume;
  44. private starting = false;
  45. update() {
  46. DataSystem.watch(BattleData, 'mission') && this.checkGuide();
  47. DataSystem.watch(UserData, 'campLv') && this.checkBarrack();
  48. DataSystem.watch(NoviceGuideData, 'openRecuitWish') && this.checkHopeHero();
  49. DataSystem.watch(NoviceGuideData, 'changeHero') && this.changeHero();
  50. DataSystem.watch(NoviceGuideData, 'openBattleResult') && this.checkBarracks();
  51. DataSystem.watch(NoviceGuideData, 'openMarshal') && this.setMarshal();
  52. DataSystem.watch(NoviceGuideData, 'openMarshalSkill') && this.setMarshal();
  53. DataSystem.watch(NoviceGuideData, 'skipBarracks') && (this.type == GuideType.Barrack && this.onClose());
  54. this.watchFormation(1);
  55. this.watchFormation(2);
  56. }
  57. watchFormation(formationID: number) {
  58. if (this.starting && DataSystem.watch(FormationData, formationID)) {
  59. this.starting = false;
  60. this.next();
  61. }
  62. }
  63. checkBarrack() {
  64. if (this.type == GuideType.Barrack && this.index != 0) {
  65. this.onClose();
  66. }
  67. }
  68. /**检测心愿武将引导 */
  69. checkHopeHero() {
  70. if (this.type == GuideType.HopeHero) {
  71. if (localStorage.getItem("NoviceGuideHopeHero" + DataSystem.getData(UserData).account)) {
  72. this.node.destroy();
  73. return;
  74. }
  75. localStorage.setItem("NoviceGuideHopeHero" + DataSystem.getData(UserData).account, '1');
  76. this.show();
  77. }
  78. }
  79. changeHero() {
  80. if (this.type == GuideType.HopeHero) {
  81. this.next();
  82. }
  83. }
  84. /***
  85. * 检测兵营引导
  86. */
  87. private checkBarracks() {
  88. if (this.type == GuideType.Barrack) {
  89. if (localStorage.getItem("NoviceGuideBarracks" + DataSystem.getData(UserData).account)) {
  90. this.node.destroy();
  91. return;
  92. }
  93. localStorage.setItem("NoviceGuideBarracks" + DataSystem.getData(UserData).account, '1');
  94. this.show();
  95. }
  96. }
  97. /** 关卡等级检测引导*/
  98. private checkGuide() {
  99. if (DataSystem.getData(BattleData).mission != this.mission) {
  100. return;
  101. }
  102. if (localStorage.getItem("NoviceGuide" + DataSystem.getData(UserData).account + this.mission)) {//已远成引导
  103. this.node.destroy();
  104. return;
  105. }
  106. switch (this.type) {
  107. case GuideType.Train:
  108. if (DataSystem.getData(BattleData).mission == this.mission) {
  109. localStorage.setItem("NoviceGuide" + DataSystem.getData(UserData).account + this.mission, '1');
  110. this.trainConsume = DataSystem.getData(ConfigData).get('serverConfig').trainConsume;
  111. if (DataSystem.getData(UserData).money < this.trainConsume) {
  112. this.node.destroy();
  113. return;
  114. }
  115. }
  116. break;
  117. case GuideType.Formation:
  118. this.starting = true;
  119. break;
  120. case GuideType.Recruit:
  121. this.recruitNode.active = true;
  122. break;
  123. case GuideType.Marshal:
  124. break;
  125. default: return;
  126. }
  127. localStorage.setItem("NoviceGuide" + DataSystem.getData(UserData).account + this.mission, '1');
  128. WindowSystem.getWindowList().length > 0 ? this.onClose() : this.show();
  129. }
  130. /**
  131. * 阵位
  132. */
  133. private setFormation() {
  134. if (this.heroUI && this.index == 1) {
  135. this.heroUI.active = true;
  136. let hero = DataSystem.getData(BattleData).heros.get(1);
  137. let camp = DataSystem.getData(UserHeroData).get(hero.id).client.camp;
  138. this.scheduleOnce(() => {
  139. this.campGroup.toggleItems[parseInt(camp + "") - 1].isChecked = true;
  140. });
  141. } else if (this.heroUI && this.index == 2) {
  142. this.handNode.active = false;
  143. }
  144. }
  145. /**
  146. * 训练武将
  147. */
  148. public onTrain() {
  149. DataSystem.getData(NoviceGuideData).isTrain = true;
  150. if (DataSystem.getData(UserData).money < this.trainConsume * 2) {
  151. this.node.destroy();
  152. return;
  153. }
  154. this.next();
  155. }
  156. /**
  157. * 打开兵营
  158. */
  159. private async setBarracks() {
  160. if (this.index == 1) {
  161. await WindowSystem.open('prefabs/ui/barracks/barracks', WindowOpenMode.NotCloseAndAdd);
  162. DataSystem.getData(NoviceGuideData).openBarracks = true;
  163. }
  164. }
  165. /**
  166. * 打开点将台
  167. */
  168. private async setRecruit() {
  169. this.recruitNode.active = false;
  170. await WindowSystem.open('prefabs/ui/recruit/recruit', WindowOpenMode.NotCloseAndAdd);
  171. }
  172. /**
  173. * 点击招募
  174. */
  175. private onRecruit() {
  176. DataSystem.getData(NoviceGuideData).isRecruit = true;
  177. this.onClose();
  178. }
  179. /**
  180. * 打开统帅台
  181. */
  182. private async setMarshal() {
  183. if (this.type == GuideType.Marshal && this.index == 1) {
  184. this.next();
  185. }
  186. }
  187. /**
  188. * 更换心愿武将
  189. */
  190. private changeHopeHero() {
  191. DataSystem.getData(NoviceGuideData).isRecuitWish = true;
  192. this.onClose();
  193. }
  194. /**
  195. * 引导开始
  196. */
  197. private show() {
  198. if (DataSystem.getData(NoviceGuideData).isShow) {
  199. this.onClose();
  200. return;
  201. }
  202. DataSystem.getData(NoviceGuideData).isShow = true;
  203. this.bgNode && (this.bgNode.active = true);
  204. let userData = DataSystem.getData(UserData);
  205. this.diamondLabel && (this.diamondLabel.string = userData.diamond > 10000 ? (userData.diamond / 1000).toFixed(1) + "k" : userData.diamond + "");
  206. this.novices[this.index].active = true;
  207. }
  208. /**下一步 */
  209. public async next() {
  210. this.novices[this.index].active = false;
  211. if (this.novices[++this.index]) {
  212. this.type == GuideType.Formation && this.setFormation();
  213. this.type == GuideType.Barrack && await this.setBarracks();
  214. this.type == GuideType.Recruit && await this.setRecruit();
  215. // this.type == GuideType.Marshal && await this.setMarshal();
  216. this.novices[this.index].active = true;
  217. } else {
  218. this.onClose();
  219. }
  220. }
  221. /**
  222. * 关闭引导
  223. */
  224. public onClose() {
  225. this.recruitNode && (this.recruitNode.active = false);
  226. this.node.active = false;
  227. this.node.destroy();
  228. this.heroUI && this.heroUI.destroy();
  229. DataSystem.getData(NoviceGuideData).isShow = false;
  230. }
  231. }