Пример #1
0
        private (string, int) getSinglarStoredType(ArrayPropertyViewModel inv)
        {
            string foundItemType = string.Empty;
            int    total         = 0;

            foreach (StructPropertyViewModel element in inv.Elements)
            {
                DynamicStructDataViewModel structData = (DynamicStructDataViewModel)element.StructData;
                InventoryItem        item             = (InventoryItem)((StructPropertyViewModel)structData.Fields[0]).StructData;
                IntPropertyViewModel numItems         = (IntPropertyViewModel)structData.Fields[1];
                if (item.ItemType != string.Empty && foundItemType != item.ItemType)
                {
                    if (foundItemType == string.Empty)
                    {
                        foundItemType = item.ItemType;
                        total         = numItems.Value;
                    }
                    else
                    {
                        // there is more than one type in this inventory
                        return(string.Empty, 0);
                    }
                }
                else
                {
                    total += numItems.Value;
                }
            }

            return(foundItemType, total);
        }
Пример #2
0
        public static PropertyViewModel TryConvert(IProperty property)
        {
            if (property == null)
            {
                return(null);
            }

            Type type = property.Type;

            if (type == typeof(string))
            {
                return(new TextBoxProperty(property));
            }

            if (typeof(Array).IsAssignableFrom(type))
            {
                var _value = (Array)property.Value;

                return(_value == null ? null : _value.Rank != 1 ? null : ArrayPropertyViewModel.CreateFromArrayProperty(property));
            }

            return(typeof(System.Collections.IEnumerable).IsAssignableFrom(type) ? ArrayPropertyViewModel.CreateFromEnumerableProperty(property)
                : type == typeof(bool) || type == typeof(bool?) ? new CheckBoxProperty(property)
                : (PropertyViewModel) new TextBoxProperty(property));
        }
Пример #3
0
        private int MassDismantle(List <SaveObjectModel> objects, ArrayProperty inventory, SaveObjectModel rootItem)
        {
            int count = 0;

            foreach (SaveObjectModel item in objects)
            {
                if (item is SaveEntityModel)
                {
                    if (IsPointInPolygon(((SaveEntityModel)item).Position, polygon) && minZ <= ((SaveEntityModel)item).Position.Z && ((SaveEntityModel)item).Position.Z <= maxZ)
                    {
                        ArrayPropertyViewModel dismantleRefund = ((SaveEntityModel)item).FindField <ArrayPropertyViewModel>("mDismantleRefund");
                        if (dismantleRefund != null)
                        {
                            foreach (SerializedPropertyViewModel property in dismantleRefund.Elements)
                            {
                                DynamicStructData itemAmountStruct = (DynamicStructData)((StructProperty)property.Model).Data;
                                string            itemPath         = ((ObjectProperty)itemAmountStruct.Fields[0]).PathName;
                                int    itemAmount = ((IntProperty)itemAmountStruct.Fields[1]).Value;
                                byte[] bytes      = PrepareForParse(itemPath, itemAmount);
                                using (MemoryStream ms = new MemoryStream(bytes))
                                    using (BinaryReader reader = new BinaryReader(ms))
                                    {
                                        SerializedProperty prop = SerializedProperty.Parse(reader);
                                        inventory.Elements.Add(prop);
                                    }
                            }
                        }
                        if (item.FindField <ObjectPropertyViewModel>("mInventory") != null)
                        {
                            inventory.Elements.AddRange(((ArrayProperty)rootItem.FindChild(item.FindField <ObjectPropertyViewModel>("mInventory").Str2, false).FindField <ArrayPropertyViewModel>("mInventoryStacks").Model).Elements);
                        }
                        if (item.FindField <ObjectPropertyViewModel>("mStorageInventory") != null)
                        {
                            inventory.Elements.AddRange(((ArrayProperty)rootItem.FindChild(item.FindField <ObjectPropertyViewModel>("mStorageInventory").Str2, false).FindField <ArrayPropertyViewModel>("mInventoryStacks").Model).Elements);
                        }
                        if (item.FindField <ObjectPropertyViewModel>("mInputInventory") != null)
                        {
                            inventory.Elements.AddRange(((ArrayProperty)rootItem.FindChild(item.FindField <ObjectPropertyViewModel>("mInputInventory").Str2, false).FindField <ArrayPropertyViewModel>("mInventoryStacks").Model).Elements);
                        }
                        if (item.FindField <ObjectPropertyViewModel>("mOutputInventory") != null)
                        {
                            inventory.Elements.AddRange(((ArrayProperty)rootItem.FindChild(item.FindField <ObjectPropertyViewModel>("mOutputInventory").Str2, false).FindField <ArrayPropertyViewModel>("mInventoryStacks").Model).Elements);
                        }
                        rootItem.Remove(item);
                        count++;
                    }
                }
            }
            return(count);
        }
        private int MassDismantle(List <SaveObjectModel> objects, ArrayProperty inventory, SaveObjectModel rootItem)
        {
            int count = 0;

            foreach (SaveObjectModel item in objects)
            {
                if (item is SaveEntityModel)
                {
                    if (IsPointInPolygon(((SaveEntityModel)item).Position, polygon) && minZ <= ((SaveEntityModel)item).Position.Z && ((SaveEntityModel)item).Position.Z <= maxZ)
                    {
                        ArrayPropertyViewModel dismantleRefund = ((SaveEntityModel)item).FindField <ArrayPropertyViewModel>("mDismantleRefund");
                        if (dismantleRefund != null)
                        {
                            foreach (SerializedPropertyViewModel property in dismantleRefund.Elements)
                            {
                                DynamicStructData itemAmountStruct = (DynamicStructData)((StructProperty)property.Model).Data;
                                string            itemPath         = ((ObjectProperty)itemAmountStruct.Fields[0]).PathName;
                                int    itemAmount = ((IntProperty)itemAmountStruct.Fields[1]).Value;
                                byte[] bytes      = PrepareForParse(itemPath, itemAmount);
                                using (MemoryStream ms = new MemoryStream(bytes))
                                    using (BinaryReader reader = new BinaryReader(ms))
                                    {
                                        SerializedProperty prop = SerializedProperty.Parse(reader);
                                        inventory.Elements.Add(prop);
                                    }
                            }
                        }
                        if (item.FindField <ObjectPropertyViewModel>("mInventory") != null)
                        {
                            inventory.Elements.AddRange(((ArrayProperty)rootItem.FindChild(item.FindField <ObjectPropertyViewModel>("mInventory").Str2, false).FindField <ArrayPropertyViewModel>("mInventoryStacks").Model).Elements);
                        }
                        if (item.FindField <ObjectPropertyViewModel>("mStorageInventory") != null)
                        {
                            inventory.Elements.AddRange(((ArrayProperty)rootItem.FindChild(item.FindField <ObjectPropertyViewModel>("mStorageInventory").Str2, false).FindField <ArrayPropertyViewModel>("mInventoryStacks").Model).Elements);
                        }
                        if (item.FindField <ObjectPropertyViewModel>("mInputInventory") != null)
                        {
                            inventory.Elements.AddRange(((ArrayProperty)rootItem.FindChild(item.FindField <ObjectPropertyViewModel>("mInputInventory").Str2, false).FindField <ArrayPropertyViewModel>("mInventoryStacks").Model).Elements);
                        }
                        if (item.FindField <ObjectPropertyViewModel>("mOutputInventory") != null)
                        {
                            inventory.Elements.AddRange(((ArrayProperty)rootItem.FindChild(item.FindField <ObjectPropertyViewModel>("mOutputInventory").Str2, false).FindField <ArrayPropertyViewModel>("mInventoryStacks").Model).Elements);
                        }
                        // Unlink miners & geysers
                        if (item.Model.TypePath.StartsWith("/Game/FactoryGame/Buildable/Factory/Miner") || item.Model.TypePath.StartsWith("/Game/FactoryGame/Buildable/Factory/GeneratorGeoThermal") || item.Model.TypePath.StartsWith("/Game/FactoryGame/Buildable/Factory/OilPump"))
                        {
                            string resourceNode = item.FindField <ObjectPropertyViewModel>("mExtractResourceNode").Str2;
                            rootItem.FindChild(resourceNode, false).FindField <BoolPropertyViewModel>("mIsOccupied", property => property.Value = false);
                        }
                        var gameState = rootItem.FindChild("Persistent_Level:PersistentLevel.BP_GameState_C_0", false);
                        if (item.Model.TypePath.StartsWith("/Game/FactoryGame/Buildable/Factory/TradingPost/Build_TradingPost.Build_TradingPost_C"))
                        {
                            gameState.FindField <BoolPropertyViewModel>("mIsTradingPostBuilt", property => property.Value = false);
                        }
                        if (item.Model.TypePath.StartsWith("/Game/FactoryGame/Buildable/Factory/SpaceElevator/Build_SpaceElevator.Build_SpaceElevator_C"))
                        {
                            gameState.FindField <BoolPropertyViewModel>("mIsSpaceElevatorBuilt", property => property.Value = false);
                        }
                        rootItem.Remove(item);
                        count++;
                    }
                }
            }
            return(count);
        }