ManageBuildings.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124
  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. * 村长和镇长
  364. * 初始化障碍物场景,装饰
  365. */
  366. if(0 != GlobalD.Dapp.UserInfo.agent_level){
  367. this.spawnDressUp();
  368. }
  369. //先初始化网络数据
  370. this.SpawnHouse();
  371. // cc.log('初始化场景建筑');
  372. let BuildingStateArray = GlobalD.GameData.GetBuildingStateArray();
  373. for (let i = 0; i < BuildingStateArray.length; i++) {
  374. if (BuildingStateArray[i] == 0) {
  375. if (this.BuildingArray[i])
  376. this.BuildingArray[i].active = false;
  377. }
  378. else {
  379. if (this.BuildingArray[i])
  380. this.BuildingArray[i].active = true;
  381. }
  382. }
  383. let BuildingNumArray = GlobalD.GameData.GetBuildingNumArray();
  384. // cc.log('BuildingNumArray',BuildingNumArray)
  385. for (let i = 3; i < this.BuildingArray.length; i++) {
  386. // cc.log('this.BuildingArray[' + i + ']=' + this.BuildingArray[i].getChildByName('Name').getComponent(cc.Label).string);
  387. if (this.BuildingArray[i])
  388. this.BuildingArray[i].getChildByName('Name').getChildByName('Num').getComponent(cc.Label).string = BuildingNumArray[i];
  389. }
  390. },
  391. //生成房子的默认值
  392. SpawnBuildingDefaultValue(buildingsInfo) {
  393. buildingsInfo.InitPos = false;
  394. buildingsInfo.InitWorkBuildingInfo = false;
  395. //激活状态,可运营
  396. buildingsInfo.buildInfo.isItActive = true;
  397. //设置销售状态
  398. buildingsInfo.buildInfo.isItSaleable = true;
  399. if (reGameStates.BuildType.Farmland == buildingsInfo.buildInfo.buildType) {
  400. buildingsInfo.buildInfo.isItSaleable = GlobalD.GameData.GetFoodTradeState() > 0 ? true : false;// GlobalD.GameData.GetFoodTradeState();
  401. // cc.log('初始化房子的信息:', buildingsInfo.buildInfo.buildingName, buildingsInfo.buildInfo.isItSaleable);
  402. }
  403. if (reGameStates.BuildType.MiningPit == buildingsInfo.buildInfo.buildType) {
  404. buildingsInfo.buildInfo.isItSaleable = GlobalD.GameData.GetMineralTradeState() > 0 ? true : false;// GlobalD.GameData.GetMineralTradeState();
  405. }
  406. if (reGameStates.BuildType.TimberYard == buildingsInfo.buildInfo.buildType) {
  407. buildingsInfo.buildInfo.isItSaleable = GlobalD.GameData.GetWoodTradeState() > 0 ? true : false;// GlobalD.GameData.GetWoodTradeState();
  408. }
  409. //设置一下,可查看信息
  410. if (reGameStates.BuildType.Housing !== buildingsInfo.buildInfo.buildType
  411. && reGameStates.BuildType.Special !== buildingsInfo.buildInfo.buildType
  412. /** 神农小镇固定土地关闭 基本的房屋信息,另外设置其他信息 */
  413. && reGameStates.BuildType.HolyFarmland !== buildingsInfo.buildInfo.buildType
  414. ) {
  415. buildingsInfo.node.getComponent('buildingsTouch').isShowBuildingInfo = true;
  416. }
  417. //设置消耗的体力值为工人的最低值 20
  418. //过高的话,会导致工人不工作
  419. // buildingsInfo.buildInfo.totalConsumption = 20;
  420. // cc.log('初始化房子的信息:', buildingsInfo.buildInfo.buildingName, buildingsInfo.buildInfo.isItSaleable)
  421. },
  422. //初始化场景的两个建筑
  423. SpawnDefaultHouse() {
  424. cc.log('初始化默认房子');
  425. //房子
  426. let housingTemp_house = this.onGetHousingPrefabFromName('Env_101_house_low');
  427. housingTemp_house.parent = this.BuildingsParent;
  428. var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(cc.v2(24, 23));
  429. housingTemp_house.setPosition(endPos.x, endPos.y);
  430. let buildingsInfo_house = housingTemp_house.getComponent("buildingsInfo");
  431. //id用时间戳来记录
  432. buildingsInfo_house.buildInfo.id = 101;//对应的id
  433. //设置tile的最底下的坐标,就是起始坐标
  434. buildingsInfo_house.buildInfo.startTilePos = cc.v2(24, 23);
  435. this.SpawnBuildingDefaultValue(buildingsInfo_house);
  436. //起始坐标,占位范围,是否占位
  437. GlobalD.game.addBuildTiled(buildingsInfo_house.buildInfo.id, buildingsInfo_house.buildInfo.startTilePos, buildingsInfo_house.buildInfo.occupyArea);
  438. //添加占位信息
  439. GlobalD.game.addBuilding(buildingsInfo_house);
  440. //农田
  441. let housingTemp_farmland = this.onGetHousingPrefabFromName('Labour_201_Farmland');
  442. housingTemp_farmland.parent = this.BuildingsParent;
  443. var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(cc.v2(26, 24));
  444. housingTemp_farmland.setPosition(endPos.x, endPos.y);
  445. let buildingsInfo_farmland = housingTemp_farmland.getComponent("buildingsInfo");
  446. //id用时间戳来记录
  447. buildingsInfo_farmland.buildInfo.id = 201;//对应的id
  448. //设置tile的最底下的坐标,就是起始坐标
  449. buildingsInfo_farmland.buildInfo.startTilePos = cc.v2(26, 24);
  450. this.SpawnBuildingDefaultValue(buildingsInfo_farmland);
  451. //起始坐标,占位范围,是否占位
  452. GlobalD.game.addBuildTiled(buildingsInfo_farmland.buildInfo.id, buildingsInfo_farmland.buildInfo.startTilePos, buildingsInfo_farmland.buildInfo.occupyArea);
  453. //添加占位信息
  454. GlobalD.game.addBuilding(buildingsInfo_farmland);
  455. },
  456. //初始化后台配置的土地数据
  457. spawnConfigLand() {
  458. if (GlobalD.ConfigLand == null) {
  459. console.error("GlobalD.ConfigLand 未初始化设置!");
  460. return;
  461. }
  462. if (GlobalD.UserLeaseLand == null) {
  463. console.error("GlobalD.UserLeaseLand 未初始化设置!");
  464. return;
  465. }
  466. let _configLand = GlobalD.ConfigLand;
  467. let _userLeaseLand = GlobalD.UserLeaseLand;
  468. // console.log(_configLand, _userLeaseLand);
  469. // console.log(this.node.getComponent("ManageUI"));
  470. for (let i = 0; i < _configLand.length; i++) {
  471. //生成默认土地
  472. //农田
  473. let housingTemp_farmland = this.onGetHousingPrefabFromName('Labour_205_Holy_Farmland');
  474. housingTemp_farmland.parent = this.BuildingsParent;
  475. var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(cc.v2(_configLand[i].posX, _configLand[i].posY));
  476. housingTemp_farmland.setPosition(endPos.x, endPos.y);
  477. let leaseFarmlandInfoScript = housingTemp_farmland.getComponent("LeaseFarmlandInfo");
  478. //记录config的土地信息
  479. leaseFarmlandInfoScript.setConfigLandInfo(_configLand[i]);
  480. for (let j = 0; j < _userLeaseLand.length; j++) {
  481. //记录已经租赁的信息(租赁里面包含了seedInfo,如果有种植的话,对应的种植信息会有)
  482. if (_userLeaseLand[j].configLandId == _configLand[i].id) {
  483. let _leaseLandInfo = _userLeaseLand[j];
  484. leaseFarmlandInfoScript.setLeaseLandInfo(_leaseLandInfo);
  485. }
  486. }
  487. let buildingsInfo_farmland = housingTemp_farmland.getComponent("buildingsInfo");
  488. //id用时间戳来记录
  489. buildingsInfo_farmland.buildInfo.id = _configLand[i].id;//对应的id
  490. /**
  491. * 服务器设置的农田 独立于其他游戏数据
  492. * 这步设置之后,addBuilding 时候不存储到 GameData_buildings
  493. */
  494. buildingsInfo_farmland.InitPosFromStore = true;
  495. //设置tile的最底下的坐标,就是起始坐标
  496. buildingsInfo_farmland.buildInfo.startTilePos = cc.v2(_configLand[i].posX, _configLand[i].posY);
  497. this.SpawnBuildingDefaultValue(buildingsInfo_farmland);
  498. //起始坐标,占位范围,是否占位
  499. GlobalD.game.addBuildTiled(buildingsInfo_farmland.buildInfo.id, buildingsInfo_farmland.buildInfo.startTilePos, buildingsInfo_farmland.buildInfo.occupyArea);
  500. //添加占位信息
  501. GlobalD.game.addBuilding(buildingsInfo_farmland);
  502. }
  503. },
  504. //初始化障碍物
  505. spawnDressUp() {
  506. //村长和镇长的区别,樱花树区别
  507. let agent_level = GlobalD.Dapp.UserInfo.agent_level; // 0普通用户,1 村长身份,2 镇长身份
  508. let _cherryTree = 2 === agent_level? "Dress_505_SmallTree02":"Dress_505_SmallTree01";
  509. let _temp = [
  510. //左边第一部分 ----start----
  511. {
  512. spawnName: "Dress_502_ChrisTree",
  513. startPos: cc.v2(14, 20)
  514. },
  515. {
  516. spawnName: "Dress_503_RailingGrassX",
  517. startPos: cc.v2(9, 20)
  518. },
  519. {
  520. spawnName: "Dress_503_RailingGrassX",
  521. startPos: cc.v2(7, 20)
  522. },
  523. //-----
  524. {
  525. spawnName: "Dress_505_FlowerBed",
  526. startPos: cc.v2(8, 22)
  527. },
  528. {
  529. spawnName: "Dress_505_FlowerBed",
  530. startPos: cc.v2(8, 23)
  531. },
  532. //喷泉
  533. {
  534. spawnName: "Dress_502_Fountain",
  535. startPos: cc.v2(10, 23)
  536. },
  537. {
  538. spawnName: "Dress_505_FlowerBed",
  539. startPos: cc.v2(11, 22)
  540. },
  541. {
  542. spawnName: "Dress_505_FlowerBed",
  543. startPos: cc.v2(11, 23)
  544. },
  545. {
  546. spawnName: "Dress_505_ChrisSanta",
  547. startPos: cc.v2(10, 25)
  548. },
  549. //-----
  550. //左边第一部分 ----end----
  551. //主路放两个灯和树
  552. {
  553. spawnName: "Dress_505_Streetlight",
  554. startPos: cc.v2(15, 29)
  555. },
  556. {
  557. spawnName: "Dress_505_Streetlight",
  558. startPos: cc.v2(18, 29)
  559. },
  560. {
  561. spawnName: "Dress_505_SmallTree",
  562. startPos: cc.v2(15, 30)
  563. },
  564. {
  565. spawnName: "Dress_505_SmallTree",
  566. startPos: cc.v2(18, 30)
  567. }
  568. ];
  569. //左边小麦区域
  570. for (let x = 0; x < 3; x++) {
  571. for (let y = 0; y < 2; y++) {
  572. _temp.push({
  573. spawnName: "Dress_502_Rice",
  574. startPos: cc.v2(4 - x * 2, 30 - y * 2)
  575. })
  576. }
  577. }
  578. //1倍土地部分木质花圃
  579. for (let x = 0; x < 6; x++) {
  580. for (let y = 0; y < 3; y++) {
  581. _temp.push({
  582. spawnName: "Dress_503_WhiteWoodRailingX",
  583. startPos: cc.v2(18 + x, 14 - y * 3)
  584. })
  585. }
  586. }
  587. //生成一个未盛开的樱花围绕,间隔1个空格 ---start ,镇长换成盛开的樱花
  588. for (let x = 0; x < 3; x++) {
  589. _temp.push({
  590. spawnName: _cherryTree,
  591. startPos: cc.v2(18 + x * 2, 17)
  592. })
  593. _temp.push({
  594. spawnName: _cherryTree,
  595. startPos: cc.v2(18 + x * 2, 5)
  596. })
  597. }
  598. for (let y = 0; y < 7; y++) {
  599. _temp.push({
  600. spawnName: _cherryTree,
  601. startPos: cc.v2(24, 17 - y * 2)
  602. })
  603. }
  604. //多倍区域
  605. for (let x = 0; x < 3; x++) {
  606. _temp.push({
  607. spawnName: _cherryTree,
  608. startPos: cc.v2(15 - x * 2, 14)
  609. })
  610. _temp.push({
  611. spawnName: _cherryTree,
  612. startPos: cc.v2(15 - x * 2, 2)
  613. })
  614. }
  615. //生成一个未盛开的樱花围绕,间隔1个空格 --- end
  616. //多倍土地部分木质花圃
  617. for (let x = 0; x < 3; x++) {
  618. for (let y = 0; y < 3; y++) {
  619. _temp.push({
  620. spawnName: "Dress_503_RailingGrassX",
  621. startPos: cc.v2(15 - x * 2, 11 - y * 3)
  622. })
  623. }
  624. }
  625. //生成番茄区域
  626. for (let x = 0; x < 3; x++) {
  627. for (let y = 0; y < 2; y++) {
  628. _temp.push({
  629. spawnName: "Dress_502_Tomato",
  630. startPos: cc.v2(26 + x * 2, 30 - y * 2)
  631. })
  632. }
  633. }
  634. //----中上别墅区域--start
  635. //生成中上三个别墅和三个树木
  636. for (let x = 0; x < 3; x++) {
  637. _temp.push({
  638. spawnName: "Dress_505_SmallTree",
  639. startPos: cc.v2(7 - x * 2, 6)
  640. })
  641. _temp.push({
  642. spawnName: "Dress_502_Villa",
  643. startPos: cc.v2(8 - x * 2, 8)
  644. })
  645. }
  646. //雪橇
  647. _temp.push({
  648. spawnName: "Dress_505_ChrisCar02",
  649. startPos: cc.v2(8, 10)
  650. })
  651. //圣诞门和栏杆
  652. for (let x = 0; x < 3; x++) {
  653. _temp.push({
  654. spawnName: "Dress_503_WhiteWoodRailingX",
  655. startPos: cc.v2(8 - x, 11)
  656. })
  657. }
  658. _temp.push({
  659. spawnName: "Dress_503_ChrisDoorX",
  660. startPos: cc.v2(5, 11)
  661. })
  662. for (let x = 0; x < 3; x++) {
  663. _temp.push({
  664. spawnName: "Dress_503_WhiteWoodRailingX",
  665. startPos: cc.v2(4 - x, 11)
  666. })
  667. }
  668. //门外区域
  669. _temp.push({
  670. spawnName: "Dress_502_florist",
  671. startPos: cc.v2(4, 15)
  672. })
  673. _temp.push({
  674. spawnName: "Dress_505_ChrisCar01",
  675. startPos: cc.v2(6, 16)
  676. })
  677. _temp.push({
  678. spawnName: "Dress_505_PondDuck",
  679. startPos: cc.v2(6, 14)
  680. })
  681. for (let y = 0; y < 3; y++) {
  682. _temp.push({
  683. spawnName: "Dress_504_ChrisRailingY",
  684. startPos: cc.v2(8, 16 - y)
  685. })
  686. }
  687. //樱花路
  688. for (let x = 0; x < 6; x++) {
  689. _temp.push({
  690. spawnName: _cherryTree,
  691. startPos: cc.v2(10 - x * 2, 17)
  692. })
  693. _temp.push({
  694. spawnName: _cherryTree,
  695. startPos: cc.v2(10 - x * 2, 19)
  696. })
  697. }
  698. //------end
  699. //----右边区域--start
  700. _temp.push({
  701. spawnName: "Dress_505_Pond",
  702. startPos: cc.v2(20, 3)
  703. })
  704. _temp.push({
  705. spawnName: "Dress_504_RailingGrassY",
  706. startPos: cc.v2(21, 3)
  707. })
  708. _temp.push({
  709. spawnName: "Dress_502_FruitTreeAndStool",
  710. startPos: cc.v2(23, 3)
  711. })
  712. //---- end
  713. for (let i = 0; i < _temp.length; i++) {
  714. for (let j = 0; j < this.DressUpArray.length; j++) {
  715. let _dressUpTemp = this.DressUpArray[j];
  716. if (_dressUpTemp.name == _temp[i].spawnName) {
  717. let prefab = cc.instantiate(_dressUpTemp);
  718. prefab.parent = this.BuildingsParent;
  719. let tipNode = prefab.getChildByName("Tip");
  720. if(tipNode){
  721. tipNode.destroy();
  722. }
  723. let buildingsInfo = prefab.getComponent("buildingsInfo");
  724. //id用时间戳来记录
  725. buildingsInfo.buildInfo.id = new Date().getTime();//对应的id
  726. buildingsInfo.buildInfo.isItActive = false;
  727. //设置tile的最底下的坐标,就是起始坐标
  728. buildingsInfo.buildInfo.startTilePos = _temp[i].startPos;
  729. buildingsInfo.InitPos = false;
  730. buildingsInfo.InitStartPos = _temp[i].startPos;
  731. var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(_temp[i].startPos);
  732. prefab.setPosition(endPos.x, endPos.y);
  733. //起始坐标,占位范围,是否占位
  734. GlobalD.game.addBuildTiled(buildingsInfo.buildInfo.id, buildingsInfo.buildInfo.startTilePos, buildingsInfo.buildInfo.occupyArea);
  735. //添加占位信息
  736. GlobalD.game.addBuilding(buildingsInfo);
  737. // console.log(_dressUpTemp.name);
  738. //跳出里面一层循环
  739. break;
  740. }
  741. }
  742. }
  743. },
  744. //初始化场景建筑
  745. SpawnHouse: function () {
  746. let BuildingJSON = Object.assign([], GlobalD.GameData.GameData_buildings);
  747. //拿到数据后,清空 GlobalD.GameData.GameData_buildings 数据,下面再添加上去
  748. GlobalD.GameData.GameData_buildings.length = 0;
  749. // cc.log('BuildingJSON', BuildingJSON);
  750. // if (BuildingJSON.length == 0) {
  751. // //初始化默认房子
  752. // this.SpawnDefaultHouse();
  753. // return
  754. // };
  755. for (let i = 0; i < BuildingJSON.length; i++) {
  756. let HouseName = BuildingJSON[i].buildingNodeName;
  757. let housingTemp = this.onGetHousingPrefabFromName(HouseName);
  758. if (!housingTemp)
  759. cc.error('housingTemp', HouseName, housingTemp);
  760. //预制为空
  761. if (!housingTemp) continue;
  762. let buildingsInfo = housingTemp.getComponent("buildingsInfo");
  763. /**
  764. * 处理数据库数据冲突问题
  765. * 这里处理判断初始化位置是否被占用,占用了回收到仓库背包系统
  766. * BuildingJSON 看做旧的数据, 拿到旧数据 BuildingJSON[i].startTilePos 起始位置 ,生成对应预制的大小occupyArea
  767. * 来判断占位信息
  768. */
  769. // //全部回收
  770. // // 背包添加对应的建筑数量
  771. // GlobalD.game.PlusBuilding(buildingsInfo.buildInfo.buildingName);
  772. // // 删除上面生成的预制节点
  773. // housingTemp.destroy();
  774. // continue;
  775. let _canNotBuild = GlobalD.game.areTheraOverlappingAreas(BuildingJSON[i].startTilePos, buildingsInfo.buildInfo.occupyArea, 1);
  776. if (_canNotBuild) {
  777. // 背包添加对应的建筑数量
  778. GlobalD.game.PlusBuilding(buildingsInfo.buildInfo.buildingName);
  779. // 删除上面生成的预制节点
  780. housingTemp.destroy();
  781. //跳过生成
  782. continue;
  783. }
  784. housingTemp.parent = this.BuildingsParent;
  785. var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(BuildingJSON[i].startTilePos);
  786. housingTemp.setPosition(endPos.x, endPos.y);
  787. //id用时间戳来记录
  788. buildingsInfo.buildInfo.id = BuildingJSON[i].buildingId;//对应的id
  789. //设置tile的最底下的坐标,就是起始坐标
  790. buildingsInfo.buildInfo.startTilePos = BuildingJSON[i].startTilePos;
  791. //初始化位置的坐标
  792. buildingsInfo.InitStartPos = BuildingJSON[i].startTilePos;
  793. this.SpawnBuildingDefaultValue(buildingsInfo);
  794. //目前应该只有商店,后面根据RunningCost来判断 todo.....
  795. // if (reGameStates.BuildType.Shop == buildingsInfo.buildInfo.buildType)
  796. {
  797. // buildingsInfo.buildInfo.isItSaleable = Number(BuildingJSON[i].isItSaleable) > 0 ? true : false;
  798. buildingsInfo.buildInfo.isItStopOperation = Number(BuildingJSON[i].isItStopOperation) > 0 ? true : false;
  799. //如果不可以运营的,加上牌子
  800. if (buildingsInfo.buildInfo.isItStopOperation) {
  801. GlobalD.game.onAddBuildingTipView(buildingsInfo);
  802. }
  803. }
  804. //建筑物的加成值
  805. buildingsInfo.buildInfo.consumeStrengthAddValue = Number(BuildingJSON[i].consumeStrengthAddValue);
  806. buildingsInfo.buildInfo.goodsPriceAddValue = Number(BuildingJSON[i].goodsPriceAddValue);
  807. /**
  808. * 判断是否占位的时候,需要进一步处理。放回背包,然后背包物品加上对应的数量
  809. */
  810. //起始坐标,占位范围,是否占位
  811. GlobalD.game.addBuildTiled(buildingsInfo.buildInfo.id, buildingsInfo.buildInfo.startTilePos, buildingsInfo.buildInfo.occupyArea);
  812. //添加占位信息
  813. GlobalD.game.addBuilding(buildingsInfo);
  814. }
  815. // console.log("GlobalD.GameData.GameData_buildings:", GlobalD.GameData.GameData_buildings);
  816. },
  817. onGetHousingPrefabFromName(HouseName) {
  818. let housing = null;
  819. //住宿地方
  820. if (HouseName == 'Env_101_house_low') {
  821. housing = cc.instantiate(this.Env_101_house_low);
  822. }
  823. else if (HouseName === 'Env_102_house_mid') {
  824. housing = cc.instantiate(this.Env_102_house_mid);
  825. }
  826. else if (HouseName == 'Env_103_house_high') {
  827. housing = cc.instantiate(this.Env_103_house_high);
  828. }
  829. else if (HouseName == 'Env_104_BlueCastle') {
  830. housing = cc.instantiate(this.Env_104_BlueCastle);
  831. }
  832. else if (HouseName == 'Env_105_PinkCastle') {
  833. housing = cc.instantiate(this.Env_105_PinkCastle);
  834. }
  835. //劳动地方
  836. else if (HouseName == 'Labour_201_Farmland') {
  837. housing = cc.instantiate(this.Labour_201_Farmland);
  838. }
  839. else if (HouseName == 'Labour_202_TimberYard') {
  840. housing = cc.instantiate(this.Labour_202_TimberYard);
  841. }
  842. else if (HouseName == 'Labour_203_MiningPit') {
  843. housing = cc.instantiate(this.Labour_203_MiningPit);
  844. }
  845. else if (HouseName == 'Labour_204_Factory') {
  846. housing = cc.instantiate(this.Labour_204_Factory);
  847. }
  848. //神农专用农田
  849. else if (HouseName == 'Labour_205_Holy_Farmland') {
  850. housing = cc.instantiate(this.Labour_205_Holy_Farmland);
  851. }
  852. //特殊建筑
  853. else if (HouseName == 'Spe_401_StreetLamp') {
  854. housing = cc.instantiate(this.Spe_401_StreetLamp);
  855. }
  856. else if (HouseName == 'Spe_402_GreenBelt') {
  857. housing = cc.instantiate(this.Spe_402_GreenBelt);
  858. }
  859. else if (HouseName == 'Spe_403_FlowerBed') {
  860. housing = cc.instantiate(this.Spe_403_FlowerBed);
  861. }
  862. else if (HouseName == 'Spe_404_Pool') {
  863. housing = cc.instantiate(this.Spe_404_Pool);
  864. }
  865. else if (HouseName == 'Spe_405_PoliceOffice') {
  866. housing = cc.instantiate(this.Spe_405_PoliceOffice);
  867. }
  868. else if (HouseName == 'Spe_406_Playground') {
  869. housing = cc.instantiate(this.Spe_406_Playground);
  870. }
  871. //商店类型
  872. else if (HouseName == 'Shops_30101_ColdDrinkStall') {
  873. housing = cc.instantiate(this.Shops_30101_ColdDrinkStall);
  874. }
  875. else if (HouseName == 'Shops_30102_SalesMachine') {
  876. housing = cc.instantiate(this.Shops_30102_SalesMachine);
  877. }
  878. else if (HouseName == 'Shops_30103_Bakery') {
  879. housing = cc.instantiate(this.Shops_30103_Bakery);
  880. }
  881. else if (HouseName == 'Shops_30104_BreakfastCar') {
  882. housing = cc.instantiate(this.Shops_30104_BreakfastCar);
  883. }
  884. else if (HouseName == 'Shops_30201_TeaShop') {
  885. housing = cc.instantiate(this.Shops_30201_TeaShop);
  886. }
  887. else if (HouseName == 'Shops_30202_confectaurant') {
  888. housing = cc.instantiate(this.Shops_30202_confectaurant);
  889. }
  890. else if (HouseName == 'Shops_30203_GourmetRestaurant') {
  891. housing = cc.instantiate(this.Shops_30203_GourmetRestaurant);
  892. }
  893. else if (HouseName == 'Shops_30204_WesternRestaurant') {
  894. housing = cc.instantiate(this.Shops_30204_WesternRestaurant);
  895. }
  896. else if (HouseName == 'Shops_30301_Florist') {
  897. housing = cc.instantiate(this.Shops_30301_Florist);
  898. }
  899. else if (HouseName == 'Shops_30302_HairSalon') {
  900. housing = cc.instantiate(this.Shops_30302_HairSalon);
  901. }
  902. else if (HouseName == 'Shops_30303_DressShop') {
  903. housing = cc.instantiate(this.Shops_30303_DressShop);
  904. }
  905. else if (HouseName == 'Shops_30304_JewelryStore') {
  906. housing = cc.instantiate(this.Shops_30304_JewelryStore);
  907. }
  908. else if (HouseName == 'Shops_30305_Cinema') {
  909. housing = cc.instantiate(this.Shops_30305_Cinema);
  910. }
  911. return housing;
  912. },
  913. //获取预制的名字
  914. onGetPrefabsBuildingName(index) {
  915. //content button 设置的index
  916. let buildingName = '';
  917. //农舍
  918. if ('101' == index) {
  919. buildingName = 'Env_101_house_low';
  920. }
  921. //单元楼
  922. else if ('102' == index) {
  923. buildingName = 'Env_102_house_mid';
  924. }
  925. //别墅
  926. else if ('103' == index) {
  927. buildingName = 'Env_103_house_high';
  928. }
  929. //蓝色城堡
  930. else if ('104' == index) {
  931. buildingName = 'Env_104_BlueCastle';
  932. }
  933. //粉色城堡
  934. else if ('105' == index) {
  935. buildingName = 'Env_105_PinkCastle';
  936. }
  937. //农田
  938. else if ('201' == index) {
  939. buildingName = 'Labour_201_Farmland';
  940. }
  941. //伐木场
  942. else if ('202' == index) {
  943. buildingName = 'Labour_202_TimberYard';
  944. }
  945. //矿坑
  946. else if ('203' == index) {
  947. buildingName = 'Labour_203_MiningPit';
  948. }
  949. //工厂
  950. else if ('204' == index) {
  951. buildingName = 'Labour_204_Factory';
  952. }
  953. //神农专用农田
  954. else if ('205' == index) {
  955. buildingName = 'Labour_205_Holy_Farmland';
  956. }
  957. //冷饮摊
  958. else if ('30101' == index) {
  959. buildingName = 'Shops_30101_ColdDrinkStall';
  960. }
  961. //贩卖机
  962. else if ('30102' == index) {
  963. buildingName = 'Shops_30102_SalesMachine';
  964. }
  965. //面包房
  966. else if ('30103' == index) {
  967. buildingName = 'Shops_30103_Bakery';
  968. }
  969. //早餐车
  970. else if ('30104' == index) {
  971. buildingName = 'Shops_30104_BreakfastCar';
  972. }
  973. //饮茶店
  974. else if ('30201' == index) {
  975. buildingName = 'Shops_30201_TeaShop';
  976. }
  977. //点心店
  978. else if ('30202' == index) {
  979. buildingName = 'Shops_30202_confectaurant';
  980. }
  981. //美食店
  982. else if ('30203' == index) {
  983. buildingName = 'Shops_30203_GourmetRestaurant';
  984. }
  985. //西餐厅
  986. else if ('30204' == index) {
  987. buildingName = 'Shops_30204_WesternRestaurant';
  988. }
  989. //花店
  990. else if ('30301' == index) {
  991. buildingName = 'Shops_30301_Florist';
  992. }
  993. //美发店
  994. else if ('30302' == index) {
  995. buildingName = 'Shops_30302_HairSalon';
  996. }
  997. //洋装店
  998. else if ('30303' == index) {
  999. buildingName = 'Shops_30303_DressShop';
  1000. }
  1001. //珠宝店
  1002. else if ('30304' == index) {
  1003. buildingName = 'Shops_30304_JewelryStore';
  1004. }
  1005. //电影院
  1006. else if ('30305' == index) {
  1007. buildingName = 'Shops_30305_Cinema';
  1008. }
  1009. //路灯
  1010. else if ('401' == index) {
  1011. buildingName = 'Spe_401_StreetLamp';
  1012. }
  1013. //绿化带
  1014. else if ('402' == index) {
  1015. buildingName = 'Spe_402_GreenBelt';
  1016. }
  1017. //花坛
  1018. else if ('403' == index) {
  1019. buildingName = 'Spe_403_FlowerBed';
  1020. }
  1021. //喷泉
  1022. else if ('404' == index) {
  1023. buildingName = 'Spe_404_Pool';
  1024. }
  1025. //警察局
  1026. else if ('405' == index) {
  1027. buildingName = 'Spe_405_PoliceOffice';
  1028. }
  1029. //游乐场
  1030. else if ('406' == index) {
  1031. buildingName = 'Spe_406_Playground';
  1032. }
  1033. return buildingName;
  1034. },
  1035. Grant() {
  1036. },
  1037. Sale() {
  1038. },
  1039. Exchange() {
  1040. }
  1041. });