internal void Reset(Item item)
 {
     ProducerRuleController.ClearProduction(_machine, Location);
     if (ProducerController.GetProducerConfig(_machine.Name) is ProducerConfig producerConfig)
     {
         if (producerConfig.NoInputStartMode != null || producerConfig.IncrementStatsOnOutput.Count > 0)
         {
             producerConfig.IncrementStats(item);
             if (producerConfig.NoInputStartMode == NoInputStartMode.Placement)
             {
                 if (ProducerController.GetProducerItem(_machine.Name, null) is ProducerRule producerRule)
                 {
                     try
                     {
                         if (producerConfig.CheckLocationCondition(Location) && producerConfig.CheckSeasonCondition())
                         {
                             ProducerRuleController.ProduceOutput(producerRule, _machine, (i, q) => true, null, Location, producerConfig);
                         }
                     }
                     catch (RestrictionException) { /*No action needed*/ }
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        public bool SetInput(IStorage input)
        {
            foreach (ITrackedStack trackedStack in input.GetItems())
            {
                if (trackedStack.Sample is SObject objectInput &&
                    !objectInput.bigCraftable.Value &&
                    ProducerController.GetProducerItem(_machine.Name, objectInput) is ProducerRule producerRule &&
                    !ProducerRuleController.IsInputExcluded(producerRule, objectInput))
                {
                    ProducerConfig producerConfig = ProducerController.GetProducerConfig(_machine.Name);

                    if (producerConfig == null || (producerConfig.CheckLocationCondition(Location) && producerConfig.CheckSeasonCondition(Location)))
                    {
                        if (input.TryGetIngredient(objectInput.ParentSheetIndex, producerRule.InputStack,
                                                   out IConsumable inputConsumable))
                        {
                            objectInput = inputConsumable.Sample as SObject;
                            List <IConsumable> requiredFuels = GetRequiredFuels(producerRule, input);
                            if (requiredFuels != null)
                            {
                                try
                                {
                                    if (objectInput != null)
                                    {
                                        objectInput.Stack = inputConsumable.Consumables.Count;
                                    }
                                    OutputConfig outputConfig = ProducerRuleController.ProduceOutput(producerRule, _machine,
                                                                                                     (i, q) => input.TryGetIngredient(i, q, out IConsumable fuel), null, Location,
                                                                                                     producerConfig, objectInput, noSoundAndAnimation: true);
                                    if (outputConfig != null)
                                    {
                                        if (outputConfig.RequiredInputStack.HasValue)
                                        {
                                            inputConsumable.Consumables.Reduce(outputConfig.RequiredInputStack.Value);
                                        }
                                        else
                                        {
                                            inputConsumable.Reduce();
                                        }
                                        requiredFuels.ForEach(f => f.Reduce());
                                        List <IConsumable> outputRequiredFuels = GetRequiredFuels(outputConfig, input);
                                        outputRequiredFuels.ForEach(f => f.Reduce());
                                        return(true);
                                    }
                                }
                                catch (RestrictionException) { /* No action needed */ }
                            }
                        }
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adapted from https://github.com/Digus/StardewValleyMods/blob/master/PFMAutomate/Automate/CustomProducerMachine.cs
        /// </summary>
        /// <param name="item"></param>
        internal void Reset(Item item)
        {
            PFMCompatability.ClearProduction(Machine, Location);
            MassProductionMachineDefinition mpm = null;
            ProducerConfig producerConfig;

            if (IsMassProducer)
            {
                mpm            = ModEntry.GetMPMMachine(Machine.name, Machine.GetMassProducerKey());
                producerConfig = ProducerController.GetProducerConfig(mpm.BaseProducerName);
            }
            else
            {
                producerConfig = ProducerController.GetProducerConfig(Machine.name);
            }

            if (producerConfig == null)
            {
                return;
            }
            else if (producerConfig.NoInputStartMode != null || producerConfig.IncrementStatsOnOutput.Count > 0)
            {
                producerConfig.IncrementStats(item);
                if (producerConfig.NoInputStartMode == NoInputStartMode.Placement)
                {
                    if (ProducerController.GetProducerItem(Machine.Name, null) is ProducerRule producerRule)
                    {
                        try
                        {
                            if (producerConfig.CheckLocationCondition(Location) && producerConfig.CheckSeasonCondition())
                            {
                                if (mpm != null)
                                {
                                    PFMCompatability.ProduceOutput(producerRule, mpm.Settings, Machine, (i, q) => true, null, Location, producerConfig);
                                }
                                else
                                {
                                    ProducerRuleController.ProduceOutput(producerRule, Machine, (i, q) => true, null, Location, producerConfig);
                                }
                            }
                        }
                        catch (RestrictionException) { /*No action needed*/ }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adapted from https://github.com/Digus/StardewValleyMods/blob/master/PFMAutomate/Automate/CustomProducerMachine.cs
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public bool SetInput(IStorage input)
        {
            if (IsMassProducer)
            {
                MassProductionMachineDefinition mpm = ModEntry.GetMPMMachine(Machine.name, Machine.GetMassProducerKey());

                foreach (ITrackedStack trackedStack in input.GetItems())
                {
                    if (trackedStack.Sample is SObject objectInput && !objectInput.bigCraftable.Value &&
                        ProducerController.GetProducerItem(Machine.Name, objectInput) is ProducerRule producerRule &&
                        !PFMCompatability.IsInputExcluded(producerRule, mpm, objectInput))
                    {
                        ProducerConfig producerConfig = mpm.GetBaseProducerConfig();

                        if (producerConfig == null || (producerConfig.CheckLocationCondition(Location) && producerConfig.CheckSeasonCondition()))
                        {
                            List <InputInfo> inputsRequired = InputInfo.ConvertPFMInputs(producerRule, objectInput);

                            if (inputsRequired.Count > 0 &&
                                input.TryGetIngredient(objectInput.ParentSheetIndex, mpm.Settings.CalculateInputRequired(inputsRequired.First()), out IConsumable inputConsumable))
                            {
                                objectInput = inputConsumable.Sample as SObject;
                                List <IConsumable> requiredFuels = GetRequiredFuels(inputsRequired, mpm.Settings, input);

                                if (requiredFuels != null)
                                {
                                    try
                                    {
                                        Dictionary <int, int> fuelQuantities = new Dictionary <int, int>();

                                        foreach (InputInfo inputInfo in inputsRequired)
                                        {
                                            if (inputInfo.IsFuel)
                                            {
                                                fuelQuantities.Add(inputInfo.ID, mpm.Settings.CalculateInputRequired(inputInfo));
                                            }
                                        }

                                        Func <int, int, bool> fuelSearch   = (i, q) => input.TryGetIngredient(i, fuelQuantities[i], out IConsumable fuel);
                                        OutputConfig          outputConfig = PFMCompatability.ProduceOutput(producerRule, mpm.Settings, Machine, fuelSearch, null, Location, producerConfig,
                                                                                                            objectInput, inputQuantity: mpm.Settings.CalculateInputRequired(inputsRequired.First()), noSoundAndAnimation: true,
                                                                                                            inputInfo: inputsRequired);

                                        if (outputConfig != null)
                                        {
                                            inputConsumable.Take();
                                            requiredFuels.ForEach(f => f.Reduce());
                                            List <IConsumable> outputRequiredFuels = GetRequiredFuels(InputInfo.ConvertPFMInputs(outputConfig), mpm.Settings, input);
                                            outputRequiredFuels.ForEach(f => f.Reduce());
                                            return(true);
                                        }
                                    }
                                    catch (RestrictionException) { /* No action needed */ }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (ITrackedStack trackedStack in input.GetItems())
                {
                    if (trackedStack.Sample is SObject objectInput && !objectInput.bigCraftable.Value &&
                        ProducerController.GetProducerItem(Machine.Name, objectInput) is ProducerRule producerRule &&
                        !ProducerRuleController.IsInputExcluded(producerRule, objectInput))
                    {
                        ProducerConfig producerConfig = ProducerController.GetProducerConfig(Machine.name);

                        if (producerConfig == null || (producerConfig.CheckLocationCondition(Location) && producerConfig.CheckSeasonCondition()))
                        {
                            if (input.TryGetIngredient(objectInput.ParentSheetIndex, producerRule.InputStack, out IConsumable inputConsumable))
                            {
                                objectInput = inputConsumable.Sample as SObject;
                                List <IConsumable> requiredFuels = GetRequiredFuels(InputInfo.ConvertPFMInputs(producerRule, objectInput), null, input);

                                if (requiredFuels != null)
                                {
                                    try
                                    {
                                        Func <int, int, bool> fuelSearch   = (i, q) => input.TryGetIngredient(i, q, out IConsumable fuel);
                                        OutputConfig          outputConfig = ProducerRuleController.ProduceOutput(producerRule, Machine, fuelSearch, null, Location, producerConfig,
                                                                                                                  objectInput, noSoundAndAnimation: true);

                                        if (outputConfig != null)
                                        {
                                            inputConsumable.Take();
                                            requiredFuels.ForEach(f => f.Reduce());
                                            List <IConsumable> outputRequiredFuels = GetRequiredFuels(InputInfo.ConvertPFMInputs(outputConfig), null, input);
                                            outputRequiredFuels.ForEach(f => f.Reduce());
                                            return(true);
                                        }
                                    }
                                    catch (RestrictionException) { /* No action needed */ }
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }