ManageBuildings.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. var reGameStates = require('GameStates');
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. //MyMapNode
  6. //建筑物的节点
  7. BuildingsParent: {
  8. default: null,
  9. type: cc.Node,
  10. },
  11. //农舍
  12. Env_101_house_low: {
  13. default: null,
  14. type: cc.Prefab,
  15. serializable: true,
  16. },
  17. //单元楼
  18. Env_102_house_mid: {
  19. default: null,
  20. type: cc.Prefab,
  21. serializable: true,
  22. },
  23. //别墅
  24. Env_103_house_high: {
  25. default: null,
  26. type: cc.Prefab,
  27. serializable: true,
  28. },
  29. //蓝色城堡
  30. Env_104_BlueCastle: {
  31. default: null,
  32. type: cc.Prefab,
  33. serializable: true,
  34. },
  35. //粉色城堡
  36. Env_105_PinkCastle: {
  37. default: null,
  38. type: cc.Prefab,
  39. serializable: true,
  40. },
  41. //农田
  42. Labour_201_Farmland: {
  43. default: null,
  44. type: cc.Prefab,
  45. serializable: true,
  46. },
  47. //伐木场
  48. Labour_202_TimberYard: {
  49. default: null,
  50. type: cc.Prefab,
  51. serializable: true,
  52. },
  53. //矿坑
  54. Labour_203_MiningPit: {
  55. default: null,
  56. type: cc.Prefab,
  57. serializable: true,
  58. },
  59. //工厂
  60. Labour_204_Factory: {
  61. default: null,
  62. type: cc.Prefab,
  63. serializable: true,
  64. },
  65. //神农专用农田
  66. Labour_205_Holy_Farmland: {
  67. default: null,
  68. type: cc.Prefab,
  69. serializable: true,
  70. },
  71. //一级
  72. // 冷饮摊
  73. Shops_30101_ColdDrinkStall: {
  74. default: null,
  75. type: cc.Prefab,
  76. serializable: true,
  77. },
  78. //贩卖机
  79. Shops_30102_SalesMachine: {
  80. default: null,
  81. type: cc.Prefab,
  82. serializable: true,
  83. },
  84. //面包房
  85. Shops_30103_Bakery: {
  86. default: null,
  87. type: cc.Prefab,
  88. serializable: true,
  89. },
  90. //早餐车
  91. Shops_30104_BreakfastCar: {
  92. default: null,
  93. type: cc.Prefab,
  94. serializable: true,
  95. },
  96. //二级
  97. //饮茶店
  98. Shops_30201_TeaShop: {
  99. default: null,
  100. type: cc.Prefab,
  101. serializable: true,
  102. },
  103. //点心店
  104. Shops_30202_confectaurant: {
  105. default: null,
  106. type: cc.Prefab,
  107. serializable: true,
  108. },
  109. //美食店
  110. Shops_30203_GourmetRestaurant: {
  111. default: null,
  112. type: cc.Prefab,
  113. serializable: true,
  114. },
  115. //西餐厅
  116. Shops_30204_WesternRestaurant: {
  117. default: null,
  118. type: cc.Prefab,
  119. serializable: true,
  120. },
  121. //三级
  122. //花店
  123. Shops_30301_Florist: {
  124. default: null,
  125. type: cc.Prefab,
  126. serializable: true,
  127. },
  128. //美发店
  129. Shops_30302_HairSalon: {
  130. default: null,
  131. type: cc.Prefab,
  132. serializable: true,
  133. },
  134. //洋装店
  135. Shops_30303_DressShop: {
  136. default: null,
  137. type: cc.Prefab,
  138. serializable: true,
  139. },
  140. //珠宝店
  141. Shops_30304_JewelryStore: {
  142. default: null,
  143. type: cc.Prefab,
  144. serializable: true,
  145. },
  146. //电影院
  147. Shops_30305_Cinema: {
  148. default: null,
  149. type: cc.Prefab,
  150. serializable: true,
  151. },
  152. //特殊建筑
  153. //路灯
  154. Spe_401_StreetLamp: {
  155. default: null,
  156. type: cc.Prefab,
  157. serializable: true,
  158. },
  159. //绿化带
  160. Spe_402_GreenBelt: {
  161. default: null,
  162. type: cc.Prefab,
  163. serializable: true,
  164. },
  165. //花坛
  166. Spe_403_FlowerBed: {
  167. default: null,
  168. type: cc.Prefab,
  169. serializable: true,
  170. },
  171. //喷泉
  172. Spe_404_Pool: {
  173. default: null,
  174. type: cc.Prefab,
  175. serializable: true,
  176. },
  177. //警察局
  178. Spe_405_PoliceOffice: {
  179. default: null,
  180. type: cc.Prefab,
  181. serializable: true,
  182. },
  183. //游乐场
  184. Spe_406_Playground: {
  185. default: null,
  186. type: cc.Prefab,
  187. serializable: true,
  188. },
  189. BuildingArray: {
  190. default: [],
  191. type: [cc.Node],
  192. serializable: true,
  193. },
  194. },
  195. onBuildHouse(index) {
  196. // cc.log(index);
  197. let mainCamera = GlobalD.game.MainCamera;
  198. let housing = null;
  199. //content button 设置的index
  200. //农舍
  201. if ('101' == index) {
  202. housing = cc.instantiate(this.Env_101_house_low);
  203. }
  204. //单元楼
  205. else if ('102' == index) {
  206. housing = cc.instantiate(this.Env_102_house_mid);
  207. }
  208. //别墅
  209. else if ('103' == index) {
  210. housing = cc.instantiate(this.Env_103_house_high);
  211. }
  212. else if ('104' == index) {
  213. housing = cc.instantiate(this.Env_104_BlueCastle);
  214. }
  215. else if ('105' == index) {
  216. housing = cc.instantiate(this.Env_105_PinkCastle);
  217. }
  218. //农田
  219. else if ('201' == index) {
  220. housing = cc.instantiate(this.Labour_201_Farmland);
  221. }
  222. //伐木场
  223. else if ('202' == index) {
  224. housing = cc.instantiate(this.Labour_202_TimberYard);
  225. }
  226. //矿坑
  227. else if ('203' == index) {
  228. housing = cc.instantiate(this.Labour_203_MiningPit);
  229. }
  230. //工厂
  231. else if ('204' == index) {
  232. housing = cc.instantiate(this.Labour_204_Factory);
  233. }
  234. //神农专用农田
  235. else if ('205' == index) {
  236. housing = cc.instantiate(this.Labour_205_Holy_Farmland);
  237. }
  238. //冷饮摊
  239. else if ('30101' == index) {
  240. housing = cc.instantiate(this.Shops_30101_ColdDrinkStall);
  241. }
  242. //贩卖机
  243. else if ('30102' == index) {
  244. housing = cc.instantiate(this.Shops_30102_SalesMachine);
  245. }
  246. //面包房
  247. else if ('30103' == index) {
  248. housing = cc.instantiate(this.Shops_30103_Bakery);
  249. }
  250. //早餐车
  251. else if ('30104' == index) {
  252. housing = cc.instantiate(this.Shops_30104_BreakfastCar);
  253. }
  254. //饮茶店
  255. else if ('30201' == index) {
  256. housing = cc.instantiate(this.Shops_30201_TeaShop);
  257. }
  258. //点心店
  259. else if ('30202' == index) {
  260. housing = cc.instantiate(this.Shops_30202_confectaurant);
  261. }
  262. //美食店
  263. else if ('30203' == index) {
  264. housing = cc.instantiate(this.Shops_30203_GourmetRestaurant);
  265. }
  266. //西餐厅
  267. else if ('30204' == index) {
  268. housing = cc.instantiate(this.Shops_30204_WesternRestaurant);
  269. }
  270. //花店
  271. else if ('30301' == index) {
  272. housing = cc.instantiate(this.Shops_30301_Florist);
  273. }
  274. //美发店
  275. else if ('30302' == index) {
  276. housing = cc.instantiate(this.Shops_30302_HairSalon);
  277. }
  278. //洋装店
  279. else if ('30303' == index) {
  280. housing = cc.instantiate(this.Shops_30303_DressShop);
  281. }
  282. //珠宝店
  283. else if ('30304' == index) {
  284. housing = cc.instantiate(this.Shops_30304_JewelryStore);
  285. }
  286. //电影院
  287. else if ('30305' == index) {
  288. housing = cc.instantiate(this.Shops_30305_Cinema);
  289. }
  290. //路灯
  291. else if ('401' == index) {
  292. housing = cc.instantiate(this.Spe_401_StreetLamp);
  293. }
  294. //绿化带
  295. else if ('402' == index) {
  296. housing = cc.instantiate(this.Spe_402_GreenBelt);
  297. }
  298. //花坛
  299. else if ('403' == index) {
  300. housing = cc.instantiate(this.Spe_403_FlowerBed);
  301. }
  302. //喷泉
  303. else if ('404' == index) {
  304. housing = cc.instantiate(this.Spe_404_Pool);
  305. }
  306. //警察局
  307. else if ('405' == index) {
  308. housing = cc.instantiate(this.Spe_405_PoliceOffice);
  309. }
  310. //游乐场
  311. else if ('406' == index) {
  312. housing = cc.instantiate(this.Spe_406_Playground);
  313. }
  314. housing.parent = this.BuildingsParent;
  315. let tempPos = housing.parent.convertToNodeSpace(mainCamera.node);
  316. let CanvasPos = GlobalD.game.Canvas.position;
  317. housing.setPosition(tempPos.x + CanvasPos.x, tempPos.y + CanvasPos.y);
  318. let buildingsInfo = housing.getComponent("buildingsInfo");
  319. //id用时间戳来记录
  320. buildingsInfo.buildInfo.id = new Date().getTime();//+= Math.random() * 1000000;
  321. this.SpawnBuildingDefaultValue(buildingsInfo);
  322. let buildingsTouch = housing.getComponent("buildingsTouch");
  323. // buildingsTouch.buildInfo = buildingsInfo.buildInfo;
  324. buildingsTouch.onEditorStatus(true);
  325. // housing.active = true;
  326. //收起菜单
  327. GlobalD.game._ManageUIScript.onHideMenu();
  328. //收起底部菜单栏
  329. GlobalD.game._ManageUIScript.onBottomMenuView(false);
  330. },
  331. start() {
  332. },
  333. //如果存储到有房子数据的话,把地图上的房屋都隐藏起来,或者删除
  334. //todo...
  335. onHideInitPosBuildings() {
  336. //删除对应层的子节点
  337. let tempNode = this.BuildingsParent.children;
  338. let length = tempNode.length;
  339. for (let i = length - 1; i >= 0; i--) {
  340. tempNode[i].active = false;
  341. }
  342. },
  343. /**
  344. * GameData里面处理的生成数据流程,生成建筑物
  345. */
  346. InitBuildings() {
  347. //如果有存储的数据,隐藏场景房屋节点
  348. // this.onHideInitPosBuildings();
  349. /**
  350. * 注释 spawnConfigLand 不初始化固定土地
  351. */
  352. //第一步初始化土地的网络数据
  353. this.spawnConfigLand();
  354. //先初始化网络数据
  355. this.SpawnHouse();
  356. // cc.log('初始化场景建筑');
  357. let BuildingStateArray = GlobalD.GameData.GetBuildingStateArray();
  358. for (let i = 0; i < BuildingStateArray.length; i++) {
  359. if (BuildingStateArray[i] == 0) {
  360. this.BuildingArray[i].active = false;
  361. }
  362. else {
  363. this.BuildingArray[i].active = true;
  364. }
  365. }
  366. let BuildingNumArray = GlobalD.GameData.GetBuildingNumArray();
  367. // cc.log('BuildingNumArray',BuildingNumArray)
  368. for (let i = 3; i < this.BuildingArray.length; i++) {
  369. // cc.log('this.BuildingArray['+i+']='+this.BuildingArray[i].getChildByName('Name').getComponent(cc.Label).string);
  370. this.BuildingArray[i].getChildByName('Name').getChildByName('Num').getComponent(cc.Label).string = BuildingNumArray[i];
  371. }
  372. //初始化两个默认的建筑
  373. //
  374. },
  375. //生成房子的默认值
  376. SpawnBuildingDefaultValue(buildingsInfo) {
  377. buildingsInfo.InitPos = false;
  378. buildingsInfo.InitWorkBuildingInfo = false;
  379. //激活状态,可运营
  380. buildingsInfo.buildInfo.isItActive = true;
  381. //设置销售状态
  382. buildingsInfo.buildInfo.isItSaleable = true;
  383. if (reGameStates.BuildType.Farmland == buildingsInfo.buildInfo.buildType) {
  384. buildingsInfo.buildInfo.isItSaleable = GlobalD.GameData.GetFoodTradeState() > 0 ? true : false;// GlobalD.GameData.GetFoodTradeState();
  385. // cc.log('初始化房子的信息:', buildingsInfo.buildInfo.buildingName, buildingsInfo.buildInfo.isItSaleable);
  386. }
  387. if (reGameStates.BuildType.MiningPit == buildingsInfo.buildInfo.buildType) {
  388. buildingsInfo.buildInfo.isItSaleable = GlobalD.GameData.GetMineralTradeState() > 0 ? true : false;// GlobalD.GameData.GetMineralTradeState();
  389. }
  390. if (reGameStates.BuildType.TimberYard == buildingsInfo.buildInfo.buildType) {
  391. buildingsInfo.buildInfo.isItSaleable = GlobalD.GameData.GetWoodTradeState() > 0 ? true : false;// GlobalD.GameData.GetWoodTradeState();
  392. }
  393. //设置一下,可查看信息
  394. if (reGameStates.BuildType.Housing !== buildingsInfo.buildInfo.buildType
  395. && reGameStates.BuildType.Special !== buildingsInfo.buildInfo.buildType
  396. /** 神农小镇固定土地关闭 基本的房屋信息,另外设置其他信息 */
  397. && reGameStates.BuildType.HolyFarmland !== buildingsInfo.buildInfo.buildType
  398. ) {
  399. buildingsInfo.node.getComponent('buildingsTouch').isShowBuildingInfo = true;
  400. }
  401. //设置消耗的体力值为工人的最低值 20
  402. //过高的话,会导致工人不工作
  403. // buildingsInfo.buildInfo.totalConsumption = 20;
  404. // cc.log('初始化房子的信息:', buildingsInfo.buildInfo.buildingName, buildingsInfo.buildInfo.isItSaleable)
  405. },
  406. //初始化场景的两个建筑
  407. SpawnDefaultHouse() {
  408. cc.log('初始化默认房子');
  409. //房子
  410. let housingTemp_house = this.onGetHousingPrefabFromName('Env_101_house_low');
  411. housingTemp_house.parent = this.BuildingsParent;
  412. var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(cc.v2(24, 23));
  413. housingTemp_house.setPosition(endPos.x, endPos.y);
  414. let buildingsInfo_house = housingTemp_house.getComponent("buildingsInfo");
  415. //id用时间戳来记录
  416. buildingsInfo_house.buildInfo.id = 101;//对应的id
  417. //设置tile的最底下的坐标,就是起始坐标
  418. buildingsInfo_house.buildInfo.startTilePos = cc.v2(24, 23);
  419. this.SpawnBuildingDefaultValue(buildingsInfo_house);
  420. //起始坐标,占位范围,是否占位
  421. GlobalD.game.addBuildTiled(buildingsInfo_house.buildInfo.id, buildingsInfo_house.buildInfo.startTilePos, buildingsInfo_house.buildInfo.occupyArea);
  422. //添加占位信息
  423. GlobalD.game.addBuilding(buildingsInfo_house);
  424. //农田
  425. let housingTemp_farmland = this.onGetHousingPrefabFromName('Labour_201_Farmland');
  426. housingTemp_farmland.parent = this.BuildingsParent;
  427. var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(cc.v2(26, 24));
  428. housingTemp_farmland.setPosition(endPos.x, endPos.y);
  429. let buildingsInfo_farmland = housingTemp_farmland.getComponent("buildingsInfo");
  430. //id用时间戳来记录
  431. buildingsInfo_farmland.buildInfo.id = 201;//对应的id
  432. //设置tile的最底下的坐标,就是起始坐标
  433. buildingsInfo_farmland.buildInfo.startTilePos = cc.v2(26, 24);
  434. this.SpawnBuildingDefaultValue(buildingsInfo_farmland);
  435. //起始坐标,占位范围,是否占位
  436. GlobalD.game.addBuildTiled(buildingsInfo_farmland.buildInfo.id, buildingsInfo_farmland.buildInfo.startTilePos, buildingsInfo_farmland.buildInfo.occupyArea);
  437. //添加占位信息
  438. GlobalD.game.addBuilding(buildingsInfo_farmland);
  439. },
  440. //初始化后台配置的土地数据
  441. spawnConfigLand() {
  442. if (GlobalD.ConfigLand == null) {
  443. console.error("GlobalD.ConfigLand 未初始化设置!");
  444. return;
  445. }
  446. if (GlobalD.UserLeaseLand == null) {
  447. console.error("GlobalD.UserLeaseLand 未初始化设置!");
  448. return;
  449. }
  450. let _configLand = GlobalD.ConfigLand;
  451. let _userLeaseLand = GlobalD.UserLeaseLand;
  452. console.log(_configLand, _userLeaseLand);
  453. for (let i = 0; i < _configLand.length; i++) {
  454. //生成默认土地
  455. //农田
  456. let housingTemp_farmland = this.onGetHousingPrefabFromName('Labour_205_Holy_Farmland');
  457. housingTemp_farmland.parent = this.BuildingsParent;
  458. var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(cc.v2(_configLand[i].posX, _configLand[i].posY));
  459. housingTemp_farmland.setPosition(endPos.x, endPos.y);
  460. for (let j = 0; j < _userLeaseLand.length; j++) {
  461. let leaseFarmlandInfoScript = housingTemp_farmland.getComponent("LeaseFarmlandInfo");
  462. //记录config的土地信息
  463. leaseFarmlandInfoScript.setConfigLandInfo(_configLand[i]);
  464. //记录已经租赁的信息
  465. if(_userLeaseLand[j].configLandId == _configLand[i].id){
  466. leaseFarmlandInfoScript.setLeaseLandInfo(_userLeaseLand[j]);
  467. }
  468. }
  469. let buildingsInfo_farmland = housingTemp_farmland.getComponent("buildingsInfo");
  470. //id用时间戳来记录
  471. buildingsInfo_farmland.buildInfo.id = _configLand[i].id;//对应的id
  472. /**
  473. * 服务器设置的农田 独立于其他游戏数据
  474. * 这步设置之后,addBuilding 时候不存储到 GameData_buildings
  475. */
  476. buildingsInfo_farmland.InitPosFromStore = true;
  477. //设置tile的最底下的坐标,就是起始坐标
  478. buildingsInfo_farmland.buildInfo.startTilePos = cc.v2(_configLand[i].posX, _configLand[i].posY);
  479. this.SpawnBuildingDefaultValue(buildingsInfo_farmland);
  480. //起始坐标,占位范围,是否占位
  481. GlobalD.game.addBuildTiled(buildingsInfo_farmland.buildInfo.id, buildingsInfo_farmland.buildInfo.startTilePos, buildingsInfo_farmland.buildInfo.occupyArea);
  482. //添加占位信息
  483. GlobalD.game.addBuilding(buildingsInfo_farmland);
  484. }
  485. },
  486. //初始化场景建筑
  487. SpawnHouse: function () {
  488. let BuildingJSON = Object.assign([], GlobalD.GameData.GameData_buildings);
  489. //拿到数据后,清空 GlobalD.GameData.GameData_buildings 数据,下面再添加上去
  490. GlobalD.GameData.GameData_buildings.length = 0;
  491. cc.log('BuildingJSON', BuildingJSON);
  492. // if (BuildingJSON.length == 0) {
  493. // //初始化默认房子
  494. // this.SpawnDefaultHouse();
  495. // return
  496. // };
  497. for (let i = 0; i < BuildingJSON.length; i++) {
  498. let HouseName = BuildingJSON[i].buildingNodeName;
  499. let housingTemp = this.onGetHousingPrefabFromName(HouseName);
  500. if (!housingTemp)
  501. cc.error('housingTemp', HouseName, housingTemp);
  502. //预制为空
  503. if (!housingTemp) return;
  504. let buildingsInfo = housingTemp.getComponent("buildingsInfo");
  505. /**
  506. * 处理数据库数据冲突问题
  507. * 这里处理判断初始化位置是否被占用,占用了回收到仓库背包系统
  508. * BuildingJSON 看做旧的数据, 拿到旧数据 BuildingJSON[i].startTilePos 起始位置 ,生成对应预制的大小occupyArea
  509. * 来判断占位信息
  510. */
  511. let _canNotBuild = GlobalD.game.areTheraOverlappingAreas(BuildingJSON[i].startTilePos, buildingsInfo.buildInfo.occupyArea, 1);
  512. if (_canNotBuild) {
  513. // 背包添加对应的建筑数量
  514. GlobalD.game.PlusBuilding(buildingsInfo.buildInfo.buildingName);
  515. // 删除上面生成的预制节点
  516. housingTemp.destroy();
  517. //跳过生成
  518. continue;
  519. }
  520. housingTemp.parent = this.BuildingsParent;
  521. var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(BuildingJSON[i].startTilePos);
  522. housingTemp.setPosition(endPos.x, endPos.y);
  523. //id用时间戳来记录
  524. buildingsInfo.buildInfo.id = BuildingJSON[i].buildingId;//对应的id
  525. //设置tile的最底下的坐标,就是起始坐标
  526. buildingsInfo.buildInfo.startTilePos = BuildingJSON[i].startTilePos;
  527. //初始化位置的坐标
  528. buildingsInfo.InitStartPos = BuildingJSON[i].startTilePos;
  529. this.SpawnBuildingDefaultValue(buildingsInfo);
  530. //目前应该只有商店,后面根据RunningCost来判断 todo.....
  531. // if (reGameStates.BuildType.Shop == buildingsInfo.buildInfo.buildType)
  532. {
  533. // buildingsInfo.buildInfo.isItSaleable = Number(BuildingJSON[i].isItSaleable) > 0 ? true : false;
  534. buildingsInfo.buildInfo.isItStopOperation = Number(BuildingJSON[i].isItStopOperation) > 0 ? true : false;
  535. //如果不可以运营的,加上牌子
  536. if (buildingsInfo.buildInfo.isItStopOperation) {
  537. GlobalD.game.onAddBuildingTipView(buildingsInfo);
  538. }
  539. }
  540. //建筑物的加成值
  541. buildingsInfo.buildInfo.consumeStrengthAddValue = Number(BuildingJSON[i].consumeStrengthAddValue);
  542. buildingsInfo.buildInfo.goodsPriceAddValue = Number(BuildingJSON[i].goodsPriceAddValue);
  543. /**
  544. * 判断是否占位的时候,需要进一步处理。放回背包,然后背包物品加上对应的数量
  545. */
  546. //起始坐标,占位范围,是否占位
  547. GlobalD.game.addBuildTiled(buildingsInfo.buildInfo.id, buildingsInfo.buildInfo.startTilePos, buildingsInfo.buildInfo.occupyArea);
  548. //添加占位信息
  549. GlobalD.game.addBuilding(buildingsInfo);
  550. }
  551. console.log("GlobalD.GameData.GameData_buildings:", GlobalD.GameData.GameData_buildings);
  552. },
  553. onGetHousingPrefabFromName(HouseName) {
  554. let housing = null;
  555. //住宿地方
  556. if (HouseName == 'Env_101_house_low') {
  557. housing = cc.instantiate(this.Env_101_house_low);
  558. }
  559. else if (HouseName === 'Env_102_house_mid') {
  560. housing = cc.instantiate(this.Env_102_house_mid);
  561. }
  562. else if (HouseName == 'Env_103_house_high') {
  563. housing = cc.instantiate(this.Env_103_house_high);
  564. }
  565. else if (HouseName == 'Env_104_BlueCastle') {
  566. housing = cc.instantiate(this.Env_104_BlueCastle);
  567. }
  568. else if (HouseName == 'Env_105_PinkCastle') {
  569. housing = cc.instantiate(this.Env_105_PinkCastle);
  570. }
  571. //劳动地方
  572. else if (HouseName == 'Labour_201_Farmland') {
  573. housing = cc.instantiate(this.Labour_201_Farmland);
  574. }
  575. else if (HouseName == 'Labour_202_TimberYard') {
  576. housing = cc.instantiate(this.Labour_202_TimberYard);
  577. }
  578. else if (HouseName == 'Labour_203_MiningPit') {
  579. housing = cc.instantiate(this.Labour_203_MiningPit);
  580. }
  581. else if (HouseName == 'Labour_204_Factory') {
  582. housing = cc.instantiate(this.Labour_204_Factory);
  583. }
  584. //神农专用农田
  585. else if (HouseName == 'Labour_205_Holy_Farmland') {
  586. housing = cc.instantiate(this.Labour_205_Holy_Farmland);
  587. }
  588. //特殊建筑
  589. else if (HouseName == 'Spe_401_StreetLamp') {
  590. housing = cc.instantiate(this.Spe_401_StreetLamp);
  591. }
  592. else if (HouseName == 'Spe_402_GreenBelt') {
  593. housing = cc.instantiate(this.Spe_402_GreenBelt);
  594. }
  595. else if (HouseName == 'Spe_403_FlowerBed') {
  596. housing = cc.instantiate(this.Spe_403_FlowerBed);
  597. }
  598. else if (HouseName == 'Spe_404_Pool') {
  599. housing = cc.instantiate(this.Spe_404_Pool);
  600. }
  601. else if (HouseName == 'Spe_405_PoliceOffice') {
  602. housing = cc.instantiate(this.Spe_405_PoliceOffice);
  603. }
  604. else if (HouseName == 'Spe_406_Playground') {
  605. housing = cc.instantiate(this.Spe_406_Playground);
  606. }
  607. //商店类型
  608. else if (HouseName == 'Shops_30101_ColdDrinkStall') {
  609. housing = cc.instantiate(this.Shops_30101_ColdDrinkStall);
  610. }
  611. else if (HouseName == 'Shops_30102_SalesMachine') {
  612. housing = cc.instantiate(this.Shops_30102_SalesMachine);
  613. }
  614. else if (HouseName == 'Shops_30103_Bakery') {
  615. housing = cc.instantiate(this.Shops_30103_Bakery);
  616. }
  617. else if (HouseName == 'Shops_30104_BreakfastCar') {
  618. housing = cc.instantiate(this.Shops_30104_BreakfastCar);
  619. }
  620. else if (HouseName == 'Shops_30201_TeaShop') {
  621. housing = cc.instantiate(this.Shops_30201_TeaShop);
  622. }
  623. else if (HouseName == 'Shops_30202_confectaurant') {
  624. housing = cc.instantiate(this.Shops_30202_confectaurant);
  625. }
  626. else if (HouseName == 'Shops_30203_GourmetRestaurant') {
  627. housing = cc.instantiate(this.Shops_30203_GourmetRestaurant);
  628. }
  629. else if (HouseName == 'Shops_30204_WesternRestaurant') {
  630. housing = cc.instantiate(this.Shops_30204_WesternRestaurant);
  631. }
  632. else if (HouseName == 'Shops_30301_Florist') {
  633. housing = cc.instantiate(this.Shops_30301_Florist);
  634. }
  635. else if (HouseName == 'Shops_30302_HairSalon') {
  636. housing = cc.instantiate(this.Shops_30302_HairSalon);
  637. }
  638. else if (HouseName == 'Shops_30303_DressShop') {
  639. housing = cc.instantiate(this.Shops_30303_DressShop);
  640. }
  641. else if (HouseName == 'Shops_30304_JewelryStore') {
  642. housing = cc.instantiate(this.Shops_30304_JewelryStore);
  643. }
  644. else if (HouseName == 'Shops_30305_Cinema') {
  645. housing = cc.instantiate(this.Shops_30305_Cinema);
  646. }
  647. return housing;
  648. },
  649. //获取预制的名字
  650. onGetPrefabsBuildingName(index) {
  651. //content button 设置的index
  652. let buildingName = '';
  653. //农舍
  654. if ('101' == index) {
  655. buildingName = 'Env_101_house_low';
  656. }
  657. //单元楼
  658. else if ('102' == index) {
  659. buildingName = 'Env_102_house_mid';
  660. }
  661. //别墅
  662. else if ('103' == index) {
  663. buildingName = 'Env_103_house_high';
  664. }
  665. //蓝色城堡
  666. else if ('104' == index) {
  667. buildingName = 'Env_104_BlueCastle';
  668. }
  669. //粉色城堡
  670. else if ('105' == index) {
  671. buildingName = 'Env_105_PinkCastle';
  672. }
  673. //农田
  674. else if ('201' == index) {
  675. buildingName = 'Labour_201_Farmland';
  676. }
  677. //伐木场
  678. else if ('202' == index) {
  679. buildingName = 'Labour_202_TimberYard';
  680. }
  681. //矿坑
  682. else if ('203' == index) {
  683. buildingName = 'Labour_203_MiningPit';
  684. }
  685. //工厂
  686. else if ('204' == index) {
  687. buildingName = 'Labour_204_Factory';
  688. }
  689. //神农专用农田
  690. else if ('205' == index) {
  691. buildingName = 'Labour_205_Holy_Farmland';
  692. }
  693. //冷饮摊
  694. else if ('30101' == index) {
  695. buildingName = 'Shops_30101_ColdDrinkStall';
  696. }
  697. //贩卖机
  698. else if ('30102' == index) {
  699. buildingName = 'Shops_30102_SalesMachine';
  700. }
  701. //面包房
  702. else if ('30103' == index) {
  703. buildingName = 'Shops_30103_Bakery';
  704. }
  705. //早餐车
  706. else if ('30104' == index) {
  707. buildingName = 'Shops_30104_BreakfastCar';
  708. }
  709. //饮茶店
  710. else if ('30201' == index) {
  711. buildingName = 'Shops_30201_TeaShop';
  712. }
  713. //点心店
  714. else if ('30202' == index) {
  715. buildingName = 'Shops_30202_confectaurant';
  716. }
  717. //美食店
  718. else if ('30203' == index) {
  719. buildingName = 'Shops_30203_GourmetRestaurant';
  720. }
  721. //西餐厅
  722. else if ('30204' == index) {
  723. buildingName = 'Shops_30204_WesternRestaurant';
  724. }
  725. //花店
  726. else if ('30301' == index) {
  727. buildingName = 'Shops_30301_Florist';
  728. }
  729. //美发店
  730. else if ('30302' == index) {
  731. buildingName = 'Shops_30302_HairSalon';
  732. }
  733. //洋装店
  734. else if ('30303' == index) {
  735. buildingName = 'Shops_30303_DressShop';
  736. }
  737. //珠宝店
  738. else if ('30304' == index) {
  739. buildingName = 'Shops_30304_JewelryStore';
  740. }
  741. //电影院
  742. else if ('30305' == index) {
  743. buildingName = 'Shops_30305_Cinema';
  744. }
  745. //路灯
  746. else if ('401' == index) {
  747. buildingName = 'Spe_401_StreetLamp';
  748. }
  749. //绿化带
  750. else if ('402' == index) {
  751. buildingName = 'Spe_402_GreenBelt';
  752. }
  753. //花坛
  754. else if ('403' == index) {
  755. buildingName = 'Spe_403_FlowerBed';
  756. }
  757. //喷泉
  758. else if ('404' == index) {
  759. buildingName = 'Spe_404_Pool';
  760. }
  761. //警察局
  762. else if ('405' == index) {
  763. buildingName = 'Spe_405_PoliceOffice';
  764. }
  765. //游乐场
  766. else if ('406' == index) {
  767. buildingName = 'Spe_406_Playground';
  768. }
  769. return buildingName;
  770. },
  771. Grant()
  772. {
  773. },
  774. Sale()
  775. {
  776. }
  777. });