public void OnButtonGainOrStealOneKeyClick() { if (!Root2dSceneManager._instance.isFriendManor) {//一键收取 var listSeedGrow = Root2dSceneManager._instance.GetListSeedGrow(); var listRipe = listSeedGrow.FindAll(x => x.currCropPeriod == SeedGrowComponent.PeriodGrow.Ripe); if (listRipe != null && listRipe.Count > 0) { CSHarvestData csHarvestData = new CSHarvestData(); for (int i = 0; i < listRipe.Count; i++) { CSHarvestStruct csHarvestStruct = new CSHarvestStruct() { SoilId = listRipe[i].tileComponent.SoilId }; csHarvestData.HarvestInfo.Add(csHarvestStruct); } ManorProtocalHelper.ManorHarvest(csHarvestData, async(succ) => { CloseAll(); //一键收取特效 for (int i = 0; i < listRipe.Count; i++) { int cropId = listRipe[i].tileComponent.CropGoodId; int gameDefineId = StaticData.configExcel.GetManorCropByCropId(cropId).IdGainGameItem; int addCount = 0; for (int j = 0; j < succ.HarvestResult.Count; j++) { if (succ.HarvestResult[j].HarvestId == gameDefineId) { addCount = succ.HarvestResult[j].HarvestNum; break; } } PlayItemHarvestEffect(listRipe[i].tileComponent, addCount); int addExp = 0; for (int k = 0; k < succ.HarvestResult.Count; k++) { addExp = succ.HarvestResult[k].HarvestExperience; } PlayExpAnim(listRipe[i].tileComponent, addExp); } for (int i = 0; i < listRipe.Count; i++) { listRipe[i].tileComponent.CropGoodId = 0; //删除 Destroy(listRipe[i].gameObject); listRipe[i].tileComponent.SetCurrGoPlant(null); //删除seedGrowCom Root2dSceneManager._instance.RemoveFromListSeedGrow(listRipe[i]); } //更新仓库 for (int i = 0; i < succ.HarvestResult.Count; i++) { //更新仓库果实数量 StaticData.UpdateWareHouseItem(succ.HarvestResult[i].HarvestId, succ.HarvestResult[i].HarvestNum); } }); } } else {//一键偷取 ListStealInfo.Clear(); for (int i = 0; i < listStealClass.Count; i++) { if (listStealClass[i].isSteal) { ListStealInfo.Add(new CSStealStruct() { SoilId = listStealClass[i].SolidId }); } } CSStealData csStealData = new CSStealData(); for (int i = 0; i < ListStealInfo.Count; i++) { csStealData.StealInfo.Add(ListStealInfo[i]); } csStealData.StealUid = IdFriend; ManorProtocalHelper.StealFriendFruit(csStealData, async(scStealData) => { StaticData.DataDot(Company.Cfg.DotEventId.FriendManorStealSucc); //已经偷取过的,设置状态为不能偷 if (scStealData == null) { return; } if (scStealData.StealResult == null) { return; } if (scStealData.StealResult.Count <= 0) { return; } //偷取特效 CloseAll(); for (int i = 0; i < scStealData.StealResult.Count; i++) { var stealClass = this.listStealClass.Find(x => x.SolidId == scStealData.StealResult[i].SoilId); if (stealClass != null) { //播放特效 TileComponent tile = null; for (int j = 0; j < Root2dSceneManager._instance.objPool.transform.childCount; j++) { var tileGo = Root2dSceneManager._instance.objPool.transform.GetChild(j); TileComponent tileCom = tileGo.GetComponent <TileComponent>(); if (tileGo.gameObject.activeInHierarchy && tileCom.SoilId == stealClass.SolidId) { tile = tileGo.GetComponent <TileComponent>(); break; } } //设置图片个数 int cropId = tile.CropGoodId; int gameDefineId = StaticData.configExcel.GetManorCropByCropId(cropId).IdGainGameItem; int addCount = 0; for (int j = 0; j < scStealData.StealResult.Count; j++) { if (scStealData.StealResult[j].StealId == gameDefineId) { addCount = scStealData.StealResult[j].StealNum; break; } } PlayItemHarvestEffect(tile, addCount); } } for (int i = 0; i < scStealData.StealResult.Count; i++) { var stealClass = this.listStealClass.Find(x => x.SolidId == scStealData.StealResult[i].SoilId); if (stealClass != null) { stealClass.isSteal = false; } //更新仓库果实数量 StaticData.UpdateWareHouseItem(scStealData.StealResult[i].StealId, scStealData.StealResult[i].StealNum); } SetFriendManorStealState(this.listStealClass); }); } }
public void OnButtonStealClick(SeedGrowComponent willSeedGrowComponent) { CSStealData csStealData = new CSStealData(); CSStealStruct csStealStruct = new CSStealStruct() { SoilId = willSeedGrowComponent.tileComponent.SoilId }; csStealData.StealInfo.Add(csStealStruct); csStealData.StealUid = IdFriend; ManorProtocalHelper.StealFriendFruit(csStealData, async(scStealData) => { StaticData.DataDot(Company.Cfg.DotEventId.FriendManorStealSucc); //已经偷取过的,设置状态为不能偷 if (scStealData == null) { return; } if (scStealData.StealResult == null) { return; } if (scStealData.StealResult.Count <= 0) { return; } //偷取特效 CloseAll(); //表示能偷 TileComponent tile = null; for (int i = 0; i < Root2dSceneManager._instance.objPool.transform.childCount; i++) { var tileGo = Root2dSceneManager._instance.objPool.transform.GetChild(i); TileComponent tileCom = tileGo.GetComponent <TileComponent>(); if (tileGo.gameObject.activeInHierarchy && tileCom.SoilId == scStealData.StealResult[0].SoilId) { tile = tileGo.GetComponent <TileComponent>(); break; } } int cropId = tile.CropGoodId; int gameDefineId = StaticData.configExcel.GetManorCropByCropId(cropId).IdGainGameItem; int addCount = 0; for (int j = 0; j < scStealData.StealResult.Count; j++) { if (scStealData.StealResult[j].StealId == gameDefineId) { addCount = scStealData.StealResult[j].StealNum; break; } } //播放偷取特效 PlayItemHarvestEffect(tile, addCount); for (int i = 0; i < scStealData.StealResult.Count; i++) { var stealClass = this.listStealClass.Find(x => x.SolidId == scStealData.StealResult[i].SoilId); if (stealClass != null) { stealClass.isSteal = false; } //更新仓库果实数量 StaticData.UpdateWareHouseItem(scStealData.StealResult[i].StealId, scStealData.StealResult[i].StealNum); } SetFriendManorStealState(this.listStealClass); }); }