Beispiel #1
0
        protected override void ServerInitialize(ServerInitializeData data)
        {
            base.ServerInitialize(data);
            var privateState = data.PrivateState;

            // create liquid states
            privateState.LiquidStateGasoline ??= new LiquidContainerState();
            privateState.LiquidStateMineralOil ??= new LiquidContainerState();

            // setup manufacturing state for gasoline
            var manufacturingStateProcessedGasoline = privateState.ManufacturingStateGasoline;

            if (manufacturingStateProcessedGasoline is null)
            {
                privateState.ManufacturingStateGasoline
                      = manufacturingStateProcessedGasoline
                      = new ManufacturingState(
                            data.GameObject,
                            containerInputSlotsCount: 1,
                            containerOutputSlotsCount: 1);
            }
            else
            {
                manufacturingStateProcessedGasoline.SetSlotsCount(input: 1, output: 1);
            }

            // setup input container types
            var itemsService = Server.Items;

            itemsService.SetContainerType <ItemsContainerLiquidMineralOil>(
                privateState.ManufacturingState.ContainerInput);

            itemsService.SetContainerType <ItemsContainerEmptyCanisters>(
                manufacturingStateProcessedGasoline.ContainerInput);
        }
Beispiel #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();
        }
Beispiel #3
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);
            }
        }
Beispiel #4
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);
            }
        }
        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);
        }
        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 ViewModelWindowWell(
     IStaticWorldObject worldObjectManufacturer,
     ManufacturingState manufacturingState,
     ManufacturingConfig manufacturingConfig,
     LiquidContainerState liquidContainerState,
     LiquidContainerConfig liquidContainerConfig)
     : base(
         worldObjectManufacturer,
         manufacturingState,
         manufacturingConfig: manufacturingConfig,
         fuelBurningState: null)
 {
     this.CommandDrink = new ActionCommand(this.ExecuteCommandDrink);
     this.ViewModelLiquidContainerState = new ViewModelLiquidContainerState(
         liquidContainerState,
         liquidContainerConfig);
 }
Beispiel #8
0
        public ViewModelWindowLithiumOreExtractor(
            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 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();
        }
        protected override void ServerInitialize(ServerInitializeData data)
        {
            base.ServerInitialize(data);

            var worldObject  = data.GameObject;
            var privateState = data.PrivateState;

            privateState.SetWaterAmount(privateState.WaterAmount,
                                        this.WaterCapacity,
                                        data.PublicState);

            // configure manufacturing state
            var manufacturingState = privateState.ManufacturingState;
            {
                var inputSlotsCount  = this.ContainerInputSlotsCount;
                var outputSlotsCount = this.ContainerOutputSlotsCount;

                if (manufacturingState is null)
                {
                    manufacturingState = new ManufacturingState(
                        worldObject,
                        containerInputSlotsCount: inputSlotsCount,
                        containerOutputSlotsCount: outputSlotsCount);
                    privateState.ManufacturingState = manufacturingState;
                }
                else
                {
                    manufacturingState.SetSlotsCount(
                        input: inputSlotsCount,
                        output: outputSlotsCount);
                }

                Server.Items.SetContainerType <ItemsContainerWaterBottles>(
                    manufacturingState.ContainerInput);
                Server.Items.SetContainerType <ItemsContainerOutput>(
                    manufacturingState.ContainerOutput);
            }
        }
Beispiel #11
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();
        }
Beispiel #12
0
        protected override void ServerInitialize(ServerInitializeData data)
        {
            base.ServerInitialize(data);

            var worldObject  = data.GameObject;
            var privateState = data.PrivateState;

            // configure manufacturing state
            var manufacturingState = privateState.ManufacturingState;
            {
                var inputSlotsCount  = this.ServerGetInputSlotsCount(worldObject);
                var outputSlotsCount = this.ServerGetOutputSlotsCount(worldObject);

                if (manufacturingState is null)
                {
                    manufacturingState = new ManufacturingState(
                        worldObject,
                        containerInputSlotsCount: inputSlotsCount,
                        containerOutputSlotsCount: outputSlotsCount);
                    privateState.ManufacturingState = manufacturingState;
                }
                else
                {
                    manufacturingState.SetSlotsCount(
                        input: inputSlotsCount,
                        output: outputSlotsCount);
                }

                Server.Items.SetContainerType <ItemsContainerOutput>(
                    manufacturingState.ContainerOutput);
            }

            // configure fuel burning state
            var fuelBurningState = privateState.FuelBurningState;

            {
                if (fuelBurningState is null)
                {
                    if (this.ContainerFuelSlotsCount > 0)
                    {
                        fuelBurningState = new FuelBurningState(worldObject, this.ContainerFuelSlotsCount);
                        privateState.FuelBurningState = fuelBurningState;
                    }
                }
                else if (this.ContainerFuelSlotsCount > 0)
                {
                    fuelBurningState.SetSlotsCount(this.ContainerFuelSlotsCount);
                }
                else
                {
                    // destroy fuel burning state
                    privateState.FuelBurningState = fuelBurningState = null;
                }

                if (fuelBurningState is not null)
                {
                    Server.Items.SetContainerType <ItemsContainerFuelSolid>(
                        fuelBurningState.ContainerFuel);
                }
            }

            if (this.ManufacturingConfig.IsProduceByproducts)
            {
                if (fuelBurningState is null)
                {
                    throw new Exception(
                              $"No fuel container - please set {nameof(this.ContainerFuelSlotsCount)} higher than zero?");
                }

                privateState.FuelBurningByproductsQueue ??= new CraftingQueue(
                    fuelBurningState.ContainerFuel,
                    manufacturingState.ContainerOutput);
            }
            else
            {
                privateState.FuelBurningByproductsQueue = null;
            }
        }
Beispiel #13
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();
        }
Beispiel #14
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;
            }
        }