Exemple #1
0
        public static void UpdateWithManufacturing(
            IStaticWorldObject worldObject,
            LiquidContainerState liquidContainerState,
            LiquidContainerConfig liquidContainerConfig,
            ManufacturingState manufacturingState,
            ManufacturingConfig manufacturingConfig,
            double deltaTime,
            bool isProduceLiquid,
            bool forceUpdateRecipe = false)
        {
            ManufacturingMechanic.UpdateRecipeOnly(
                worldObject,
                manufacturingState,
                manufacturingConfig,
                force: forceUpdateRecipe);

            var isUseRequested = manufacturingState.HasActiveRecipe;

            UpdateWithoutManufacturing(
                liquidContainerState,
                liquidContainerConfig,
                deltaTime,
                isProduceLiquid,
                isUseRequested,
                out var wasUsed);

            if (wasUsed)
            {
                ManufacturingMechanic.UpdateCraftingQueueOnly(
                    manufacturingState,
                    deltaTime);
            }
        }
Exemple #2
0
        public ViewModelWindowMulchbox(
            IStaticWorldObject worldObjectManufacturer,
            ManufacturingState manufacturingState,
            ManufacturingConfig manufacturingConfig)
            : base(
                worldObjectManufacturer,
                manufacturingState,
                manufacturingConfig,
                null)
        {
            var protoMulchbox = (IProtoObjectMulchbox)worldObjectManufacturer.ProtoStaticWorldObject;

            this.OrganicCapacity = protoMulchbox.OrganicCapacity;

            this.privateState = protoMulchbox.GetMulchboxPrivateState(worldObjectManufacturer);
            this.privateState.ClientSubscribe(
                _ => _.OrganicAmount,
                _ => this.RefreshOrganicAmount(),
                this);

            manufacturingState.ClientSubscribe(
                _ => _.SelectedRecipe,
                _ => this.RefreshRecipe(),
                this);

            this.RefreshOrganicAmount();
            this.RefreshRecipe();
        }
        public ViewModelWindowSprinkler(
            IStaticWorldObject worldObject,
            ProtoObjectSprinkler.PrivateState privateState,
            ManufacturingConfig manufacturingConfig)
        {
            this.protoSprinkler = (IProtoObjectSprinkler)worldObject.ProtoStaticWorldObject;
            this.worldObject    = worldObject;
            this.privateState   = privateState;

            this.ViewModelManufacturingState = new ViewModelManufacturingState(
                worldObject,
                this.privateState.ManufacturingState,
                manufacturingConfig);

            this.privateState.ClientSubscribe(
                _ => _.WaterAmount,
                _ => this.RefreshWaterAmount(),
                this);

            this.privateState.ClientSubscribe(
                _ => _.NextWateringTime,
                _ => this.NotifyPropertyChanged(nameof(this.NextWateringInText)),
                this);

            this.RefreshWaterAmount();

            this.RefreshNextWateringInText();
        }
Exemple #4
0
        protected override void PrepareProtoStaticWorldObject()
        {
            base.PrepareProtoStaticWorldObject();

            var manufacturingConfig = this.PrepareManufacturingConfig();

            this.ManufacturingConfig = manufacturingConfig;
        }
Exemple #5
0
        public static void UpdateWithManufacturing(
            IStaticWorldObject worldObject,
            LiquidContainerState liquidContainerState,
            LiquidContainerConfig liquidContainerConfig,
            ManufacturingState manufacturingState,
            ManufacturingConfig manufacturingConfig,
            double deltaTime,
            bool isProduceLiquid,
            bool forceUpdateRecipe = false)
        {
            ManufacturingMechanic.UpdateRecipeOnly(
                worldObject,
                manufacturingState,
                manufacturingConfig,
                force: forceUpdateRecipe);

            var isUseRequested = manufacturingState.HasActiveRecipe;

            var wasFull = liquidContainerState.Amount >= liquidContainerConfig.Capacity;

            UpdateWithoutManufacturing(
                liquidContainerState,
                liquidContainerConfig,
                deltaTime,
                isProduceLiquid,
                isUseRequested,
                out var wasUsed);

            if (!wasFull &&
                liquidContainerState.Amount >= liquidContainerConfig.Capacity)
            {
                /* Note: This is a special workaround for oil pump.
                 * The problem with it is that it becomes inactive (IsActive set to false) for single server update
                 * once the full capacity is reached. With this workaround we're forcing it to refresh the recipe
                 * that will in turn update the crafting queue and produce the output without interruption. */

                // became full, update the recipe
                ManufacturingMechanic.UpdateRecipeOnly(
                    worldObject,
                    manufacturingState,
                    manufacturingConfig,
                    force: forceUpdateRecipe);

                // force crafting system update
                wasUsed = true;
            }

            if (wasUsed)
            {
                ManufacturingMechanic.UpdateCraftingQueueOnly(
                    manufacturingState,
                    deltaTime);
            }
        }
        protected sealed override void PrepareProtoStaticWorldObject()
        {
            base.PrepareProtoStaticWorldObject();

            this.manufacturingConfig = new ManufacturingConfig(
                this,
                recipes: new[] { GetProtoEntity <RecipeSprinklerEmptyBottleFromWaterBottle>() },
                recipesForByproducts: null,
                isProduceByproducts: false,
                isAutoSelectRecipe: true);

            this.PrepareProtoObjectSprinkler();
        }
        public ViewModelWindowOilRefinery(
            IStaticWorldObject worldObject,
            ManufacturingState manufacturingState,
            ManufacturingState manufacturingStateProcessedGasoline,
            ManufacturingState manufacturingStateProcessedMineralOil,
            ManufacturingConfig manufacturingConfig,
            ManufacturingConfig manufacturingConfigProcessedGasoline,
            ManufacturingConfig manufacturingConfigProcessedMineralOil,
            LiquidContainerState liquidStateRawPetroleum,
            LiquidContainerState liquidStateProcessedGasoline,
            LiquidContainerState liquidStateProcessedMineralOil,
            LiquidContainerConfig liquidConfigRawPetroleum,
            LiquidContainerConfig liquidConfigProcessedGasoline,
            LiquidContainerConfig liquidConfigProcessedMineralOil)
        {
            this.WorldObjectManufacturer = worldObject;

            this.ViewModelManufacturingStateRawPetroleum = new ViewModelManufacturingState(
                worldObject,
                manufacturingState,
                manufacturingConfig);

            this.ViewModelManufacturingStateProcessedGasoline = new ViewModelManufacturingState(
                worldObject,
                manufacturingStateProcessedGasoline,
                manufacturingConfigProcessedGasoline);

            this.ViewModelManufacturingStateProcessedMineralOil = new ViewModelManufacturingState(
                worldObject,
                manufacturingStateProcessedMineralOil,
                manufacturingConfigProcessedMineralOil);

            this.ViewModelLiquidStateRawPetroleum = new ViewModelLiquidContainerState(
                liquidStateRawPetroleum,
                liquidConfigRawPetroleum);

            this.ViewModelLiquidStateProcessedGasoline = new ViewModelLiquidContainerState(
                liquidStateProcessedGasoline,
                liquidConfigProcessedGasoline);

            this.ViewModelLiquidStateProcessedMineralOil = new ViewModelLiquidContainerState(
                liquidStateProcessedMineralOil,
                liquidConfigProcessedMineralOil);

            // prepare active state property
            this.manufacturerPublicState = worldObject.GetPublicState <ObjectManufacturerPublicState>();
            this.manufacturerPublicState.ClientSubscribe(_ => _.IsActive,
                                                         _ => this.NotifyPropertyChanged(
                                                             nameof(this.IsManufacturingActive)),
                                                         this);
        }
Exemple #8
0
 public ViewModelWindowGeneratorSteam(
     IStaticWorldObject worldObjectGenerator,
     ObjectGeneratorSteam.PrivateState privateState,
     ManufacturingConfig manufacturingConfig,
     LiquidContainerState liquidContainerState,
     LiquidContainerConfig liquidContainerConfig)
     : base(worldObjectGenerator,
            privateState,
            manufacturingConfig,
            liquidContainerState,
            liquidContainerConfig)
 {
     this.privateState   = privateState;
     this.protoGenerator = (IProtoObjectGeneratorWithFuel)worldObjectGenerator.ProtoStaticWorldObject;
 }
 public ViewModelWindowWell(
     IStaticWorldObject worldObjectManufacturer,
     ObjectManufacturerPrivateState privateState,
     ManufacturingConfig manufacturingConfig,
     LiquidContainerState liquidContainerState,
     LiquidContainerConfig liquidContainerConfig)
     : base(
         worldObjectManufacturer,
         privateState,
         manufacturingConfig: manufacturingConfig)
 {
     this.CommandDrink = new ActionCommand(this.ExecuteCommandDrink);
     this.ViewModelLiquidContainerState = new ViewModelLiquidContainerState(
         liquidContainerState,
         liquidContainerConfig);
 }
        public ViewModelWindowLithiumOreExtractor(
            IStaticWorldObject worldObjectManufacturer,
            IStaticWorldObject worldObjectDeposit,
            ObjectManufacturerPrivateState privateState,
            ManufacturingConfig manufacturingConfig,
            LiquidContainerState liquidContainerState,
            LiquidContainerConfig liquidContainerConfig)
            : base(worldObjectManufacturer,
                   privateState,
                   manufacturingConfig)
        {
            this.ViewModelLiquidContainerState = new ViewModelLiquidContainerState(liquidContainerState,
                                                                                   liquidContainerConfig);

            this.ViewModelDepositCapacityStatsControl = new ViewModelDepositCapacityStatsControl(worldObjectDeposit);
        }
        public ViewModelWindowOilCrackingPlant(
            IStaticWorldObject worldObject,
            ManufacturingState manufacturingState,
            ManufacturingState manufacturingStateProcessedGasoline,
            ManufacturingConfig manufacturingConfig,
            ManufacturingConfig manufacturingConfigProcessedGasoline,
            LiquidContainerState liquidStateMineralOil,
            LiquidContainerState liquidStateProcessedGasoline,
            LiquidContainerConfig liquidConfigMineralOil,
            LiquidContainerConfig liquidConfigProcessedGasoline)
        {
            this.WorldObjectManufacturer = worldObject;

            this.ViewModelManufacturingStateMineralOil = new ViewModelManufacturingState(
                worldObject,
                manufacturingState,
                manufacturingConfig);

            this.ViewModelManufacturingStateProcessedGasoline = new ViewModelManufacturingState(
                worldObject,
                manufacturingStateProcessedGasoline,
                manufacturingConfigProcessedGasoline);

            this.ViewModelLiquidStateMineralOil = new ViewModelLiquidContainerState(
                liquidStateMineralOil,
                liquidConfigMineralOil);

            this.ViewModelLiquidStateProcessedGasoline = new ViewModelLiquidContainerState(
                liquidStateProcessedGasoline,
                liquidConfigProcessedGasoline);
            // prepare active state property
            this.manufacturerPublicState = worldObject.GetPublicState <ObjectManufacturerPublicState>();
            this.manufacturerPublicState.ClientSubscribe(_ => _.IsActive,
                                                         _ => NotifyPropertyChanged(nameof(IsManufacturingActive)), this);
            viewModelManufacturerExchange = new ViewModelManufacturerExchange(
                new List <IItemsContainer>
            {
                manufacturingState.ContainerOutput,
                manufacturingStateProcessedGasoline.ContainerOutput
            },
                new List <IItemsContainer>
            {
                manufacturingState.ContainerInput,
                manufacturingStateProcessedGasoline.ContainerInput
            },
                true);
        }
        public ViewModelWindowMulchbox(
            IStaticWorldObject worldObjectManufacturer,
            ObjectMulchboxPrivateState privateState,
            ManufacturingConfig manufacturingConfig)
            : base(
                worldObjectManufacturer,
                privateState,
                manufacturingConfig)
        {
            this.protoMulchbox = (IProtoObjectMulchbox)worldObjectManufacturer.ProtoStaticWorldObject;
            this.privateState  = privateState;

            this.privateState.ClientSubscribe(
                _ => _.OrganicAmount,
                _ => this.NotifyPropertyChanged(nameof(this.OrganicAmount)),
                this);
        }
Exemple #13
0
        public ViewModelWindowManufacturer(
            IStaticWorldObject worldObjectManufacturer,
            ObjectManufacturerPrivateState privateState,
            ManufacturingConfig manufacturingConfig)
        {
            this.WorldObjectManufacturer = worldObjectManufacturer;
            var fuelBurningState   = privateState.FuelBurningState;
            var manufacturingState = privateState.ManufacturingState;

            // please note - the order of creating these view models is important for the proper container exchange order
            this.ViewModelFuelBurningState = fuelBurningState is not null
                                                 ? new ViewModelFuelBurningState(fuelBurningState)
                                                 : null;

            this.ViewModelManufacturingState = new ViewModelManufacturingState(
                worldObjectManufacturer,
                manufacturingState,
                manufacturingConfig);

            this.ViewModelBurningFuel = ViewModelBurningFuel.Create(worldObjectManufacturer, fuelBurningState);

            this.ViewModelManufacturingState.SubscribePropertyChange(
                _ => _.SelectedRecipe,
                this.RefreshIsNeedFuel);

            this.ViewModelManufacturingState.SubscribePropertyChange(
                _ => _.IsInputMatchSelectedRecipe,
                this.RefreshIsNeedFuel);

            this.ViewModelBurningFuel?.SubscribePropertyChange(
                _ => _.IsActive,
                this.RefreshIsNeedFuel);

            this.ViewModelFuelBurningState?.SubscribePropertyChange(
                _ => _.FuelUsageCurrentValue,
                this.RefreshIsNeedFuel);

            this.ViewModelManufacturingState.ContainerInput.StateHashChanged += this.ContainerInputStateChanged;

            this.RefreshIsNeedFuel();

            this.publicState = worldObjectManufacturer.GetPublicState <ObjectManufacturerPublicState>();
            this.publicState.ClientSubscribe(_ => _.IsActive,
                                             _ => this.NotifyPropertyChanged(nameof(this.IsManufacturingActive)),
                                             this);
        }
        public ViewModelWindowManufacturer(
            IStaticWorldObject worldObjectManufacturer,
            ManufacturingState manufacturingState,
            ManufacturingConfig manufacturingConfig,
            FuelBurningState fuelBurningState)
        {
            this.WorldObjectManufacturer = worldObjectManufacturer;

            // please note - the order of creating these view models is important for the proper container exchange order
            this.ViewModelFuelBurningState = fuelBurningState != null
                                                 ? new ViewModelFuelBurningState(fuelBurningState)
                                                 : null;

            this.ViewModelManufacturingState = new ViewModelManufacturingState(
                worldObjectManufacturer,
                manufacturingState,
                manufacturingConfig);

            this.VisibilityFuelControls = this.ViewModelFuelBurningState != null
                                              ? Visibility.Visible
                                              : Visibility.Collapsed;

            this.ViewModelBurningFuel = ViewModelBurningFuel.Create(worldObjectManufacturer, fuelBurningState);

            this.ViewModelManufacturingState.SubscribePropertyChange(
                _ => _.SelectedRecipe,
                this.RefreshIsNeedFuel);

            this.ViewModelManufacturingState.SubscribePropertyChange(
                _ => _.IsInputMatchSelectedRecipe,
                this.RefreshIsNeedFuel);

            this.ViewModelBurningFuel?.SubscribePropertyChange(
                _ => _.IsActive,
                this.RefreshIsNeedFuel);

            this.ViewModelFuelBurningState?.SubscribePropertyChange(
                _ => _.FuelUsageCurrentValue,
                this.RefreshIsNeedFuel);

            this.ViewModelManufacturingState.ContainerInput.StateHashChanged += this.ContainerInputStateChanged;

            this.RefreshIsNeedFuel();
        }
Exemple #15
0
        protected override void PrepareProtoStaticWorldObject()
        {
            base.PrepareProtoStaticWorldObject();

            this.ManufacturingConfigGasoline = new ManufacturingConfig(
                this,
                recipes: new List <Recipe>
            {
                GetProtoEntity <RecipeOilRefineryGasolineCanister>()
            },
                recipesForByproducts: null,
                isProduceByproducts: false,
                isAutoSelectRecipe: true);

            this.ManufacturingConfigMineralOil = new ManufacturingConfig(
                this,
                recipes: new List <Recipe>
            {
                GetProtoEntity <RecipeOilRefineryMineralOilCanister>()
            },
                recipesForByproducts: null,
                isProduceByproducts: false,
                isAutoSelectRecipe: true);

            this.LiquidConfigRawPetroleum = new LiquidContainerConfig(
                capacity: this.LiquidCapacityRawPetroleum,
                // Not increased via "generation"
                // it's increased when a special recipe (petroleum canister->empty canister) is completed.
                amountAutoIncreasePerSecond: 0,
                amountAutoDecreasePerSecondWhenUse: this.LiquidRawPetroleumConsumptionPerSecond);

            this.LiquidConfigMineralOil = new LiquidContainerConfig(
                capacity: this.LiquidCapacityMineralOil,
                amountAutoIncreasePerSecond: this.LiquidMineralOilProductionPerSecond,
                // not decreased via "use", but via recipe
                amountAutoDecreasePerSecondWhenUse: 0);

            this.LiquidConfigGasoline = new LiquidContainerConfig(
                capacity: this.LiquidCapacityGasoline,
                amountAutoIncreasePerSecond: this.LiquidGasolineProductionPerSecond,
                // not decreased via "use", but via recipe
                amountAutoDecreasePerSecondWhenUse: 0);
        }
Exemple #16
0
        public ViewModelWindowGeneratorWithFuel(
            IStaticWorldObject worldObjectGenerator,
            ObjectManufacturerPrivateState privateState,
            ManufacturingConfig manufacturingConfig,
            LiquidContainerState liquidContainerState,
            LiquidContainerConfig liquidContainerConfig)
            : base(
                worldObjectGenerator,
                privateState,
                manufacturingConfig)
        {
            this.protoGenerator = (IProtoObjectGeneratorWithFuel)worldObjectGenerator.ProtoStaticWorldObject;
            this.ViewModelLiquidContainerState = new ViewModelLiquidContainerState(
                liquidContainerState,
                liquidContainerConfig,
                liquidType: this.protoGenerator.LiquidType);

            this.Refresh();
        }
Exemple #17
0
        public ViewModelWindowOilPump(
            IStaticWorldObject worldObjectManufacturer,
            IStaticWorldObject worldObjectDeposit,
            ObjectManufacturerPrivateState privateState,
            ManufacturingConfig manufacturingConfig,
            LiquidContainerState liquidContainerState,
            LiquidContainerConfig liquidContainerConfig)
            : base(
                worldObjectManufacturer,
                privateState,
                manufacturingConfig)
        {
            this.ViewModelLiquidContainerState = new ViewModelLiquidContainerState(
                liquidContainerState,
                liquidContainerConfig);

            this.ViewModelDepositCapacityStatsControl
                = new ViewModelDepositCapacityStatsControl(worldObjectDeposit,
                                                           worldObjectManufacturer.TilePosition);
        }
        public ViewModelWindowOilPump(
            IStaticWorldObject worldObjectManufacturer,
            IStaticWorldObject worldObjectDeposit,
            ManufacturingState manufacturingState,
            ManufacturingConfig manufacturingConfig,
            FuelBurningState fuelBurningState,
            LiquidContainerState liquidContainerState,
            LiquidContainerConfig liquidContainerConfig)
            : base(
                worldObjectManufacturer,
                manufacturingState,
                manufacturingConfig,
                fuelBurningState)
        {
            this.ViewModelLiquidContainerState = new ViewModelLiquidContainerState(
                liquidContainerState,
                liquidContainerConfig);

            this.ViewModelDepositCapacityStatsControl = new ViewModelDepositCapacityStatsControl(worldObjectDeposit);
        }
        public ViewModelWindowBarrel(
            IStaticWorldObject worldObjectManufacturer,
            ObjectManufacturerPrivateState privateState,
            ManufacturingConfig manufacturingConfig)
            : base(
                worldObjectManufacturer,
                privateState,
                manufacturingConfig)
        {
            this.protoBarrel    = (IProtoObjectBarrel)worldObjectManufacturer.ProtoStaticWorldObject;
            this.LiquidCapacity = this.protoBarrel.LiquidCapacity;

            this.privateState = this.protoBarrel.GetBarrelPrivateState(worldObjectManufacturer);
            this.privateState.ClientSubscribe(
                _ => _.LiquidAmount,
                _ => this.RefreshLiquidAmount(),
                this);

            this.privateState.ClientSubscribe(
                _ => _.LiquidType,
                _ => this.RefreshLiquidType(),
                this);

            var manufacturingState = privateState.ManufacturingState;

            manufacturingState.ClientSubscribe(
                _ => _.SelectedRecipe,
                _ => this.RefreshRecipe(),
                this);

            this.craftingQueueItems = manufacturingState.CraftingQueue.QueueItems;
            this.craftingQueueItems.ClientAnyModification += this.QueueItemsClientAnyModificationHandler;

            this.RefreshLiquidAmount();
            this.RefreshRecipe();

            // no need - automatically refreshed with the recipe refresh
            //this.RefreshLiquidType();
        }
Exemple #20
0
        public ViewModelWindowBarrel(
            IStaticWorldObject worldObjectManufacturer,
            ManufacturingState manufacturingState,
            ManufacturingConfig manufacturingConfig)
            : base(
                worldObjectManufacturer,
                manufacturingState,
                manufacturingConfig,
                null)
        {
            var protoBarrel = (IProtoObjectBarrel)worldObjectManufacturer.ProtoStaticWorldObject;

            this.LiquidCapacity = protoBarrel.LiquidCapacity;

            this.privateState = protoBarrel.GetBarrelPrivateState(worldObjectManufacturer);
            this.privateState.ClientSubscribe(
                _ => _.LiquidAmount,
                _ => this.RefreshLiquidAmount(),
                this);

            this.privateState.ClientSubscribe(
                _ => _.LiquidType,
                _ => this.RefreshLiquidType(),
                this);

            manufacturingState.ClientSubscribe(
                _ => _.SelectedRecipe,
                _ => this.RefreshRecipe(),
                this);

            this.RefreshLiquidAmount();
            this.RefreshRecipe();

            // no need - automatically refreshed with the recipe refresh
            //this.RefreshLiquidType();
        }
Exemple #21
0
        public ViewModelWindowOilRefinery(
            IStaticWorldObject worldObject,
            ManufacturingState manufacturingState,
            ManufacturingState manufacturingStateProcessedGasoline,
            ManufacturingState manufacturingStateProcessedMineralOil,
            ManufacturingConfig manufacturingConfig,
            ManufacturingConfig manufacturingConfigProcessedGasoline,
            ManufacturingConfig manufacturingConfigProcessedMineralOil,
            FuelBurningState fuelBurningState,
            LiquidContainerState liquidStateRawPetroleum,
            LiquidContainerState liquidStateProcessedGasoline,
            LiquidContainerState liquidStateProcessedMineralOil,
            LiquidContainerConfig liquidConfigRawPetroleum,
            LiquidContainerConfig liquidConfigProcessedGasoline,
            LiquidContainerConfig liquidConfigProcessedMineralOil)
        {
            this.WorldObjectManufacturer = worldObject;

            // please note - the order of creating these view models is important for the proper container exchange order
            this.ViewModelFuelBurningState = new ViewModelFuelBurningState(fuelBurningState);
            this.ViewModelBurningFuel      = ViewModelBurningFuel.Create(this.WorldObjectManufacturer, fuelBurningState);

            this.ViewModelManufacturingStateRawPetroleum = new ViewModelManufacturingState(
                worldObject,
                manufacturingState,
                manufacturingConfig);

            this.ViewModelManufacturingStateProcessedGasoline = new ViewModelManufacturingState(
                worldObject,
                manufacturingStateProcessedGasoline,
                manufacturingConfigProcessedGasoline);

            this.ViewModelManufacturingStateProcessedMineralOil = new ViewModelManufacturingState(
                worldObject,
                manufacturingStateProcessedMineralOil,
                manufacturingConfigProcessedMineralOil);

            this.ViewModelLiquidStateRawPetroleum = new ViewModelLiquidContainerState(
                liquidStateRawPetroleum,
                liquidConfigRawPetroleum);

            this.ViewModelLiquidStateProcessedGasoline = new ViewModelLiquidContainerState(
                liquidStateProcessedGasoline,
                liquidConfigProcessedGasoline);

            this.ViewModelLiquidStateProcessedMineralOil = new ViewModelLiquidContainerState(
                liquidStateProcessedMineralOil,
                liquidConfigProcessedMineralOil);

            // prepare active state property
            var manufacturerPublicState = worldObject.GetPublicState <ObjectManufacturerPublicState>();

            manufacturerPublicState.ClientSubscribe(_ => _.IsManufacturingActive,
                                                    _ => RefreshIsManufacturerActive(),
                                                    this);
            RefreshIsManufacturerActive();

            void RefreshIsManufacturerActive()
            {
                this.IsManufacturerActive = manufacturerPublicState.IsManufacturingActive;
            }
        }
        public ViewModelWindowManufacturer(
            IStaticWorldObject worldObjectManufacturer,
            ObjectManufacturerPrivateState privateState,
            ManufacturingConfig manufacturingConfig)
        {
            this.WorldObjectManufacturer = worldObjectManufacturer;
            var fuelBurningState   = privateState.FuelBurningState;
            var manufacturingState = privateState.ManufacturingState;

            // please note - the order of creating these view models is important for the proper container exchange order
            this.ViewModelFuelBurningState = fuelBurningState != null
                ? new ViewModelFuelBurningState(fuelBurningState)
                : null;

            this.ViewModelManufacturingState = new ViewModelManufacturingState(
                worldObjectManufacturer,
                manufacturingState,
                manufacturingConfig);

            this.ViewModelBurningFuel = ViewModelBurningFuel.Create(worldObjectManufacturer, fuelBurningState);

            this.ViewModelManufacturingState.SubscribePropertyChange(
                _ => _.SelectedRecipe,
                this.RefreshIsNeedFuel);

            this.ViewModelManufacturingState.SubscribePropertyChange(
                _ => _.IsInputMatchSelectedRecipe,
                this.RefreshIsNeedFuel);

            this.ViewModelBurningFuel?.SubscribePropertyChange(
                _ => _.IsActive,
                this.RefreshIsNeedFuel);

            this.ViewModelFuelBurningState?.SubscribePropertyChange(
                _ => _.FuelUsageCurrentValue,
                this.RefreshIsNeedFuel);

            this.ViewModelManufacturingState.ContainerInput.StateHashChanged += this.ContainerInputStateChanged;

            this.RefreshIsNeedFuel();

            this.publicState = worldObjectManufacturer.GetPublicState <ObjectManufacturerPublicState>();
            this.publicState.ClientSubscribe(_ => _.IsActive,
                                             _ => this.NotifyPropertyChanged(nameof(this.IsManufacturingActive)),
                                             this);

            var insertIfInputEmpty = worldObjectManufacturer.ProtoStaticWorldObject switch
            {
                ProtoObjectWell _ => true,
                ProtoObjectOilPump _ => true,
                ObjectGeneratorEngine _ => true,
                _ => false
            };

            viewModelManufacturerExchange = new ViewModelManufacturerExchange(
                privateState.ManufacturingState.ContainerOutput,
                new List <IItemsContainer> {
                privateState.ManufacturingState.ContainerInput
            },
                insertIfInputEmpty);
        }
Exemple #23
0
        public ViewModelManufacturingState(
            IStaticWorldObject worldObjectManufacturer,
            ManufacturingState manufacturingState,
            ManufacturingConfig manufacturingConfig)
        {
            this.worldObjectManufacturer = worldObjectManufacturer;
            this.ManufacturingState      = manufacturingState;
            this.ManufacturingConfig     = manufacturingConfig;

            this.ContainerInput  = (IClientItemsContainer)manufacturingState.ContainerInput;
            this.ContainerOutput = (IClientItemsContainer)manufacturingState.ContainerOutput;

            this.CommandBrowseRecipes           = new ActionCommand(this.ExecuteCommandBrowseRecipes);
            this.CommandCloseRecipesBrowser     = new ActionCommand(this.CloseRecipesBrowser);
            this.CommandSelectRecipeFromBrowser =
                new ActionCommandWithParameter(this.ExecuteCommandSelectRecipeFromBrowser);
            this.CommandApplyBestMatchingRecipe = new ActionCommand(this.ExecuteCommandApplyBestMatchingRecipe);

            this.VisibilityRecipesSelection = manufacturingConfig.IsAutoSelectRecipe
                                                  ? Visibility.Collapsed
                                                  : Visibility.Visible;

            this.SelectedRecipe = manufacturingState.SelectedRecipe;
            //this.BestMatchingRecipe = manufacturingState.BestMatchingRecipe;

            this.RefreshCraftingProgressPercents();

            this.ManufacturingState.ClientSubscribe(
                _ => _.SelectedRecipe,
                recipe => this.SelectedRecipe = recipe,
                this);

            //this.ManufacturingState.ClientSubscribe(
            //    _ => _.BestMatchingRecipe,
            //    recipe => this.BestMatchingRecipe = recipe,
            //    this);

            this.ManufacturingState.CraftingQueue.ClientSubscribe(
                _ => _.IsContainerOutputFull,
                _ => this.NotifyPropertyChanged(nameof(this.IsContainerOutputFull)),
                this);

            this.craftingQueue = this.ManufacturingState.CraftingQueue.QueueItems;
            this.craftingQueue.ClientAnyModification
                += this.CraftingQueueAnyModificationHandler;

            this.ManufacturingState.CraftingQueue.ClientSubscribe(
                _ => _.TimeRemainsToComplete,
                time => this.RefreshCraftingProgressPercents(),
                this);

            // register containers exchange
            var character = Client.Characters.CurrentPlayerCharacter;

            ClientContainersExchangeManager.Register(
                this,
                this.ManufacturingState.ContainerOutput,
                allowedTargets: new[]
            {
                character.SharedGetPlayerContainerInventory(),
                character.SharedGetPlayerContainerHotbar()
            });

            ClientContainersExchangeManager.Register(
                this,
                this.ManufacturingState.ContainerInput,
                allowedTargets: new[]
            {
                character.SharedGetPlayerContainerInventory(),
                character.SharedGetPlayerContainerHotbar()
            });

            this.ContainerInput.StateHashChanged += this.ContainerInputStateChangedHandler;

            this.RefreshIsInputMatchSelectedRecipe();
            this.RefreshBestMatchingRecipe();
        }