//收获 public static void ManorHarvest(CSHarvestData csHarvestData, Action <SCHarvestData> ResponseSCHarvestDataCallBack) { if (StaticData.IsUsedLocalDataNotServer) { SCHarvestStruct sc1 = new SCHarvestStruct() { SoilId = 1001, HarvestId = 500001, HarvestNum = 30, HarvestExperience = 20 }; //测试 SCHarvestData scHarvestData = new SCHarvestData(); scHarvestData.HarvestResult.Add(sc1); ResponseSCHarvestDataCallBack(scHarvestData); } else { ProtocalManager.Instance().SendCSHarvestData(csHarvestData, async(succ) => { //保存本地数据 收获总数量 for (int i = 0; i < succ.HarvestResult.Count; i++) { LocalInfoData.localManorInfoData.countTotalGain += succ.HarvestResult[i].HarvestNum; } JsonHelper.SaveDataToPersist <LocalManorInfoData>(LocalInfoData.localManorInfoData); StaticData.DebugGreen($"==============GainOneTile id:{csHarvestData.HarvestInfo[0].SoilId} middleTime:{Time.realtimeSinceStartup}"); //播放音效点击 GameSoundPlayer.Instance.PlaySoundEffect(MusicHelper.SoundEffectReward); //收获引导完成 if (StaticData.isOpenGuide && GuideCanvasComponent._instance != null && GuideCanvasComponent._instance.CurrExecuteGuideLittleStepDefine.Id == 10005) { GuideCanvasComponent._instance.SetLittleStepFinish(); } //回调,播放动画 ResponseSCHarvestDataCallBack(succ); await Cysharp.Threading.Tasks.UniTask.Delay(1600); //播完动画增加经验 StaticData.AddPlayerExp(succ); }, (error) => { }, false); } }
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 SendCSHarvestData(CSHarvestData csharvestdata, Action <SCHarvestData> ResponseSCHarvestDataCallBack, Action <ErrorInfo> errorCallBack, bool isShowDefaultTip = true) { OpCodeType opCodeType = ListOPRelation.GetOpCodeTypeByRequest <CSHarvestData> (); ProtoSendMethod.BusinessRequest <SCHarvestData>(csharvestdata, opCodeType, ResponseSCHarvestDataCallBack, errorCallBack, isShowDefaultTip); }