ManageWorker.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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. {
  37. PhysicalStrength: '50',
  38. Labor: '5',
  39. Wages: '50',
  40. UpgradeCost: '20',
  41. MoveSpeed: '100',
  42. },
  43. {
  44. PhysicalStrength: '55',
  45. Labor: '7',
  46. Wages: '100',
  47. UpgradeCost: '50',
  48. MoveSpeed: '120',
  49. },
  50. {
  51. PhysicalStrength: '60',
  52. Labor: '9',
  53. Wages: '200',
  54. UpgradeCost: '100',
  55. MoveSpeed: '140',
  56. },
  57. {
  58. PhysicalStrength: '65',
  59. Labor: '11',
  60. Wages: '300',
  61. UpgradeCost: '500',
  62. MoveSpeed: '160',
  63. },
  64. {
  65. PhysicalStrength: '70',
  66. Labor: '13',
  67. Wages: '400',
  68. UpgradeCost: '1000',
  69. MoveSpeed: '180',
  70. },
  71. {
  72. PhysicalStrength: '75',
  73. Labor: '15',
  74. Wages: '500',
  75. UpgradeCost: '1500',
  76. MoveSpeed: '200',
  77. },
  78. {
  79. PhysicalStrength: '80',
  80. Labor: '17',
  81. Wages: '600',
  82. UpgradeCost: '2000',
  83. MoveSpeed: '220',
  84. },
  85. {
  86. PhysicalStrength: '85',
  87. Labor: '18',
  88. Wages: '700',
  89. UpgradeCost: '2500',
  90. MoveSpeed: '240',
  91. },
  92. {
  93. PhysicalStrength: '90',
  94. Labor: '19',
  95. Wages: '800',
  96. UpgradeCost: '3000',
  97. MoveSpeed: '260',
  98. },
  99. {
  100. PhysicalStrength: '100',
  101. Labor: '20',
  102. Wages: '900',
  103. UpgradeCost: '0',
  104. MoveSpeed: '280',
  105. },
  106. ]
  107. this.WorkerNum.getComponent(cc.Label).string =
  108. GlobalD.GameData.GetWorkerNum()
  109. //容量是定死的值,不用存储,也不用读取
  110. this.WorkerCapacity.getComponent(cc.Label).string =
  111. GlobalD.GameData.GetWorkerCapacity()
  112. this.SetBar_RecruitLength(
  113. GlobalD.GameData.GetWorkerNum() / GlobalD.GameData.GetWorkerCapacity()
  114. )
  115. this.LV.getComponent(cc.Label).string = GlobalD.GameData.GetWorkerLV() + 1
  116. this.MaxWorkLV.getComponent(cc.Label).string =
  117. this.WorkerLVPropertyJSON.length
  118. this.SetBar_TrainLength(
  119. (GlobalD.GameData.GetWorkerLV() + 1) / this.WorkerLVPropertyJSON.length
  120. )
  121. let CurrentGradeJson =
  122. this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()]
  123. this.PhysicalStrength.getComponent(cc.Label).string =
  124. CurrentGradeJson.PhysicalStrength
  125. this.Labor.getComponent(cc.Label).string = CurrentGradeJson.Labor
  126. this.Wages.getComponent(cc.Label).string = CurrentGradeJson.Wages
  127. this.RecruitCost.getComponent(cc.Label).string = CurrentGradeJson.Wages
  128. this.UpGradeCost.getComponent(cc.Label).string =
  129. CurrentGradeJson.UpgradeCost
  130. this._ManageAI = this.ManageAI.getComponent('ManageAI')
  131. this._ManageAI.InitCurrentGradeJson = CurrentGradeJson
  132. //生成存储的工人数据
  133. this._ManageAI.onSpawnWorkerAIFromStoredData()
  134. // cc.log('工人');
  135. },
  136. //招聘
  137. onRecruit: function () {
  138. if (task.TaskIconCountClick == 1) {
  139. //现在关掉招聘的 页面 弹出对话框 提示 要点击建造
  140. task.managerUi.onButtonEvent_Personnel_Close()
  141. task.showManagerhide()
  142. var Canvas = cc.find('Canvas/UICamera')
  143. //移动camera 对应位置
  144. cc.find('GameNode/ManageTask')
  145. .getComponent('ManageTask')
  146. .onMoveToTiledTile(16, 16)
  147. //招聘了人马上设置对应的数
  148. task.TaskIconCountClick = -1
  149. dialogmanager.init(
  150. Canvas,
  151. function () {
  152. dialogmanager.pickUp(dialogmanager.dialogue[30])
  153. }.bind(this)
  154. )
  155. dialogmanager.setOnCloseDialog(
  156. function () {
  157. task.removeTaskNode(task.taskCursorName[3])
  158. // task._setTaskIconCountClick(12);
  159. // task._setTaskIconCountClick(13);
  160. // setTimeout(() => {
  161. // task.taskCallBack();
  162. // }, 500);
  163. //建房子
  164. GlobalD.ManageTask.onInitGameStartTask()
  165. }.bind(this)
  166. )
  167. }
  168. if (
  169. GlobalD.GameData.GetWorkerNum() + 1 >
  170. GlobalD.GameData.GetWorkerCapacity()
  171. ) {
  172. cc.loader.loadRes(
  173. 'resUI/ShowNotEnoughMoney',
  174. function (err, texture) {
  175. var prefab = cc.instantiate(texture)
  176. prefab.getComponent('ShowNotEnoughMoney').Text('超员了!!')
  177. this.AlertUIView.addChild(prefab)
  178. }.bind(this)
  179. )
  180. return
  181. }
  182. if (
  183. GlobalD.GameData.GetGolden() <
  184. parseInt(this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()].Wages)
  185. ) {
  186. cc.loader.loadRes(
  187. 'resUI/ShowNotEnoughMoney',
  188. function (err, texture) {
  189. var prefab = cc.instantiate(texture)
  190. prefab.getComponent('ShowNotEnoughMoney').Text('金币不足!!')
  191. this.AlertUIView.addChild(prefab)
  192. }.bind(this)
  193. )
  194. return
  195. }
  196. GlobalD.GameData.PlusGolden(
  197. -parseInt(this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()].Wages)
  198. )
  199. GlobalD.GameData.PlusWorkerNum(1)
  200. this.WorkerNum.getComponent(cc.Label).string =
  201. GlobalD.GameData.GetWorkerNum()
  202. this._ManageAI.onSpawnWorkerAI()
  203. this.SetBar_RecruitLength(
  204. GlobalD.GameData.GetWorkerNum() / GlobalD.GameData.GetWorkerCapacity()
  205. )
  206. },
  207. Building_t: function () {
  208. var Canvas = cc.find('Canvas/UICamera')
  209. var Building = cc.find('Canvas/UICamera/BelowTheMask/Building')
  210. task.addTaskTips(
  211. Canvas,
  212. task.taskPrefab[6],
  213. 0,
  214. 0,
  215. task.taskCursorName[1],
  216. function (nodePrefabs1) {
  217. UtilsPrefabs.setOn(
  218. nodePrefabs1.getChildByName('SureBtn'),
  219. function () {
  220. task.removeTaskNode(task.taskCursorName[1])
  221. task.addTaskTips(
  222. Building,
  223. task.taskPrefab[1],
  224. -50,
  225. -50,
  226. task.taskCursorName[0],
  227. function (nodePrefabs) {}.bind(this)
  228. )
  229. }.bind(this)
  230. )
  231. }.bind(this)
  232. )
  233. },
  234. //解雇
  235. onFire: function () {
  236. if (GlobalD.GameData.GetWorkerNum() - 1 < 0) return
  237. if (this._ManageAI.onRemoveWorkerAI()) {
  238. //如果成功删除AI
  239. GlobalD.GameData.PlusWorkerNum(-1)
  240. this.WorkerNum.getComponent(cc.Label).string =
  241. GlobalD.GameData.GetWorkerNum()
  242. }
  243. },
  244. onFireNum() {
  245. this.FirePerson(5)
  246. },
  247. FirePerson: function (num) {
  248. if (GlobalD.GameData.GetWorkerNum() - num < 0) {
  249. num = GlobalD.GameData.GetWorkerNum()
  250. }
  251. //不需要解雇
  252. if (num <= 0) return
  253. if (this.AutoFireWorker) this.unschedule(this.AutoFireWorker)
  254. //自动存储数据
  255. this.AutoFireWorker = function () {
  256. if (num <= 0) return
  257. for (let i = 0; i < num; i++) {
  258. //只能解雇可以解雇状态下的工人
  259. if (this._ManageAI.onRemoveWorkerAI()) {
  260. //如果成功删除AI
  261. GlobalD.GameData.PlusWorkerNum(-1)
  262. this.WorkerNum.getComponent(cc.Label).string =
  263. GlobalD.GameData.GetWorkerNum()
  264. num--
  265. }
  266. }
  267. }
  268. this.schedule(this.AutoFireWorker, 0.5)
  269. },
  270. //培训
  271. onUpgrade: function () {
  272. if (this.WorkerLVPropertyJSON.length - 2 < GlobalD.GameData.GetWorkerLV())
  273. return
  274. let CurrentGradeJson =
  275. this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()]
  276. let UpgradeCost = CurrentGradeJson.UpgradeCost
  277. if (GlobalD.GameData.GetDiamond() < UpgradeCost) {
  278. cc.loader.loadRes(
  279. 'resUI/ShowNotEnoughMoney',
  280. function (err, texture) {
  281. var prefab = cc.instantiate(texture)
  282. prefab.getComponent('ShowNotEnoughMoney').Text('钻石不足!!')
  283. this.AlertUIView.addChild(prefab)
  284. }.bind(this)
  285. )
  286. return
  287. }
  288. GlobalD.GameData.PlusDiamond(-UpgradeCost)
  289. // this.GoldLabel.getComponent(cc.Label).string = GlobalD.GameData.GetDiamond();
  290. // this.DiamondNowlabel.string = result + '/30000'
  291. this.DiamondLabel.getComponent(cc.Label).string =
  292. GlobalD.GameData.GetDiamond()
  293. GlobalD.GameData.PlusWorkerLV(1)
  294. this.LV.getComponent(cc.Label).string = GlobalD.GameData.GetWorkerLV() + 1
  295. CurrentGradeJson = this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()]
  296. this.PhysicalStrength.getComponent(cc.Label).string =
  297. CurrentGradeJson.PhysicalStrength
  298. this.Labor.getComponent(cc.Label).string = CurrentGradeJson.Labor
  299. this.Wages.getComponent(cc.Label).string = CurrentGradeJson.Wages
  300. GlobalD.GameData.SetWorkerCapacity(CurrentGradeJson.Labor)
  301. this.WorkerCapacity.getComponent(cc.Label).string = CurrentGradeJson.Labor
  302. //修改全体人物属性
  303. this._ManageAI.InitCurrentGradeJson = CurrentGradeJson
  304. this._ManageAI.onUpgradeAllWorker()
  305. this.SetBar_TrainLength(
  306. (GlobalD.GameData.GetWorkerLV() + 1) / this.WorkerLVPropertyJSON.length
  307. )
  308. this.SetBar_RecruitLength(
  309. GlobalD.GameData.GetWorkerNum() / GlobalD.GameData.GetWorkerCapacity()
  310. )
  311. this.RecruitCost.getComponent(cc.Label).string = CurrentGradeJson.Wages
  312. this.UpGradeCost.getComponent(cc.Label).string =
  313. CurrentGradeJson.UpgradeCost
  314. },
  315. onDegrade: function () {
  316. if (GlobalD.GameData.GetWorkerLV() - 1 < 0) return
  317. GlobalD.GameData.PlusWorkerLV(-1)
  318. this.LV.getComponent(cc.Label).string = GlobalD.GameData.GetWorkerLV() + 1
  319. let CurrentGradeJson =
  320. this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()]
  321. CurrentGradeJson = this.WorkerLVPropertyJSON[GlobalD.GameData.GetWorkerLV()]
  322. this.PhysicalStrength.getComponent(cc.Label).string =
  323. CurrentGradeJson.PhysicalStrength
  324. this.Labor.getComponent(cc.Label).string = CurrentGradeJson.Labor
  325. this.Wages.getComponent(cc.Label).string = CurrentGradeJson.Wages
  326. GlobalD.GameData.SetWorkerCapacity(CurrentGradeJson.Labor)
  327. this.WorkerCapacity.getComponent(cc.Label).string = CurrentGradeJson.Labor
  328. //修改全体人物属性
  329. this._ManageAI.InitCurrentGradeJson = CurrentGradeJson
  330. this._ManageAI.onUpgradeAllWorker()
  331. this.SetBar_TrainLength(
  332. (GlobalD.GameData.GetWorkerLV() + 1) / this.WorkerLVPropertyJSON.length
  333. )
  334. this.SetBar_RecruitLength(
  335. GlobalD.GameData.GetWorkerNum() / GlobalD.GameData.GetWorkerCapacity()
  336. )
  337. },
  338. //招聘进度条
  339. SetBar_RecruitLength: function (BarLength) {
  340. //BarLength(0~1,float)
  341. this.ManagementProgressBar_Recruit.getComponent(cc.ProgressBar).progress =
  342. BarLength
  343. },
  344. //培训进度条
  345. SetBar_TrainLength: function (BarLength) {
  346. //BarLength(0~1,float)
  347. this.ManagementProgressBar_Train.getComponent(cc.ProgressBar).progress =
  348. BarLength
  349. },
  350. })