ManageBuildings.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  1. var reGameStates = require('GameStates');
  2. import date from "../Unit/date.js"
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. //MyMapNode
  7. //建筑物的节点
  8. BuildingsParent: {
  9. default: null,
  10. type: cc.Node,
  11. },
  12. //农舍
  13. Env_101_house_low: {
  14. default: null,
  15. type: cc.Prefab,
  16. serializable: true,
  17. },
  18. //单元楼
  19. Env_102_house_mid: {
  20. default: null,
  21. type: cc.Prefab,
  22. serializable: true,
  23. },
  24. //别墅
  25. Env_103_house_high: {
  26. default: null,
  27. type: cc.Prefab,
  28. serializable: true,
  29. },
  30. //蓝色城堡
  31. Env_104_BlueCastle: {
  32. default: null,
  33. type: cc.Prefab,
  34. serializable: true,
  35. },
  36. //粉色城堡
  37. Env_105_PinkCastle: {
  38. default: null,
  39. type: cc.Prefab,
  40. serializable: true,
  41. },
  42. //农田
  43. Labour_201_Farmland: {
  44. default: null,
  45. type: cc.Prefab,
  46. serializable: true,
  47. },
  48. //伐木场
  49. Labour_202_TimberYard: {
  50. default: null,
  51. type: cc.Prefab,
  52. serializable: true,
  53. },
  54. //矿坑
  55. Labour_203_MiningPit: {
  56. default: null,
  57. type: cc.Prefab,
  58. serializable: true,
  59. },
  60. //工厂
  61. Labour_204_Factory: {
  62. default: null,
  63. type: cc.Prefab,
  64. serializable: true,
  65. },
  66. //神农专用农田
  67. Labour_205_Holy_Farmland: {
  68. default: null,
  69. type: cc.Prefab,
  70. serializable: true,
  71. },
  72. //一级
  73. // 冷饮摊
  74. Shops_30101_ColdDrinkStall: {
  75. default: null,
  76. type: cc.Prefab,
  77. serializable: true,
  78. },
  79. //贩卖机
  80. Shops_30102_SalesMachine: {
  81. default: null,
  82. type: cc.Prefab,
  83. serializable: true,
  84. },
  85. //面包房
  86. Shops_30103_Bakery: {
  87. default: null,
  88. type: cc.Prefab,
  89. serializable: true,
  90. },
  91. //早餐车
  92. Shops_30104_BreakfastCar: {
  93. default: null,
  94. type: cc.Prefab,
  95. serializable: true,
  96. },
  97. //二级
  98. //饮茶店
  99. Shops_30201_TeaShop: {
  100. default: null,
  101. type: cc.Prefab,
  102. serializable: true,
  103. },
  104. //点心店
  105. Shops_30202_confectaurant: {
  106. default: null,
  107. type: cc.Prefab,
  108. serializable: true,
  109. },
  110. //美食店
  111. Shops_30203_GourmetRestaurant: {
  112. default: null,
  113. type: cc.Prefab,
  114. serializable: true,
  115. },
  116. //西餐厅
  117. Shops_30204_WesternRestaurant: {
  118. default: null,
  119. type: cc.Prefab,
  120. serializable: true,
  121. },
  122. //三级
  123. //花店
  124. Shops_30301_Florist: {
  125. default: null,
  126. type: cc.Prefab,
  127. serializable: true,
  128. },
  129. //美发店
  130. Shops_30302_HairSalon: {
  131. default: null,
  132. type: cc.Prefab,
  133. serializable: true,
  134. },
  135. //洋装店
  136. Shops_30303_DressShop: {
  137. default: null,
  138. type: cc.Prefab,
  139. serializable: true,
  140. },
  141. //珠宝店
  142. Shops_30304_JewelryStore: {
  143. default: null,
  144. type: cc.Prefab,
  145. serializable: true,
  146. },
  147. //电影院
  148. Shops_30305_Cinema: {
  149. default: null,
  150. type: cc.Prefab,
  151. serializable: true,
  152. },
  153. //特殊建筑
  154. //路灯
  155. Spe_401_StreetLamp: {
  156. default: null,
  157. type: cc.Prefab,
  158. serializable: true,
  159. },
  160. //绿化带
  161. Spe_402_GreenBelt: {
  162. default: null,
  163. type: cc.Prefab,
  164. serializable: true,
  165. },
  166. //花坛
  167. Spe_403_FlowerBed: {
  168. default: null,
  169. type: cc.Prefab,
  170. serializable: true,
  171. },
  172. //喷泉
  173. Spe_404_Pool: {
  174. default: null,
  175. type: cc.Prefab,
  176. serializable: true,
  177. },
  178. //警察局
  179. Spe_405_PoliceOffice: {
  180. default: null,
  181. type: cc.Prefab,
  182. serializable: true,
  183. },
  184. //游乐场
  185. Spe_406_Playground: {
  186. default: null,
  187. type: cc.Prefab,
  188. serializable: true,
  189. },
  190. BuildingArray: {
  191. default: [],
  192. type: [cc.Node],
  193. serializable: true,
  194. },
  195. /**
  196. * 定义一个场景预制对象
  197. */
  198. DressUpArray: {
  199. default: [],
  200. type: [cc.Prefab]
  201. }
  202. },
  203. onBuildHouse(index) {
  204. // cc.log(index);
  205. let mainCamera = GlobalD.game.MainCamera;
  206. let housing = null;
  207. //content button 设置的index
  208. //农舍
  209. if ('101' == index) {
  210. housing = cc.instantiate(this.Env_101_house_low);
  211. }
  212. //单元楼
  213. else if ('102' == index) {
  214. housing = cc.instantiate(this.Env_102_house_mid);
  215. }
  216. //别墅
  217. else if ('103' == index) {
  218. housing = cc.instantiate(this.Env_103_house_high);
  219. }
  220. else if ('104' == index) {
  221. housing = cc.instantiate(this.Env_104_BlueCastle);
  222. }
  223. else if ('105' == index) {
  224. housing = cc.instantiate(this.Env_105_PinkCastle);
  225. }
  226. //农田
  227. else if ('201' == index) {
  228. housing = cc.instantiate(this.Labour_201_Farmland);
  229. }
  230. //伐木场
  231. else if ('202' == index) {
  232. housing = cc.instantiate(this.Labour_202_TimberYard);
  233. }
  234. //矿坑
  235. else if ('203' == index) {
  236. housing = cc.instantiate(this.Labour_203_MiningPit);
  237. }
  238. //工厂
  239. else if ('204' == index) {
  240. housing = cc.instantiate(this.Labour_204_Factory);
  241. }
  242. //神农专用农田
  243. else if ('205' == index) {
  244. housing = cc.instantiate(this.Labour_205_Holy_Farmland);
  245. }
  246. //冷饮摊
  247. else if ('30101' == index) {
  248. housing = cc.instantiate(this.Shops_30101_ColdDrinkStall);
  249. }
  250. //贩卖机
  251. else if ('30102' == index) {
  252. housing = cc.instantiate(this.Shops_30102_SalesMachine);
  253. }
  254. //面包房
  255. else if ('30103' == index) {
  256. housing = cc.instantiate(this.Shops_30103_Bakery);
  257. }
  258. //早餐车
  259. else if ('30104' == index) {
  260. housing = cc.instantiate(this.Shops_30104_BreakfastCar);
  261. }
  262. //饮茶店
  263. else if ('30201' == index) {
  264. housing = cc.instantiate(this.Shops_30201_TeaShop);
  265. }
  266. //点心店
  267. else if ('30202' == index) {
  268. housing = cc.instantiate(this.Shops_30202_confectaurant);
  269. }
  270. //美食店
  271. else if ('30203' == index) {
  272. housing = cc.instantiate(this.Shops_30203_GourmetRestaurant);
  273. }
  274. //西餐厅
  275. else if ('30204' == index) {
  276. housing = cc.instantiate(this.Shops_30204_WesternRestaurant);
  277. }
  278. //花店
  279. else if ('30301' == index) {
  280. housing = cc.instantiate(this.Shops_30301_Florist);
  281. }
  282. //美发店
  283. else if ('30302' == index) {
  284. housing = cc.instantiate(this.Shops_30302_HairSalon);
  285. }
  286. //洋装店
  287. else if ('30303' == index) {
  288. housing = cc.instantiate(this.Shops_30303_DressShop);
  289. }
  290. //珠宝店
  291. else if ('30304' == index) {
  292. housing = cc.instantiate(this.Shops_30304_JewelryStore);
  293. }
  294. //电影院
  295. else if ('30305' == index) {
  296. housing = cc.instantiate(this.Shops_30305_Cinema);
  297. }
  298. //路灯
  299. else if ('401' == index) {
  300. housing = cc.instantiate(this.Spe_401_StreetLamp);
  301. }
  302. //绿化带
  303. else if ('402' == index) {
  304. housing = cc.instantiate(this.Spe_402_GreenBelt);
  305. }
  306. //花坛
  307. else if ('403' == index) {
  308. housing = cc.instantiate(this.Spe_403_FlowerBed);
  309. }
  310. //喷泉
  311. else if ('404' == index) {
  312. housing = cc.instantiate(this.Spe_404_Pool);
  313. }
  314. //警察局
  315. else if ('405' == index) {
  316. housing = cc.instantiate(this.Spe_405_PoliceOffice);
  317. }
  318. //游乐场
  319. else if ('406' == index) {
  320. housing = cc.instantiate(this.Spe_406_Playground);
  321. }
  322. housing.parent = this.BuildingsParent;
  323. let tempPos = housing.parent.convertToNodeSpace(mainCamera.node);
  324. let CanvasPos = GlobalD.game.Canvas.position;
  325. housing.setPosition(tempPos.x + CanvasPos.x, tempPos.y + CanvasPos.y);
  326. let buildingsInfo = housing.getComponent("buildingsInfo");
  327. //id用时间戳来记录
  328. buildingsInfo.buildInfo.id = new Date().getTime();//+= Math.random() * 1000000;
  329. this.SpawnBuildingDefaultValue(buildingsInfo);
  330. let buildingsTouch = housing.getComponent("buildingsTouch");
  331. // buildingsTouch.buildInfo = buildingsInfo.buildInfo;
  332. buildingsTouch.onEditorStatus(true);
  333. // housing.active = true;
  334. //收起菜单
  335. GlobalD.game._ManageUIScript.onHideMenu();
  336. //收起底部菜单栏
  337. GlobalD.game._ManageUIScript.onBottomMenuView(false);
  338. },
  339. start() {
  340. },
  341. //如果存储到有房子数据的话,把地图上的房屋都隐藏起来,或者删除
  342. //todo...
  343. onHideInitPosBuildings() {
  344. //删除对应层的子节点
  345. let tempNode = this.BuildingsParent.children;
  346. let length = tempNode.length;
  347. for (let i = length - 1; i >= 0; i--) {
  348. tempNode[i].active = false;
  349. }
  350. },
  351. /**
  352. * GameData里面处理的生成数据流程,生成建筑物
  353. */
  354. InitBuildings() {
  355. //如果有存储的数据,隐藏场景房屋节点
  356. // this.onHideInitPosBuildings();
  357. /**
  358. * 注释 spawnConfigLand 不初始化固定土地
  359. */
  360. //第一步初始化土地的网络数据
  361. this.spawnConfigLand();
  362. /**
  363. * todo 之类初始化场景障碍物操作,如果不需要直接注释即可。
  364. * 村长和镇长
  365. * 初始化障碍物场景,装饰
  366. */
  367. // if(0 != GlobalD.Dapp.UserInfo.agent_level){
  368. // this.spawnDressUp();
  369. // }
  370. //先初始化网络数据
  371. this.SpawnHouse();
  372. // cc.log('初始化场景建筑');
  373. let BuildingStateArray = GlobalD.GameData.GetBuildingStateArray();
  374. for (let i = 0; i < BuildingStateArray.length; i++) {
  375. if (BuildingStateArray[i] == 0) {
  376. if (this.BuildingArray[i])
  377. this.BuildingArray[i].active = false;
  378. }
  379. else {
  380. if (this.BuildingArray[i])
  381. this.BuildingArray[i].active = true;
  382. }
  383. }
  384. let BuildingNumArray = GlobalD.GameData.GetBuildingNumArray();
  385. // cc.log('BuildingNumArray',BuildingNumArray)
  386. for (let i = 3; i < this.BuildingArray.length; i++) {
  387. // cc.log('this.BuildingArray[' + i + ']=' + this.BuildingArray[i].getChildByName('Name').getComponent(cc.Label).string);
  388. if (this.BuildingArray[i])
  389. this.BuildingArray[i].getChildByName('Name').getChildByName('Num').getComponent(cc.Label).string = BuildingNumArray[i];
  390. }
  391. },
  392. //生成房子的默认值
  393. SpawnBuildingDefaultValue(buildingsInfo) {
  394. buildingsInfo.InitPos = false;
  395. buildingsInfo.InitWorkBuildingInfo = false;
  396. //激活状态,可运营
  397. buildingsInfo.buildInfo.isItActive = true;
  398. //设置销售状态
  399. buildingsInfo.buildInfo.isItSaleable = true;
  400. if (reGameStates.BuildType.Farmland == buildingsInfo.buildInfo.buildType) {
  401. buildingsInfo.buildInfo.isItSaleable = GlobalD.GameData.GetFoodTradeState() > 0 ? true : false;// GlobalD.GameData.GetFoodTradeState();
  402. // cc.log('初始化房子的信息:', buildingsInfo.buildInfo.buildingName, buildingsInfo.buildInfo.isItSaleable);
  403. }
  404. if (reGameStates.BuildType.MiningPit == buildingsInfo.buildInfo.buildType) {
  405. buildingsInfo.buildInfo.isItSaleable = GlobalD.GameData.GetMineralTradeState() > 0 ? true : false;// GlobalD.GameData.GetMineralTradeState();
  406. }
  407. if (reGameStates.BuildType.TimberYard == buildingsInfo.buildInfo.buildType) {
  408. buildingsInfo.buildInfo.isItSaleable = GlobalD.GameData.GetWoodTradeState() > 0 ? true : false;// GlobalD.GameData.GetWoodTradeState();
  409. }
  410. //设置一下,可查看信息
  411. if (reGameStates.BuildType.Housing !== buildingsInfo.buildInfo.buildType
  412. && reGameStates.BuildType.Special !== buildingsInfo.buildInfo.buildType
  413. /** 神农小镇固定土地关闭 基本的房屋信息,另外设置其他信息 */
  414. && reGameStates.BuildType.HolyFarmland !== buildingsInfo.buildInfo.buildType
  415. ) {
  416. buildingsInfo.node.getComponent('buildingsTouch').isShowBuildingInfo = true;
  417. }
  418. //设置消耗的体力值为工人的最低值 20
  419. //过高的话,会导致工人不工作
  420. // buildingsInfo.buildInfo.totalConsumption = 20;
  421. // cc.log('初始化房子的信息:', buildingsInfo.buildInfo.buildingName, buildingsInfo.buildInfo.isItSaleable)
  422. },
  423. //初始化场景的两个建筑
  424. SpawnDefaultHouse() {
  425. cc.log('初始化默认房子');
  426. //房子
  427. let housingTemp_house = this.onGetHousingPrefabFromName('Env_101_house_low');
  428. housingTemp_house.parent = this.BuildingsParent;
  429. var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(cc.v2(24, 23));
  430. housingTemp_house.setPosition(endPos.x, endPos.y);
  431. let buildingsInfo_house = housingTemp_house.getComponent("buildingsInfo");
  432. //id用时间戳来记录
  433. buildingsInfo_house.buildInfo.id = 101;//对应的id
  434. //设置tile的最底下的坐标,就是起始坐标
  435. buildingsInfo_house.buildInfo.startTilePos = cc.v2(24, 23);
  436. this.SpawnBuildingDefaultValue(buildingsInfo_house);
  437. //起始坐标,占位范围,是否占位
  438. GlobalD.game.addBuildTiled(buildingsInfo_house.buildInfo.id, buildingsInfo_house.buildInfo.startTilePos, buildingsInfo_house.buildInfo.occupyArea);
  439. //添加占位信息
  440. GlobalD.game.addBuilding(buildingsInfo_house);
  441. //农田
  442. let housingTemp_farmland = this.onGetHousingPrefabFromName('Labour_201_Farmland');
  443. housingTemp_farmland.parent = this.BuildingsParent;
  444. var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(cc.v2(26, 24));
  445. housingTemp_farmland.setPosition(endPos.x, endPos.y);
  446. let buildingsInfo_farmland = housingTemp_farmland.getComponent("buildingsInfo");
  447. //id用时间戳来记录
  448. buildingsInfo_farmland.buildInfo.id = 201;//对应的id
  449. //设置tile的最底下的坐标,就是起始坐标
  450. buildingsInfo_farmland.buildInfo.startTilePos = cc.v2(26, 24);
  451. this.SpawnBuildingDefaultValue(buildingsInfo_farmland);
  452. //起始坐标,占位范围,是否占位
  453. GlobalD.game.addBuildTiled(buildingsInfo_farmland.buildInfo.id, buildingsInfo_farmland.buildInfo.startTilePos, buildingsInfo_farmland.buildInfo.occupyArea);
  454. //添加占位信息
  455. GlobalD.game.addBuilding(buildingsInfo_farmland);
  456. },
  457. //初始化后台配置的土地数据
  458. spawnConfigLand() {
  459. if (GlobalD.ConfigLand == null) {
  460. console.error("GlobalD.ConfigLand 未初始化设置!");
  461. return;
  462. }
  463. if (GlobalD.UserLeaseLand == null) {
  464. console.error("GlobalD.UserLeaseLand 未初始化设置!");
  465. return;
  466. }
  467. let _configLand = GlobalD.ConfigLand;
  468. let _userLeaseLand = GlobalD.UserLeaseLand;
  469. // console.log(_configLand, _userLeaseLand);
  470. // console.log(this.node.getComponent("ManageUI"));
  471. for (let i = 0; i < _configLand.length; i++) {
  472. //生成默认土地
  473. //农田
  474. let housingTemp_farmland = this.onGetHousingPrefabFromName('Labour_205_Holy_Farmland');
  475. housingTemp_farmland.parent = this.BuildingsParent;
  476. var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(cc.v2(_configLand[i].posX, _configLand[i].posY));
  477. housingTemp_farmland.setPosition(endPos.x, endPos.y);
  478. let leaseFarmlandInfoScript = housingTemp_farmland.getComponent("LeaseFarmlandInfo");
  479. //记录config的土地信息
  480. leaseFarmlandInfoScript.setConfigLandInfo(_configLand[i]);
  481. for (let j = 0; j < _userLeaseLand.length; j++) {
  482. //记录已经租赁的信息(租赁里面包含了seedInfo,如果有种植的话,对应的种植信息会有)
  483. if (_userLeaseLand[j].configLandId == _configLand[i].id) {
  484. let _leaseLandInfo = _userLeaseLand[j];
  485. leaseFarmlandInfoScript.setLeaseLandInfo(_leaseLandInfo);
  486. }
  487. }
  488. let buildingsInfo_farmland = housingTemp_farmland.getComponent("buildingsInfo");
  489. //id用时间戳来记录
  490. buildingsInfo_farmland.buildInfo.id = _configLand[i].id;//对应的id
  491. /**
  492. * 服务器设置的农田 独立于其他游戏数据
  493. * 这步设置之后,addBuilding 时候不存储到 GameData_buildings
  494. */
  495. buildingsInfo_farmland.InitPosFromStore = true;
  496. //设置tile的最底下的坐标,就是起始坐标
  497. buildingsInfo_farmland.buildInfo.startTilePos = cc.v2(_configLand[i].posX, _configLand[i].posY);
  498. this.SpawnBuildingDefaultValue(buildingsInfo_farmland);
  499. //起始坐标,占位范围,是否占位
  500. GlobalD.game.addBuildTiled(buildingsInfo_farmland.buildInfo.id, buildingsInfo_farmland.buildInfo.startTilePos, buildingsInfo_farmland.buildInfo.occupyArea);
  501. //添加占位信息
  502. GlobalD.game.addBuilding(buildingsInfo_farmland);
  503. }
  504. },
  505. /**
  506. * 初始化障碍物
  507. * 生成的预制信息,需要在 DressUpArray 添加对应的预制件,才可以添加
  508. */
  509. spawnDressUp() {
  510. //村长和镇长的区别,樱花树区别
  511. let agent_level = GlobalD.Dapp.UserInfo.agent_level; // 0普通用户,1 村长身份,2 镇长身份
  512. let _cherryTree = 2 === agent_level? "Dress_505_SmallTree02":"Dress_505_SmallTree01";
  513. let _temp = [
  514. //左边第一部分 ----start----
  515. {
  516. spawnName: "Dress_502_ChrisTree",
  517. startPos: cc.v2(14, 20)
  518. },
  519. //拱门
  520. {
  521. spawnName: "Dress_505_MainDoor01",
  522. startPos: cc.v2(18, 17)
  523. },
  524. {
  525. spawnName: "Dress_503_RailingGrassX",
  526. startPos: cc.v2(9, 20)
  527. },
  528. {
  529. spawnName: "Dress_503_RailingGrassX",
  530. startPos: cc.v2(7, 20)
  531. },
  532. //-----
  533. {
  534. spawnName: "Dress_505_FlowerBed",
  535. startPos: cc.v2(8, 22)
  536. },
  537. {
  538. spawnName: "Dress_505_FlowerBed",
  539. startPos: cc.v2(8, 23)
  540. },
  541. //喷泉
  542. {
  543. spawnName: "Dress_502_Fountain",
  544. startPos: cc.v2(10, 23)
  545. },
  546. {
  547. spawnName: "Dress_505_FlowerBed",
  548. startPos: cc.v2(11, 22)
  549. },
  550. {
  551. spawnName: "Dress_505_FlowerBed",
  552. startPos: cc.v2(11, 23)
  553. },
  554. {
  555. spawnName: "Dress_505_ChrisSanta",
  556. startPos: cc.v2(10, 25)
  557. },
  558. //-----
  559. //左边第一部分 ----end----
  560. //主路放两个灯和树
  561. {
  562. spawnName: "Dress_505_Streetlight",
  563. startPos: cc.v2(15, 29)
  564. },
  565. {
  566. spawnName: "Dress_505_Streetlight",
  567. startPos: cc.v2(18, 29)
  568. },
  569. {
  570. spawnName: "Dress_505_SmallTree",
  571. startPos: cc.v2(15, 30)
  572. },
  573. {
  574. spawnName: "Dress_505_SmallTree",
  575. startPos: cc.v2(18, 30)
  576. }
  577. ];
  578. //左边小麦区域
  579. // for (let x = 0; x < 3; x++) {
  580. // for (let y = 0; y < 2; y++) {
  581. // _temp.push({
  582. // spawnName: "Dress_502_Rice",
  583. // startPos: cc.v2(4 - x * 2, 30 - y * 2)
  584. // })
  585. // }
  586. // }
  587. //1倍土地部分木质花圃
  588. // for (let x = 0; x < 6; x++) {
  589. // for (let y = 0; y < 3; y++) {
  590. // _temp.push({
  591. // spawnName: "Dress_503_WhiteWoodRailingX",
  592. // startPos: cc.v2(18 + x, 14 - y * 3)
  593. // })
  594. // }
  595. // }
  596. //生成一个未盛开的樱花围绕,间隔1个空格 ---start ,镇长换成盛开的樱花
  597. // for (let x = 0; x < 3; x++) {
  598. // _temp.push({
  599. // spawnName: _cherryTree,
  600. // startPos: cc.v2(18 + x * 2, 17)
  601. // })
  602. // _temp.push({
  603. // spawnName: _cherryTree,
  604. // startPos: cc.v2(18 + x * 2, 5)
  605. // })
  606. // }
  607. // for (let y = 0; y < 7; y++) {
  608. // _temp.push({
  609. // spawnName: _cherryTree,
  610. // startPos: cc.v2(24, 17 - y * 2)
  611. // })
  612. // }
  613. //多倍区域
  614. // for (let x = 0; x < 3; x++) {
  615. // _temp.push({
  616. // spawnName: _cherryTree,
  617. // startPos: cc.v2(15 - x * 2, 14)
  618. // })
  619. // _temp.push({
  620. // spawnName: _cherryTree,
  621. // startPos: cc.v2(15 - x * 2, 2)
  622. // })
  623. // }
  624. //生成一个未盛开的樱花围绕,间隔1个空格 --- end
  625. //多倍土地部分木质花圃
  626. // for (let x = 0; x < 3; x++) {
  627. // for (let y = 0; y < 3; y++) {
  628. // _temp.push({
  629. // spawnName: "Dress_503_RailingGrassX",
  630. // startPos: cc.v2(15 - x * 2, 11 - y * 3)
  631. // })
  632. // }
  633. // }
  634. //生成番茄区域
  635. // for (let x = 0; x < 3; x++) {
  636. // for (let y = 0; y < 2; y++) {
  637. // _temp.push({
  638. // spawnName: "Dress_502_Tomato",
  639. // startPos: cc.v2(26 + x * 2, 30 - y * 2)
  640. // })
  641. // }
  642. // }
  643. //----中上别墅区域--start
  644. //生成中上三个别墅和三个树木
  645. for (let x = 0; x < 3; x++) {
  646. _temp.push({
  647. spawnName: "Dress_505_SmallTree",
  648. startPos: cc.v2(7 - x * 2, 6)
  649. })
  650. _temp.push({
  651. spawnName: "Dress_502_Villa",
  652. startPos: cc.v2(8 - x * 2, 8)
  653. })
  654. }
  655. //雪橇
  656. _temp.push({
  657. spawnName: "Dress_505_ChrisCar02",
  658. startPos: cc.v2(8, 10)
  659. })
  660. //圣诞门和栏杆
  661. for (let x = 0; x < 3; x++) {
  662. _temp.push({
  663. spawnName: "Dress_503_WhiteWoodRailingX",
  664. startPos: cc.v2(8 - x, 11)
  665. })
  666. }
  667. _temp.push({
  668. spawnName: "Dress_503_ChrisDoorX",
  669. startPos: cc.v2(5, 11)
  670. })
  671. for (let x = 0; x < 3; x++) {
  672. _temp.push({
  673. spawnName: "Dress_503_WhiteWoodRailingX",
  674. startPos: cc.v2(4 - x, 11)
  675. })
  676. }
  677. //门外区域
  678. _temp.push({
  679. spawnName: "Dress_502_florist",
  680. startPos: cc.v2(4, 15)
  681. })
  682. _temp.push({
  683. spawnName: "Dress_505_ChrisCar01",
  684. startPos: cc.v2(6, 16)
  685. })
  686. _temp.push({
  687. spawnName: "Dress_505_PondDuck",
  688. startPos: cc.v2(6, 14)
  689. })
  690. for (let y = 0; y < 3; y++) {
  691. _temp.push({
  692. spawnName: "Dress_504_ChrisRailingY",
  693. startPos: cc.v2(8, 16 - y)
  694. })
  695. }
  696. //樱花路
  697. for (let x = 0; x < 5; x++) {
  698. _temp.push({
  699. spawnName: _cherryTree,
  700. startPos: cc.v2(10 - x * 2, 17)
  701. })
  702. _temp.push({
  703. spawnName: _cherryTree,
  704. startPos: cc.v2(10 - x * 2, 19)
  705. })
  706. }
  707. //------end
  708. //----右边区域--start
  709. _temp.push({
  710. spawnName: "Dress_505_Pond",
  711. startPos: cc.v2(20, 3)
  712. })
  713. _temp.push({
  714. spawnName: "Dress_504_RailingGrassY",
  715. startPos: cc.v2(21, 3)
  716. })
  717. _temp.push({
  718. spawnName: "Dress_502_FruitTreeAndStool",
  719. startPos: cc.v2(23, 3)
  720. })
  721. //---- end
  722. for (let i = 0; i < _temp.length; i++) {
  723. for (let j = 0; j < this.DressUpArray.length; j++) {
  724. let _dressUpTemp = this.DressUpArray[j];
  725. if (_dressUpTemp.name == _temp[i].spawnName) {
  726. let prefab = cc.instantiate(_dressUpTemp);
  727. prefab.parent = this.BuildingsParent;
  728. let tipNode = prefab.getChildByName("Tip");
  729. if(tipNode){
  730. tipNode.destroy();
  731. }
  732. let buildingsInfo = prefab.getComponent("buildingsInfo");
  733. //id用时间戳来记录
  734. buildingsInfo.buildInfo.id = new Date().getTime();//对应的id
  735. buildingsInfo.buildInfo.isItActive = false;
  736. //设置tile的最底下的坐标,就是起始坐标
  737. buildingsInfo.buildInfo.startTilePos = _temp[i].startPos;
  738. buildingsInfo.InitPos = false;
  739. buildingsInfo.InitStartPos = _temp[i].startPos;
  740. var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(_temp[i].startPos);
  741. prefab.setPosition(endPos.x, endPos.y);
  742. //起始坐标,占位范围,是否占位
  743. GlobalD.game.addBuildTiled(buildingsInfo.buildInfo.id, buildingsInfo.buildInfo.startTilePos, buildingsInfo.buildInfo.occupyArea);
  744. //添加占位信息
  745. GlobalD.game.addBuilding(buildingsInfo);
  746. // console.log(_dressUpTemp.name);
  747. //跳出里面一层循环
  748. break;
  749. }
  750. }
  751. }
  752. },
  753. //初始化场景建筑
  754. SpawnHouse: function () {
  755. let BuildingJSON = Object.assign([], GlobalD.GameData.GameData_buildings);
  756. //拿到数据后,清空 GlobalD.GameData.GameData_buildings 数据,下面再添加上去
  757. GlobalD.GameData.GameData_buildings.length = 0;
  758. // cc.log('BuildingJSON', BuildingJSON);
  759. // if (BuildingJSON.length == 0) {
  760. // //初始化默认房子
  761. // this.SpawnDefaultHouse();
  762. // return
  763. // };
  764. for (let i = 0; i < BuildingJSON.length; i++) {
  765. let HouseName = BuildingJSON[i].buildingNodeName;
  766. let housingTemp = this.onGetHousingPrefabFromName(HouseName);
  767. if (!housingTemp)
  768. cc.error('housingTemp', HouseName, housingTemp);
  769. //预制为空
  770. if (!housingTemp) continue;
  771. let buildingsInfo = housingTemp.getComponent("buildingsInfo");
  772. /**
  773. * 处理数据库数据冲突问题
  774. * 这里处理判断初始化位置是否被占用,占用了回收到仓库背包系统
  775. * BuildingJSON 看做旧的数据, 拿到旧数据 BuildingJSON[i].startTilePos 起始位置 ,生成对应预制的大小occupyArea
  776. * 来判断占位信息
  777. */
  778. // //全部回收
  779. // // 背包添加对应的建筑数量
  780. // GlobalD.game.PlusBuilding(buildingsInfo.buildInfo.buildingName);
  781. // // 删除上面生成的预制节点
  782. // housingTemp.destroy();
  783. // continue;
  784. let _canNotBuild = GlobalD.game.areTheraOverlappingAreas(BuildingJSON[i].startTilePos, buildingsInfo.buildInfo.occupyArea, 1);
  785. if (_canNotBuild) {
  786. // 背包添加对应的建筑数量
  787. GlobalD.game.PlusBuilding(buildingsInfo.buildInfo.buildingName);
  788. // 删除上面生成的预制节点
  789. housingTemp.destroy();
  790. //跳过生成
  791. continue;
  792. }
  793. housingTemp.parent = this.BuildingsParent;
  794. var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(BuildingJSON[i].startTilePos);
  795. housingTemp.setPosition(endPos.x, endPos.y);
  796. //id用时间戳来记录
  797. buildingsInfo.buildInfo.id = BuildingJSON[i].buildingId;//对应的id
  798. //设置tile的最底下的坐标,就是起始坐标
  799. buildingsInfo.buildInfo.startTilePos = BuildingJSON[i].startTilePos;
  800. //初始化位置的坐标
  801. buildingsInfo.InitStartPos = BuildingJSON[i].startTilePos;
  802. this.SpawnBuildingDefaultValue(buildingsInfo);
  803. //目前应该只有商店,后面根据RunningCost来判断 todo.....
  804. // if (reGameStates.BuildType.Shop == buildingsInfo.buildInfo.buildType)
  805. {
  806. // buildingsInfo.buildInfo.isItSaleable = Number(BuildingJSON[i].isItSaleable) > 0 ? true : false;
  807. buildingsInfo.buildInfo.isItStopOperation = Number(BuildingJSON[i].isItStopOperation) > 0 ? true : false;
  808. //如果不可以运营的,加上牌子
  809. if (buildingsInfo.buildInfo.isItStopOperation) {
  810. GlobalD.game.onAddBuildingTipView(buildingsInfo);
  811. }
  812. }
  813. //建筑物的加成值
  814. buildingsInfo.buildInfo.consumeStrengthAddValue = Number(BuildingJSON[i].consumeStrengthAddValue);
  815. buildingsInfo.buildInfo.goodsPriceAddValue = Number(BuildingJSON[i].goodsPriceAddValue);
  816. /**
  817. * 判断是否占位的时候,需要进一步处理。放回背包,然后背包物品加上对应的数量
  818. */
  819. //起始坐标,占位范围,是否占位
  820. GlobalD.game.addBuildTiled(buildingsInfo.buildInfo.id, buildingsInfo.buildInfo.startTilePos, buildingsInfo.buildInfo.occupyArea);
  821. //添加占位信息
  822. GlobalD.game.addBuilding(buildingsInfo);
  823. }
  824. // console.log("GlobalD.GameData.GameData_buildings:", GlobalD.GameData.GameData_buildings);
  825. },
  826. onGetHousingPrefabFromName(HouseName) {
  827. let housing = null;
  828. //住宿地方
  829. if (HouseName == 'Env_101_house_low') {
  830. housing = cc.instantiate(this.Env_101_house_low);
  831. }
  832. else if (HouseName === 'Env_102_house_mid') {
  833. housing = cc.instantiate(this.Env_102_house_mid);
  834. }
  835. else if (HouseName == 'Env_103_house_high') {
  836. housing = cc.instantiate(this.Env_103_house_high);
  837. }
  838. else if (HouseName == 'Env_104_BlueCastle') {
  839. housing = cc.instantiate(this.Env_104_BlueCastle);
  840. }
  841. else if (HouseName == 'Env_105_PinkCastle') {
  842. housing = cc.instantiate(this.Env_105_PinkCastle);
  843. }
  844. //劳动地方
  845. else if (HouseName == 'Labour_201_Farmland') {
  846. housing = cc.instantiate(this.Labour_201_Farmland);
  847. }
  848. else if (HouseName == 'Labour_202_TimberYard') {
  849. housing = cc.instantiate(this.Labour_202_TimberYard);
  850. }
  851. else if (HouseName == 'Labour_203_MiningPit') {
  852. housing = cc.instantiate(this.Labour_203_MiningPit);
  853. }
  854. else if (HouseName == 'Labour_204_Factory') {
  855. housing = cc.instantiate(this.Labour_204_Factory);
  856. }
  857. //神农专用农田
  858. else if (HouseName == 'Labour_205_Holy_Farmland') {
  859. housing = cc.instantiate(this.Labour_205_Holy_Farmland);
  860. }
  861. //特殊建筑
  862. else if (HouseName == 'Spe_401_StreetLamp') {
  863. housing = cc.instantiate(this.Spe_401_StreetLamp);
  864. }
  865. else if (HouseName == 'Spe_402_GreenBelt') {
  866. housing = cc.instantiate(this.Spe_402_GreenBelt);
  867. }
  868. else if (HouseName == 'Spe_403_FlowerBed') {
  869. housing = cc.instantiate(this.Spe_403_FlowerBed);
  870. }
  871. else if (HouseName == 'Spe_404_Pool') {
  872. housing = cc.instantiate(this.Spe_404_Pool);
  873. }
  874. else if (HouseName == 'Spe_405_PoliceOffice') {
  875. housing = cc.instantiate(this.Spe_405_PoliceOffice);
  876. }
  877. else if (HouseName == 'Spe_406_Playground') {
  878. housing = cc.instantiate(this.Spe_406_Playground);
  879. }
  880. //商店类型
  881. else if (HouseName == 'Shops_30101_ColdDrinkStall') {
  882. housing = cc.instantiate(this.Shops_30101_ColdDrinkStall);
  883. }
  884. else if (HouseName == 'Shops_30102_SalesMachine') {
  885. housing = cc.instantiate(this.Shops_30102_SalesMachine);
  886. }
  887. else if (HouseName == 'Shops_30103_Bakery') {
  888. housing = cc.instantiate(this.Shops_30103_Bakery);
  889. }
  890. else if (HouseName == 'Shops_30104_BreakfastCar') {
  891. housing = cc.instantiate(this.Shops_30104_BreakfastCar);
  892. }
  893. else if (HouseName == 'Shops_30201_TeaShop') {
  894. housing = cc.instantiate(this.Shops_30201_TeaShop);
  895. }
  896. else if (HouseName == 'Shops_30202_confectaurant') {
  897. housing = cc.instantiate(this.Shops_30202_confectaurant);
  898. }
  899. else if (HouseName == 'Shops_30203_GourmetRestaurant') {
  900. housing = cc.instantiate(this.Shops_30203_GourmetRestaurant);
  901. }
  902. else if (HouseName == 'Shops_30204_WesternRestaurant') {
  903. housing = cc.instantiate(this.Shops_30204_WesternRestaurant);
  904. }
  905. else if (HouseName == 'Shops_30301_Florist') {
  906. housing = cc.instantiate(this.Shops_30301_Florist);
  907. }
  908. else if (HouseName == 'Shops_30302_HairSalon') {
  909. housing = cc.instantiate(this.Shops_30302_HairSalon);
  910. }
  911. else if (HouseName == 'Shops_30303_DressShop') {
  912. housing = cc.instantiate(this.Shops_30303_DressShop);
  913. }
  914. else if (HouseName == 'Shops_30304_JewelryStore') {
  915. housing = cc.instantiate(this.Shops_30304_JewelryStore);
  916. }
  917. else if (HouseName == 'Shops_30305_Cinema') {
  918. housing = cc.instantiate(this.Shops_30305_Cinema);
  919. }
  920. return housing;
  921. },
  922. //获取预制的名字
  923. onGetPrefabsBuildingName(index) {
  924. //content button 设置的index
  925. let buildingName = '';
  926. //农舍
  927. if ('101' == index) {
  928. buildingName = 'Env_101_house_low';
  929. }
  930. //单元楼
  931. else if ('102' == index) {
  932. buildingName = 'Env_102_house_mid';
  933. }
  934. //别墅
  935. else if ('103' == index) {
  936. buildingName = 'Env_103_house_high';
  937. }
  938. //蓝色城堡
  939. else if ('104' == index) {
  940. buildingName = 'Env_104_BlueCastle';
  941. }
  942. //粉色城堡
  943. else if ('105' == index) {
  944. buildingName = 'Env_105_PinkCastle';
  945. }
  946. //农田
  947. else if ('201' == index) {
  948. buildingName = 'Labour_201_Farmland';
  949. }
  950. //伐木场
  951. else if ('202' == index) {
  952. buildingName = 'Labour_202_TimberYard';
  953. }
  954. //矿坑
  955. else if ('203' == index) {
  956. buildingName = 'Labour_203_MiningPit';
  957. }
  958. //工厂
  959. else if ('204' == index) {
  960. buildingName = 'Labour_204_Factory';
  961. }
  962. //神农专用农田
  963. else if ('205' == index) {
  964. buildingName = 'Labour_205_Holy_Farmland';
  965. }
  966. //冷饮摊
  967. else if ('30101' == index) {
  968. buildingName = 'Shops_30101_ColdDrinkStall';
  969. }
  970. //贩卖机
  971. else if ('30102' == index) {
  972. buildingName = 'Shops_30102_SalesMachine';
  973. }
  974. //面包房
  975. else if ('30103' == index) {
  976. buildingName = 'Shops_30103_Bakery';
  977. }
  978. //早餐车
  979. else if ('30104' == index) {
  980. buildingName = 'Shops_30104_BreakfastCar';
  981. }
  982. //饮茶店
  983. else if ('30201' == index) {
  984. buildingName = 'Shops_30201_TeaShop';
  985. }
  986. //点心店
  987. else if ('30202' == index) {
  988. buildingName = 'Shops_30202_confectaurant';
  989. }
  990. //美食店
  991. else if ('30203' == index) {
  992. buildingName = 'Shops_30203_GourmetRestaurant';
  993. }
  994. //西餐厅
  995. else if ('30204' == index) {
  996. buildingName = 'Shops_30204_WesternRestaurant';
  997. }
  998. //花店
  999. else if ('30301' == index) {
  1000. buildingName = 'Shops_30301_Florist';
  1001. }
  1002. //美发店
  1003. else if ('30302' == index) {
  1004. buildingName = 'Shops_30302_HairSalon';
  1005. }
  1006. //洋装店
  1007. else if ('30303' == index) {
  1008. buildingName = 'Shops_30303_DressShop';
  1009. }
  1010. //珠宝店
  1011. else if ('30304' == index) {
  1012. buildingName = 'Shops_30304_JewelryStore';
  1013. }
  1014. //电影院
  1015. else if ('30305' == index) {
  1016. buildingName = 'Shops_30305_Cinema';
  1017. }
  1018. //路灯
  1019. else if ('401' == index) {
  1020. buildingName = 'Spe_401_StreetLamp';
  1021. }
  1022. //绿化带
  1023. else if ('402' == index) {
  1024. buildingName = 'Spe_402_GreenBelt';
  1025. }
  1026. //花坛
  1027. else if ('403' == index) {
  1028. buildingName = 'Spe_403_FlowerBed';
  1029. }
  1030. //喷泉
  1031. else if ('404' == index) {
  1032. buildingName = 'Spe_404_Pool';
  1033. }
  1034. //警察局
  1035. else if ('405' == index) {
  1036. buildingName = 'Spe_405_PoliceOffice';
  1037. }
  1038. //游乐场
  1039. else if ('406' == index) {
  1040. buildingName = 'Spe_406_Playground';
  1041. }
  1042. return buildingName;
  1043. },
  1044. Grant() {
  1045. },
  1046. Sale() {
  1047. },
  1048. Exchange() {
  1049. }
  1050. });