private static Promise InternalUpdateAchievementToServer(bool showDialog) { Deferred deferred = new Deferred(); //BacktoryCloudUrl.Url = "http://localhost:8086"; UpdateAchievementsRequest request = new UpdateAchievementsRequest(); List <ServerAchievement> serverAchievements = new List <ServerAchievement>(); foreach ( AchievementInfo achievementInfo in InfoResolver.Resolve <FortInfo>().Achievement.AchievementInfos.Where(info => info != null)) { NoneLevelBaseAchievementInfo noneLevelBaseAchievementInfo = achievementInfo as NoneLevelBaseAchievementInfo; if (noneLevelBaseAchievementInfo != null) { serverAchievements.Add(new ServerAchievement { Name = noneLevelBaseAchievementInfo.Name, AchievementId = noneLevelBaseAchievementInfo.Id, Score = noneLevelBaseAchievementInfo.Score, Values = noneLevelBaseAchievementInfo.Balance.Values }); } else { LevelBaseAchievementInfo levelBaseAchievementInfo = (LevelBaseAchievementInfo)achievementInfo; AchievementLevelInfo[] achievementLevelInfos = levelBaseAchievementInfo.GetAchievementLevelInfos(); for (int i = 0; i < achievementLevelInfos.Length; i++) { serverAchievements.Add(new ServerAchievement { Name = achievementLevelInfos[i].Name, AchievementId = achievementLevelInfos[i].Id, Score = achievementLevelInfos[i].Score, Values = achievementLevelInfos[i].Balance.Values }); } } } request.Items = serverAchievements.ToArray(); EditorUtility.DisplayProgressBar("Syncronizing Achievements", "Syncronizing Achievements", 0); InfoResolver.Resolve <FortInfo>() .ServerConnectionProvider.EditorConnection.Call <object>("UpdateAchievements", request) .Then( o => { EditorUtility.ClearProgressBar(); if (showDialog) { EditorUtility.DisplayDialog("Syncronizing Achievements", "Achievemet syncronization succeeded", "Ok"); } deferred.Resolve(); }, error => { EditorUtility.ClearProgressBar(); deferred.Reject(); throw new Exception("Achievemet syncronization failed"); }); return(deferred.Promise()); }
public void ClaimAchievement(Type noneLevelBaseType) { NoneLevelBaseAchievementInfo noneLevelBaseAchievementInfo = (NoneLevelBaseAchievementInfo)InfoResolver.Resolve <FortInfo>().Achievement.AchievementTypes[noneLevelBaseType]; string achievementId = noneLevelBaseAchievementInfo.Id; AchievementStoredData achievementStoredData = ServiceLocator.Resolve <IStorageService>().ResolveData <AchievementStoredData>(); if (achievementStoredData == null) { achievementStoredData = new AchievementStoredData(); } if (achievementStoredData.Achievements.ContainsKey(achievementId)) { return; //throw new Exception("Achievement Already Claimed"); } achievementStoredData.Achievements.Add(achievementId, 0); ServiceLocator.Resolve <IStorageService>().UpdateData(achievementStoredData); //Add to Server cashe AchievementCache achievementCache = ServiceLocator.Resolve <IStorageService>().ResolveData <AchievementCache>(); if (achievementCache == null) { achievementCache = new AchievementCache(); } if (!achievementCache.ServerAchievementIds.ContainsKey(achievementId)) { achievementCache.ServerAchievementIds.Add(achievementId, false); } ServiceLocator.Resolve <IStorageService>().UpdateData(achievementCache); ScoreBalance scoreBalance = ResolveAchievementScoreBalance(noneLevelBaseAchievementInfo.Id); ServiceLocator.Resolve <IUserManagementService>() .AddScoreAndBalance(scoreBalance.Score, scoreBalance.Balance); ServiceLocator.Resolve <IAnalyticsService>().StatAchievementClaimed(noneLevelBaseAchievementInfo.Id, scoreBalance); ServiceLocator.Resolve <IEventAggregatorService>().GetEvent <AchievementClaimedEvent>().Publish(new NoneLeveBaseAchievementClaimedEventArgs(noneLevelBaseAchievementInfo)); }
public static void ExportAchievements() { string path = EditorUtility.SaveFilePanel("Export Achievements", "", "", "xls"); if (string.IsNullOrEmpty(path)) { return; } using (System.IO.Stream writer = File.Create(path)) { ExportData exportData = new ExportData(); foreach (AchievementInfo achievementInfo in InfoResolver.Resolve <FortInfo>().Achievement.AchievementInfos) { NoneLevelBaseAchievementInfo noneLevelBaseAchievementInfo = achievementInfo as NoneLevelBaseAchievementInfo; if (noneLevelBaseAchievementInfo != null) { ExportRow exportRow = new ExportRow(); exportRow.AddParameter("Id", new Parameter { Value = noneLevelBaseAchievementInfo.Id, Type = typeof(string) }); exportRow.AddParameter("Name", new Parameter { Value = achievementInfo.GetType().Name, Type = typeof(string) }); exportRow.AddParameter("Score", new Parameter { Value = noneLevelBaseAchievementInfo.Score, Type = typeof(int) }); foreach (string valueDefenition in InfoResolver.Resolve <FortInfo>().ValueDefenitions) { exportRow.AddParameter(valueDefenition, new Parameter { Value = noneLevelBaseAchievementInfo.Balance == null || noneLevelBaseAchievementInfo.Balance.Values == null ? 0 : noneLevelBaseAchievementInfo.Balance[valueDefenition], Type = typeof(int) }); } exportRow.AddCustomExportParameter(noneLevelBaseAchievementInfo); exportData.AddRow(exportRow); } else { LevelBaseAchievementInfo levelBaseAchievementInfo = (LevelBaseAchievementInfo)achievementInfo; AchievementLevelInfo[] achievementLevelInfos = levelBaseAchievementInfo.GetAchievementLevelInfos(); int index = 0; foreach (AchievementLevelInfo achievementLevelInfo in achievementLevelInfos) { ExportRow exportRow = new ExportRow(); exportRow.AddParameter("Id", new Parameter { Value = achievementLevelInfo.Id, Type = typeof(string) }); exportRow.AddParameter("Name", new Parameter { Value = string.Format("{0}_{1}", achievementInfo.GetType().Name, index++), Type = typeof(string) }); exportRow.AddParameter("Score", new Parameter { Value = achievementLevelInfo.Score, Type = typeof(int) }); foreach (string valueDefenition in InfoResolver.Resolve <FortInfo>().ValueDefenitions) { exportRow.AddParameter(valueDefenition, new Parameter { Value = achievementLevelInfo.Balance == null || achievementLevelInfo.Balance.Values == null ? 0 : achievementLevelInfo.Balance[valueDefenition], Type = typeof(int) }); } exportRow.AddCustomExportParameter(achievementLevelInfo); exportData.AddRow(exportRow); } } } HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet("Achievements"); exportData.SerializeToSheet(sheet); workbook.Write(writer); } }
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(); }
public static ScoreBalance GetRealScoreBalance(this NoneLevelBaseAchievementInfo noneLevelBaseAchievement) { return (ServiceLocator.Resolve <IAchievementService>() .ResolveAchievementScoreBalance(noneLevelBaseAchievement.Id)); }
public static void ClaimAchievement(this NoneLevelBaseAchievementInfo noneLevelBaseAchievementInfo) { ServiceLocator.Resolve <IAchievementService>().ClaimAchievement(noneLevelBaseAchievementInfo.GetType()); }
public NoneLeveBaseAchievementClaimedEventArgs(NoneLevelBaseAchievementInfo achievementInfo) : base(achievementInfo) { NoneLevelBaseAchievementInfo = achievementInfo; }