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*/ } } } } } }
[HarmonyPriority(801)] //Just before ProducerFrameworkMod. Can't use HarmonyBefore attribute, that wasn't working for some reason internal static bool performDropDownAction_Prefix(SObject __instance, Farmer who, bool __result) { if (string.IsNullOrEmpty(__instance.GetMassProducerKey())) { return(true); } MassProductionMachineDefinition mpm = ModEntry.GetMPMMachine(__instance.name, __instance.GetMassProducerKey()); if (mpm == null) { return(true); } if (ProducerController.GetProducerConfig(__instance.Name) is ProducerConfig producerConfig) { try { if (!producerConfig.CheckLocationCondition(who.currentLocation)) { throw new RestrictionException(ModEntry.Instance.Helper.Translation.Get("Message.Condition.Location")); } if (producerConfig.NoInputStartMode != null) { if (producerConfig.CheckSeasonCondition() && NoInputStartMode.Placement == producerConfig.NoInputStartMode) { if (ProducerController.GetProducerItem(__instance.Name, null) is ProducerRule producerRule) { PFMCompatability.ProduceOutput(producerRule, mpm.Settings, __instance, (i, q) => who.hasItemInInventory(i, q), who, who.currentLocation, producerConfig); } } return(__result = false); } } catch (RestrictionException e) { if (e.Message != null && who.IsLocalPlayer) { Game1.showRedMessage(e.Message); } return(__result = false); } } else if (StaticValues.SUPPORTED_VANILLA_MACHINES.ContainsKey(__instance.name) && StaticValues.SUPPORTED_VANILLA_MACHINES[__instance.name] == InputRequirement.NoInputsOnly) { IVanillaOverride vanillaOverride = VanillaOverrideList.GetFor(__instance.name); if (vanillaOverride != null && vanillaOverride.Manual_PerformDropDownAction(__instance, mpm)) { return(true); } } return(true); }
[HarmonyPriority(Priority.First + 1)] //Just before ProducerFrameworkMod. Can't use HarmonyBefore attribute, that wasn't working for some reason public static bool DayUpdate_Prefix(SObject __instance, GameLocation location) { if (__instance == null || string.IsNullOrEmpty(__instance.GetMassProducerKey())) { return(true); } MassProductionMachineDefinition mpm = ModEntry.GetMPMMachine(__instance.name, __instance.GetMassProducerKey()); if (mpm == null) { return(true); } if (__instance.bigCraftable.Value) { if (ProducerController.GetProducerConfig(__instance.Name) is ProducerConfig producerConfig) { if (producerConfig != null) { if (ProducerController.GetProducerItem(__instance.Name, null) is ProducerRule producerRule) { if (!producerConfig.CheckSeasonCondition() || !producerConfig.CheckLocationCondition(location)) { ProducerRuleController.ClearProduction(__instance, location); return(false); } else if (producerConfig.NoInputStartMode != null) { if (producerConfig.NoInputStartMode == NoInputStartMode.DayUpdate || producerConfig.NoInputStartMode == NoInputStartMode.Placement) { if (__instance.heldObject.Value == null) { try { Farmer who = Game1.getFarmer((long)__instance.owner); PFMCompatability.ProduceOutput(producerRule, mpm.Settings, __instance, (i, q) => who.hasItemInInventory(i, q), who, who.currentLocation, producerConfig); } catch (RestrictionException) { //Does not show the restriction error since the machine is auto-starting. } } } return(false); } } } } } return(true); }
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); }
/// <summary> /// Defines all mass production machines. /// </summary> /// <param name="settings">Specifies the kinds of machines being set up.</param> /// <returns>All mass production machine definitions.</returns> public static List <MassProductionMachineDefinition> Setup(Dictionary <string, MPMSettings> settings) { List <MassProductionMachineDefinition> mpms = new List <MassProductionMachineDefinition>(); //PFM integration List <ProducerRule> allProducerRules = ProducerController.GetProducerRules(); List <string> baseProducers = new List <string>(); foreach (ProducerRule rule in allProducerRules) { if (ProducerController.GetProducerConfig(rule.ProducerName) != null && !baseProducers.Contains(rule.ProducerName)) { baseProducers.Add(rule.ProducerName); } } foreach (string baseProducerName in baseProducers) { ProducerConfig config = ProducerController.GetProducerConfig(baseProducerName); foreach (MPMSettings setting in settings.Values) { if (config == null || (config.NoInputStartMode.HasValue && setting.InputRequirementEnum == InputRequirement.InputRequired) || (!config.NoInputStartMode.HasValue && setting.InputRequirementEnum == InputRequirement.NoInputsOnly)) { continue; } mpms.Add(new MassProductionMachineDefinition(baseProducerName, setting)); } } //Other vanilla machines foreach (string vanillaMachineName in StaticValues.SUPPORTED_VANILLA_MACHINES.Keys) { if (!baseProducers.Contains(vanillaMachineName)) { InputRequirement inputRequirement = StaticValues.SUPPORTED_VANILLA_MACHINES[vanillaMachineName]; foreach (MPMSettings setting in settings.Values) { if (setting.InputRequirementEnum == inputRequirement || setting.InputRequirementEnum == InputRequirement.NoRequirements) { mpms.Add(new MassProductionMachineDefinition(vanillaMachineName, setting)); } } } } return(mpms); }
/// <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*/ } } } } }
/// <summary> /// Gets the current configuration of the machine. /// </summary> /// <param name="mpm"></param> /// <returns></returns> private ProducerConfig GetCurrentConfig(out MassProductionMachineDefinition mpm) { mpm = null; ProducerConfig producerConfig; if (IsMassProducer) { mpm = ModEntry.GetMPMMachine(Machine.name, Machine.GetMassProducerKey()); producerConfig = ProducerController.GetProducerConfig(mpm.BaseProducerName); } else { producerConfig = ProducerController.GetProducerConfig(Machine.name); } return(producerConfig); }
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)) { if (input.TryGetIngredient(objectInput.ParentSheetIndex, producerRule.InputStack, out IConsumable inputConsumable)) { objectInput = inputConsumable.Sample as SObject; List <IConsumable> requiredFuels = GetRequiredFuels(producerRule, input); if (requiredFuels != null) { Random random = ProducerRuleController.GetRandomForProducing(_machine.TileLocation); OutputConfig outputConfig = OutputConfigController.ChooseOutput(producerRule.OutputConfigs, random); SObject output = OutputConfigController.CreateOutput(outputConfig, objectInput, random); _machine.heldObject.Value = output; OutputConfigController.LoadOutputName(outputConfig, output, objectInput); _machine.MinutesUntilReady = producerRule.MinutesUntilReady; if (ProducerController.GetProducerConfig(_machine.Name) is ProducerConfig producerConfig) { _machine.showNextIndex.Value = producerConfig.AlternateFrameProducing; } _machine.initializeLightSource(_machine.TileLocation, false); producerRule.IncrementStatsOnInput.ForEach(s => StatsController.IncrementStardewStats(s, producerRule.InputStack)); inputConsumable.Take(); requiredFuels.ForEach(f => f.Reduce()); return(true); } } } } return(false); }
public MachineState GetState() { if (_machine.heldObject.Value != null && _machine.minutesUntilReady <= 0 && _machine.readyForHarvest.Value) { return(MachineState.Done); } if (ProducerController.GetProducerConfig(_machine.Name) is ProducerConfig producerConfig) { if (!producerConfig.CheckWeatherCondition() || !producerConfig.CheckSeasonCondition() || !producerConfig.CheckLocationCondition(Location) || !producerConfig.CheckCurrentTimeCondition()) { return(MachineState.Disabled); } if (producerConfig.NoInputStartMode != null) { //A no input machine is considered processing even while empty. return(MachineState.Processing); } } if (_machine.heldObject.Value == null) { return(MachineState.Empty); } return(MachineState.Processing); }
/// <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); }
public static void GetFor(ref object __result, SObject obj) { string machineFullName = __result?.GetType().FullName; if (SupportedVanillaMachines.Contains(machineFullName) && (ProducerController.HasProducerRule(obj.Name) || ProducerController.GetProducerConfig(obj.Name) != null)) { __result = new VanillaProducerMachine((IMachine)__result); } }
public static void GetFor(ref object __result, Object obj) { string machineFullName = __result?.GetType().FullName; if (machineFullName == "CCRMAutomate.Automate.ClonerMachine" && (ProducerController.HasProducerRule(obj.Name) || ProducerController.GetProducerConfig(obj.Name) != null)) { __result = new CustomClonerMachine((IMachine)__result); } }
/// <summary> /// Overrides the base Automate machine factory's return value with one from this mod if that machine needs special support to /// make use of the mass production upgrades. Also replicated PFMAutomate's functionality. /// </summary> /// <param name="__result"></param> /// <param name="obj"></param> public static void GetFor(ref object __result, SObject obj) { if (__result != null && __result is IMachine machine) { string machineFullName = __result.GetType().FullName; if (VanillaOverrides.VanillaOverrideList.AUTOMATE_OVERRIDES.ContainsKey(machineFullName) || PFM_SUPPORTED_VANILLA_MACHINES.Contains(machineFullName) && (ProducerController.HasProducerRule(obj.Name) || ProducerController.GetProducerConfig(obj.Name) != null)) { __result = new VanillaAutomatedOverride((IMachine)__result); } } }
/// <summary> /// Gets the PFM config for the base machine. /// </summary> /// <returns></returns> public ProducerConfig GetBaseProducerConfig() { return(ProducerController.GetProducerConfig(BaseProducerName)); }