public NoneLevelBaseItemPurchasedEventArgs(NoneLevelBasePurchasableItemInfo noneLevelBasePurchasableItemInfo, Balance cost) : base(noneLevelBasePurchasableItemInfo, cost)
 {
     NoneLevelBasePurchasableItemInfo = noneLevelBasePurchasableItemInfo;
 }
 public static bool IsItemRented(this NoneLevelBasePurchasableItemInfo purchasableItemInfo)
 {
     return(ServiceLocator.Resolve <IStoreService>().IsItemRented(purchasableItemInfo.Id));
 }
        public static void ExportPurchaseItems()
        {
            string path = EditorUtility.SaveFilePanel("Export Purchase Items", "", "", "xls");

            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            using (System.IO.Stream writer = File.Create(path))
            {
                ExportData exportData = new ExportData();
                foreach (PurchasableItemInfo purchasableItemInfo in InfoResolver.Resolve <FortInfo>().Purchase.GetAllPurchasableItemInfos())
                {
                    ExportRow exportRow = new ExportRow();
                    exportRow.AddParameter("Id", new Parameter
                    {
                        Value = purchasableItemInfo.Id,
                        Type  = typeof(string)
                    });
                    exportRow.AddParameter("Name", new Parameter
                    {
                        Value = purchasableItemInfo.Name,
                        Type  = typeof(string)
                    });

/*                    exportRow.AddParameter("DisplayName", new Parameter
 *                  {
 *                      Value = purchasableItemInfo.DisplayName,
 *                      Type = typeof(string)
 *                  });*/
                    exportRow.AddParameter("Description", new Parameter
                    {
                        Value = purchasableItemInfo.Description,
                        Type  = typeof(string)
                    });
                    exportRow.AddParameter("DefaultBought", new Parameter
                    {
                        Value = purchasableItemInfo.DefaultBought,
                        Type  = typeof(bool)
                    });
                    NoneLevelBasePurchasableItemInfo noneLevelBasePurchasableItemInfo = purchasableItemInfo as NoneLevelBasePurchasableItemInfo;
                    if (noneLevelBasePurchasableItemInfo != null)
                    {
                        foreach (string valueDefenition in InfoResolver.Resolve <FortInfo>().ValueDefenitions)
                        {
                            exportRow.AddParameter(string.Format("PurchaseCost-{0}", valueDefenition), new Parameter
                            {
                                Value = noneLevelBasePurchasableItemInfo.Costs == null || noneLevelBasePurchasableItemInfo.Costs.Purchase == null ||
                                        noneLevelBasePurchasableItemInfo.Costs.Purchase.Values == null
                                    ? 0
                                    : noneLevelBasePurchasableItemInfo.Costs.Purchase[valueDefenition],
                                Type = typeof(int)
                            });
                        }
                        foreach (string valueDefenition in InfoResolver.Resolve <FortInfo>().ValueDefenitions)
                        {
                            exportRow.AddParameter(string.Format("RentCost-{0}", valueDefenition), new Parameter
                            {
                                Value = noneLevelBasePurchasableItemInfo.Costs == null || noneLevelBasePurchasableItemInfo.Costs.Rent == null ||
                                        noneLevelBasePurchasableItemInfo.Costs.Rent.Values == null
                                    ? 0
                                    : noneLevelBasePurchasableItemInfo.Costs.Rent[valueDefenition],
                                Type = typeof(int)
                            });
                        }
                        exportRow.AddCustomExportParameter(purchasableItemInfo);
                        exportData.AddRow(exportRow);
                    }
                    else
                    {
                        exportRow.AddCustomExportParameter(purchasableItemInfo);
                        exportData.AddRow(exportRow);
                        LevelBasePurchasableItemInfo levelBasePurchasableItemInfo = purchasableItemInfo as LevelBasePurchasableItemInfo;
                        if (levelBasePurchasableItemInfo != null)
                        {
                            PurchasableLevelInfo[] purchasableLevelInfos = levelBasePurchasableItemInfo.GetPurchasableLevelInfos();
                            int index = 0;
                            foreach (PurchasableLevelInfo purchasableLevelInfo in purchasableLevelInfos)
                            {
                                ExportRow levelExportRow = new ExportRow();
                                levelExportRow.AddParameter("Id", new Parameter
                                {
                                    Value = purchasableLevelInfo.Id,
                                    Type  = typeof(string)
                                });
                                levelExportRow.AddParameter("Name", new Parameter
                                {
                                    Value = string.Format("{0}_{1}", purchasableItemInfo.Name, index++),
                                    Type  = typeof(string)
                                });

/*                                levelExportRow.AddParameter("DisplayName", new Parameter
 *                              {
 *                                  Value = purchasableLevelInfo.DisplayName,
 *                                  Type = typeof(string)
 *                              });*/
                                levelExportRow.AddParameter("Description", new Parameter
                                {
                                    Value = purchasableLevelInfo.Description,
                                    Type  = typeof(string)
                                });
                                levelExportRow.AddParameter("DefaultBought", new Parameter
                                {
                                    Value = purchasableLevelInfo.DefaultBought,
                                    Type  = typeof(bool)
                                });

                                foreach (string valueDefenition in InfoResolver.Resolve <FortInfo>().ValueDefenitions)
                                {
                                    levelExportRow.AddParameter(string.Format("PurchaseCost-{0}", valueDefenition), new Parameter
                                    {
                                        Value = purchasableLevelInfo.Costs == null || purchasableLevelInfo.Costs.Purchase == null ||
                                                purchasableLevelInfo.Costs.Purchase.Values == null
                                            ? 0
                                            : purchasableLevelInfo.Costs.Purchase[valueDefenition],
                                        Type = typeof(int)
                                    });
                                }
                                foreach (string valueDefenition in InfoResolver.Resolve <FortInfo>().ValueDefenitions)
                                {
                                    levelExportRow.AddParameter(string.Format("RentCost-{0}", valueDefenition), new Parameter
                                    {
                                        Value = purchasableLevelInfo.Costs == null || purchasableLevelInfo.Costs.Rent == null ||
                                                purchasableLevelInfo.Costs.Rent.Values == null
                                            ? 0
                                            : purchasableLevelInfo.Costs.Rent[valueDefenition],
                                        Type = typeof(int)
                                    });
                                }
                                levelExportRow.AddCustomExportParameter(purchasableLevelInfo);
                                exportData.AddRow(levelExportRow);
                            }
                        }
                    }
                }

                HSSFWorkbook workbook = new HSSFWorkbook();

                HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet("Purchasable Items");
                exportData.SerializeToSheet(sheet);
                workbook.Write(writer);
            }
        }
        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();
        }
Esempio n. 5
0
        private static Promise InternalUpdatePurchasableItemsToServer(bool showDialog)
        {
            Deferred deferred = new Deferred();
            //BacktoryCloudUrl.Url = "http://localhost:8086";
            UpdateItemsRequest           request = new UpdateItemsRequest();
            List <ServerPurchasableItem> serverPurchasableItems = new List <ServerPurchasableItem>();

            foreach (
                PurchasableItemInfo purchasableItemInfo in
                InfoResolver.Resolve <FortInfo>().Purchase.GetAllPurchasableItemInfos().Where(info => info != null))
            {
                NoneLevelBasePurchasableItemInfo noneLevelBasePurchasableItemInfo =
                    purchasableItemInfo as NoneLevelBasePurchasableItemInfo;
                if (noneLevelBasePurchasableItemInfo != null)
                {
                    serverPurchasableItems.Add(new ServerPurchasableItem
                    {
                        ItemId       = noneLevelBasePurchasableItemInfo.Id,
                        Name         = noneLevelBasePurchasableItemInfo.Name,
                        PurchaseCost = noneLevelBasePurchasableItemInfo.Costs.Purchase.Values,
                        RentCost     = noneLevelBasePurchasableItemInfo.Costs.Rent.Values
                    });
                }
                else
                {
                    LevelBasePurchasableItemInfo levelBasePurchasableItemInfo =
                        (LevelBasePurchasableItemInfo)purchasableItemInfo;
                    PurchasableLevelInfo[] purchasableLevelInfos = levelBasePurchasableItemInfo.GetPurchasableLevelInfos();
                    for (int i = 0; i < purchasableLevelInfos.Length; i++)
                    {
                        serverPurchasableItems.Add(new ServerPurchasableItem
                        {
                            ItemId       = purchasableLevelInfos[i].Id,
                            Name         = purchasableLevelInfos[i].Name,
                            PurchaseCost = purchasableLevelInfos[i].Costs.Purchase.Values,
                            RentCost     = purchasableLevelInfos[i].Costs.Rent.Values
                        });
                    }
                }
            }
            request.Items = serverPurchasableItems.ToArray();
            EditorUtility.DisplayProgressBar("Syncronizing Purchasable items", "Syncronizing Purchasable items", 0);
            InfoResolver.Resolve <FortInfo>()
            .ServerConnectionProvider.EditorConnection.Call <object>("UpdateItems", request)
            .Then(
                o =>
            {
                EditorUtility.ClearProgressBar();
                if (showDialog)
                {
                    EditorUtility.DisplayDialog("Syncronizing Purchasable items",
                                                "Purchasable items syncronization succeeded", "Ok");
                }
                deferred.Resolve();
            }, error =>
            {
                EditorUtility.ClearProgressBar();
                deferred.Reject();
                throw new Exception("purchasable items syncronization failed");
            });
            return(deferred.Promise());
        }