private IEnumerable <CMsgClientStoreUserStats2.Stats> GetStatsToSet(List <CMsgClientStoreUserStats2.Stats> statsToSet, StatData statToSet, bool set = true) { if (statToSet == null) { yield break; //it should never happen } CMsgClientStoreUserStats2.Stats?currentstat = statsToSet.Find(stat => stat.stat_id == statToSet.StatNum); if (currentstat == null) { currentstat = new CMsgClientStoreUserStats2.Stats() { stat_id = statToSet.StatNum, stat_value = statToSet.StatValue }; yield return(currentstat); } uint statMask = ((uint)1 << statToSet.BitNum); if (set) { currentstat.stat_value = currentstat.stat_value | statMask; } else { currentstat.stat_value = currentstat.stat_value & ~statMask; } if (!string.IsNullOrEmpty(statToSet.DependancyName)) { CMsgClientStoreUserStats2.Stats?dependancystat = statsToSet.Find(stat => stat.stat_id == statToSet.Dependancy); if (dependancystat == null) { dependancystat = new CMsgClientStoreUserStats2.Stats() { stat_id = statToSet.Dependancy, stat_value = set ? statToSet.DependancyValue : 0 }; yield return(dependancystat); } } }
private void SetStat(List <CMsgClientStoreUserStats2.Stats> statsToSet, List <StatData> Stats, StoredResponse storedResponse, int achievementnum, bool set = true) { if (achievementnum < 0 || achievementnum > Stats.Count) { return; //it should never happen } CMsgClientStoreUserStats2.Stats?currentstat = statsToSet.Find(stat => stat.stat_id == Stats[achievementnum].StatNum); if (currentstat == null) { currentstat = new CMsgClientStoreUserStats2.Stats() { stat_id = Stats[achievementnum].StatNum, //stat_value = storedResponse.Response.stats.Find(stat => stat.stat_id == Stats[achievementnum].StatNum) != null ? storedResponse.Response.stats.Find(stat => stat.stat_id == Stats[achievementnum].StatNum).stat_value : 0 stat_value = storedResponse?.Response?.stats?.Find(stat => stat.stat_id == Stats[achievementnum].StatNum)?.stat_value ?? 0 }; statsToSet.Add(currentstat); } if (set) { currentstat.stat_value = currentstat.stat_value | ((uint)1 << Stats[achievementnum].BitNum); } else { currentstat.stat_value = currentstat.stat_value & ~((uint)1 << Stats[achievementnum].BitNum); } if (Stats[achievementnum].DependancyName != "") { CMsgClientStoreUserStats2.Stats?dependancystat = statsToSet.Find(stat => stat.stat_id == Stats[achievementnum].Dependancy); if (dependancystat == null) { dependancystat = new CMsgClientStoreUserStats2.Stats() { stat_id = Stats[achievementnum].Dependancy, stat_value = set ? Stats[achievementnum].DependancyValue : 0 }; statsToSet.Add(dependancystat); } } }