public static bool IsItemRented(this PurchasableLevelInfo purchasableLevelInfo) { return(ServiceLocator.Resolve <IStoreService>().IsItemRented(purchasableLevelInfo.Id)); }
public static void ImportAchievements() { string path = EditorUtility.OpenFilePanel("Import Purchase Items", "", "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(NoneLevelBasePurchasableItemInfo).IsAssignableFrom(type)) .Concat( TypeHelper.GetAllTypes(AllTypeCategory.Game) .Where(type => typeof(LevelBasePurchasableItemInfo).IsAssignableFrom(type))) .Concat( TypeHelper.GetAllTypes(AllTypeCategory.Game) .Where(type => typeof(PurchasableLevelInfo).IsAssignableFrom(type))) .ToArray()); Dictionary <string, Type> parameters = new Dictionary <string, Type>(); parameters["Id"] = typeof(string); parameters["Name"] = typeof(string); //parameters["DisplayName"] = typeof(string); parameters["Description"] = typeof(string); parameters["DefaultBought"] = typeof(bool); foreach (string valueDefenition in InfoResolver.Resolve <FortInfo>().ValueDefenitions) { parameters[string.Format("PurchaseCost-{0}", valueDefenition)] = typeof(int); parameters[string.Format("RentCost-{0}", 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>().Purchase.PurchasableTokens.ContainsKey(id)) { continue; } PurchasableToken purchasableToken = InfoResolver.Resolve <FortInfo>().Purchase.PurchasableTokens[id]; if (purchasableToken.NoneLevelBase) { NoneLevelBasePurchasableItemInfo noneLevelBasePurchasableItemInfo = (NoneLevelBasePurchasableItemInfo)purchasableToken.PurchasableItemInfo; if (exportRow.ContainsParameter("Name")) { noneLevelBasePurchasableItemInfo.Name = (string)exportRow.GetValue("Name").Value; } /* if (exportRow.ContainsParameter("DisplayName")) * { * noneLevelBasePurchasableItemInfo.DisplayName = (string)exportRow.GetValue("DisplayName").Value; * }*/ if (exportRow.ContainsParameter("Description")) { noneLevelBasePurchasableItemInfo.Description = (string)exportRow.GetValue("Description").Value; } if (exportRow.ContainsParameter("DefaultBought")) { noneLevelBasePurchasableItemInfo.DefaultBought = (bool)exportRow.GetValue("DefaultBought").Value; } if (noneLevelBasePurchasableItemInfo.Costs == null) { noneLevelBasePurchasableItemInfo.Costs = new ItemCosts(); } foreach (string valueDefenition in InfoResolver.Resolve <FortInfo>().ValueDefenitions) { string purchaseValueDefenition = string.Format("PurchaseCost-{0}", valueDefenition); if (exportRow.ContainsParameter(purchaseValueDefenition)) { noneLevelBasePurchasableItemInfo.Costs.Purchase[valueDefenition] = (int)exportRow.GetValue(purchaseValueDefenition).Value; } string rentValueDefenition = string.Format("RentCost-{0}", valueDefenition); if (exportRow.ContainsParameter(rentValueDefenition)) { noneLevelBasePurchasableItemInfo.Costs.Purchase[valueDefenition] = (int)exportRow.GetValue(rentValueDefenition).Value; } } exportRow.FillCustomExportParameter(noneLevelBasePurchasableItemInfo); } else { if (purchasableToken.PurchasableLevelInfo == null) { LevelBasePurchasableItemInfo levelBasePurchasableItemInfo = (LevelBasePurchasableItemInfo)purchasableToken.PurchasableItemInfo; if (exportRow.ContainsParameter("Name")) { levelBasePurchasableItemInfo.Name = (string)exportRow.GetValue("Name").Value; } /* if (exportRow.ContainsParameter("DisplayName")) * { * levelBasePurchasableItemInfo.DisplayName = (string)exportRow.GetValue("DisplayName").Value; * }*/ if (exportRow.ContainsParameter("Description")) { levelBasePurchasableItemInfo.Description = (string)exportRow.GetValue("Description").Value; } if (exportRow.ContainsParameter("DefaultBought")) { levelBasePurchasableItemInfo.DefaultBought = (bool)exportRow.GetValue("DefaultBought").Value; } exportRow.FillCustomExportParameter(levelBasePurchasableItemInfo); } else { PurchasableLevelInfo purchasableLevelInfo = purchasableToken.PurchasableLevelInfo; /* if (exportRow.ContainsParameter("DisplayName")) * { * purchasableLevelInfo.DisplayName = (string)exportRow.GetValue("DisplayName").Value; * }*/ if (exportRow.ContainsParameter("Description")) { purchasableLevelInfo.Description = (string)exportRow.GetValue("Description").Value; } if (exportRow.ContainsParameter("DefaultBought")) { purchasableLevelInfo.DefaultBought = (bool)exportRow.GetValue("DefaultBought").Value; } foreach (string valueDefenition in InfoResolver.Resolve <FortInfo>().ValueDefenitions) { string purchaseValueDefenition = string.Format("PurchaseCost-{0}", valueDefenition); if (exportRow.ContainsParameter(purchaseValueDefenition)) { purchasableLevelInfo.Costs.Purchase[valueDefenition] = (int)exportRow.GetValue(purchaseValueDefenition).Value; } string rentValueDefenition = string.Format("RentCost-{0}", valueDefenition); if (exportRow.ContainsParameter(rentValueDefenition)) { purchasableLevelInfo.Costs.Purchase[valueDefenition] = (int)exportRow.GetValue(rentValueDefenition).Value; } } exportRow.FillCustomExportParameter(purchasableLevelInfo); } } } } InfoResolver.Resolve <FortInfo>().Save(); }