public ScoreBalance ResolveAchievementScoreBalance(string id)
        {
            AchievementStoredData achievementStoredData =
                ServiceLocator.Resolve <IStorageService>().ResolveData <AchievementStoredData>();

            if (achievementStoredData == null)
            {
                achievementStoredData = new AchievementStoredData();
            }
            if (achievementStoredData.ServerAchievementInfos.ContainsKey(id))
            {
                return(new ScoreBalance
                {
                    Balance = achievementStoredData.ServerAchievementInfos[id].Balance,
                    Score = achievementStoredData.ServerAchievementInfos[id].Score
                });
            }
            AchievementToken achievementToken = InfoResolver.Resolve <FortInfo>().Achievement.AchievementTokens[id];

            if (achievementToken.NoneLevelBase)
            {
                return(new ScoreBalance
                {
                    Balance = ((NoneLevelBaseAchievementInfo)achievementToken.AchievementInfo).Balance,
                    Score = ((NoneLevelBaseAchievementInfo)achievementToken.AchievementInfo).Score
                });
            }
            return(new ScoreBalance
            {
                Balance = achievementToken.AchievementLevelInfo.Balance,
                Score = achievementToken.AchievementLevelInfo.Score
            });
        }
Beispiel #2
0
        public static bool IsAchievementClaimed(this AchievementLevelInfo achievementLevelInfo)
        {
            AchievementToken achievementToken = InfoResolver.Resolve <FortInfo>().Achievement.AchievementTokens[achievementLevelInfo.Id];
            int achievementClaimedIndex       = ServiceLocator.Resolve <IAchievementService>().GetAchievementClaimedIndex(achievementToken.AchievementInfo.GetType());

            return(achievementToken.Index <= achievementClaimedIndex);
        }
Beispiel #3
0
        public void StatAchievementClaimed(string achievementId, ScoreBalance award)
        {
            if (InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider == null)
            {
                return;
            }

            if (!InfoResolver.Resolve <FortInfo>().Analytic.StatAchievementClaimed)
            {
                return;
            }
            AchievementToken achievementToken = InfoResolver.Resolve <FortInfo>().Achievement.AchievementTokens[achievementId];

            if (achievementToken.NoneLevelBase)
            {
                InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider.StateEvent(achievementToken.AchievementInfo.Name,
                                                                                        achievementToken.AchievementInfo.DisplayName, "AchievementClaimed",
                                                                                        new AchievementClaimedAnalyticStat
                {
                    AchievementId   = achievementId,
                    AchievementName = achievementToken.AchievementInfo.Name,
                    Award           = award
                });
            }
            else
            {
                InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider.StateEvent(achievementToken.AchievementInfo.Name,
                                                                                        achievementToken.AchievementInfo.DisplayName, "AchievementClaimed",
                                                                                        new AchievementClaimedAnalyticStat
                {
                    AchievementId   = achievementId,
                    AchievementName = achievementToken.AchievementInfo.Name,
                    Level           = achievementToken.Index,
                    Award           = award
                });
            }
        }
        public static void ImportAchievements()
        {
            string path = EditorUtility.OpenFilePanel("Import Achievements", "", "xls");

            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            using (System.IO.Stream reader = File.OpenRead(path))
            {
                IDictionary <string, PropertyInfo> customPossibleProperties =
                    ExportData.GetCustomPossibleProperties(
                        TypeHelper.GetAllTypes(AllTypeCategory.Game)
                        .Where(type => typeof(NoneLevelBaseAchievementInfo).IsAssignableFrom(type))
                        .Concat(
                            TypeHelper.GetAllTypes(AllTypeCategory.Game)
                            .Where(type => typeof(AchievementLevelInfo).IsAssignableFrom(type)))
                        .ToArray());
                Dictionary <string, Type> parameters = new Dictionary <string, Type>();
                parameters["Id"]   = typeof(string);
                parameters["Name"] = typeof(string);
                foreach (string valueDefenition in InfoResolver.Resolve <FortInfo>().ValueDefenitions)
                {
                    parameters[valueDefenition] = typeof(int);
                }
                foreach (KeyValuePair <string, PropertyInfo> pair in customPossibleProperties)
                {
                    parameters[pair.Key] = pair.Value.PropertyType;
                }
                HSSFWorkbook workbook   = new HSSFWorkbook(reader);
                ExportData   exportData = ExportData.DeserializeFromSheet(parameters, workbook.GetSheetAt(0));
                foreach (ExportRow exportRow in exportData.ExportRows)
                {
                    if (!exportRow.ContainsParameter("Id"))
                    {
                        continue;
                    }
                    string id = (string)exportRow.GetValue("Id").Value;
                    if (!InfoResolver.Resolve <FortInfo>().Achievement.AchievementTokens.ContainsKey(id))
                    {
                        continue;
                    }
                    AchievementToken achievementToken = InfoResolver.Resolve <FortInfo>().Achievement.AchievementTokens[id];
                    if (achievementToken.NoneLevelBase)
                    {
                        NoneLevelBaseAchievementInfo noneLevelBaseAchievementInfo = (NoneLevelBaseAchievementInfo)achievementToken.AchievementInfo;
                        if (exportRow.ContainsParameter("Score"))
                        {
                            noneLevelBaseAchievementInfo.Score = (int)exportRow.GetValue("Score").Value;
                        }
                        foreach (string valueDefenition in InfoResolver.Resolve <FortInfo>().ValueDefenitions)
                        {
                            if (exportRow.ContainsParameter(valueDefenition))
                            {
                                noneLevelBaseAchievementInfo.Balance[valueDefenition] =
                                    (int)exportRow.GetValue(valueDefenition).Value;
                            }
                        }
                        exportRow.FillCustomExportParameter(noneLevelBaseAchievementInfo);
                    }
                    else
                    {
                        AchievementLevelInfo achievementLevelInfo = achievementToken.AchievementLevelInfo;
                        if (exportRow.ContainsParameter("Score"))
                        {
                            achievementLevelInfo.Score = (int)exportRow.GetValue("Score").Value;
                        }
                        foreach (string valueDefenition in InfoResolver.Resolve <FortInfo>().ValueDefenitions)
                        {
                            if (exportRow.ContainsParameter(valueDefenition))
                            {
                                achievementLevelInfo.Balance[valueDefenition] =
                                    (int)exportRow.GetValue(valueDefenition).Value;
                            }
                        }
                        exportRow.FillCustomExportParameter(achievementLevelInfo);
                    }
                }
            }
            InfoResolver.Resolve <FortInfo>().Save();
        }