ChangeJob.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. const JobPageType = require('../utils/GameEnum').JobPageType;
  2. const JobApi = require('../net/JobApi');
  3. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  4. const jobLevelList = require('../data/jobLevel');
  5. const jobList = require('../data/job');
  6. const cardList = require('../data/item');
  7. const GameModule = require('../utils/GameModule');
  8. cc.Class({
  9. extends: cc.Component,
  10. properties: {
  11. titleText: cc.RichText,
  12. confirmButton: cc.Button,
  13. confirmText: cc.RichText,
  14. pageView: cc.PageView,
  15. levelUpNode: cc.Node,
  16. bgNode: cc.Node,
  17. top: cc.Node,
  18. consume: cc.Node,
  19. user: cc.Node,
  20. myActorList: [],
  21. changeJobSuccessPrefab: cc.Prefab,
  22. levelUpSuccessPrefab: cc.Prefab,
  23. failPrefab: cc.Prefab,
  24. tipsNode: cc.Node,
  25. tipsLabel: cc.Label,
  26. },
  27. // LIFE-CYCLE CALLBACKS:
  28. onLoad() {
  29. this.node.height = cc.view.getVisibleSize().height;
  30. if (cc.view.getVisibleSize().height >= 1624) {
  31. this.top.getComponent(cc.Widget).top = 50;
  32. this.bgNode.getComponent(cc.Widget).top = -50;
  33. // this.informationNode.getComponent(cc.Widget).top = 185;
  34. // this.infoTop = 185;
  35. }
  36. this.consume.getComponent('Consume').setConfirmButton(this.confirmButton);
  37. },
  38. start() {
  39. },
  40. showFromTalent(type, actors) {
  41. this.myActorList = actors;
  42. this.show(type, this.myActorList.pop(), 0);
  43. },
  44. show(type, actorInfo, zIndex) {
  45. this.type = type;
  46. this.actorInfo = actorInfo;
  47. this.node.parent = cc.find('Canvas');
  48. this.node.active = true;
  49. this.node.zIndex = zIndex + 1;
  50. switch (type) {
  51. case JobPageType.ChangeJob:
  52. this.changeJob();
  53. break;
  54. case JobPageType.ChooseJob:
  55. this.chooseJob(actorInfo);
  56. break;
  57. case JobPageType.LevelUp:
  58. this.levelUp();
  59. break;
  60. }
  61. },
  62. changeJob() {
  63. this.consume.active = true;
  64. this.user.active = false;
  65. this.pageView.node.active = true;
  66. this.levelUpNode.active = false;
  67. this.pageView.getComponent('PVCtrl').bind(this.actorInfo.jobId, this.actorInfo.gender);
  68. this.titleText.string = '<b>职业转换</b>';
  69. this.confirmText.string = '<outline color=#690802 width=1><b>转职</b></outline>';
  70. this.pageViewScript = this.pageView.getComponent('PVCtrl');
  71. JobApi.changeJobList(this.actorInfo.uid,
  72. (response) => {
  73. this.userPack = response.userPack;
  74. this.bindChangeJobComsume(this.pageViewScript.getSelectedJob());
  75. },
  76. (code, msg) => {
  77. this.showTips('网络错误');
  78. }
  79. );
  80. },
  81. bindChangeJobComsume(selectedJob) {
  82. let needCard = '';
  83. let itemKey = Object.keys(selectedJob.itemInfo)[0];
  84. cardList.forEach((cardInfo) => {
  85. if (cardInfo.id == itemKey) {
  86. needCard = cardInfo;
  87. needCard.number = selectedJob.itemInfo[itemKey];
  88. }
  89. });
  90. this.pageViewScript.bindSelectedJobText();
  91. this.consume.getComponent('Consume').bindChangeJob(selectedJob.gold, needCard, this.userPack);
  92. },
  93. chooseJob() {
  94. this.consume.active = false;
  95. this.user.active = true;
  96. this.pageView.node.active = true;
  97. this.levelUpNode.active = false;
  98. this.pageView.getComponent('PVCtrl').bind(0, this.actorInfo.gender);
  99. this.titleText.string = '<b>选择职业</b>';
  100. this.confirmText.string = '<outline color=#690802 width=1><b>确定</b></outline>';
  101. this.pageViewScript = this.pageView.getComponent('PVCtrl');
  102. this.pageViewScript.bindSelectedJobText();
  103. this.bindChooseJob(this.actorInfo);
  104. },
  105. levelUp() {
  106. this.consume.active = true;
  107. this.user.active = false;
  108. this.pageView.node.active = false;
  109. this.levelUpNode.active = true;
  110. this.titleText.string = '<b>进阶</b>';
  111. this.confirmText.string = '<outline color=#690802 width=1><b>进阶</b></outline>';
  112. this.currentJobLevel = null;
  113. this.nextJobLevel = null;
  114. for (var i = 0; i < jobLevelList.length; i++) {
  115. let jobLevelInfo = jobLevelList[i];
  116. if (this.actorInfo.jobId === jobLevelInfo.jobId && this.actorInfo.jobLevel === jobLevelInfo.level) {
  117. this.currentJobLevel = jobLevelInfo;
  118. if (i >= jobLevelList.length - 1) {
  119. return;
  120. }
  121. this.nextJobLevel = jobLevelList[i + 1];
  122. this.spend = this.nextJobLevel.salary;
  123. }
  124. }
  125. let needCard = '';
  126. let itemKey = Object.keys(this.nextJobLevel.itemInfo)[0];
  127. cardList.forEach((cardInfo) => {
  128. if (cardInfo.id == itemKey) {
  129. needCard = cardInfo;
  130. needCard.number = this.nextJobLevel.itemInfo[itemKey];
  131. }
  132. });
  133. this.upgradeName = this.nextJobLevel.name;
  134. this.upgradeLevel = this.nextJobLevel.level;
  135. let self = this;
  136. JobApi.levelUpInfo(this.actorInfo.uid,
  137. (response) => {
  138. this.consume.getComponent('Consume').bindDataLevelUp(self.nextJobLevel.salary, needCard, response.userPack);
  139. this.levelUpNode.getComponent('LevelUp').bind(self.actorInfo, self.nextJobLevel, response.wish);
  140. },
  141. (code, msg) => {
  142. this.showTips('网络错误');
  143. }
  144. );
  145. },
  146. confirmClick() {
  147. switch (this.type) {
  148. case JobPageType.ChangeJob:
  149. var job = this.pageView.getComponent('PVCtrl').getSelectedJob();
  150. this.spend = job.gold;
  151. JobApi.changeJob(this.actorInfo.uid, job.id,
  152. (response, msg) => {
  153. this.onChangeJobSuccess(msg);
  154. GameModule.audioMng.playSignSuccess();
  155. },
  156. (code, msg) => {
  157. this.onFail(msg);
  158. GameModule.audioMng.playSignFail();
  159. });
  160. break;
  161. case JobPageType.ChooseJob:
  162. var job = this.pageView.getComponent('PVCtrl').getSelectedJob();
  163. JobApi.chooseJob(this.actorInfo.uid, job.id,
  164. (response) => {
  165. GameModule.audioMng.playSignSuccess();
  166. this.onFail('选择成功', () => {
  167. this.nextChoose();
  168. });
  169. },
  170. (code, msg) => {
  171. this.onFail(msg);
  172. GameModule.audioMng.playSignFail();
  173. });
  174. break;
  175. case JobPageType.LevelUp:
  176. JobApi.levelUp(this.actorInfo.uid,
  177. (response) => {
  178. this.onLevelUpSuccess();
  179. GameModule.audioMng.playSignSuccess();
  180. },
  181. (code, msg) => {
  182. this.onFail(msg);
  183. GameModule.audioMng.playSignFail();
  184. });
  185. break;
  186. }
  187. },
  188. close() {
  189. GameEvent.fire(GameNotificationKey.RefreshFriendList);
  190. this.node.zIndex = 0;
  191. this.node.destroy();
  192. },
  193. nextChoose() {
  194. if (this.myActorList && this.myActorList.length > 0) {
  195. this.actorInfo = this.myActorList.pop();
  196. this.bindChooseJob();
  197. } else {
  198. this.close();
  199. GameEvent.fire(GameNotificationKey.RefreshUserInformation);
  200. }
  201. },
  202. bindChooseJob() {
  203. this.user.getComponent('Actor').bind(this.actorInfo);
  204. },
  205. onChangeJobSuccess(msg) {
  206. GameModule.userInfo.grossIncome -= this.spend;
  207. let self = this;
  208. let targetJob = this.pageViewScript.getSelectedJob();
  209. let lastJob = null;
  210. jobList.forEach(jobInfo => {
  211. if (jobInfo.id === this.actorInfo.jobId) {
  212. lastJob = jobInfo;
  213. }
  214. });
  215. this.changeJobSuccess = cc.instantiate(this.changeJobSuccessPrefab);
  216. this.changeJobSuccess = this.changeJobSuccess.getComponent('ChangeJobSuccess');
  217. this.changeJobSuccess.show(this.node, lastJob, targetJob, () => {
  218. self.close();
  219. });
  220. GameEvent.fire(GameNotificationKey.RefreshUserInformation);
  221. GameEvent.fire(GameNotificationKey.PlaySuccessAnimation);
  222. },
  223. onLevelUpSuccess() {
  224. GameModule.userInfo.grossIncome -= this.spend;
  225. let self = this;
  226. this.levelUpSuccess = cc.instantiate(this.levelUpSuccessPrefab);
  227. this.levelUpSuccess = this.levelUpSuccess.getComponent('JobLevelUpSuccess');
  228. this.levelUpSuccess.show(this.node, '进阶成功', '恭喜你的艺人进阶成为:', this.upgradeLevel, this.upgradeName, () => {
  229. self.close();
  230. });
  231. GameEvent.fire(GameNotificationKey.RefreshUserInformation);
  232. GameEvent.fire(GameNotificationKey.PlaySuccessAnimation);
  233. },
  234. onFail(msg, callback) {
  235. this.fail = cc.instantiate(this.failPrefab);
  236. this.fail = this.fail.getComponent('JobPageFail');
  237. this.fail.show(this.node, msg, callback);
  238. },
  239. setNeedChooseJobUsers(users) {
  240. this.myActorList = users;
  241. },
  242. pageviewChangeEvent() {
  243. if (this.type === JobPageType.ChangeJob) {
  244. this.bindChangeJobComsume(this.pageViewScript.getSelectedJob());
  245. } else if (this.type === JobPageType.ChooseJob) {
  246. this.pageViewScript.bindSelectedJobText();
  247. }
  248. },
  249. showTips(text) {
  250. this.tipsNode.active = true;
  251. this.tipsLabel.string = text;
  252. this.scheduleOnce(() => {
  253. this.tipsNode.active = false;
  254. }, 2);
  255. }
  256. // update (dt) {},
  257. });