ManageWorker.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. task.showManagerhide();
  72. var Canvas = cc.find("Canvas/UICamera");
  73. //移动camera 对应位置
  74. cc.find('GameNode/ManageTask').getComponent('ManageTask').onMoveToTiledTile(16, 16);
  75. //招聘了人马上设置对应的数
  76. task.TaskIconCountClick = -1;
  77. dialogmanager.init(Canvas, function () {
  78. dialogmanager.pickUp(dialogmanager.dialogue[30]);
  79. }.bind(this));
  80. dialogmanager.setOnCloseDialog(function () {
  81. task.removeTaskNode(task.taskCursorName[3]);
  82. // task._setTaskIconCountClick(12);
  83. // task._setTaskIconCountClick(13);
  84. // setTimeout(() => {
  85. // task.taskCallBack();
  86. // }, 500);
  87. //建房子
  88. GlobalD.ManageTask.onInitGameStartTask();
  89. }.bind(this));
  90. }
  91. if (GlobalD.GameData.GetWorkerNum() + 1 > GlobalD.GameData.GetWorkerCapacity()) {
  92. cc.loader.loadRes('resUI/ShowNotEnoughMoney', function (err, texture) {
  93. var prefab = cc.instantiate(texture);
  94. prefab.getComponent('ShowNotEnoughMoney').Text('超员了!!');
  95. this.AlertUIView.addChild(prefab);
  96. }.bind(this));
  97. return;
  98. }
  99. if (GlobalD.GameData.GetGolden() < parseInt(this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()].Wages)) {
  100. cc.loader.loadRes('resUI/ShowNotEnoughMoney', function (err, texture) {
  101. var prefab = cc.instantiate(texture);
  102. prefab.getComponent('ShowNotEnoughMoney').Text('金币不足!!');
  103. this.AlertUIView.addChild(prefab);
  104. }.bind(this));
  105. return;
  106. }
  107. GlobalD.GameData.PlusGolden(-parseInt(this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()].Wages));
  108. GlobalD.GameData.PlusWorkerNum(1);
  109. this.WorkerNum.getComponent(cc.Label).string = GlobalD.GameData.GetWorkerNum();
  110. this._ManageAI.onSpawnWorkerAI();
  111. this.SetBar_RecruitLength(GlobalD.GameData.GetWorkerNum() / GlobalD.GameData.GetWorkerCapacity());
  112. },
  113. Building_t: function () {
  114. var Canvas = cc.find("Canvas/UICamera");
  115. var Building = cc.find("Canvas/UICamera/BelowTheMask/Building");
  116. task.addTaskTips(Canvas, task.taskPrefab[6], 0, 0, task.taskCursorName[1], function (nodePrefabs1) {
  117. UtilsPrefabs.setOn(nodePrefabs1.getChildByName("SureBtn"), function () {
  118. task.removeTaskNode(task.taskCursorName[1]);
  119. task.addTaskTips(Building, task.taskPrefab[1], -50, -50, task.taskCursorName[0], function (nodePrefabs) {
  120. }.bind(this));
  121. }.bind(this))
  122. }.bind(this));
  123. },
  124. //解雇
  125. onFire: function () {
  126. if (GlobalD.GameData.GetWorkerNum() - 1 < 0) return;
  127. if (this._ManageAI.onRemoveWorkerAI()) {
  128. //如果成功删除AI
  129. GlobalD.GameData.PlusWorkerNum(-1);
  130. this.WorkerNum.getComponent(cc.Label).string = GlobalD.GameData.GetWorkerNum();
  131. }
  132. },
  133. onFireNum() {
  134. this.FirePerson(5);
  135. },
  136. FirePerson: function (num) {
  137. if (GlobalD.GameData.GetWorkerNum() - num < 0) {
  138. num = GlobalD.GameData.GetWorkerNum();
  139. }
  140. //不需要解雇
  141. if (num <= 0) return;
  142. if (this.AutoFireWorker)
  143. this.unschedule(this.AutoFireWorker);
  144. //自动存储数据
  145. this.AutoFireWorker = function () {
  146. if (num <= 0) return;
  147. for (let i = 0; i < num; i++) {
  148. //只能解雇可以解雇状态下的工人
  149. if (this._ManageAI.onRemoveWorkerAI()) {
  150. //如果成功删除AI
  151. GlobalD.GameData.PlusWorkerNum(-1);
  152. this.WorkerNum.getComponent(cc.Label).string = GlobalD.GameData.GetWorkerNum();
  153. num--;
  154. }
  155. }
  156. }
  157. this.schedule(this.AutoFireWorker, 0.5);
  158. },
  159. //培训
  160. onUpgrade: function () {
  161. if (this.WorkerLVPropertyJSON.length - 2 < GlobalD.GameData.GetWorkerLV()) return;
  162. let CurrentGradeJson = this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()];
  163. let UpgradeCost = CurrentGradeJson.UpgradeCost;
  164. if (GlobalD.GameData.GetDiamond() < UpgradeCost) {
  165. cc.loader.loadRes('resUI/ShowNotEnoughMoney', function (err, texture) {
  166. var prefab = cc.instantiate(texture);
  167. prefab.getComponent('ShowNotEnoughMoney').Text('钻石不足!!');
  168. this.AlertUIView.addChild(prefab);
  169. }.bind(this));
  170. return;
  171. }
  172. GlobalD.GameData.PlusDiamond(-UpgradeCost);
  173. // this.GoldLabel.getComponent(cc.Label).string = GlobalD.GameData.GetDiamond();
  174. this.DiamondLabel.getComponent(cc.Label).string = GlobalD.GameData.GetDiamond();
  175. GlobalD.GameData.PlusWorkerLV(1);
  176. this.LV.getComponent(cc.Label).string = GlobalD.GameData.GetWorkerLV() + 1;
  177. CurrentGradeJson = this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()];
  178. this.PhysicalStrength.getComponent(cc.Label).string = CurrentGradeJson.PhysicalStrength;
  179. this.Labor.getComponent(cc.Label).string = CurrentGradeJson.Labor;
  180. this.Wages.getComponent(cc.Label).string = CurrentGradeJson.Wages;
  181. GlobalD.GameData.SetWorkerCapacity(CurrentGradeJson.Labor);
  182. this.WorkerCapacity.getComponent(cc.Label).string = CurrentGradeJson.Labor;
  183. //修改全体人物属性
  184. this._ManageAI.InitCurrentGradeJson = CurrentGradeJson;
  185. this._ManageAI.onUpgradeAllWorker();
  186. this.SetBar_TrainLength((GlobalD.GameData.GetWorkerLV() + 1) / this.WorkerLVPropertyJSON.length);
  187. this.SetBar_RecruitLength(GlobalD.GameData.GetWorkerNum() / GlobalD.GameData.GetWorkerCapacity());
  188. this.RecruitCost.getComponent(cc.Label).string = CurrentGradeJson.Wages;
  189. this.UpGradeCost.getComponent(cc.Label).string = CurrentGradeJson.UpgradeCost;
  190. },
  191. onDegrade: function () {
  192. if (GlobalD.GameData.GetWorkerLV() - 1 < 0) return;
  193. GlobalD.GameData.PlusWorkerLV(-1);
  194. this.LV.getComponent(cc.Label).string = GlobalD.GameData.GetWorkerLV() + 1;
  195. let CurrentGradeJson = this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()];
  196. CurrentGradeJson = this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()];
  197. this.PhysicalStrength.getComponent(cc.Label).string = CurrentGradeJson.PhysicalStrength;
  198. this.Labor.getComponent(cc.Label).string = CurrentGradeJson.Labor;
  199. this.Wages.getComponent(cc.Label).string = CurrentGradeJson.Wages;
  200. GlobalD.GameData.SetWorkerCapacity(CurrentGradeJson.Labor);
  201. this.WorkerCapacity.getComponent(cc.Label).string = CurrentGradeJson.Labor;
  202. //修改全体人物属性
  203. this._ManageAI.InitCurrentGradeJson = CurrentGradeJson;
  204. this._ManageAI.onUpgradeAllWorker();
  205. this.SetBar_TrainLength((GlobalD.GameData.GetWorkerLV() + 1) / this.WorkerLVPropertyJSON.length);
  206. this.SetBar_RecruitLength(GlobalD.GameData.GetWorkerNum() / GlobalD.GameData.GetWorkerCapacity());
  207. },
  208. //招聘进度条
  209. SetBar_RecruitLength: function (BarLength) {//BarLength(0~1,float)
  210. this.ManagementProgressBar_Recruit.getComponent(cc.ProgressBar).progress = BarLength;
  211. },
  212. //培训进度条
  213. SetBar_TrainLength: function (BarLength) {//BarLength(0~1,float)
  214. this.ManagementProgressBar_Train.getComponent(cc.ProgressBar).progress = BarLength;
  215. },
  216. });