ManageBuildings.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  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. let _configLand = GlobalD.ConfigLand;
  447. console.log(_configLand);
  448. for (let i = 0; i < _configLand.length; i++) {
  449. //生成默认土地
  450. //农田
  451. let housingTemp_farmland = this.onGetHousingPrefabFromName('Labour_205_Holy_Farmland');
  452. housingTemp_farmland.parent = this.BuildingsParent;
  453. var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(cc.v2(_configLand[i].posX, _configLand[i].posY));
  454. housingTemp_farmland.setPosition(endPos.x, endPos.y);
  455. let buildingsInfo_farmland = housingTemp_farmland.getComponent("buildingsInfo");
  456. //id用时间戳来记录
  457. buildingsInfo_farmland.buildInfo.id = _configLand[i].id;//对应的id
  458. /**
  459. * 服务器设置的农田 独立于其他游戏数据
  460. * 这步设置之后,addBuilding 时候不存储到 GameData_buildings
  461. */
  462. buildingsInfo_farmland.InitPosFromStore = true;
  463. //设置tile的最底下的坐标,就是起始坐标
  464. buildingsInfo_farmland.buildInfo.startTilePos = cc.v2(_configLand[i].posX, _configLand[i].posY);
  465. this.SpawnBuildingDefaultValue(buildingsInfo_farmland);
  466. //起始坐标,占位范围,是否占位
  467. GlobalD.game.addBuildTiled(buildingsInfo_farmland.buildInfo.id, buildingsInfo_farmland.buildInfo.startTilePos, buildingsInfo_farmland.buildInfo.occupyArea);
  468. //添加占位信息
  469. GlobalD.game.addBuilding(buildingsInfo_farmland);
  470. }
  471. },
  472. //初始化场景建筑
  473. SpawnHouse: function () {
  474. let BuildingJSON = Object.assign([], GlobalD.GameData.GameData_buildings);
  475. //拿到数据后,清空 GlobalD.GameData.GameData_buildings 数据,下面再添加上去
  476. GlobalD.GameData.GameData_buildings.length = 0;
  477. cc.log('BuildingJSON', BuildingJSON);
  478. // if (BuildingJSON.length == 0) {
  479. // //初始化默认房子
  480. // this.SpawnDefaultHouse();
  481. // return
  482. // };
  483. for (let i = 0; i < BuildingJSON.length; i++) {
  484. let HouseName = BuildingJSON[i].buildingNodeName;
  485. let housingTemp = this.onGetHousingPrefabFromName(HouseName);
  486. if (!housingTemp)
  487. cc.error('housingTemp', HouseName, housingTemp);
  488. //预制为空
  489. if (!housingTemp) return;
  490. let buildingsInfo = housingTemp.getComponent("buildingsInfo");
  491. /**
  492. * 处理数据库数据冲突问题
  493. * 这里处理判断初始化位置是否被占用,占用了回收到仓库背包系统
  494. * BuildingJSON 看做旧的数据, 拿到旧数据 BuildingJSON[i].startTilePos 起始位置 ,生成对应预制的大小occupyArea
  495. * 来判断占位信息
  496. */
  497. let _canNotBuild = GlobalD.game.areTheraOverlappingAreas(BuildingJSON[i].startTilePos, buildingsInfo.buildInfo.occupyArea, 1);
  498. if (_canNotBuild) {
  499. // 背包添加对应的建筑数量
  500. GlobalD.game.PlusBuilding(buildingsInfo.buildInfo.buildingName);
  501. // 删除上面生成的预制节点
  502. housingTemp.destroy();
  503. //跳过生成
  504. continue;
  505. }
  506. housingTemp.parent = this.BuildingsParent;
  507. var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(BuildingJSON[i].startTilePos);
  508. housingTemp.setPosition(endPos.x, endPos.y);
  509. //id用时间戳来记录
  510. buildingsInfo.buildInfo.id = BuildingJSON[i].buildingId;//对应的id
  511. //设置tile的最底下的坐标,就是起始坐标
  512. buildingsInfo.buildInfo.startTilePos = BuildingJSON[i].startTilePos;
  513. //初始化位置的坐标
  514. buildingsInfo.InitStartPos = BuildingJSON[i].startTilePos;
  515. this.SpawnBuildingDefaultValue(buildingsInfo);
  516. //目前应该只有商店,后面根据RunningCost来判断 todo.....
  517. // if (reGameStates.BuildType.Shop == buildingsInfo.buildInfo.buildType)
  518. {
  519. // buildingsInfo.buildInfo.isItSaleable = Number(BuildingJSON[i].isItSaleable) > 0 ? true : false;
  520. buildingsInfo.buildInfo.isItStopOperation = Number(BuildingJSON[i].isItStopOperation) > 0 ? true : false;
  521. //如果不可以运营的,加上牌子
  522. if (buildingsInfo.buildInfo.isItStopOperation) {
  523. GlobalD.game.onAddBuildingTipView(buildingsInfo);
  524. }
  525. }
  526. //建筑物的加成值
  527. buildingsInfo.buildInfo.consumeStrengthAddValue = Number(BuildingJSON[i].consumeStrengthAddValue);
  528. buildingsInfo.buildInfo.goodsPriceAddValue = Number(BuildingJSON[i].goodsPriceAddValue);
  529. /**
  530. * 判断是否占位的时候,需要进一步处理。放回背包,然后背包物品加上对应的数量
  531. */
  532. //起始坐标,占位范围,是否占位
  533. GlobalD.game.addBuildTiled(buildingsInfo.buildInfo.id, buildingsInfo.buildInfo.startTilePos, buildingsInfo.buildInfo.occupyArea);
  534. //添加占位信息
  535. GlobalD.game.addBuilding(buildingsInfo);
  536. }
  537. console.log("GlobalD.GameData.GameData_buildings:", GlobalD.GameData.GameData_buildings);
  538. },
  539. onGetHousingPrefabFromName(HouseName) {
  540. let housing = null;
  541. //住宿地方
  542. if (HouseName == 'Env_101_house_low') {
  543. housing = cc.instantiate(this.Env_101_house_low);
  544. }
  545. else if (HouseName === 'Env_102_house_mid') {
  546. housing = cc.instantiate(this.Env_102_house_mid);
  547. }
  548. else if (HouseName == 'Env_103_house_high') {
  549. housing = cc.instantiate(this.Env_103_house_high);
  550. }
  551. else if (HouseName == 'Env_104_BlueCastle') {
  552. housing = cc.instantiate(this.Env_104_BlueCastle);
  553. }
  554. else if (HouseName == 'Env_105_PinkCastle') {
  555. housing = cc.instantiate(this.Env_105_PinkCastle);
  556. }
  557. //劳动地方
  558. else if (HouseName == 'Labour_201_Farmland') {
  559. housing = cc.instantiate(this.Labour_201_Farmland);
  560. }
  561. else if (HouseName == 'Labour_202_TimberYard') {
  562. housing = cc.instantiate(this.Labour_202_TimberYard);
  563. }
  564. else if (HouseName == 'Labour_203_MiningPit') {
  565. housing = cc.instantiate(this.Labour_203_MiningPit);
  566. }
  567. else if (HouseName == 'Labour_204_Factory') {
  568. housing = cc.instantiate(this.Labour_204_Factory);
  569. }
  570. //神农专用农田
  571. else if (HouseName == 'Labour_205_Holy_Farmland') {
  572. housing = cc.instantiate(this.Labour_205_Holy_Farmland);
  573. }
  574. //特殊建筑
  575. else if (HouseName == 'Spe_401_StreetLamp') {
  576. housing = cc.instantiate(this.Spe_401_StreetLamp);
  577. }
  578. else if (HouseName == 'Spe_402_GreenBelt') {
  579. housing = cc.instantiate(this.Spe_402_GreenBelt);
  580. }
  581. else if (HouseName == 'Spe_403_FlowerBed') {
  582. housing = cc.instantiate(this.Spe_403_FlowerBed);
  583. }
  584. else if (HouseName == 'Spe_404_Pool') {
  585. housing = cc.instantiate(this.Spe_404_Pool);
  586. }
  587. else if (HouseName == 'Spe_405_PoliceOffice') {
  588. housing = cc.instantiate(this.Spe_405_PoliceOffice);
  589. }
  590. else if (HouseName == 'Spe_406_Playground') {
  591. housing = cc.instantiate(this.Spe_406_Playground);
  592. }
  593. //商店类型
  594. else if (HouseName == 'Shops_30101_ColdDrinkStall') {
  595. housing = cc.instantiate(this.Shops_30101_ColdDrinkStall);
  596. }
  597. else if (HouseName == 'Shops_30102_SalesMachine') {
  598. housing = cc.instantiate(this.Shops_30102_SalesMachine);
  599. }
  600. else if (HouseName == 'Shops_30103_Bakery') {
  601. housing = cc.instantiate(this.Shops_30103_Bakery);
  602. }
  603. else if (HouseName == 'Shops_30104_BreakfastCar') {
  604. housing = cc.instantiate(this.Shops_30104_BreakfastCar);
  605. }
  606. else if (HouseName == 'Shops_30201_TeaShop') {
  607. housing = cc.instantiate(this.Shops_30201_TeaShop);
  608. }
  609. else if (HouseName == 'Shops_30202_confectaurant') {
  610. housing = cc.instantiate(this.Shops_30202_confectaurant);
  611. }
  612. else if (HouseName == 'Shops_30203_GourmetRestaurant') {
  613. housing = cc.instantiate(this.Shops_30203_GourmetRestaurant);
  614. }
  615. else if (HouseName == 'Shops_30204_WesternRestaurant') {
  616. housing = cc.instantiate(this.Shops_30204_WesternRestaurant);
  617. }
  618. else if (HouseName == 'Shops_30301_Florist') {
  619. housing = cc.instantiate(this.Shops_30301_Florist);
  620. }
  621. else if (HouseName == 'Shops_30302_HairSalon') {
  622. housing = cc.instantiate(this.Shops_30302_HairSalon);
  623. }
  624. else if (HouseName == 'Shops_30303_DressShop') {
  625. housing = cc.instantiate(this.Shops_30303_DressShop);
  626. }
  627. else if (HouseName == 'Shops_30304_JewelryStore') {
  628. housing = cc.instantiate(this.Shops_30304_JewelryStore);
  629. }
  630. else if (HouseName == 'Shops_30305_Cinema') {
  631. housing = cc.instantiate(this.Shops_30305_Cinema);
  632. }
  633. return housing;
  634. },
  635. //获取预制的名字
  636. onGetPrefabsBuildingName(index) {
  637. //content button 设置的index
  638. let buildingName = '';
  639. //农舍
  640. if ('101' == index) {
  641. buildingName = 'Env_101_house_low';
  642. }
  643. //单元楼
  644. else if ('102' == index) {
  645. buildingName = 'Env_102_house_mid';
  646. }
  647. //别墅
  648. else if ('103' == index) {
  649. buildingName = 'Env_103_house_high';
  650. }
  651. //蓝色城堡
  652. else if ('104' == index) {
  653. buildingName = 'Env_104_BlueCastle';
  654. }
  655. //粉色城堡
  656. else if ('105' == index) {
  657. buildingName = 'Env_105_PinkCastle';
  658. }
  659. //农田
  660. else if ('201' == index) {
  661. buildingName = 'Labour_201_Farmland';
  662. }
  663. //伐木场
  664. else if ('202' == index) {
  665. buildingName = 'Labour_202_TimberYard';
  666. }
  667. //矿坑
  668. else if ('203' == index) {
  669. buildingName = 'Labour_203_MiningPit';
  670. }
  671. //工厂
  672. else if ('204' == index) {
  673. buildingName = 'Labour_204_Factory';
  674. }
  675. //神农专用农田
  676. else if ('205' == index) {
  677. buildingName = 'Labour_205_Holy_Farmland';
  678. }
  679. //冷饮摊
  680. else if ('30101' == index) {
  681. buildingName = 'Shops_30101_ColdDrinkStall';
  682. }
  683. //贩卖机
  684. else if ('30102' == index) {
  685. buildingName = 'Shops_30102_SalesMachine';
  686. }
  687. //面包房
  688. else if ('30103' == index) {
  689. buildingName = 'Shops_30103_Bakery';
  690. }
  691. //早餐车
  692. else if ('30104' == index) {
  693. buildingName = 'Shops_30104_BreakfastCar';
  694. }
  695. //饮茶店
  696. else if ('30201' == index) {
  697. buildingName = 'Shops_30201_TeaShop';
  698. }
  699. //点心店
  700. else if ('30202' == index) {
  701. buildingName = 'Shops_30202_confectaurant';
  702. }
  703. //美食店
  704. else if ('30203' == index) {
  705. buildingName = 'Shops_30203_GourmetRestaurant';
  706. }
  707. //西餐厅
  708. else if ('30204' == index) {
  709. buildingName = 'Shops_30204_WesternRestaurant';
  710. }
  711. //花店
  712. else if ('30301' == index) {
  713. buildingName = 'Shops_30301_Florist';
  714. }
  715. //美发店
  716. else if ('30302' == index) {
  717. buildingName = 'Shops_30302_HairSalon';
  718. }
  719. //洋装店
  720. else if ('30303' == index) {
  721. buildingName = 'Shops_30303_DressShop';
  722. }
  723. //珠宝店
  724. else if ('30304' == index) {
  725. buildingName = 'Shops_30304_JewelryStore';
  726. }
  727. //电影院
  728. else if ('30305' == index) {
  729. buildingName = 'Shops_30305_Cinema';
  730. }
  731. //路灯
  732. else if ('401' == index) {
  733. buildingName = 'Spe_401_StreetLamp';
  734. }
  735. //绿化带
  736. else if ('402' == index) {
  737. buildingName = 'Spe_402_GreenBelt';
  738. }
  739. //花坛
  740. else if ('403' == index) {
  741. buildingName = 'Spe_403_FlowerBed';
  742. }
  743. //喷泉
  744. else if ('404' == index) {
  745. buildingName = 'Spe_404_Pool';
  746. }
  747. //警察局
  748. else if ('405' == index) {
  749. buildingName = 'Spe_405_PoliceOffice';
  750. }
  751. //游乐场
  752. else if ('406' == index) {
  753. buildingName = 'Spe_406_Playground';
  754. }
  755. return buildingName;
  756. },
  757. Grant()
  758. {
  759. },
  760. Sale()
  761. {
  762. }
  763. });