ManageWorker.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. ManageAI: cc.Node,
  5. GoldLabel: cc.Node,
  6. DiamondLabel: cc.Node,
  7. LV: cc.Node,
  8. MaxWorkLV: cc.Node,
  9. WorkerNum: cc.Node,
  10. WorkerCapacity: cc.Node,
  11. PhysicalStrength: cc.Node,
  12. Labor: cc.Node,
  13. Wages: cc.Node,
  14. RecruitCost: cc.Node,
  15. UpGradeCost: cc.Node,
  16. // //工人容量值
  17. // workerCapacity: { default: 32, type: cc.Integer, tooltip: '可招聘工人最大值' },
  18. //“管理”界面的招聘进度条 Recruit
  19. ManagementProgressBar_Recruit: {
  20. default: null,
  21. type: cc.Node,
  22. },
  23. //“管理”界面的培训进度条
  24. ManagementProgressBar_Train: {
  25. default: null,
  26. type: cc.Node,
  27. },
  28. AlertUIView: cc.Node
  29. },
  30. start() {
  31. // this.InitWorkerAI();
  32. },
  33. InitWorkerAI: function () {
  34. //体力 劳动力 薪资 培训费用
  35. this.WorkerLVPropertyJSON = [
  36. { "PhysicalStrength": "50", "Labor": "5", "Wages": "50", "UpgradeCost": "20", "MoveSpeed": "100" },
  37. { "PhysicalStrength": "55", "Labor": "7", "Wages": "100", "UpgradeCost": "50", "MoveSpeed": "120" },
  38. { "PhysicalStrength": "60", "Labor": "9", "Wages": "200", "UpgradeCost": "100", "MoveSpeed": "140" },
  39. { "PhysicalStrength": "65", "Labor": "11", "Wages": "300", "UpgradeCost": "500", "MoveSpeed": "160" },
  40. { "PhysicalStrength": "70", "Labor": "13", "Wages": "400", "UpgradeCost": "1000", "MoveSpeed": "180" },
  41. { "PhysicalStrength": "75", "Labor": "15", "Wages": "500", "UpgradeCost": "1500", "MoveSpeed": "200" },
  42. { "PhysicalStrength": "80", "Labor": "17", "Wages": "600", "UpgradeCost": "2000", "MoveSpeed": "220" },
  43. { "PhysicalStrength": "85", "Labor": "18", "Wages": "700", "UpgradeCost": "2500", "MoveSpeed": "240" },
  44. { "PhysicalStrength": "90", "Labor": "19", "Wages": "800", "UpgradeCost": "3000", "MoveSpeed": "260" },
  45. { "PhysicalStrength": "100", "Labor": "20", "Wages": "900", "UpgradeCost": "0", "MoveSpeed": "280" },
  46. ];
  47. this.WorkerNum.getComponent(cc.Label).string = GlobalD.GameData.GetWorkerNum();
  48. //容量是定死的值,不用存储,也不用读取
  49. this.WorkerCapacity.getComponent(cc.Label).string = GlobalD.GameData.GetWorkerCapacity();
  50. this.SetBar_RecruitLength(GlobalD.GameData.GetWorkerNum() / GlobalD.GameData.GetWorkerCapacity());
  51. this.LV.getComponent(cc.Label).string = GlobalD.GameData.GetWorkerLV() + 1;
  52. this.MaxWorkLV.getComponent(cc.Label).string = this.WorkerLVPropertyJSON.length;
  53. this.SetBar_TrainLength((GlobalD.GameData.GetWorkerLV() + 1) / this.WorkerLVPropertyJSON.length);
  54. let CurrentGradeJson = this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()];
  55. this.PhysicalStrength.getComponent(cc.Label).string = CurrentGradeJson.PhysicalStrength;
  56. this.Labor.getComponent(cc.Label).string = CurrentGradeJson.Labor;
  57. this.Wages.getComponent(cc.Label).string = CurrentGradeJson.Wages;
  58. this.RecruitCost.getComponent(cc.Label).string = CurrentGradeJson.Wages;
  59. this.UpGradeCost.getComponent(cc.Label).string = CurrentGradeJson.UpgradeCost;
  60. this._ManageAI = this.ManageAI.getComponent('ManageAI');
  61. this._ManageAI.InitCurrentGradeJson = CurrentGradeJson;
  62. //生成存储的工人数据
  63. this._ManageAI.onSpawnWorkerAIFromStoredData();
  64. // cc.log('工人');
  65. },
  66. //招聘
  67. onRecruit: function () {
  68. if (task.TaskIconCountClick == 1) {
  69. //现在关掉招聘的 页面 弹出对话框 提示 要点击建造
  70. task.managerUi.onButtonEvent_Personnel_Close();
  71. var Canvas = cc.find("Canvas/UICamera");
  72. //移动camera 对应位置
  73. cc.find('GameNode/ManageTask').getComponent('ManageTask').onMoveToTiledTile(29, 20);
  74. dialogmanager.init(Canvas, function () {
  75. dialogmanager.pickUp(dialogmanager.dialogue[30]);
  76. }.bind(this));
  77. dialogmanager.setOnCloseDialog(function () {
  78. task.removeTaskNode(task.taskCursorName[3]);
  79. task._setTaskIconCountClick(12);
  80. setTimeout(() => {
  81. task.taskCallBack();
  82. }, 500);
  83. }.bind(this));
  84. }
  85. if (GlobalD.GameData.GetWorkerNum() + 1 > GlobalD.GameData.GetWorkerCapacity()) {
  86. cc.loader.loadRes('resUI/ShowNotEnoughMoney', function (err, texture) {
  87. var prefab = cc.instantiate(texture);
  88. prefab.getComponent('ShowNotEnoughMoney').Text('超员了!!');
  89. this.AlertUIView.addChild(prefab);
  90. }.bind(this));
  91. return;
  92. }
  93. if (GlobalD.GameData.GetGolden() < parseInt(this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()].Wages)) {
  94. cc.loader.loadRes('resUI/ShowNotEnoughMoney', function (err, texture) {
  95. var prefab = cc.instantiate(texture);
  96. prefab.getComponent('ShowNotEnoughMoney').Text('金币不足!!');
  97. this.AlertUIView.addChild(prefab);
  98. }.bind(this));
  99. return;
  100. }
  101. GlobalD.GameData.PlusGolden(-parseInt(this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()].Wages));
  102. GlobalD.GameData.PlusWorkerNum(1);
  103. this.WorkerNum.getComponent(cc.Label).string = GlobalD.GameData.GetWorkerNum();
  104. this._ManageAI.onSpawnWorkerAI();
  105. this.SetBar_RecruitLength(GlobalD.GameData.GetWorkerNum() / GlobalD.GameData.GetWorkerCapacity());
  106. },
  107. Building_t: function () {
  108. var Canvas = cc.find("Canvas/UICamera");
  109. var Building = cc.find("Canvas/UICamera/BelowTheMask/Building");
  110. task.addTaskTips(Canvas, task.taskPrefab[6], 0, 0, task.taskCursorName[1], function (nodePrefabs1) {
  111. UtilsPrefabs.setOn(nodePrefabs1.getChildByName("SureBtn"), function () {
  112. task.removeTaskNode(task.taskCursorName[1]);
  113. task.addTaskTips(Building, task.taskPrefab[1], -50, -50, task.taskCursorName[0], function (nodePrefabs) {
  114. }.bind(this));
  115. }.bind(this))
  116. }.bind(this));
  117. },
  118. //解雇
  119. onFire: function () {
  120. if (GlobalD.GameData.GetWorkerNum() - 1 < 0) return;
  121. if (this._ManageAI.onRemoveWorkerAI()) {
  122. //如果成功删除AI
  123. GlobalD.GameData.PlusWorkerNum(-1);
  124. this.WorkerNum.getComponent(cc.Label).string = GlobalD.GameData.GetWorkerNum();
  125. }
  126. },
  127. onFireNum() {
  128. this.FirePerson(5);
  129. },
  130. FirePerson: function (num) {
  131. if (GlobalD.GameData.GetWorkerNum() - num < 0) {
  132. num = GlobalD.GameData.GetWorkerNum();
  133. }
  134. //不需要解雇
  135. if (num <= 0) return;
  136. if (this.AutoFireWorker)
  137. this.unschedule(this.AutoFireWorker);
  138. //自动存储数据
  139. this.AutoFireWorker = function () {
  140. if (num <= 0) return;
  141. for (let i = 0; i < num; i++) {
  142. //只能解雇可以解雇状态下的工人
  143. if (this._ManageAI.onRemoveWorkerAI()) {
  144. //如果成功删除AI
  145. GlobalD.GameData.PlusWorkerNum(-1);
  146. this.WorkerNum.getComponent(cc.Label).string = GlobalD.GameData.GetWorkerNum();
  147. num--;
  148. }
  149. }
  150. }
  151. this.schedule(this.AutoFireWorker, 0.5);
  152. },
  153. //培训
  154. onUpgrade: function () {
  155. if (this.WorkerLVPropertyJSON.length - 2 < GlobalD.GameData.GetWorkerLV()) return;
  156. let CurrentGradeJson = this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()];
  157. let UpgradeCost = CurrentGradeJson.UpgradeCost;
  158. if (GlobalD.GameData.GetDiamond() < UpgradeCost) {
  159. cc.loader.loadRes('resUI/ShowNotEnoughMoney', function (err, texture) {
  160. var prefab = cc.instantiate(texture);
  161. prefab.getComponent('ShowNotEnoughMoney').Text('钻石不足!!');
  162. this.AlertUIView.addChild(prefab);
  163. }.bind(this));
  164. return;
  165. }
  166. GlobalD.GameData.PlusDiamond(-UpgradeCost);
  167. // this.GoldLabel.getComponent(cc.Label).string = GlobalD.GameData.GetDiamond();
  168. this.DiamondLabel.getComponent(cc.Label).string = GlobalD.GameData.GetDiamond();
  169. GlobalD.GameData.PlusWorkerLV(1);
  170. this.LV.getComponent(cc.Label).string = GlobalD.GameData.GetWorkerLV() + 1;
  171. CurrentGradeJson = this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()];
  172. this.PhysicalStrength.getComponent(cc.Label).string = CurrentGradeJson.PhysicalStrength;
  173. this.Labor.getComponent(cc.Label).string = CurrentGradeJson.Labor;
  174. this.Wages.getComponent(cc.Label).string = CurrentGradeJson.Wages;
  175. GlobalD.GameData.SetWorkerCapacity(CurrentGradeJson.Labor);
  176. this.WorkerCapacity.getComponent(cc.Label).string = CurrentGradeJson.Labor;
  177. //修改全体人物属性
  178. this._ManageAI.InitCurrentGradeJson = CurrentGradeJson;
  179. this._ManageAI.onUpgradeAllWorker();
  180. this.SetBar_TrainLength((GlobalD.GameData.GetWorkerLV() + 1) / this.WorkerLVPropertyJSON.length);
  181. this.SetBar_RecruitLength(GlobalD.GameData.GetWorkerNum() / GlobalD.GameData.GetWorkerCapacity());
  182. this.RecruitCost.getComponent(cc.Label).string = CurrentGradeJson.Wages;
  183. this.UpGradeCost.getComponent(cc.Label).string = CurrentGradeJson.UpgradeCost;
  184. },
  185. onDegrade: function () {
  186. if (GlobalD.GameData.GetWorkerLV() - 1 < 0) return;
  187. GlobalD.GameData.PlusWorkerLV(-1);
  188. this.LV.getComponent(cc.Label).string = GlobalD.GameData.GetWorkerLV() + 1;
  189. let CurrentGradeJson = this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()];
  190. CurrentGradeJson = this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()];
  191. this.PhysicalStrength.getComponent(cc.Label).string = CurrentGradeJson.PhysicalStrength;
  192. this.Labor.getComponent(cc.Label).string = CurrentGradeJson.Labor;
  193. this.Wages.getComponent(cc.Label).string = CurrentGradeJson.Wages;
  194. GlobalD.GameData.SetWorkerCapacity(CurrentGradeJson.Labor);
  195. this.WorkerCapacity.getComponent(cc.Label).string = CurrentGradeJson.Labor;
  196. //修改全体人物属性
  197. this._ManageAI.InitCurrentGradeJson = CurrentGradeJson;
  198. this._ManageAI.onUpgradeAllWorker();
  199. this.SetBar_TrainLength((GlobalD.GameData.GetWorkerLV() + 1) / this.WorkerLVPropertyJSON.length);
  200. this.SetBar_RecruitLength(GlobalD.GameData.GetWorkerNum() / GlobalD.GameData.GetWorkerCapacity());
  201. },
  202. //招聘进度条
  203. SetBar_RecruitLength: function (BarLength) {//BarLength(0~1,float)
  204. this.ManagementProgressBar_Recruit.getComponent(cc.ProgressBar).progress = BarLength;
  205. },
  206. //培训进度条
  207. SetBar_TrainLength: function (BarLength) {//BarLength(0~1,float)
  208. this.ManagementProgressBar_Train.getComponent(cc.ProgressBar).progress = BarLength;
  209. },
  210. });