public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JToken jToken = JToken.ReadFrom(reader); if (jToken.Type == JTokenType.Null || jToken.Type == JTokenType.None) { return(new MarketInfo[0]); } return(jToken.ToObject <string[]>().Select(s => InfoResolver.Resolve <FortInfo>().MarketInfos.FirstOrDefault(info => info.MarketName == s)).Where(info => info != null).ToArray()); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JToken jToken = JToken.ReadFrom(reader); if (jToken.Type == JTokenType.Null || jToken.Type == JTokenType.None) { return(null); } return(InfoResolver.Resolve <FortInfo>().SkinnerBox.BoxInfos.FirstOrDefault(info => info.Id == jToken.ToObject <string>())); }
public Promise Relogin() { IDispatcher dispatcher = GameDispatcher.Dispatcher; Deferred deferred = new Deferred(); if (!IsReloginCapable()) { throw new Exception("Relogin is not capable.No saved refresh token found"); } string authenticationId = InfoResolver.Resolve <BacktoryInfo>().AuthenticationId; string authenticationClientKey = InfoResolver.Resolve <BacktoryInfo>().AuthenticationClientKey; string url = "https://api.backtory.com/auth/login"; ThreadPool.QueueUserWorkItem(state => { try { BacktoryAccessData backtoryAccessData = ServiceLocator.Resolve <IStorageService>().ResolveData <BacktoryAccessData>(); string result = MultiPartCall(url, new Dictionary <string, string> { { "refresh_token", backtoryAccessData.RefreshToken }, }, new Dictionary <string, string> { { "X-Backtory-Authentication-Id", authenticationId }, { "X-Backtory-Authentication-Key", authenticationClientKey }, { "X-Backtory-Authentication-Refresh", "1" } }); LoginResponse loginResponse = JsonConvert.DeserializeObject <LoginResponse>(result); dispatcher.Dispach(() => { if (string.IsNullOrEmpty(loginResponse.AccessToken)) { deferred.Reject(); } else { backtoryAccessData = ServiceLocator.Resolve <IStorageService>().ResolveData <BacktoryAccessData>(); backtoryAccessData.AccessToken = loginResponse.AccessToken; backtoryAccessData.RefreshToken = loginResponse.RefreshToken; backtoryAccessData.TokenType = loginResponse.TokenType; ServiceLocator.Resolve <IStorageService>().UpdateData(backtoryAccessData); deferred.Resolve(); } }); } catch (Exception) { dispatcher.Dispach(() => { deferred.Reject(); }); } }); return(deferred.Promise()); }
public void OnServerAchievementResolved(Dictionary <string, ServerAchievementInfo> achievementInfos, string[] claimedAchievementIds) { AchievementCache achievementCache = ServiceLocator.Resolve <IStorageService>().ResolveData <AchievementCache>(); if (achievementCache == null) { achievementCache = new AchievementCache(); } foreach (string claimedAchievementId in claimedAchievementIds) { achievementCache.ServerAchievementIds[claimedAchievementId] = true; } ServiceLocator.Resolve <IStorageService>().UpdateData(achievementCache); AchievementStoredData achievementStoredData = ServiceLocator.Resolve <IStorageService>().ResolveData <AchievementStoredData>(); if (achievementStoredData == null) { achievementStoredData = new AchievementStoredData(); } Dictionary <AchievementInfo, AchievementToken[]> achievementTokenses = claimedAchievementIds.Where(s => InfoResolver.Resolve <FortInfo>().Achievement.AchievementTokens.ContainsKey(s)) .Select(s => InfoResolver.Resolve <FortInfo>().Achievement.AchievementTokens[s]) .GroupBy(token => token.AchievementInfo) .ToDictionary(tokens => tokens.Key, tokens => tokens.Select(token => token).ToArray()); foreach (KeyValuePair <AchievementInfo, AchievementToken[]> pair in achievementTokenses) { if (pair.Value.Length > 0) { if (pair.Key is NoneLevelBaseAchievementInfo) { achievementStoredData.Achievements[pair.Key.Id] = 0; } else { int max = pair.Value.Max(token => token.Index); if ( !(achievementStoredData.Achievements.ContainsKey(pair.Key.Id) && achievementStoredData.Achievements[pair.Key.Id] >= max)) { achievementStoredData.Achievements[pair.Key.Id] = max; } } } } foreach (KeyValuePair <string, ServerAchievementInfo> pair in achievementInfos) { achievementStoredData.ServerAchievementInfos[pair.Key] = pair.Value; } ServiceLocator.Resolve <IStorageService>().UpdateData(achievementStoredData); }
public void StateCustomEvent(string eventName, string label, string category, IAnalyticStatValue value) { if (InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider == null) { return; } if (!InfoResolver.Resolve <FortInfo>().Analytic.StatCustomEvent) { return; } InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider.StateEvent(eventName, label, category, value); }
public bool IsAchievementClaimed(Type noneLevelBaseType) { string achievementId = InfoResolver.Resolve <FortInfo>().Achievement.AchievementTypes[noneLevelBaseType].Id; AchievementStoredData achievementStoredData = ServiceLocator.Resolve <IStorageService>().ResolveData <AchievementStoredData>(); if (achievementStoredData == null) { achievementStoredData = new AchievementStoredData(); } return(achievementStoredData.Achievements.ContainsKey(achievementId)); }
public static AchievementLevelInfo GetNextClaimableAchievementLevelInfo(this IAchievementService achievementService, Type levelBaseType) { int index = achievementService.GetAchievementClaimedIndex(levelBaseType) + 1; AchievementInfo achievementInfo = InfoResolver.Resolve <FortInfo>().Achievement.AchievementTypes[levelBaseType]; Array value = (Array)levelBaseType.GetProperty("LevelInfo").GetValue(achievementInfo, new object[0]); if (index >= value.Length) { return(null); } return((AchievementLevelInfo)value.GetValue(index)); }
public InstanceResolverResult ResolvePossibleData(object baseObject, object data, PropertyInfo property) { InstanceResolverResult result = new InstanceResolverResult { PossibleInstanceTokens = InfoResolver.Resolve <FortInfo>().SkinnerBox.BoxInfos.OfType <PurchableSkinnerBoxInfo>().Select(info => new InstanceToken(info.Name, info)).ToArray() }; InstanceToken instanceToken = result.PossibleInstanceTokens.FirstOrDefault(token => ReferenceEquals(token.Value, data)); result.PresentableInstanceTokens = instanceToken == null ? new InstanceToken[0] : new[] { instanceToken }; return(result); }
public InstanceResolverResult ResolvePossibleData(object baseObject, object data, PropertyInfo property) { InstanceResolverResult result = new InstanceResolverResult { PossibleInstanceTokens = InfoResolver.Resolve <FortInfo>().Purchase.GetAllPurchasableItemInfos().OfType <NoneLevelBasePurchasableItemInfo>().Select(info => new InstanceToken(info.Name, info)).ToArray()//InfoResolver.Resolve<FortInfo>().Package.Packages.Where(info => !(info is DiscountIapPackage)).Select(info => new InstanceToken(info.Sku, info)).ToArray() }; InstanceToken instanceToken = result.PossibleInstanceTokens.FirstOrDefault(token => ReferenceEquals(token.Value, data)); result.PresentableInstanceTokens = instanceToken == null ? new InstanceToken[0] : new[] { instanceToken }; return(result); }
private string GetCategorySceneName(GameLevelCategory category) { if (!FortScene.IsNullOrEmpty(category.DefaultScene)) { return(category.DefaultScene.Value.SceneName); } if (InfoResolver.Resolve <FortInfo>().GameLevel.LevelCategoriesParentMap.ContainsKey(category.Id)) { return(GetCategorySceneName(InfoResolver.Resolve <FortInfo>().GameLevel.LevelCategoriesParentMap[category.Id])); } return(string.Empty); }
public void StatUserRegisterd() { if (InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider == null) { return; } if (!InfoResolver.Resolve <FortInfo>().Analytic.StatUserRegistered) { return; } InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider.StateEvent("UserRegistered", "User Registered", "UserRegistered", null); }
public void StatInvitationApplied() { if (InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider == null) { return; } if (!InfoResolver.Resolve <FortInfo>().Analytic.StatInvitationApplied) { return; } InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider.StateEvent("InvitationApplied", "Invitation Applied", "InvitationApplied", null); }
public void StatIapPurchased(IapPackageInfo iapPackage, string market) { if (InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider == null) { return; } if (!InfoResolver.Resolve <FortInfo>().Analytic.StatIapPackePurchases) { return; } InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider.StatIapPackagePurchased(iapPackage.Sku, iapPackage.DisplayName, iapPackage.Price, market); }
private string ResolveGameLevelSceneName(GameLevelInfo level) { if (!FortScene.IsNullOrEmpty(level.Scene)) { return(level.Scene.Value.SceneName); } string categorySceneName = GetCategorySceneName(InfoResolver.Resolve <FortInfo>().GameLevel.LevelCategoriesParentMap[level.Id]); if (!string.IsNullOrEmpty(categorySceneName)) { return(categorySceneName); } return(FortScene.IsNullOrEmpty(InfoResolver.Resolve <FortInfo>().GameLevel.DefaultScene)?null: InfoResolver.Resolve <FortInfo>().GameLevel.DefaultScene.Value.SceneName); }
public Promise Login(string username, string password) { IDispatcher dispatcher = GameDispatcher.Dispatcher; Deferred deferred = new Deferred(); string authenticationId = InfoResolver.Resolve <BacktoryInfo>().AuthenticationId; string authenticationClientKey = InfoResolver.Resolve <BacktoryInfo>().AuthenticationClientKey; string url = "https://api.backtory.com/auth/login"; ThreadPool.QueueUserWorkItem(state => { try { string result = MultiPartCall(url, new Dictionary <string, string> { { "username", username }, { "password", password } }, new Dictionary <string, string> { { "X-Backtory-Authentication-Id", authenticationId }, { "X-Backtory-Authentication-Key", authenticationClientKey } }); LoginResponse loginResponse = JsonConvert.DeserializeObject <LoginResponse>(result); dispatcher.Dispach(() => { if (string.IsNullOrEmpty(loginResponse.AccessToken)) { deferred.Reject(); } else { BacktoryAccessData backtoryAccessData = ServiceLocator.Resolve <IStorageService>().ResolveData <BacktoryAccessData>() ?? new BacktoryAccessData(); backtoryAccessData.AccessToken = loginResponse.AccessToken; backtoryAccessData.RefreshToken = loginResponse.RefreshToken; backtoryAccessData.TokenType = loginResponse.TokenType; ServiceLocator.Resolve <IStorageService>().UpdateData(backtoryAccessData); deferred.Resolve(); } }); } catch (Exception) { dispatcher.Dispach(() => { deferred.Reject(); }); } }); return(deferred.Promise()); }
public void LoadGameLevelAsync(GameLevelInfo level) { if (FortScene.IsNullOrEmpty(InfoResolver.Resolve <FortInfo>().GameLevel.LoaderScene.Value)) { throw new Exception("No Loader Scene is defined in Game Level config"); } _lastLoadGameAsync = level; ServiceLocator.Resolve <ISceneLoaderService>().Load(new SceneLoadParameters(InfoResolver.Resolve <FortInfo>().GameLevel.LoaderScene.Value.SceneName) { AddToSceneStack = false, CaptureReturnKey = false, Context = level, FlushSceneStack = true }); }
public void StatInterstitialBanner(string advertismentProvider) { if (InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider == null) { return; } if (!InfoResolver.Resolve <FortInfo>().Analytic.StatInterstitialBanner) { return; } InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider.StateEvent("InterstitialBanner", "Interstitial Banner", "InterstitialBanner", new InterstitialBannerAnalyticStat { AdvertismentProvider = advertismentProvider }); }
public void StatSceneLoaded(string sceneName) { if (InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider == null) { return; } if (!InfoResolver.Resolve <FortInfo>().Analytic.StatSceneLoad) { return; } InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider.StateEvent("SceneLoaded", "Scene Loaded", "SceneLoaded", new SceneLoadedAnalyticStat { SceneName = sceneName }); }
public void StatVideoResult(string advertismentProvider, string zone, bool skipable, ShowVideoResult videoResult) { if (InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider == null) { return; } if (!InfoResolver.Resolve <FortInfo>().Analytic.StatVideo) { return; } InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider.StateEvent("VideoResult", "Video Result", "VideoResult", new VideoResultAnalyticStat { AdvertismentProvider = advertismentProvider, Zone = zone, Skipable = skipable, VideoResult = videoResult }); }
public int GetAchievementClaimedIndex(Type levelBaseType) { AchievementInfo achievementinfo = InfoResolver.Resolve <FortInfo>().Achievement.AchievementTypes[levelBaseType]; AchievementStoredData achievementStoredData = ServiceLocator.Resolve <IStorageService>().ResolveData <AchievementStoredData>(); if (achievementStoredData == null) { achievementStoredData = new AchievementStoredData(); } if (achievementStoredData.Achievements.ContainsKey(achievementinfo.Id)) { return(achievementStoredData.Achievements[achievementinfo.Id]); } return(-1); }
public InstanceResolverResult ResolvePossibleData(object baseObject, object data, PropertyInfo property) { LanguageInfo[] editorLanguages = FortLanguage.ResolveLanguageEditorInfo().Languages; InstanceResolverResult result = new InstanceResolverResult { PossibleInstanceTokens = InfoResolver.Resolve <FortInfo>().Language.ActiveLanguages.Where( info => editorLanguages.Any(languageInfo => languageInfo.Id == info.Id)) .Select(info => new InstanceToken(info.Name, info)) .ToArray() }; InstanceToken instanceToken = result.PossibleInstanceTokens.FirstOrDefault(token => ReferenceEquals(token.Value, data)); result.PresentableInstanceTokens = instanceToken == null ? new InstanceToken[0] : new[] { instanceToken }; return(result); }
public static void ExportGameLevels() { string path = EditorUtility.SaveFilePanel("Export Game Levels", "", "", "xls"); if (string.IsNullOrEmpty(path)) { return; } using (Stream writer = File.Create(path)) { ExportData exportData = new ExportData(); foreach (GameLevelInfo gameLevel in InfoResolver.Resolve <FortInfo>().GameLevel.GameLevelInfos.Select(pair => pair.Value)) { ExportRow exportRow = new ExportRow(); exportRow.AddParameter("Id", new Parameter { Value = gameLevel.Id, Type = typeof(string) }); /* exportRow.AddParameter("Scene", new Parameter * { * Value = gameLevel.Scene == null?null: gameLevel.Scene.Value.SceneName, * Type = typeof(string) * });*/ /* exportRow.AddParameter("DisplayName", new Parameter * { * Value = gameLevel.DisplayName, * Type = typeof(string) * });*/ exportRow.AddParameter("Name", new Parameter { Value = gameLevel.Name, Type = typeof(string) }); exportRow.AddCustomExportParameter(gameLevel); exportData.AddRow(exportRow); } HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet("Game Levels"); exportData.SerializeToSheet(sheet); workbook.Write(writer); } }
public InstanceResolverResult ResolvePossibleData(object baseObject, object data, PropertyInfo property) { MarketInfo[] marketInfos = (MarketInfo[])data; if (marketInfos == null) { marketInfos = new MarketInfo[0]; } MarketInfo[] possibleMarkets = InfoResolver.Resolve <FortInfo>().MarketInfos.Where(info => marketInfos.All(marketInfo => marketInfo.GetType() != info.GetType())).ToArray(); InstanceResolverResult result = new InstanceResolverResult { PossibleInstanceTokens = possibleMarkets.Select(market => new InstanceToken(market.GetType().Name, market)).ToArray(), PresentableInstanceTokens = marketInfos.Select(info => new InstanceToken(info.GetType().Name, info)).ToArray(), IsEditable = false, UseValueTypeForEdit = false }; return(result); }
public ErrorPromise <RegisterationErrorResultStatus> Register(string username, string password) { ErrorDeferred <RegisterationErrorResultStatus> deferred = new ErrorDeferred <RegisterationErrorResultStatus>(); if (InfoResolver.Resolve <FortInfo>().ServerConnectionProvider == null) { throw new Exception("No Server connection provider added"); } InfoResolver.Resolve <FortInfo>().ServerConnectionProvider.UserConnection.Register(username, password).Then(() => { ServiceLocator.Resolve <IAnalyticsService>().StatUserRegisterd(); ServiceLocator.Resolve <IStorageService>().UpdateData(new AuthenticationInfo { UserName = username }); deferred.Resolve(); }, status => deferred.Reject(status)); return(deferred.Promise()); }
public LanguageInfo GetActiveLanguage() { LanguageSavedData languageSavedData = ServiceLocator.Resolve <IStorageService>().ResolveData <LanguageSavedData>() ?? new LanguageSavedData(); LanguageInfo result = InfoResolver.Resolve <FortInfo>().Language.ActiveLanguages.Where(info => info != null).FirstOrDefault( info => info.Id == languageSavedData.LanguageId); if (result == null) { result = InfoResolver.Resolve <FortInfo>().Language.DefaultLanguage; if (result == null) { result = InfoResolver.Resolve <FortInfo>().Language.ActiveLanguages.FirstOrDefault(info => info != null); } } return(result); }
public void StatIapRetry(IapPackageInfo iapPackage, string purchaseToken, string market) { if (InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider == null) { return; } if (!InfoResolver.Resolve <FortInfo>().Analytic.StatIapPackePurchases) { return; } InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider.StateEvent(iapPackage.Sku, "Iap Retry", "IapRetry", new IapRetryAnalyticStat { IapPackage = iapPackage, PurchaseToken = purchaseToken, Market = market }); }
public void Initialize() { if (_isInitialized) { return; } _isInitialized = true; Tapsell.initialize(InfoResolver.Resolve <TapsellInfo>().Key); Tapsell.setRewardListener( result => { if (!result.completed) { if (result.rewarded && _isSkipable) { ErrorDeferred <ShowVideoFailed> errorDeferred = _deferred; _deferred = null; errorDeferred.Resolve(); } else { FailedDefered(ShowVideoFailed.Cancel); } } else { if (!result.rewarded) { FailedDefered(ShowVideoFailed.ProviderError); } else { ErrorDeferred <ShowVideoFailed> errorDeferred = _deferred; _deferred = null; errorDeferred.Resolve(); } } } ); }
public void StatItemRent(string itemId, Balance cost, int discount, TimeSpan duration) { if (InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider == null) { return; } if (!InfoResolver.Resolve <FortInfo>().Analytic.StatItemRented) { return; } PurchasableToken purchasableToken = InfoResolver.Resolve <FortInfo>().Purchase.PurchasableTokens[itemId]; if (purchasableToken.NoneLevelBase) { InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider.StateEvent(purchasableToken.PurchasableItemInfo.Name, purchasableToken.PurchasableItemInfo.DisplayName, "ItemRented", new ItemRentAnalyticStat { ItemId = itemId, ItemName = purchasableToken.PurchasableItemInfo.Name, Discount = discount, Cost = cost, RentDuration = duration }); } else { InfoResolver.Resolve <FortInfo>().Analytic.AnalyticsProvider.StateEvent(purchasableToken.PurchasableItemInfo.Name, purchasableToken.PurchasableItemInfo.DisplayName, "ItemRented", new ItemRentAnalyticStat { ItemId = itemId, ItemName = purchasableToken.PurchasableItemInfo.Name, Level = purchasableToken.Index, Discount = discount, Cost = cost, RentDuration = duration }); } }
public static void SyncFortAndSave(this LanguageEditorInfo languageEditorInfo, bool saveFort) { foreach (LanguageInfo languageInfo in languageEditorInfo.Languages) { for (int i = 0; i < InfoResolver.Resolve <FortInfo>().Language.ActiveLanguages.Length; i++) { if (InfoResolver.Resolve <FortInfo>().Language.ActiveLanguages[i].Id == languageInfo.Id) { InfoResolver.Resolve <FortInfo>().Language.ActiveLanguages[i] = languageInfo; } } if (InfoResolver.Resolve <FortInfo>().Language.DefaultLanguage != null && InfoResolver.Resolve <FortInfo>().Language.DefaultLanguage.Id == languageInfo.Id) { InfoResolver.Resolve <FortInfo>().Language.DefaultLanguage = languageInfo; } } if (saveFort) { InfoResolver.Resolve <FortInfo>().Save(); } languageEditorInfo.Save(); }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { for (int i = 0; i < movedAssets.Length; i++) { SceneAsset sceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(movedAssets[i]); if (sceneAsset != null) { FortScene[] fortScenes = TypeHelper.FindType(InfoResolver.Resolve <FortInfo>(), typeof(FortScene)).Cast <FortScene>().ToArray(); foreach (FortScene fortScene in fortScenes.Where(scene => scene != null)) { if (fortScene.SceneName == movedFromAssetPaths[i]) { fortScene.SceneName = movedAssets[i]; } } FortInfoScriptable fortInfoScriptable = Resources.Load <FortInfoScriptable>("FortInfo"); fortInfoScriptable.Save(InfoResolver.Resolve <FortInfo>()); EditorUtility.SetDirty(fortInfoScriptable); } } }