| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 | 
							- var reGameStates = require('GameStates');
 
- cc.Class({
 
-     extends: cc.Component,
 
-     properties: {
 
-         //MyMapNode
 
-         //建筑物的节点
 
-         BuildingsParent: {
 
-             default: null,
 
-             type: cc.Node,
 
-         },
 
-         //神农专用农田
 
-         Labour_205_Holy_Farmland: {
 
-             default: null,
 
-             type: cc.Prefab,
 
-             serializable: true,
 
-         },
 
-         Labour_206_Holy_Animal: {
 
-             default: null,
 
-             type: cc.Prefab,
 
-             serializable: true,
 
-         },
 
-         animalSpriteFrame: {
 
-             default: [],
 
-             type: [cc.SpriteFrame]
 
-         },
 
-         animalPanelSpriteFrame: {
 
-             default: [],
 
-             type: [cc.SpriteFrame]
 
-         }
 
-     },
 
-     // start() {
 
-     // },
 
-     /**
 
-      * GameData里面处理的生成数据流程,生成建筑物
 
-      */
 
-     InitBuildings() {
 
-         /**
 
-          * 注释 spawnConfigLand 不初始化固定土地
 
-          */
 
-         //第一步初始化土地的网络数据
 
-         this.spawnConfigLand(GlobalD.UserLeaseLand, true);
 
-     },
 
-     //生成房子的默认值
 
-     SpawnBuildingDefaultValue(buildingsInfo) {
 
-         buildingsInfo.InitPos = false;
 
-         buildingsInfo.InitWorkBuildingInfo = false;
 
-         //激活状态,可运营
 
-         buildingsInfo.buildInfo.isItActive = true;
 
-         //设置销售状态
 
-         buildingsInfo.buildInfo.isItSaleable = true;
 
-         if (reGameStates.BuildType.Farmland == buildingsInfo.buildInfo.buildType) {
 
-             buildingsInfo.buildInfo.isItSaleable = GlobalD.GameData.GetFoodTradeState() > 0 ? true : false;// GlobalD.GameData.GetFoodTradeState();
 
-             // cc.log('初始化房子的信息:', buildingsInfo.buildInfo.buildingName, buildingsInfo.buildInfo.isItSaleable);
 
-         }
 
-         if (reGameStates.BuildType.MiningPit == buildingsInfo.buildInfo.buildType) {
 
-             buildingsInfo.buildInfo.isItSaleable = GlobalD.GameData.GetMineralTradeState() > 0 ? true : false;// GlobalD.GameData.GetMineralTradeState();
 
-         }
 
-         if (reGameStates.BuildType.TimberYard == buildingsInfo.buildInfo.buildType) {
 
-             buildingsInfo.buildInfo.isItSaleable = GlobalD.GameData.GetWoodTradeState() > 0 ? true : false;// GlobalD.GameData.GetWoodTradeState();
 
-         }
 
-         //设置一下,可查看信息
 
-         if (reGameStates.BuildType.Housing !== buildingsInfo.buildInfo.buildType
 
-             && reGameStates.BuildType.Special !== buildingsInfo.buildInfo.buildType
 
-             /** 神农小镇固定土地关闭 基本的房屋信息,另外设置其他信息 */
 
-             && reGameStates.BuildType.HolyFarmland !== buildingsInfo.buildInfo.buildType
 
-         ) {
 
-             buildingsInfo.node.getComponent('buildingsTouch').isShowBuildingInfo = true;
 
-         }
 
-     },
 
-     /**
 
-      * 按钮调用
 
-      * 回到用户自己的农场
 
-      */
 
-     onBackSelfFarmland() {
 
-         //刷新一下自己的用户信息
 
-         GlobalD.GameData.getSelfUserLandList(() => {
 
-             this.spawnConfigLand(GlobalD.UserLeaseLand, true);
 
-             //显示底部菜单栏
 
-             GlobalD.game._ManageUIScript.onBottomMenuView(true);
 
-             //收起其他用户场景后菜单操作
 
-             GlobalD.game._ManageUIScript.onOtherFarmerView(false);
 
-         })
 
-         //更新自己的狗
 
-         let _dogContainerScript = cc.find("Canvas/DogContainer").getComponent("DogContainer")
 
-         _dogContainerScript.onGetSelfList();
 
-         GlobalD.GameData.onSwitchAddressBg(GlobalD.Dapp.UserInfo.agent_level);
 
-     },
 
-     /**
 
-      * 初始化后台配置的土地数据
 
-      * 切换时候需要重置其他用户数据
 
-      * @returns 
 
-      */
 
-     spawnConfigLand(_userLeaseLand, bSelf) {
 
-         if (GlobalD.ConfigLand == null) {
 
-             console.error("GlobalD.ConfigLand 未初始化设置!");
 
-             return;
 
-         }
 
-         if (_userLeaseLand == null) {
 
-             console.error("_userLeaseLand 未初始化设置!");
 
-             return;
 
-         }
 
-         let _configLand = GlobalD.ConfigLand;
 
-         if (bSelf) {
 
-             let _bInitFarmland = false;
 
-             let _landBuildingsInfo = this.BuildingsParent.children;
 
-             for (let i = _landBuildingsInfo.length - 1; i >= 0; i--) {
 
-                 let resetLandInfo = _landBuildingsInfo[i];
 
-                 if (resetLandInfo.name == "Labour_205_Holy_Farmland") {
 
-                     let leaseFarmlandInfoScript = resetLandInfo.getComponent("LeaseFarmlandInfo");
 
-                     //如果存在开锁的土地,重置状态
 
-                     if (!leaseFarmlandInfoScript.onGetUnlockLandState()) {
 
-                         leaseFarmlandInfoScript.onLockLand();
 
-                     }
 
-                     leaseFarmlandInfoScript.onSwitchEnvBgFromLevel(0);
 
-                     for (let j = 0; j < _userLeaseLand.length; j++) {
 
-                         //记录已经租赁的信息(租赁里面包含了seedInfo,如果有种植的话,对应的种植信息会有)
 
-                         if (_userLeaseLand[j].configLandId == leaseFarmlandInfoScript.initConfigLandId) {
 
-                             // console.log(leaseFarmlandInfoScript.initConfigLandId);
 
-                             let _leaseLandInfo = _userLeaseLand[j];
 
-                             leaseFarmlandInfoScript.setLeaseLandInfo(_leaseLandInfo, bSelf);
 
-                         }
 
-                     }
 
-                     _bInitFarmland = true;
 
-                 } else if (resetLandInfo.name == "Labour_206_Holy_Animal") {
 
-                     //牧场
 
-                     let leaseAnimalInfoScript = resetLandInfo.getComponent("LeaseAnimalInfo");
 
-                     //如果存在开锁的土地,重置状态
 
-                     if (!leaseAnimalInfoScript.onGetUnlockLandState()) {
 
-                         leaseAnimalInfoScript.onLockLand();
 
-                     }
 
-                     for (let j = 0; j < _userLeaseLand.length; j++) {
 
-                         //记录已经租赁的信息(租赁里面包含了seedInfo,如果有种植的话,对应的种植信息会有)
 
-                         if (_userLeaseLand[j].configLandId == leaseAnimalInfoScript.initConfigLandId) {
 
-                             let _leaseLandInfo = _userLeaseLand[j];
 
-                             leaseAnimalInfoScript.setLeaseLandInfo(_leaseLandInfo, bSelf);
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             if (_bInitFarmland) {
 
-                 console.log("已经初始化过土地数据!");
 
-                 return;
 
-             }
 
-             //获取tiled的配置点
 
-             let _tiledPosArray = GlobalD.TiledMap.onGetLandList();
 
-             let _tiledPosArrayAni = GlobalD.TiledMap.onGetBreedList();
 
-             // console.log("_userLeaseLand", _userLeaseLand);
 
-             // console.log("_tiledPosArray:", _tiledPosArray);
 
-             // console.log("_tiledPosArrayAni", _tiledPosArrayAni);
 
-             // console.log("_configLand:", _configLand);
 
-             // if (_tiledPosArray.length != _configLand.length) {
 
-             //     console.error("服务器土地id配置对应地图配置错误!")
 
-             //     return;
 
-             // }
 
-             //此时是第一次生成, 目前_configLand 签名24块地就是种植相关,后面的是牧场区域
 
-             for (let i = 0; i < 24; i++) {
 
-                 let _index = _configLand[i].id - 1;
 
-                 let _spawnPos = _tiledPosArray[_index];
 
-                 //生成默认土地
 
-                 //农田
 
-                 let housingTemp_farmland = this.onGetHousingPrefabFromName('Labour_205_Holy_Farmland');
 
-                 housingTemp_farmland.parent = this.BuildingsParent;
 
-                 //cc.v2(_configLand[i].posX, _configLand[i].posY)
 
-                 var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(_spawnPos);
 
-                 housingTemp_farmland.setPosition(endPos.x, endPos.y);
 
-                 let leaseFarmlandInfoScript = housingTemp_farmland.getComponent("LeaseFarmlandInfo");
 
-                 //记录一下第一次初始化时候的id
 
-                 leaseFarmlandInfoScript.initConfigLandId = _configLand[i].id;
 
-                 // console.log(housingTemp_farmland.name +" = "+ leaseFarmlandInfoScript.initConfigLandId);
 
-                 //记录config的土地信息
 
-                 leaseFarmlandInfoScript.setConfigLandInfo(_configLand[i]);
 
-                 for (let j = 0; j < _userLeaseLand.length; j++) {
 
-                     //记录已经租赁的信息(租赁里面包含了seedInfo,如果有种植的话,对应的种植信息会有)
 
-                     if (_userLeaseLand[j].configLandId == _configLand[i].id) {
 
-                         let _leaseLandInfo = _userLeaseLand[j];
 
-                         leaseFarmlandInfoScript.setLeaseLandInfo(_leaseLandInfo, bSelf);
 
-                     }
 
-                 }
 
-                 let buildingsInfo_farmland = housingTemp_farmland.getComponent("buildingsInfo");
 
-                 //id用时间戳来记录
 
-                 buildingsInfo_farmland.buildInfo.id = _configLand[i].id;//对应的id
 
-                 /**
 
-                  * 服务器设置的农田 独立于其他游戏数据
 
-                  * 这步设置之后,addBuilding 时候不存储到 GameData_buildings
 
-                  */
 
-                 buildingsInfo_farmland.InitPosFromStore = true;
 
-                 //设置tile的最底下的坐标,就是起始坐标
 
-                 buildingsInfo_farmland.buildInfo.startTilePos = _spawnPos;
 
-                 this.SpawnBuildingDefaultValue(buildingsInfo_farmland);
 
-                 //起始坐标,占位范围,是否占位
 
-                 GlobalD.game.addBuildTiled(buildingsInfo_farmland.buildInfo.id, buildingsInfo_farmland.buildInfo.startTilePos, buildingsInfo_farmland.buildInfo.occupyArea);
 
-                 //添加占位信息
 
-                 GlobalD.game.addBuilding(buildingsInfo_farmland);
 
-             }
 
-             //除去24块种植区域,后面是牧场区域,用配置表对应
 
-             for (let i = 0; i < 12; i++) {
 
-                 let _id = _tiledPosArrayAni[i].id;
 
-                 let _spawnPos = new cc.Vec2(_tiledPosArrayAni[i].InitX, _tiledPosArrayAni[i].InitY);
 
-                 //生成默认养殖场
 
-                 let housingTemp_animal = this.onGetHousingPrefabFromName('Labour_206_Holy_Animal');
 
-                 housingTemp_animal.parent = this.BuildingsParent;
 
-                 var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(_spawnPos);
 
-                 housingTemp_animal.setPosition(endPos.x, endPos.y);
 
-                 let _configLandTemp = null;
 
-                 let _brandFarm = housingTemp_animal.getChildByName("midSliderContainer").getChildByName("brand_farm");
 
-                 let _farmTitle = housingTemp_animal.getChildByName("infoBox").getChildByName("sliderContainer").getChildByName("farmTitle");
 
-                 let _envBg = housingTemp_animal.getChildByName("EnvBg");
 
-                 //根据名字切换贴图
 
-                 switch (_tiledPosArrayAni[i].name) {
 
-                     //牧场区
 
-                     case 'pasture_01':
 
-                         _envBg.getComponent(cc.Sprite).spriteFrame = this.animalSpriteFrame[6];
 
-                         _brandFarm.getComponent(cc.Sprite).spriteFrame = this.animalPanelSpriteFrame[0];
 
-                         _configLandTemp = _configLand[24];
 
-                         _farmTitle.getComponent(cc.Label).string = "牧场1区";
 
-                         break;
 
-                     case 'pasture_02':
 
-                         _envBg.getComponent(cc.Sprite).spriteFrame = this.animalSpriteFrame[7];
 
-                         _brandFarm.getComponent(cc.Sprite).spriteFrame = this.animalPanelSpriteFrame[0];
 
-                         _configLandTemp = _configLand[25];
 
-                         _farmTitle.getComponent(cc.Label).string = "牧场2区";
 
-                         break;
 
-                     case 'pasture_03':
 
-                         _envBg.getComponent(cc.Sprite).spriteFrame = this.animalSpriteFrame[8];
 
-                         _brandFarm.getComponent(cc.Sprite).spriteFrame = this.animalPanelSpriteFrame[0];
 
-                         _configLandTemp = _configLand[26];
 
-                         _farmTitle.getComponent(cc.Label).string = "牧场3区";
 
-                         break;
 
-                     //养殖区
 
-                     case 'farm_01':
 
-                         _envBg.getComponent(cc.Sprite).spriteFrame = this.animalSpriteFrame[0];
 
-                         _brandFarm.getComponent(cc.Sprite).spriteFrame = this.animalPanelSpriteFrame[1];
 
-                         _configLandTemp = _configLand[27];
 
-                         _farmTitle.getComponent(cc.Label).string = "农场1区";
 
-                         break;
 
-                     case 'farm_02':
 
-                         _envBg.getComponent(cc.Sprite).spriteFrame = this.animalSpriteFrame[1];
 
-                         _brandFarm.getComponent(cc.Sprite).spriteFrame = this.animalPanelSpriteFrame[1];
 
-                         _configLandTemp = _configLand[28];
 
-                         _farmTitle.getComponent(cc.Label).string = "农场2区";
 
-                         break;
 
-                     case 'farm_03':
 
-                         _envBg.getComponent(cc.Sprite).spriteFrame = this.animalSpriteFrame[2];
 
-                         _brandFarm.getComponent(cc.Sprite).spriteFrame = this.animalPanelSpriteFrame[1];
 
-                         _configLandTemp = _configLand[29];
 
-                         _farmTitle.getComponent(cc.Label).string = "农场3区";
 
-                         break;
 
-                     //淡水区
 
-                     case 'freshwater_01':
 
-                         _envBg.getComponent(cc.Sprite).spriteFrame = this.animalSpriteFrame[3];
 
-                         _brandFarm.getComponent(cc.Sprite).spriteFrame = this.animalPanelSpriteFrame[2];
 
-                         _configLandTemp = _configLand[30];
 
-                         _brandFarm.setPosition(_brandFarm.getPosition(cc.Vec2).x, 13);
 
-                         _farmTitle.getComponent(cc.Label).string = "淡水1区";
 
-                         break;
 
-                     case 'freshwater_02':
 
-                         _envBg.getComponent(cc.Sprite).spriteFrame = this.animalSpriteFrame[4];
 
-                         _brandFarm.getComponent(cc.Sprite).spriteFrame = this.animalPanelSpriteFrame[2];
 
-                         _configLandTemp = _configLand[31];
 
-                         _brandFarm.setPosition(_brandFarm.getPosition(cc.Vec2).x, 13);
 
-                         _farmTitle.getComponent(cc.Label).string = "淡水2区";
 
-                         break;
 
-                     case 'freshwater_03':
 
-                         _envBg.getComponent(cc.Sprite).spriteFrame = this.animalSpriteFrame[5];
 
-                         _brandFarm.getComponent(cc.Sprite).spriteFrame = this.animalPanelSpriteFrame[2];
 
-                         _configLandTemp = _configLand[32];
 
-                         _brandFarm.setPosition(_brandFarm.getPosition(cc.Vec2).x, 13);
 
-                         _farmTitle.getComponent(cc.Label).string = "淡水3区";
 
-                         break;
 
-                     //海水区
 
-                     case 'seawater_01':
 
-                         _envBg.getComponent(cc.Sprite).spriteFrame = this.animalSpriteFrame[9];
 
-                         _brandFarm.getComponent(cc.Sprite).spriteFrame = this.animalPanelSpriteFrame[3];
 
-                         _configLandTemp = _configLand[33];
 
-                         _brandFarm.setPosition(_brandFarm.getPosition(cc.Vec2).x, 13);
 
-                         _farmTitle.getComponent(cc.Label).string = "海水1区";
 
-                         break;
 
-                     case 'seawater_02':
 
-                         _envBg.getComponent(cc.Sprite).spriteFrame = this.animalSpriteFrame[10];
 
-                         _brandFarm.getComponent(cc.Sprite).spriteFrame = this.animalPanelSpriteFrame[3];
 
-                         _configLandTemp = _configLand[34];
 
-                         _brandFarm.setPosition(_brandFarm.getPosition(cc.Vec2).x, 13);
 
-                         _farmTitle.getComponent(cc.Label).string = "海水2区";
 
-                         break;
 
-                     case 'seawater_03':
 
-                         _envBg.getComponent(cc.Sprite).spriteFrame = this.animalSpriteFrame[11];
 
-                         _brandFarm.getComponent(cc.Sprite).spriteFrame = this.animalPanelSpriteFrame[3];
 
-                         _configLandTemp = _configLand[35];
 
-                         _brandFarm.setPosition(_brandFarm.getPosition(cc.Vec2).x, 13);
 
-                         _farmTitle.getComponent(cc.Label).string = "海水3区";
 
-                         break;
 
-                 }
 
-                 if (_configLandTemp == null) {
 
-                     console.error("_configLandTemp 错误!");
 
-                     return;
 
-                 };
 
-                 // console.log("_configLandTemp:", _configLandTemp);
 
-                 //牧场设置
 
-                 let leaseAnimalInfoScript = housingTemp_animal.getComponent("LeaseAnimalInfo");
 
-                 //记录一下第一次初始化时候的id
 
-                 leaseAnimalInfoScript.initConfigLandId = _configLandTemp.id;
 
-                 leaseAnimalInfoScript.setConfigLandInfo(_configLandTemp);
 
-                 for (let j = 0; j < _userLeaseLand.length; j++) {
 
-                     //记录已经租赁的信息(租赁里面包含了seedInfo,如果有种植的话,对应的种植信息会有)
 
-                     if (_userLeaseLand[j].configLandId == _configLandTemp.id) {
 
-                         let _leaseLandInfo = _userLeaseLand[j];
 
-                         leaseAnimalInfoScript.setLeaseLandInfo(_leaseLandInfo, bSelf);
 
-                     }
 
-                 }
 
-                 let buildingsInfo_farmland = housingTemp_animal.getComponent("buildingsInfo");
 
-                 //id用时间戳来记录
 
-                 buildingsInfo_farmland.buildInfo.id = _id;//对应的id
 
-                 buildingsInfo_farmland.InitPosFromStore = true;
 
-                 buildingsInfo_farmland.buildInfo.startTilePos = _spawnPos;
 
-                 buildingsInfo_farmland.buildInfo.occupyArea = new cc.Vec2(_tiledPosArrayAni[i].tiledX, _tiledPosArrayAni[i].tiledY);
 
-                 this.SpawnBuildingDefaultValue(buildingsInfo_farmland);
 
-                 GlobalD.game.addBuildTiled(buildingsInfo_farmland.buildInfo.id, buildingsInfo_farmland.buildInfo.startTilePos, buildingsInfo_farmland.buildInfo.occupyArea);
 
-                 GlobalD.game.addBuilding(buildingsInfo_farmland);
 
-             }
 
-             // console.log(this.BuildingsParent.children);
 
-         } else {
 
-             //访问其他用户时候,已经有土地了
 
-             //重置土地信息
 
-             let _landBuildingsInfo = this.BuildingsParent.children;
 
-             for (let i = _landBuildingsInfo.length - 1; i >= 0; i--) {
 
-                 let resetLandInfo = _landBuildingsInfo[i];
 
-                 if (resetLandInfo.name == "Labour_205_Holy_Farmland") {
 
-                     let leaseFarmlandInfoScript = resetLandInfo.getComponent("LeaseFarmlandInfo");
 
-                     //如果存在开锁的土地,重置状态
 
-                     if (!leaseFarmlandInfoScript.onGetUnlockLandState()) {
 
-                         leaseFarmlandInfoScript.onLockLand();
 
-                     }
 
-                     //全部设置成普通的土地
 
-                     leaseFarmlandInfoScript.onSwitchEnvBgFromLevel(0);
 
-                     //访问其他农场时候,全部不显示待租按钮
 
-                     leaseFarmlandInfoScript.onUnlockLand();
 
-                     for (let j = 0; j < _userLeaseLand.length; j++) {
 
-                         //记录已经租赁的信息(租赁里面包含了seedInfo,如果有种植的话,对应的种植信息会有)
 
-                         if (_userLeaseLand[j].configLandId == leaseFarmlandInfoScript.initConfigLandId) {
 
-                             let _leaseLandInfo = _userLeaseLand[j];
 
-                             leaseFarmlandInfoScript.setLeaseLandInfo(_leaseLandInfo, bSelf);
 
-                         }
 
-                     }
 
-                 } else if (resetLandInfo.name == "Labour_206_Holy_Animal") {
 
-                     //牧场
 
-                     let leaseAnimalInfoScript = resetLandInfo.getComponent("LeaseAnimalInfo");
 
-                     //如果存在开锁的土地,重置状态
 
-                     if (!leaseAnimalInfoScript.onGetUnlockLandState()) {
 
-                         leaseAnimalInfoScript.onLockLand();
 
-                     }
 
-                     //访问其他农场时候,全部不显示待租按钮
 
-                     leaseAnimalInfoScript.onUnlockLand();
 
-                     for (let j = 0; j < _userLeaseLand.length; j++) {
 
-                         //记录已经租赁的信息(租赁里面包含了seedInfo,如果有种植的话,对应的种植信息会有)
 
-                         if (_userLeaseLand[j].configLandId == leaseAnimalInfoScript.initConfigLandId) {
 
-                             let _leaseLandInfo = _userLeaseLand[j];
 
-                             leaseAnimalInfoScript.setLeaseLandInfo(_leaseLandInfo, bSelf);
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             // console.log("other:", this.BuildingsParent.children);
 
-         }
 
-     },
 
-     onGetHousingPrefabFromName(HouseName) {
 
-         let housing = null;
 
-         //神农专用农田
 
-         if (HouseName == 'Labour_205_Holy_Farmland') {
 
-             housing = cc.instantiate(this.Labour_205_Holy_Farmland);
 
-         }
 
-         else if (HouseName == 'Labour_206_Holy_Animal') {
 
-             housing = cc.instantiate(this.Labour_206_Holy_Animal);
 
-         }
 
-         return housing;
 
-     },
 
-     //获取预制的名字
 
-     onGetPrefabsBuildingName(index) {
 
-         //content button 设置的index
 
-         let buildingName = '';
 
-         //神农专用农田
 
-         if ('205' == index) {
 
-             buildingName = 'Labour_205_Holy_Farmland';
 
-         }
 
-         else if ('206' == index) {
 
-             housing = 'Labour_206_Holy_Animal';
 
-         }
 
-         return buildingName;
 
-     }
 
- });
 
 
  |