Exemple #1
0
 internal static bool performDropDownAction(Object __instance, Farmer who, bool __result)
 {
     if (ProducerController.GetProducerConfig(__instance.Name) is ProducerConfig producerConfig)
     {
         if (producerConfig.NoInputStartMode != null)
         {
             try
             {
                 if (!producerConfig.CheckLocationCondition(who.currentLocation))
                 {
                     throw new RestrictionException(DataLoader.Helper.Translation.Get("Message.Condition.Location"));
                 }
                 else if (producerConfig.CheckSeasonCondition() && NoInputStartMode.Placement == producerConfig.NoInputStartMode)
                 {
                     if (ProducerController.GetProducerItem(__instance.Name, null) is ProducerRule producerRule)
                     {
                         ProducerRuleController.ProduceOutput(producerRule, __instance, (i, q) => who.hasItemInInventory(i, q), who, who.currentLocation, producerConfig);
                     }
                 }
             }
             catch (RestrictionException e)
             {
                 if (e.Message != null && who.IsLocalPlayer)
                 {
                     Game1.showRedMessage(e.Message);
                 }
             }
             return(__result = false);
         }
     }
     return(true);
 }
Exemple #2
0
 internal static void checkForActionPostfix(Object __instance, bool justCheckingForActivity, bool __result)
 {
     if (ProducerController.GetProducerConfig(__instance.Name) is ProducerConfig producerConfig && __instance.heldObject.Value == null && __instance.MinutesUntilReady <= 0)
     {
         __instance.showNextIndex.Value = false;
     }
 }
Exemple #3
0
 internal static void minutesElapsedPostfix(Object __instance)
 {
     if (ProducerController.GetProducerConfig(__instance.Name) is ProducerConfig producerConfig && __instance.heldObject.Value != null && __instance.MinutesUntilReady <= 0)
     {
         __instance.showNextIndex.Value = producerConfig.AlternateFrameWhenReady;
     }
 }
Exemple #4
0
 public static Vector2 getScale(Object __instance)
 {
     if (ProducerController.GetProducerConfig(__instance.Name) is ProducerConfig producerConfig && __instance.MinutesUntilReady > 0 && __instance.heldObject.Value != null)
     {
         if (producerConfig.DisableBouncingAnimationWhileWorking)
         {
             return(Vector2.Zero);
         }
         else if (!producerConfig.CheckLocationCondition(Game1.currentLocation))
         {
             return(Vector2.Zero);
         }
         else if (!producerConfig.CheckSeasonCondition())
         {
             return(Vector2.Zero);
         }
         else if (!producerConfig.CheckWeatherCondition())
         {
             return(Vector2.Zero);
         }
         else if (!producerConfig.CheckCurrentTimeCondition())
         {
             return(Vector2.Zero);
         }
     }
     return(__instance.getScale());
 }
Exemple #5
0
 public static void DrawAnimation(
     SpriteBatch spriteBatch,
     Texture2D texture,
     Rectangle destinationRectangle,
     Rectangle?sourceRectangle,
     Color color,
     float rotation,
     Vector2 origin,
     SpriteEffects effects,
     float layerDepth,
     Object producer)
 {
     if (ProducerController.GetProducerConfig(producer.Name) is ProducerConfig producerConfig)
     {
         if (producerConfig.ProducingAnimation is Animation producingAnimation && producer.minutesUntilReady > 0 && producingAnimation.RelativeFrameIndex.Any())
         {
             int frame = producingAnimation.RelativeFrameIndex[((Game1.ticks + GetLocationSeed(producer.TileLocation)) % (producingAnimation.RelativeFrameIndex.Count * producingAnimation.FrameInterval)) / producingAnimation.FrameInterval];
             spriteBatch.Draw(texture, destinationRectangle, new Rectangle?(Object.getSourceRectForBigCraftable(producer.ParentSheetIndex + frame)), color, rotation, origin, effects, layerDepth);
             return;
         }
         else if (producerConfig.ReadyAnimation is Animation readyAnimation && producer.readyForHarvest.Value && readyAnimation.RelativeFrameIndex.Any())
         {
             int frame = readyAnimation.RelativeFrameIndex[((Game1.ticks + GetLocationSeed(producer.TileLocation)) % (readyAnimation.RelativeFrameIndex.Count * readyAnimation.FrameInterval)) / readyAnimation.FrameInterval];
             spriteBatch.Draw(texture, destinationRectangle, new Rectangle?(Object.getSourceRectForBigCraftable(producer.ParentSheetIndex + frame)), color, rotation, origin, effects, layerDepth);
             return;
         }
     }
 public static void DrawAnimation(
     SpriteBatch spriteBatch,
     Texture2D texture,
     Rectangle destinationRectangle,
     Rectangle?sourceRectangle,
     Color color,
     float rotation,
     Vector2 origin,
     SpriteEffects effects,
     float layerDepth,
     Object producer)
 {
     if (producer.heldObject.Value != null && ProducerController.GetProducerConfig(producer.Name) is ProducerConfig producerConfig)
     {
         if (producerConfig.ProducingAnimation is Animation producingAnimation && producer.minutesUntilReady > 0 && producerConfig.CheckSeasonCondition(Game1.currentLocation) && producerConfig.CheckWeatherCondition() && producerConfig.CheckCurrentTimeCondition())
         {
             List <int> animationList;
             if (producingAnimation.AdditionalAnimationsId.ContainsKey(producer.heldObject.Value.ParentSheetIndex))
             {
                 animationList = producingAnimation.AdditionalAnimationsId[producer.heldObject.Value.ParentSheetIndex];
             }
             else if (producingAnimation.AdditionalAnimationsId.ContainsKey(producer.heldObject.Value.Category))
             {
                 animationList = producingAnimation.AdditionalAnimationsId[producer.heldObject.Value.Category];
             }
             else
             {
                 animationList = producingAnimation.RelativeFrameIndex;
             }
             if (animationList.Any())
             {
                 int frame = animationList[((Game1.ticks + GetLocationSeed(producer.TileLocation)) % (animationList.Count * producingAnimation.FrameInterval)) / producingAnimation.FrameInterval];
                 spriteBatch.Draw(texture, destinationRectangle, new Rectangle?(Object.getSourceRectForBigCraftable(producer.ParentSheetIndex + frame)), color, rotation, origin, effects, layerDepth);
                 return;
             }
         }
         else if (producerConfig.ReadyAnimation is Animation readyAnimation && producer.readyForHarvest.Value)
         {
             List <int> animationList;
             if (readyAnimation.AdditionalAnimationsId.ContainsKey(producer.heldObject.Value.ParentSheetIndex))
             {
                 animationList = readyAnimation.AdditionalAnimationsId[producer.heldObject.Value.ParentSheetIndex];
             }
             else if (readyAnimation.AdditionalAnimationsId.ContainsKey(producer.heldObject.Value.Category))
             {
                 animationList = readyAnimation.AdditionalAnimationsId[producer.heldObject.Value.Category];
             }
             else
             {
                 animationList = readyAnimation.RelativeFrameIndex;
             }
             if (animationList.Any())
             {
                 int frame = animationList[((Game1.ticks + GetLocationSeed(producer.TileLocation)) % (animationList.Count * readyAnimation.FrameInterval)) / readyAnimation.FrameInterval];
                 spriteBatch.Draw(texture, destinationRectangle, new Rectangle?(Object.getSourceRectForBigCraftable(producer.ParentSheetIndex + frame)), color, rotation, origin, effects, layerDepth);
                 return;
             }
         }
     }
Exemple #7
0
 internal static void minutesElapsedPostfix(Object __instance, bool __state)
 {
     if (ProducerController.GetProducerConfig(__instance.Name) is ProducerConfig producerConfig && __instance.heldObject.Value != null && __instance.MinutesUntilReady <= 0)
     {
         __instance.showNextIndex.Value = producerConfig.AlternateFrameWhenReady;
     }
     if (__state)
     {
         __instance.initializeLightSource(__instance.tileLocation);
     }
 }
        internal static bool minutesElapsedPrefix(Object __instance, ref int minutes, GameLocation environment, out bool __state)
        {
            __state = false;
            if (ProducerController.GetProducerConfig(__instance.Name) is ProducerConfig producerConfig)
            {
                if (!producerConfig.CheckWeatherCondition())
                {
                    return(false);
                }

                if (!producerConfig.CheckElapsedTimeCondition(ref minutes))
                {
                    return(false);
                }

                if (producerConfig.ProducerName == "Bee House" && producerConfig.WorkingOutdoors != true)
                {
                    if (Game1.IsMasterGame)
                    {
                        __instance.minutesUntilReady.Value -= minutes;
                    }
                    if (__instance.minutesUntilReady.Value <= 0)
                    {
                        if (!__instance.readyForHarvest.Value)
                        {
                            environment.playSound("dwop", NetAudio.SoundContext.Default);
                        }
                        __instance.readyForHarvest.Value   = true;
                        __instance.minutesUntilReady.Value = 0;
                        __instance.onReadyForHarvest(environment);
                        __instance.showNextIndex.Value = true;
                        if (__instance.lightSource != null)
                        {
                            environment.removeLightSource(__instance.lightSource.identifier.Value);
                            __instance.lightSource = (LightSource)null;
                        }
                    }
                    if (!__instance.readyForHarvest.Value && Game1.random.NextDouble() < 0.33)
                    {
                        __instance.addWorkingAnimation(environment);
                    }
                    return(false);
                }

                if (producerConfig.LightSource?.AlwaysOn == true && __instance.minutesUntilReady - minutes <= 0 && __instance.heldObject.Value != null && !__instance.readyForHarvest)
                {
                    __state = true;
                }
            }
            return(true);
        }
Exemple #9
0
 internal static bool initializeLightSource(Object __instance, Vector2 tileLocation)
 {
     if (__instance.bigCraftable.Value)
     {
         if (ProducerController.GetProducerConfig(__instance.Name) is ProducerConfig producerConfig && producerConfig.LightSource is ContentPack.LightSourceConfig lightSourceConfig)
         {
             if (__instance.minutesUntilReady > 0 || lightSourceConfig.AlwaysOn)
             {
                 LightSourceConfigController.CreateLightSource(__instance, tileLocation, lightSourceConfig);
             }
             return(false);
         }
     }
     return(true);
 }
Exemple #10
0
        internal static bool minutesElapsedPrefix(Object __instance, ref int minutes, GameLocation environment)
        {
            if (ProducerController.GetProducerConfig(__instance.Name) is ProducerConfig producerConfig)
            {
                if (!producerConfig.CheckWeatherCondition())
                {
                    return(false);
                }

                if (!producerConfig.CheckTimeCondition(ref minutes))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #11
0
        public static void ClearProduction(Object producer, GameLocation location)
        {
            producer.heldObject.Value        = (Object)null;
            producer.readyForHarvest.Value   = false;
            producer.showNextIndex.Value     = false;
            producer.minutesUntilReady.Value = -1;

            if (ProducerController.GetProducerConfig(producer.Name) is ProducerConfig producerConfig && producerConfig.LightSource?.AlwaysOn == true)
            {
                int identifier = LightSourceConfigController.GenerateIdentifier(producer.tileLocation);
                if (location.hasLightSource(identifier))
                {
                    location.removeLightSource(identifier);
                    producer.initializeLightSource(producer.tileLocation);
                }
            }
        }
Exemple #12
0
        internal static void checkForActionPostfix(Object __instance, Farmer who, bool justCheckingForActivity, bool __result, bool __state)
        {
            if (ProducerController.GetProducerConfig(__instance.Name) is ProducerConfig producerConfig && __instance.heldObject.Value == null)
            {
                if (__instance.MinutesUntilReady <= 0)
                {
                    __instance.showNextIndex.Value = false;
                }

                if (!__state && !justCheckingForActivity && __result && producerConfig.LightSource?.AlwaysOn == true)
                {
                    int identifier = LightSourceConfigController.GenerateIdentifier(__instance.tileLocation);
                    if (who.currentLocation.hasLightSource(identifier))
                    {
                        who.currentLocation.removeLightSource(identifier);
                        __instance.initializeLightSource(__instance.tileLocation);
                    }
                }
            }
        }
Exemple #13
0
        internal static bool minutesElapsedPrefix(Object __instance, ref int minutes, GameLocation environment, out bool __state)
        {
            __state = false;
            if (ProducerController.GetProducerConfig(__instance.Name) is ProducerConfig producerConfig)
            {
                if (!producerConfig.CheckWeatherCondition())
                {
                    return(false);
                }

                if (!producerConfig.CheckElapsedTimeCondition(ref minutes))
                {
                    return(false);
                }

                if (producerConfig.LightSource?.AlwaysOn == true && __instance.minutesUntilReady - minutes <= 0 && __instance.heldObject.Value != null && !__instance.readyForHarvest)
                {
                    __state = true;
                }
            }
            return(true);
        }
Exemple #14
0
 public static bool DayUpdate(Object __instance, GameLocation location)
 {
     if (__instance.bigCraftable.Value)
     {
         if (ProducerController.GetProducerConfig(__instance.Name) is ProducerConfig producerConfig)
         {
             if (ProducerController.GetProducerItem(__instance.Name, null) is ProducerRule producerRule)
             {
                 if (!producerConfig.CheckSeasonCondition() || !producerConfig.CheckLocationCondition(location))
                 {
                     ProducerRuleController.ClearProduction(__instance);
                     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);
                                 ProducerRuleController.ProduceOutput(producerRule, __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);
 }
Exemple #15
0
        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;

            bool failLocationCondition = false;
            bool failSeasonCondition   = false;

            if (__instance.heldObject.Value != null && !__instance.name.Equals("Crystalarium") || input.bigCraftable.Value)
            {
                return(true);
            }

            ProducerConfig producerConfig = ProducerController.GetProducerConfig(__instance.Name);

            GameLocation location = who.currentLocation;

            if (producerConfig != null)
            {
                if (!producerConfig.CheckLocationCondition(location))
                {
                    failLocationCondition = true;
                }
                if (!producerConfig.CheckSeasonCondition())
                {
                    failSeasonCondition = true;
                }
                if (producerConfig.NoInputStartMode != null)
                {
                    return(false);
                }
            }

            if (ProducerController.GetProducerItem(__instance.name, input) is ProducerRule producerRule)
            {
                if (ProducerRuleController.IsInputExcluded(producerRule, input))
                {
                    return(true);
                }

                if (__instance.bigCraftable.Value && !probe && __instance.heldObject.Value == null)
                {
                    __instance.scale.X = 5f;
                }

                try
                {
                    if (failLocationCondition)
                    {
                        throw new RestrictionException(DataLoader.Helper.Translation.Get("Message.Condition.Location"));
                    }
                    if (failSeasonCondition)
                    {
                        throw new RestrictionException(DataLoader.Helper.Translation.Get("Message.Condition.Season"));
                    }

                    ProducerRuleController.ValidateIfInputStackLessThanRequired(producerRule, input);
                    ProducerRuleController.ValidateIfAnyFuelStackLessThanRequired(producerRule, who);

                    OutputConfig outputConfig = ProducerRuleController.ProduceOutput(producerRule, __instance,
                                                                                     (i, q) => who.hasItemInInventory(i, q), who, location, producerConfig, input, probe);
                    if (outputConfig != null)
                    {
                        if (!probe)
                        {
                            foreach (var fuel in producerRule.FuelList)
                            {
                                RemoveItemsFromInventory(who, fuel.Item1, fuel.Item2);
                            }

                            foreach (var fuel in outputConfig.FuelList)
                            {
                                RemoveItemsFromInventory(who, fuel.Item1, fuel.Item2);
                            }

                            input.Stack -= producerRule.InputStack;
                            __result     = input.Stack <= 0;
                        }
                        else
                        {
                            __result = true;
                        }
                    }
                }
                catch (RestrictionException e)
                {
                    __result = false;
                    if (e.Message != null && !probe && who.IsLocalPlayer)
                    {
                        Game1.showRedMessage(e.Message);
                    }
                }
                return(false);
            }
            return(!failLocationCondition && !failSeasonCondition);
        }
Exemple #16
0
        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);
        }