/// <summary> /// 打印获得的奖品 /// </summary> /// <param name="awardDatas"></param> private void PrintAwardDatas(AwardDatas awardDatas) { if (awardDatas != null && awardDatas.Datas != null && awardDatas.Datas.Count > 0) { foreach (var awardData in awardDatas.Datas) { Debug.LogFormat("<><AwardDataHelper.PrintAwardDatas>{0}", awardData); } } }
bool DailyGoalPercentProcess(int intake) { if (IsAchieveGoal()) { uiState.PushNewState(UIStateEnum.eDailyGoal100CompleteNotify, dataManager.missionId); } else { dataManager.currIntake += intake; uiState.PushNewState(UIStateEnum.eDailyProcessIncrease, dataManager.percentOfDailyGoal); for (int i = 0; i < CrownPersent.Length; ++i) { if (!dataManager.DidCrownGet(i)) { if (dataManager.percentOfDailyGoal >= CrownPersent[i]) { ++dataManager.todayCrownGotCount; ++dataManager.CrownCount; dataManager.TrySendPlayerData2Server(); int expDelta = dataManager.GetDailyGoalExp(this.CrownPersent[i]); //计算获取的经验 DailyGoal dailyGoal = this.LevelConfig.GetLevelDailyGoal(this.dataManager.playerLevel, this.CrownPersent[i]); //获取当前等级与当日饮水进度对应的配饰数据 AwardDatas awardDatas = this.AwardDataHelper.GetAwards(dailyGoal.Coin, dailyGoal.Award); //根据获得的奖励的总价值及奖品产出规则,计算获得的金币及道具 if (awardDatas != null && awardDatas.Datas != null) { awardDatas.Datas.ForEach(t => this.AwardDataHelper.AddItem(t));//记录获得的金币和道具(食物,材料等) } uiState.PushNewState(UIStateEnum.eDailyGoalCrownComplete, i, expDelta, true, awardDatas); AddCrownItem(i); dataManager.exp += expDelta; uiState.PushNewState(UIStateEnum.eExpIncrease, GetExpPercent()); RefreshLevelAfterExpChange(); if (i == CrownPersent.Length - 1) { uiState.PushNewState(UIStateEnum.eDailyGoal100CompleteNotify, dataManager.missionId); } else { uiState.PushNewState(UIStateEnum.eDailyProcessIncrease, dataManager.percentOfDailyGoal); } return(true); } } } } return(false); }
/// <summary> /// 根据指定的总价格及产出规则,计算获得的金币数及道具数量 /// </summary> /// <param name="totalCost">产出物总价格</param> /// <param name="awardID"></param> /// <returns>返回计算得出的奖品列表,或返回null</returns> public AwardDatas GetAwards(int totalCost, int awardID) { AwardInfo awardInfo = this.AwardConfig.GetAward(awardID); if (awardInfo != null) { Debug.LogFormat("<><AwardDataHelper.GetAwards>AwardInfo: {0}", awardInfo); AwardDatas awardDatas = new AwardDatas(); try { foreach (var awardConfig in awardInfo.Awards) { if (awardConfig is CoinAward) { awardDatas.Datas.Add(new AwardData() { ID = this.FundDataManager.GetCoinId(), Count = (int)(totalCost * awardConfig.Percent), Icon = "coin", AwardType = AwardTypes.COIN }); } else if (awardConfig is PropAward) { PropAward propAward = awardConfig as PropAward; //转成道具奖品产出规则 int cost = (int)(totalCost * propAward.Percent); //计算道具奖品的总价格 List <AwardData> sourceData = new List <AwardData>(); if (propAward.FoodAward) {//将食物表中的所有数据转成统一格式 List <PropertyItem> foods = this.PropertyConfig.GetPropertyList(); sourceData.AddRange(this.PropertyItemList2AwardDataList(foods)); } if (propAward.MaterialAward) {//将配饰表中所有的材料数据转成统一格式 } List <AwardData> propAwards = this.GetPropAwards(cost, sourceData);//根据金币数,从源数据中随机取出1~2个奖品 if (propAwards != null && propAwards.Count > 0) { awardDatas.Datas.AddRange(propAwards); } } } if (awardDatas.Datas.Count == 0) { Debug.LogErrorFormat("<><AwardDataHelper.GetAwards>Award config dosen't work, you should get a few coins as least. (totalCost: {0}, awardID: {1})", totalCost, awardID); } this.PrintAwardDatas(awardDatas); return(awardDatas); } catch (System.Exception ex) { Debug.LogErrorFormat("<><AwardDataHelper.GetAwards>Unknown error: {0}", ex.Message); return(null); } } else { Debug.LogErrorFormat("<><AwardDataHelper.GetAwards>Can't find the award config: {0}", awardID); return(null); } }