public static OutputConfig ProduceOutput(ProducerRule producerRule, Object producer, Func <int, int, bool> fuelSearch, Farmer who, GameLocation location , ProducerConfig producerConfig = null, Object input = null , bool probe = false, bool noSoundAndAnimation = false) { if (who == null) { who = Game1.getFarmer((long)producer.owner); } Vector2 tileLocation = producer.TileLocation; Random random = ProducerRuleController.GetRandomForProducing(tileLocation); OutputConfig outputConfig = OutputConfigController.ChooseOutput(producerRule.OutputConfigs, random, fuelSearch, location, input); if (outputConfig != null) { Object output = OutputConfigController.CreateOutput(outputConfig, input, random); producer.heldObject.Value = output; if (!probe) { OutputConfigController.LoadOutputName(outputConfig, producer.heldObject.Value, input, who); if (!noSoundAndAnimation) { SoundUtil.PlaySound(producerRule.Sounds, location); SoundUtil.PlayDelayedSound(producerRule.DelayedSounds, location); } producer.minutesUntilReady.Value = outputConfig.MinutesUntilReady ?? producerRule.MinutesUntilReady; if (producerRule.SubtractTimeOfDay) { producer.minutesUntilReady.Value = Math.Max(producer.minutesUntilReady.Value - Game1.timeOfDay, 1); } if (producerConfig != null) { producer.showNextIndex.Value = producerConfig.AlternateFrameProducing; } if (producerRule.PlacingAnimation.HasValue && !noSoundAndAnimation) { AnimationController.DisplayAnimation(producerRule.PlacingAnimation.Value, producerRule.PlacingAnimationColor, location, tileLocation, new Vector2(producerRule.PlacingAnimationOffsetX, producerRule.PlacingAnimationOffsetY)); } producer.initializeLightSource(tileLocation, false); producerRule.IncrementStatsOnInput.ForEach(s => StatsController.IncrementStardewStats(s, producerRule.InputStack)); } } return(outputConfig); }
internal static bool checkForActionPrefix(Object __instance, Farmer who, bool justCheckingForActivity, ref bool __result) { if (__instance.isTemporarilyInvisible || !__instance.readyForHarvest.Value || justCheckingForActivity) { return(true); } if (ProducerController.GetProducerConfig(__instance.Name) is ProducerConfig producerConfig) { if (producerConfig.NoInputStartMode != null || producerConfig.IncrementStatsOnOutput.Count > 0) { Object previousObject = __instance.heldObject.Value; if (who.isMoving()) { Game1.haltAfterCheck = false; } __instance.heldObject.Value = (Object)null; if (who.IsLocalPlayer) { if (!who.addItemToInventoryBool((Item)previousObject, false)) { __instance.heldObject.Value = previousObject; Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:Crop.cs.588")); return(__result = false); } Game1.playSound("coin"); foreach (KeyValuePair <StardewStats, string> keyValuePair in producerConfig.IncrementStatsOnOutput) { if (keyValuePair.Value == null || keyValuePair.Value == previousObject.Name || keyValuePair.Value == previousObject.ParentSheetIndex.ToString() || keyValuePair.Value == previousObject.Category.ToString() || previousObject.HasContextTag(keyValuePair.Value)) { StatsController.IncrementStardewStats(keyValuePair.Key, previousObject.Stack); if (!producerConfig.MultipleStatsIncrement) { break; } } } } __instance.readyForHarvest.Value = false; __instance.showNextIndex.Value = false; __result = true; if (producerConfig.NoInputStartMode == NoInputStartMode.Placement) { if (ProducerController.GetProducerItem(__instance.Name, null) is ProducerRule producerRule) { try { if (!producerConfig.CheckLocationCondition(who.currentLocation)) { throw new RestrictionException(DataLoader.Helper.Translation.Get("Message.Condition.Location")); } else if (producerConfig.CheckSeasonCondition()) { __result = ProducerRuleController.ProduceOutput(producerRule, __instance, (i, q) => who.hasItemInInventory(i, q), who, who.currentLocation, producerConfig) != null; } } catch (RestrictionException e) { __result = false; if (e.Message != null && who.IsLocalPlayer) { Game1.showRedMessage(e.Message); } } } } return(false); } } return(true); }
internal static bool PerformObjectDropInAction(Object __instance, Item dropInItem, bool probe, Farmer who, ref bool __result) { if (__instance.isTemporarilyInvisible || !(dropInItem is Object)) { return(false); } Object input = (Object)dropInItem; if (ProducerController.GetProducerItem(__instance.name, input) is ProducerRule producerRule) { if (__instance.heldObject.Value != null && !__instance.name.Equals("Crystalarium") || (bool)((NetFieldBase <bool, NetBool>)input.bigCraftable)) { return(true); } if (ProducerRuleController.IsInputExcluded(producerRule, input)) { return(true); } if ((bool)((NetFieldBase <bool, NetBool>)__instance.bigCraftable) && !probe && (__instance.heldObject.Value == null)) { __instance.scale.X = 5f; } bool shouldDisplayMessages = !probe && who.IsLocalPlayer; if (ProducerRuleController.IsInputStackLessThanRequired(producerRule, input, shouldDisplayMessages)) { return(false); } if (ProducerRuleController.IsAnyFuelStackLessThanRequired(producerRule, who, shouldDisplayMessages)) { return(false); } Vector2 tileLocation = __instance.tileLocation.Value; Random random = ProducerRuleController.GetRandomForProducing(tileLocation); OutputConfig outputConfig = OutputConfigController.ChooseOutput(producerRule.OutputConfigs, random); Object output = OutputConfigController.CreateOutput(outputConfig, input, random); __instance.heldObject.Value = output; if (!probe) { OutputConfigController.LoadOutputName(outputConfig, __instance.heldObject.Value, input, who); GameLocation currentLocation = who.currentLocation; PlaySound(producerRule.Sounds, currentLocation); PlayDelayedSound(producerRule.DelayedSounds, currentLocation); __instance.minutesUntilReady.Value = producerRule.MinutesUntilReady; if (ProducerController.GetProducerConfig(__instance.Name) is ProducerConfig producerConfig) { __instance.showNextIndex.Value = producerConfig.AlternateFrameProducing; } if (producerRule.PlacingAnimation.HasValue) { AnimationController.DisplayAnimation(producerRule.PlacingAnimation.Value, producerRule.PlacingAnimationColor, currentLocation, tileLocation, new Vector2(producerRule.PlacingAnimationOffsetX, producerRule.PlacingAnimationOffsetY)); } __instance.initializeLightSource(tileLocation, false); foreach (var fuel in producerRule.FuelList) { RemoveItemsFromInventory(who, fuel.Item1, fuel.Item2); } producerRule.IncrementStatsOnInput.ForEach(s => StatsController.IncrementStardewStats(s, producerRule.InputStack)); input.Stack -= producerRule.InputStack; __result = input.Stack <= 0; } else { __result = true; } return(false); } return(true); }