Exemple #1
0
 /// <summary>
 /// 製品価格を設定
 /// </summary>
 /// <param name="WorkArea"></param>
 /// <param name="saveData"></param>
 private void SetWarePrice(IWorkArea WorkArea, SaveDataStationItem saveData)
 {
     foreach (var ware in saveData.XElement.XPathSelectElements("/economylog/*[not(self::cargo)]"))
     {
         var wareID = ware.Attribute("ware").Value;
         var prod   = WorkArea.StationData.ProductsInfo.Products.FirstOrDefault(x => x.Ware.WareID == wareID);
         if (prod != null)
         {
             prod.UnitPrice = long.Parse(ware.Attribute("price").Value);
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// インポート実行メイン
        /// </summary>
        /// <param name="WorkArea"></param>
        /// <param name="saveData"></param>
        /// <returns></returns>
        private bool ImportMain(IWorkArea WorkArea, SaveDataStationItem saveData)
        {
            // モジュール一覧を設定
            SetModules(WorkArea, saveData);

            // 製品価格を設定
            SetWarePrice(WorkArea, saveData);

            // 保管庫割当状態を設定
            SetStorageAssign(WorkArea, saveData);

            WorkArea.Title = saveData.StationName;

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// 保管庫割当状態を設定
        /// </summary>
        /// <param name="WorkArea"></param>
        /// <param name="saveData"></param>
        private void SetStorageAssign(IWorkArea WorkArea, SaveDataStationItem saveData)
        {
            foreach (var ware in saveData.XElement.XPathSelectElements("overrides/max/ware"))
            {
                var wareID = ware.Attribute("ware").Value;

                var storage = WorkArea.StationData.StorageAssignInfo.StorageAssign.FirstOrDefault(x => x.WareID == wareID);
                if (storage != null)
                {
                    var amount = long.Parse(ware.Attribute("amount").Value);

                    storage.AllocCount = amount;
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// モジュール一覧を設定
        /// </summary>
        /// <param name="WorkArea"></param>
        /// <param name="saveData"></param>
        private void SetModules(IWorkArea WorkArea, SaveDataStationItem saveData)
        {
            var modParam    = new SQLiteCommandParameters(1);
            var eqParam     = new SQLiteCommandParameters(3);
            var moduleCount = 0;

            foreach (var entry in saveData.XElement.XPathSelectElements("construction/sequence/entry"))
            {
                var index = int.Parse(entry.Attribute("index").Value);
                modParam.Add("macro", System.Data.DbType.String, entry.Attribute("macro").Value);

                foreach (var equipmet in entry.XPathSelectElements("upgrades/groups/*"))
                {
                    eqParam.Add("index", System.Data.DbType.Int32, index);
                    eqParam.Add("macro", System.Data.DbType.String, equipmet.Attribute("macro").Value);
                    eqParam.Add("count", System.Data.DbType.Int32, int.Parse(equipmet.Attribute("exact")?.Value ?? "1"));
                }

                moduleCount++;
            }


            var modules = new List <ModulesGridItem>(moduleCount);

            // モジュール追加
            {
                var query = @"
SELECT
    ModuleID
FROM
    Module
WHERE
    Macro = :macro";


                X4Database.Instance.ExecQuery(query, modParam, (dr, _) =>
                {
                    var module = Module.Get((string)dr["ModuleID"]);

                    if (module != null)
                    {
                        modules.Add(new ModulesGridItem(module));
                    }
                });
            }


            // 装備追加
            {
                var query = @"
SELECT
    EquipmentID,
    :index AS 'Index',
    :count AS Count
FROM
    Equipment
WHERE
    MacroName = :macro";

                X4Database.Instance.ExecQuery(query, eqParam, (dr, _) =>
                {
                    var index           = (int)(long)dr["Index"] - 1;
                    var moduleEquipment = modules[index].ModuleEquipment;

                    var equipment = Equipment.Get((string)dr["EquipmentID"]);
                    if (equipment == null)
                    {
                        return;
                    }

                    var count = (long)dr["Count"];
                    moduleEquipment.AddEquipment(equipment, count);
                });
            }

            // 同一モジュールをマージ
            var dict = new Dictionary <int, (int, Module, ModuleProduction, long)>();

            foreach (var(module, idx) in modules.Select((x, idx) => (x, idx)))
            {
                var hash = HashCode.Combine(module.Module, module.SelectedMethod);
                if (dict.ContainsKey(hash))
                {
                    var tmp = dict[hash];
                    tmp.Item4 += module.ModuleCount;
                    dict[hash] = tmp;
                }
                else
                {
                    dict.Add(hash, (idx, module.Module, module.SelectedMethod, module.ModuleCount));
                }
            }

            // モジュール一覧に追加
            var range = dict.Select(x => (x.Value)).OrderBy(x => x.Item1).Select(x => new ModulesGridItem(x.Item2, x.Item3, x.Item4));

            WorkArea.StationData.ModulesInfo.Modules.AddRange(range);
        }