示例#1
0
        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 = producerRule.LookForInputWhenReady == null?OutputConfigController.CreateOutput(outputConfig, input, random) : new Object(outputConfig.OutputIndex, 1);

                producer.heldObject.Value = output;
                if (!probe)
                {
                    if (producerRule.LookForInputWhenReady == null)
                    {
                        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));
                    }

                    if (location.hasLightSource(LightSourceConfigController.GenerateIdentifier(tileLocation)))
                    {
                        location.removeLightSource(LightSourceConfigController.GenerateIdentifier(tileLocation));
                    }
                    producer.initializeLightSource(tileLocation, false);

                    producerRule.IncrementStatsOnInput.ForEach(s => StatsController.IncrementStardewStats(s, producerRule.InputStack));
                }
            }
            return(outputConfig);
        }
        public ITrackedStack GetOutput()
        {
            SObject machine    = this.Machine;
            SObject heldObject = machine.heldObject.Value;

            return(new TrackedItem(heldObject.getOne(), item =>
            {
                CustomCloner cloner = ClonerController.GetCloner(machine.Name);
                int?machineMinutesUntilReady = null;
                if (cloner.CloningDataId.ContainsKey(item.ParentSheetIndex))
                {
                    machineMinutesUntilReady = cloner.CloningDataId[item.ParentSheetIndex];
                }
                else if (cloner.CloningDataId.ContainsKey(item.Category))
                {
                    machineMinutesUntilReady = cloner.CloningDataId[item.Category];
                }
                if (machineMinutesUntilReady.HasValue)
                {
                    machine.heldObject.Value = heldObject;
                    machine.MinutesUntilReady = machineMinutesUntilReady.Value;
                    machine.initializeLightSource(machine.TileLocation, false);
                }
                else
                {
                    machine.heldObject.Value = (SObject)null;
                    machine.MinutesUntilReady = -1;
                }
                machine.readyForHarvest.Value = false;
            }));
        }
示例#3
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);
     }
 }
示例#4
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);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Awkward override to specifically place a Propagator instead of a BigCraftable Object.
        /// </summary>
        /// <param name="location">Current location.</param>
        /// <param name="x">X-coord.</param>
        /// <param name="y">Y-coord.</param>
        /// <param name="who">Farmer placing the machine.</param>
        /// <returns>Always true.</returns>
        public override bool placementAction(GameLocation location, int x, int y, Farmer who = null)
        {
            Vector2 index1 = new Vector2(x / 64, y / 64);

            health = 10;

            // Determine player.
            if (who != null)
            {
                owner.Value = who.UniqueMultiplayerID;
            }
            else
            {
                owner.Value = Game1.player.UniqueMultiplayerID;
            }

            // Spawn object.
            location.objects.Add(index1, new Propagator(index1));
            location.playSound("hammer", NetAudio.SoundContext.Default);
            if (!performDropDownAction(who))
            {
                StardewValley.Object one = (StardewValley.Object)getOne();
                one.shakeTimer   = 50;
                one.TileLocation = index1;

                // Avoid placement conflicts.
                if (location.objects.ContainsKey(index1))
                {
                    if (location.objects[index1].ParentSheetIndex != ParentSheetIndex)
                    {
                        Game1.createItemDebris(location.objects[index1], index1 * 64f, -1, null, -1);
                        location.objects[index1] = one;
                    }
                }
                else
                {
                    location.objects.Add(index1, one);
                }
                one.initializeLightSource(index1, false);
            }
            location.playSound("woodyStep", NetAudio.SoundContext.Default);
            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))
                {
                    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);
        }
示例#7
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);
                    }
                }
            }
        }
        /// <summary>
        /// Checks for right mouse button iteraction with the world.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void Input_CheckForObjectInteraction(object sender, StardewModdingAPI.Events.ButtonPressedEventArgs e)
        {
            if (e.Button == StardewModdingAPI.SButton.MouseRight)
            {
                SObject obj = GetItemAtMouseTile();
                if (obj == null)
                {
                    return;
                }
                if (ObjectUtilities.IsObjectFurnace(obj) && ObjectUtilities.IsObjectHoldingItem(obj) == false)
                {
                    bool crafted = VanillaRecipeBook.VanillaRecipes.TryToCraftRecipe(obj);
                    if (crafted == false)
                    {
                        return;
                    }
                    obj.initializeLightSource((Vector2)(obj.TileLocation), false);
                    obj.showNextIndex.Value = true;

                    /*
                     * Game1.multiplayer.broadcastSprites(who.currentLocation, new TemporaryAnimatedSprite(30, this.tileLocation.Value * 64f + new Vector2(0.0f, -16f), Color.White, 4, false, 50f, 10, 64, (float)(((double)this.tileLocation.Y + 1.0) * 64.0 / 10000.0 + 9.99999974737875E-05), -1, 0)
                     * {
                     *  alphaFade = 0.005f
                     * });
                     */
                    (Game1.player.currentLocation).TemporarySprites.Add(new TemporaryAnimatedSprite(30, obj.TileLocation * 64f + new Vector2(0.0f, -16f), Color.White, 4, false, 50f, 10, 64, (float)(((double)obj.TileLocation.Y + 1.0) * 64.0 / 10000.0 + 9.99999974737875E-05), -1, 0));
                    obj.addWorkingAnimation(Game1.player.currentLocation);
                    if (TrackedMachines.ContainsKey(Game1.player.currentLocation))
                    {
                        TrackedMachines[Game1.player.currentLocation].Add(obj);
                    }
                    else
                    {
                        TrackedMachines.Add(Game1.player.currentLocation, new List <SObject>()
                        {
                            obj
                        });
                    }
                }
            }
        }
示例#9
0
        public static bool Prefix(StardewValley.Object __instance, Item dropInItem, bool probe, Farmer who, ref bool __result)
        {
            if (__instance.name == "Furnace")
            {
                if (who.IsLocalPlayer && __instance.GetTallyOfObject(who, 382, false) > 0 && __instance.heldObject.Value == null && dropInItem is IDGAItem ditem && ditem.FullId == ItemIds.MythiciteOre && dropInItem.Stack >= 5)
                {
                    __instance.heldObject.Value        = (StardewValley.Object)Mod.dga.SpawnDGAItem(ItemIds.MythiciteBar);
                    __instance.minutesUntilReady.Value = 720;

                    if (probe)
                    {
                        __result = true;
                    }
                    else
                    {
                        who.currentLocation.playSound("furnace");
                        __instance.initializeLightSource(__instance.tileLocation);
                        __instance.showNextIndex.Value = true;
                        // TODO: Don't be lazy and actually do this when Game1.multiplayer is public

                        /*Game1.multiplayer.broadcastSprites(who.currentLocation, new TemporaryAnimatedSprite(30, this.tileLocation.Value * 64f + new Vector2(0f, -16f), Color.White, 4, flipped: false, 50f, 10, 64, (this.tileLocation.Y + 1f) * 64f / 10000f + 0.0001f)
                         * {
                         *  alphaFade = 0.005f
                         * });*/
                        __instance.ConsumeInventoryItem(who, 382, 1);
                        dropInItem.Stack -= 5;
                        if (dropInItem.Stack <= 0)
                        {
                            __result = true;
                        }
                        __result = false;
                        return(false);
                    }
                    return(false);
                }
            }

            return(true);
        }
示例#10
0
        private void ProcessObject(GameLocation location, Vector2 tile, SObject obj)
        {
            switch (obj.name)
            {
            case "Furnace":
            {
                List <Chest> chests = Automation.GetConnectedChests(location, tile);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest.addItem(obj.heldObject) == null)
                        {
                            obj.heldObject      = null;
                            obj.readyForHarvest = false;
                            break;
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    if (Automation.DoChestsHaveItem(chests, 382, 1))
                    {
                        if (Automation.DoChestsHaveItem(chests, 378, 5))
                        {
                            Automation.RemoveItemFromChests(chests, 382);
                            Automation.RemoveItemFromChests(chests, 378, 5);
                            obj.heldObject        = new SObject(Vector2.Zero, 334, 1);
                            obj.minutesUntilReady = 30;
                        }
                        else if (Automation.DoChestsHaveItem(chests, 380, 5))
                        {
                            Automation.RemoveItemFromChests(chests, 382);
                            Automation.RemoveItemFromChests(chests, 380, 5);
                            obj.heldObject        = new SObject(Vector2.Zero, 335, 1);
                            obj.minutesUntilReady = 120;
                        }
                        else if (Automation.DoChestsHaveItem(chests, 384, 5))
                        {
                            Automation.RemoveItemFromChests(chests, 382);
                            Automation.RemoveItemFromChests(chests, 384, 5);
                            obj.heldObject        = new SObject(Vector2.Zero, 336, 1);
                            obj.minutesUntilReady = 300;
                        }
                        else if (Automation.DoChestsHaveItem(chests, 386, 5))
                        {
                            Automation.RemoveItemFromChests(chests, 382);
                            Automation.RemoveItemFromChests(chests, 386, 5);
                            obj.heldObject        = new SObject(Vector2.Zero, 337, 1);
                            obj.minutesUntilReady = 480;
                        }
                        else if (Automation.DoChestsHaveItem(chests, 80, 1))
                        {
                            Automation.RemoveItemFromChests(chests, 382);
                            Automation.RemoveItemFromChests(chests, 80);
                            obj.heldObject        = new SObject(Vector2.Zero, 338, "Refined Quartz", false, true, false, false);
                            obj.minutesUntilReady = 90;
                        }
                    }

                    if (obj.heldObject != null)
                    {
                        obj.initializeLightSource(tile);
                        obj.showNextIndex = true;
                    }
                }
            }
            break;

            case "Crystalarium":
            {
                List <Chest> chests = Automation.GetConnectedChests(location, tile);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest.addItem(obj.heldObject.getOne()) == null)
                        {
                            obj.minutesUntilReady = Automation.GetMinutesForCrystalarium(obj.heldObject.parentSheetIndex);
                            obj.readyForHarvest   = false;
                            break;
                        }
                    }
                }
            }
            break;

            case "Mayonnaise Machine":
            {
                List <Chest> chests = Automation.GetConnectedChests(location, tile);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest.addItem(obj.heldObject) == null)
                        {
                            obj.heldObject      = null;
                            obj.readyForHarvest = false;
                            break;
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    if (Automation.RemoveItemFromChests(chests, 176) || Automation.RemoveItemFromChests(chests, 180))
                    {
                        // small white egg / small brown egg -> normal mayonnaise
                        obj.heldObject        = new SObject(Vector2.Zero, 306, null, false, true, false, false);
                        obj.minutesUntilReady = 180;
                    }
                    else
                    if (Automation.RemoveItemFromChests(chests, 107) || Automation.RemoveItemFromChests(chests, 174) || Automation.RemoveItemFromChests(chests, 182))
                    {
                        // dino egg / white large egg / brown large egg -> gold quality mayonnaise
                        obj.heldObject = new SObject(Vector2.Zero, 306, null, false, true, false, false)
                        {
                            quality = 2
                        };
                        obj.minutesUntilReady = 180;
                    }
                    else
                    if (Automation.RemoveItemFromChests(chests, 442))
                    {
                        // duck egg -> duck mayonnaise
                        obj.heldObject        = new SObject(Vector2.Zero, 307, null, false, true, false, false);
                        obj.minutesUntilReady = 180;
                    }
                    else
                    if (Automation.RemoveItemFromChests(chests, 305))
                    {
                        // void egg -> void mayonnaise
                        obj.heldObject        = new SObject(Vector2.Zero, 308, null, false, true, false, false);
                        obj.minutesUntilReady = 180;
                    }
                }
            }
            break;

            case "Keg":
            {
                List <Chest> chests = Automation.GetConnectedChests(location, tile);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest.addItem(obj.heldObject) == null)
                        {
                            obj.heldObject      = null;
                            obj.readyForHarvest = false;
                            break;
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    foreach (var chest in chests)
                    {
                        foreach (var stack in chest.items)
                        {
                            switch (stack.parentSheetIndex)
                            {
                            case 340:             // honey, regardless of flower type
                                obj.heldObject        = new SObject(Vector2.Zero, 459, "Mead", false, true, false, false);
                                obj.minutesUntilReady = 600;
                                obj.heldObject.name   = "Mead";
                                break;

                            case 262:             // wheat
                                obj.heldObject        = new SObject(Vector2.Zero, 346, "Beer", false, true, false, false);
                                obj.minutesUntilReady = 1750;
                                obj.heldObject.name   = "Beer";
                                break;

                            case 304:             // hops
                                obj.heldObject        = new SObject(Vector2.Zero, 303, "Pale Ale", false, true, false, false);
                                obj.minutesUntilReady = 2250;
                                obj.heldObject.name   = "Pale Ale";
                                break;

                            case 433:             // coffee bean
                                obj.heldObject        = new SObject(Vector2.Zero, 395, "Coffee", false, true, false, false);
                                obj.heldObject.name   = "Coffee";
                                obj.minutesUntilReady = 120;
                                break;

                            case 256:             // tomato, default would produce tomato wine instead of juice
                                obj.heldObject        = new SObject(Vector2.Zero, 350, stack.Name + " Juice", false, true, false, false);
                                obj.heldObject.Price  = (int)(((SObject)stack).Price * 2.25d);
                                obj.heldObject.name   = stack.Name + " Juice";
                                obj.minutesUntilReady = 6000;
                                break;

                            case 260:             // hot pepper, default would produce juice instead of wine
                                obj.heldObject        = new SObject(Vector2.Zero, 348, stack.Name + " Wine", false, true, false, false);
                                obj.heldObject.Price  = ((SObject)stack).Price * 3;
                                obj.heldObject.name   = stack.Name + " Wine";
                                obj.minutesUntilReady = 10000;
                                break;

                            default:
                                if (stack.category == -79)             // fruit
                                {
                                    obj.heldObject        = new SObject(Vector2.Zero, 348, stack.Name + " Wine", false, true, false, false);
                                    obj.heldObject.name   = stack.Name + " Wine";
                                    obj.heldObject.Price  = ((SObject)stack).Price * 3;
                                    obj.minutesUntilReady = 10000;
                                }
                                else if (stack.category == -75)             // veggie
                                {
                                    obj.heldObject        = new SObject(Vector2.Zero, 350, stack.Name + " Juice", false, true, false, false);
                                    obj.heldObject.Price  = (int)(((SObject)stack).Price * 2.25d);
                                    obj.heldObject.name   = stack.Name + " Juice";
                                    obj.minutesUntilReady = 6000;
                                }
                                break;
                            }
                            if (obj.heldObject != null)         // we have put something in the keg, no need to loop over more chests/stacks
                            {
                                Automation.DecreaseStack(chest, stack);
                                return;
                            }
                        }
                    }
                }
            }
            break;

            case "Charcoal Kiln":
            {
                List <Chest> chests = Automation.GetConnectedChests(location, tile);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest.addItem(obj.heldObject) == null)
                        {
                            obj.heldObject      = null;
                            obj.readyForHarvest = false;
                            break;
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    if (Automation.RemoveItemFromChests(chests, 388, 10))
                    {
                        obj.heldObject        = new SObject(382, 1);
                        obj.minutesUntilReady = 30;
                        obj.showNextIndex     = true;
                    }
                }
            }
            break;

            case "Cheese Press":
            {
                List <Chest> chests = Automation.GetConnectedChests(location, tile);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest.addItem(obj.heldObject) == null)
                        {
                            obj.heldObject      = null;
                            obj.readyForHarvest = false;
                            break;
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    if (Automation.RemoveItemFromChests(chests, 184))
                    {
                        obj.heldObject        = new SObject(Vector2.Zero, 424, null, false, true, false, false);
                        obj.minutesUntilReady = 200;
                    }
                    else if (Automation.RemoveItemFromChests(chests, 186))
                    {
                        obj.heldObject = new SObject(Vector2.Zero, 424, "Cheese (=)", false, true, false, false)
                        {
                            quality = 2
                        };
                        obj.minutesUntilReady = 200;
                    }
                    else if (Automation.RemoveItemFromChests(chests, 436))
                    {
                        obj.heldObject        = new SObject(Vector2.Zero, 426, null, false, true, false, false);
                        obj.minutesUntilReady = 200;
                    }
                    else if (Automation.RemoveItemFromChests(chests, 438))
                    {
                        obj.heldObject = new SObject(Vector2.Zero, 426, null, false, true, false, false)
                        {
                            quality = 2
                        };
                        obj.minutesUntilReady = 200;
                    }
                }
            }
            break;

            case "Preserves Jar":
            {
                List <Chest> chests = Automation.GetConnectedChests(location, tile);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest.addItem(obj.heldObject) == null)
                        {
                            obj.heldObject      = null;
                            obj.readyForHarvest = false;
                            break;
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    SObject item =
                        (SObject)Automation.GetItemFromChestsByCategory(chests, -79, -1)
                        ?? (SObject)Automation.GetItemFromChestsByCategory(chests, -75, -1);

                    if (item != null)
                    {
                        if (item.category == -79)
                        {
                            obj.heldObject        = new SObject(Vector2.Zero, 344, item.Name + " Jelly", false, true, false, false);
                            obj.heldObject.Price  = 50 + item.Price * 2;
                            obj.heldObject.name   = item.Name + " Jelly";
                            obj.minutesUntilReady = 4000;
                            Automation.RemoveItemFromChestsCategory(chests, -79, -1);
                        }
                        if (item.category == -75)
                        {
                            obj.heldObject        = new SObject(Vector2.Zero, 342, "Pickled " + item.Name, false, true, false, false);
                            obj.heldObject.Price  = 50 + item.Price * 2;
                            obj.heldObject.name   = "Pickled " + item.Name;
                            obj.minutesUntilReady = 4000;
                            Automation.RemoveItemFromChestsCategory(chests, -75, -1);
                        }
                    }
                }
            }
            break;

            case "Loom":
            {
                List <Chest> chests = Automation.GetConnectedChests(location, tile);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest.addItem(obj.heldObject) == null)
                        {
                            obj.heldObject      = null;
                            obj.readyForHarvest = false;
                            obj.showNextIndex   = false;
                            break;
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    if (Automation.RemoveItemFromChests(chests, 440))
                    {
                        obj.heldObject        = new SObject(Vector2.Zero, 428, null, false, true, false, false);
                        obj.minutesUntilReady = 240;
                        obj.showNextIndex     = true;
                    }
                }
            }
            break;

            case "Bee House":
            {
                if (Game1.currentSeason != "winter")
                {
                    List <Chest> chests = Automation.GetConnectedChests(location, tile);
                    if (obj.heldObject != null && obj.readyForHarvest)
                    {
                        foreach (Chest chest in chests)
                        {
                            if (chest.items.Count < 36)
                            {
                                string str   = "Wild";
                                int    price = 0;
                                if (location is Farm)
                                {
                                    Crop crop = Utility.findCloseFlower(obj.tileLocation);
                                    if (crop != null)
                                    {
                                        str   = Game1.objectInformation[crop.indexOfHarvest].Split('/')[0];
                                        price = Convert.ToInt32(Game1.objectInformation[crop.indexOfHarvest].Split('/')[1]) * 2;
                                    }
                                }
                                obj.heldObject.name   = str + " Honey";
                                obj.heldObject.price += price;
                                if (chest.addItem(obj.heldObject) == null)
                                {
                                    obj.heldObject = new SObject(Vector2.Zero, 340, null, false, true, false, false);
                                    if (Game1.currentSeason == "winter")
                                    {
                                        obj.heldObject = null;
                                    }
                                    obj.minutesUntilReady = 2400 - Game1.timeOfDay + 4320;
                                    obj.readyForHarvest   = false;
                                    obj.showNextIndex     = false;
                                    break;
                                }
                            }
                        }
                    }
                }
                break;
            }

            case "Worm Bin":
            {
                List <Chest> chests = Automation.GetConnectedChests(location, tile);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest.addItem(obj.heldObject) == null)
                        {
                            obj.heldObject        = new SObject(685, Game1.random.Next(2, 6));
                            obj.minutesUntilReady = 2400 - Game1.timeOfDay;
                            obj.readyForHarvest   = false;
                            obj.showNextIndex     = false;
                            break;
                        }
                    }
                }
            }
            break;

            case "Seed Maker":
            {
                List <Chest> chests = Automation.GetConnectedChests(location, tile);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest.addItem(obj.heldObject) == null)
                        {
                            obj.heldObject      = null;
                            obj.readyForHarvest = false;
                            break;
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    int seedId = Automation.RemoveItemFromChestsIfCrop(chests);
                    if (seedId != -1)
                    {
                        Random random = new Random((int)(Game1.stats.DaysPlayed + (uint)((int)Game1.uniqueIDForThisGame / 2) + (uint)((int)obj.tileLocation.X) + (uint)((int)obj.tileLocation.Y * 77) + (uint)Game1.timeOfDay));
                        obj.heldObject = new SObject(seedId, random.Next(1, 4));
                        if (random.NextDouble() < 0.005)
                        {
                            obj.heldObject = new SObject(499, 1);
                        }
                        else if (random.NextDouble() < 0.02)
                        {
                            obj.heldObject = new SObject(770, random.Next(1, 5));
                        }
                        obj.minutesUntilReady = 20;
                    }
                }
            }
            break;

            case "Recycling Machine":
            {
                List <Chest> chests = Automation.GetConnectedChests(location, tile);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest.addItem(obj.heldObject) == null)
                        {
                            obj.heldObject      = null;
                            obj.readyForHarvest = false;
                            break;
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    Random random2 = new Random((int)Game1.uniqueIDForThisGame / 2 + (int)Game1.stats.DaysPlayed + Game1.timeOfDay + (int)obj.tileLocation.X * 200 + (int)obj.tileLocation.Y);
                    if (Automation.RemoveItemFromChests(chests, 168))
                    {
                        obj.heldObject                     = new SObject((random2.NextDouble() < 0.3) ? 382 : ((random2.NextDouble() < 0.3) ? 380 : 390), random2.Next(1, 4));
                        obj.minutesUntilReady              = 60;
                        Game1.stats.PiecesOfTrashRecycled += 1u;
                    }
                    else if (Automation.RemoveItemFromChests(chests, 169))
                    {
                        obj.heldObject                     = new SObject((random2.NextDouble() < 0.25) ? 382 : 388, random2.Next(1, 4));
                        obj.minutesUntilReady              = 60;
                        Game1.stats.PiecesOfTrashRecycled += 1u;
                    }
                    else if (Automation.RemoveItemFromChests(chests, 170) || Automation.RemoveItemFromChests(chests, 171))
                    {
                        obj.heldObject                     = new SObject(338, 1);
                        obj.minutesUntilReady              = 60;
                        Game1.stats.PiecesOfTrashRecycled += 1u;
                    }
                    else if (Automation.RemoveItemFromChests(chests, 172))
                    {
                        obj.heldObject                     = ((random2.NextDouble() < 0.1) ? new SObject(428, 1) : new Torch(Vector2.Zero, 3));
                        obj.minutesUntilReady              = 60;
                        Game1.stats.PiecesOfTrashRecycled += 1u;
                    }
                }
            }
            break;

            case "Oil Maker":
            {
                List <Chest> chests = Automation.GetConnectedChests(location, tile);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest.addItem(obj.heldObject) == null)
                        {
                            obj.heldObject      = null;
                            obj.readyForHarvest = false;
                            break;
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    if (Automation.RemoveItemFromChests(chests, 270))
                    {
                        obj.heldObject        = new SObject(Vector2.Zero, 247, null, false, true, false, false);
                        obj.minutesUntilReady = 1000;
                    }
                    else if (Automation.RemoveItemFromChests(chests, 421))
                    {
                        obj.heldObject        = new SObject(Vector2.Zero, 247, null, false, true, false, false);
                        obj.minutesUntilReady = 60;
                    }
                    else if (Automation.RemoveItemFromChests(chests, 430))
                    {
                        obj.heldObject        = new SObject(Vector2.Zero, 432, null, false, true, false, false);
                        obj.minutesUntilReady = 360;
                    }
                    else if (Automation.RemoveItemFromChests(chests, 431))
                    {
                        obj.heldObject        = new SObject(247, 1);
                        obj.minutesUntilReady = 3200;
                    }
                }
            }
            break;

            case "Tapper":
            {
                List <Chest> chests = Automation.GetConnectedChests(location, tile);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest.addItem(obj.heldObject) == null)
                        {
                            int id = obj.heldObject.parentSheetIndex;

                            if (id == 724)
                            {
                                obj.minutesUntilReady = 16000 - Game1.timeOfDay;
                            }
                            else if (id == 725)
                            {
                                obj.minutesUntilReady = 13000 - Game1.timeOfDay;
                            }
                            else if (id == 726)
                            {
                                obj.minutesUntilReady = 10000 - Game1.timeOfDay;
                            }
                            else if (id == 422)
                            {
                                obj.minutesUntilReady = 3000 - Game1.timeOfDay;
                                obj.heldObject        = new SObject(420, 1);
                            }
                            else if (id == 404 || id == 420)
                            {
                                obj.minutesUntilReady = 3000 - Game1.timeOfDay;
                                if (Game1.currentSeason != "fall")
                                {
                                    obj.heldObject        = new SObject(404, 1);
                                    obj.minutesUntilReady = 6000 - Game1.timeOfDay;
                                }
                                if (Game1.dayOfMonth % 10 == 0)
                                {
                                    obj.heldObject = new SObject(422, 1);
                                }
                                if (Game1.currentSeason == "winter")
                                {
                                    obj.minutesUntilReady = 80000 - Game1.timeOfDay;
                                }
                            }
                            if (obj.heldObject != null)
                            {
                                obj.heldObject = (SObject)obj.heldObject.getOne();
                            }
                            obj.readyForHarvest = false;
                            break;
                        }
                    }
                }
            }
            break;

            case "Lightning Rod":
            {
                List <Chest> chests = Automation.GetConnectedChests(location, tile);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest.addItem(obj.heldObject.getOne()) == null)
                        {
                            obj.heldObject      = null;
                            obj.readyForHarvest = false;
                            break;
                        }
                    }
                }
            }
            break;

            case "Cask":
            {
                if (location.Name != "Cellar")
                {
                    return;
                }
                var chests = Automation.GetConnectedChests(location, tile);
                if (obj.heldObject != null && obj.heldObject.quality == 4)
                {
                    foreach (var chest in chests)
                    {
                        if (chest.addItem(obj.heldObject.getOne()) == null)
                        {
                            obj.heldObject           = null;
                            obj.minutesUntilReady    = 0;
                            obj.readyForHarvest      = false;
                            ((Cask)obj).agingRate    = 0.0f;
                            ((Cask)obj).daysToMature = 0.0f;
                            break;
                        }
                    }
                }
                if (obj.heldObject == null)
                {
                    foreach (var chest in chests)
                    {
                        foreach (var stack in chest.items)
                        {
                            if ((((SObject)stack).quality) == 4)         // skip already-iridium stuff
                            {
                                continue;
                            }
                            float agingRate = -1f;
                            switch (stack.parentSheetIndex)
                            {
                            case 424:             // cheese
                            case 426:             // goat cheese
                                agingRate = 4f;
                                break;

                            case 459:             // mead
                            case 346:             // beer
                                agingRate = 2f;
                                break;

                            case 303:             // pale ale
                                agingRate = 1.66f;
                                break;

                            case 348:             // wine
                                agingRate = 1f;
                                break;
                            }
                            if (agingRate < 0)         // not something we could age
                            {
                                continue;
                            }
                            obj.heldObject = (SObject)stack.getOne();
                            switch (((SObject)stack).quality)
                            {
                            case 0:
                                ((Cask)obj).daysToMature = 56f;
                                break;

                            case 1:
                                ((Cask)obj).daysToMature = 42f;
                                break;

                            case 2:
                                ((Cask)obj).daysToMature = 28f;
                                break;
                            }
                            ((Cask)obj).agingRate = agingRate;
                            obj.minutesUntilReady = 999999;
                            Automation.DecreaseStack(chest, stack);
                            return;
                        }
                    }
                }
            }
            break;

            case "Slime Egg-Press":
            {
                List <Chest> chests = Automation.GetConnectedChests(location, tile);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest.addItem(obj.heldObject.getOne()) == null)
                        {
                            obj.heldObject      = null;
                            obj.readyForHarvest = false;
                            break;
                        }
                    }
                }
                if (obj.heldObject == null)
                {
                    if (Automation.RemoveItemFromChestsByName(chests, "Slime", -1, 99))
                    {
                        int parentSheetIndex = 680;
                        if (Game1.random.NextDouble() < 0.05)
                        {
                            parentSheetIndex = 439;
                        }
                        else if (Game1.random.NextDouble() < 0.1)
                        {
                            parentSheetIndex = 437;
                        }
                        else if (Game1.random.NextDouble() < 0.25)
                        {
                            parentSheetIndex = 413;
                        }
                        obj.heldObject        = new SObject(parentSheetIndex, 1);
                        obj.minutesUntilReady = 1200;
                    }
                }
            }
            break;

            default:
                if (obj.Name.Contains("Mushroom Box"))
                {
                    if (obj.heldObject != null && obj.readyForHarvest)
                    {
                        IEnumerable <Chest> chests = Automation.GetConnectedChests(location, tile);
                        if (!chests.Any())
                        {
                            // two possible modes
                            // - output mushrooms to adjancent chests like other machines (for realism)
                            // - output to any single chest inside the mushroom cave to save space, but only as long as there is
                            //   exactly one in the whole cave
                            chests = Automation.GetChestsInLocation(location);
                            if (chests.Skip(1).Any())
                            {
                                return;
                            }
                        }
                        foreach (Chest chest in chests)
                        {
                            if (chest.addItem(obj.heldObject) == null)
                            {
                                obj.heldObject        = null;
                                obj.readyForHarvest   = false;
                                obj.minutesUntilReady = -1;
                                obj.showNextIndex     = false;
                                break;
                            }
                        }
                    }
                }
                break;
            }
        }
示例#11
0
        /// <summary>
        /// Makes the machine produce an appropriate output.
        /// Adapted from https://github.com/Digus/StardewValleyMods/blob/master/ProducerFrameworkMod/OutputConfigController.cs
        /// </summary>
        /// <param name="producerRule"></param>
        /// <param name="settings"></param>
        /// <param name="producer"></param>
        /// <param name="fuelSearch"></param>
        /// <param name="who"></param>
        /// <param name="location"></param>
        /// <param name="producerConfig"></param>
        /// <param name="input"></param>
        /// <param name="probe"></param>
        /// <param name="noSoundAndAnimation"></param>
        /// <returns>Base output config - no values altered for mass production machine</returns>
        public static OutputConfig ProduceOutput(ProducerRule producerRule, MPMSettings settings, SObject producer, Func <int, int, bool> fuelSearch, Farmer who, GameLocation location,
                                                 ProducerConfig producerConfig = null, SObject input = null, int inputQuantity = 0, bool probe = false, bool noSoundAndAnimation = false,
                                                 List <InputInfo> inputInfo    = null)
        {
            if (who == null)
            {
                who = Game1.getFarmer((long)producer.owner);
            }

            if (inputInfo == null)
            {
                inputInfo = new List <InputInfo>();
            }

            Vector2      tileLocation = producer.TileLocation;
            Random       random       = ProducerRuleController.GetRandomForProducing(tileLocation);
            OutputConfig outputConfig = OutputConfigController.ChooseOutput(producerRule.OutputConfigs, random, fuelSearch, location, input);

            if (outputConfig != null)
            {
                SObject output = producerRule.LookForInputWhenReady == null?OutputConfigController.CreateOutput(outputConfig, input, random) : new SObject(outputConfig.OutputIndex, 1);

                output.Stack = settings.CalculateOutputProduced(output.Stack, inputInfo.ToArray());

                if (settings.Quality.HasValue)
                {
                    if (settings.Quality == QualitySetting.KeepInput)
                    {
                        output.Quality = input.Quality;
                    }
                    else
                    {
                        output.Quality = settings.GetOutputQuality();
                    }
                }

                producer.heldObject.Value = output;

                if (!probe)
                {
                    if (producerRule.LookForInputWhenReady == null)
                    {
                        OutputConfigController.LoadOutputName(outputConfig, producer.heldObject.Value, input, who);
                    }

                    //if (!noSoundAndAnimation)
                    //{
                    //    SoundUtil.PlaySound(producerRule.Sounds, location);
                    //    SoundUtil.PlayDelayedSound(producerRule.DelayedSounds, location);
                    //}

                    int minutesUntilReadyBase = outputConfig.MinutesUntilReady ?? producerRule.MinutesUntilReady;
                    int minutesUntilReady     = settings.CalculateTimeRequired(minutesUntilReadyBase, inputInfo.ToArray());

                    producer.minutesUntilReady.Value = 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));
                    //}

                    if (location.hasLightSource(LightSourceConfigController.GenerateIdentifier(tileLocation)))
                    {
                        location.removeLightSource(LightSourceConfigController.GenerateIdentifier(tileLocation));
                    }
                    producer.initializeLightSource(tileLocation, false);

                    int statsIncrement = inputQuantity;
                    producerRule.IncrementStatsOnInput.ForEach(s => StatsController.IncrementStardewStats(s, statsIncrement));
                }
            }
            return(outputConfig);
        }
        public override bool placementAction(GameLocation location, int x, int y, StardewValley.Farmer who = null)
        {
            Point point = new Point(x / Game1.tileSize, y / Game1.tileSize);

            this.TileLocation = new Vector2(point.X, point.Y);
            if (this.furniture_type.Value == 6 || this.furniture_type.Value == 13 || this.ParentSheetIndex == 1293)
            {
                Game1.showRedMessage("Can only be placed in House");
                return(false);
            }
            for (int index1 = point.X; index1 < point.X + this.getTilesWide(); ++index1)
            {
                for (int index2 = point.Y; index2 < point.Y + this.getTilesHigh(); ++index2)
                {
                    if (location.doesTileHaveProperty(index1, index2, "NoFurniture", "Back") != null)
                    {
                        Game1.showRedMessage("Furniture can't be placed here");
                        return(false);
                    }
                    if (location.getTileIndexAt(index1, index2, "Buildings") != -1)
                    {
                        return(false);
                    }
                }
            }
            this.boundingBox.Value = new Rectangle(x / Game1.tileSize * Game1.tileSize, y / Game1.tileSize * Game1.tileSize, this.boundingBox.Width, this.boundingBox.Height);
            foreach (Character character in Game1.getAllFarmers())
            {
                if (character.currentLocation == location && character.GetBoundingBox().Intersects(this.boundingBox.Value))
                {
                    Game1.showRedMessage("Can't place on top of a person.");
                    return(false);
                }
            }
            foreach (StardewValley.Object i in location.objects.Values)
            {
                if (i is CustomFurniture.CustomFurniture)
                {
                    CustomFurniture.CustomFurniture furniture = (CustomFurniture.CustomFurniture)i;

                    if (furniture.getBoundingBox(furniture.TileLocation).Intersects(this.boundingBox.Value))
                    {
                        Game1.showRedMessage("Furniture can't be placed here");
                        return(false);
                    }
                }
            }
            this.updateDrawPosition();
            if (!this.performDropDownAction(who))
            {
                StardewValley.Object @object = (StardewValley.Object) this.getOne();
                @object.shakeTimer   = 50;
                @object.TileLocation = this.TileLocation;
                if (location.objects.ContainsKey(this.TileLocation))
                {
                    if (location.objects[this.TileLocation].ParentSheetIndex != this.ParentSheetIndex)
                    {
                        Game1.createItemDebris(location.objects[this.TileLocation], this.TileLocation * Game1.tileSize, Game1.random.Next(4), null);
                        location.objects[this.TileLocation] = @object;
                    }
                }
                else
                {
                    location.objects.Add(this.TileLocation, @object);
                }
                (@object as AnywhereCustomFurniture).sourceRect.Value  = this.sourceRect.Value;
                (@object as AnywhereCustomFurniture).boundingBox.Value = this.boundingBox.Value;
                @object.initializeLightSource(this.TileLocation);
            }

            Game1.playSound("woodyStep");
            return(true);
        }
示例#13
0
        private void ProcessObject(GameLocation gLoc, Vector2 objLoc, StardewValley.Object obj)
        {
            if (obj.name.Equals("Furnace"))
            {
                List <Chest> chests = Automation.GetChestsFromSurroundingLocation(gLoc, objLoc);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest != null)
                        {
                            if (chest.addItem(obj.heldObject) == null)
                            {
                                obj.heldObject      = null;
                                obj.readyForHarvest = false;
                                break;
                            }
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    if (Automation.DoesChestsHaveItem(chests, 382, 1))
                    {
                        if (Automation.DoesChestsHaveItem(chests, 378, 5))
                        {
                            Automation.RemoveItemFromChests(chests, 382, 1);
                            Automation.RemoveItemFromChests(chests, 378, 5);
                            obj.heldObject        = new StardewValley.Object(Vector2.Zero, 334, 1);
                            obj.minutesUntilReady = 30;
                        }
                        else if (Automation.DoesChestsHaveItem(chests, 380, 5))
                        {
                            Automation.RemoveItemFromChests(chests, 382, 1);
                            Automation.RemoveItemFromChests(chests, 380, 5);
                            obj.heldObject        = new StardewValley.Object(Vector2.Zero, 335, 1);
                            obj.minutesUntilReady = 120;
                        }
                        else if (Automation.DoesChestsHaveItem(chests, 384, 5))
                        {
                            Automation.RemoveItemFromChests(chests, 382, 1);
                            Automation.RemoveItemFromChests(chests, 384, 5);
                            obj.heldObject        = new StardewValley.Object(Vector2.Zero, 336, 1);
                            obj.minutesUntilReady = 300;
                        }
                        else if (Automation.DoesChestsHaveItem(chests, 386, 5))
                        {
                            Automation.RemoveItemFromChests(chests, 382, 1);
                            Automation.RemoveItemFromChests(chests, 386, 5);
                            obj.heldObject        = new StardewValley.Object(Vector2.Zero, 337, 1);
                            obj.minutesUntilReady = 480;
                        }
                    }
                    if (obj.heldObject == null && Automation.DoesChestsHaveItem(chests, 80, 1))
                    {
                        Automation.RemoveItemFromChests(chests, 80, 1);
                        obj.heldObject        = new StardewValley.Object(Vector2.Zero, 338, "Refined Quartz", false, true, false, false);
                        obj.minutesUntilReady = 90;
                    }

                    if (obj.heldObject != null)
                    {
                        obj.initializeLightSource(objLoc);
                        obj.showNextIndex = true;
                    }
                }
            }
            else if (obj.name.Equals("Crystalarium"))
            {
                List <Chest> chests = Automation.GetChestsFromSurroundingLocation(gLoc, objLoc);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest != null)
                        {
                            if (chest.addItem(obj.heldObject.getOne()) == null)
                            {
                                obj.minutesUntilReady = Automation.getMinutesForCrystalarium(obj.heldObject.parentSheetIndex);
                                obj.readyForHarvest   = false;
                                break;
                            }
                        }
                    }
                }
            }
            else if (obj.name.Equals("Mayonnaise Machine"))
            {
                List <Chest> chests = Automation.GetChestsFromSurroundingLocation(gLoc, objLoc);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest != null)
                        {
                            if (chest.addItem(obj.heldObject) == null)
                            {
                                obj.heldObject      = null;
                                obj.readyForHarvest = false;
                                break;
                            }
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    if (Automation.RemoveItemFromChests(chests, 176) || Automation.RemoveItemFromChests(chests, 180))
                    {
                        obj.heldObject        = new StardewValley.Object(Vector2.Zero, 306, (string)null, false, true, false, false);
                        obj.minutesUntilReady = 180;
                    }
                    else
                    if (Automation.RemoveItemFromChests(chests, 107) || Automation.RemoveItemFromChests(chests, 174) || Automation.RemoveItemFromChests(chests, 182))
                    {
                        obj.heldObject = new StardewValley.Object(Vector2.Zero, 306, (string)null, false, true, false, false)
                        {
                            quality = 2
                        };
                        obj.minutesUntilReady = 180;
                    }
                    else
                    if (Automation.RemoveItemFromChests(chests, 442))
                    {
                        obj.heldObject        = new StardewValley.Object(Vector2.Zero, 307, (string)null, false, true, false, false);
                        obj.minutesUntilReady = 180;
                    }
                }
            }
            else if (obj.name.Equals("Keg"))
            {
                List <Chest> chests = Automation.GetChestsFromSurroundingLocation(gLoc, objLoc);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest != null)
                        {
                            if (chest.addItem(obj.heldObject) == null)
                            {
                                obj.heldObject      = null;
                                obj.readyForHarvest = false;
                                break;
                            }
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    if (Automation.RemoveItemFromChestsByName(chests, "Wheat", -1))
                    {
                        obj.heldObject        = new StardewValley.Object(Vector2.Zero, 346, "Beer", false, true, false, false);
                        obj.heldObject.name   = "Beer";
                        obj.minutesUntilReady = 1750;
                    }
                    else
                    if (Automation.RemoveItemFromChestsByName(chests, "Hops", -1))
                    {
                        obj.heldObject        = new StardewValley.Object(Vector2.Zero, 303, "Pale Ale", false, true, false, false);
                        obj.heldObject.name   = "Pale Ale";
                        obj.minutesUntilReady = 2250;
                    }
                    else
                    {
                        StardewValley.Object item = (StardewValley.Object)Automation.GetItemFromChestsByCategory(chests, -79, -1);
                        if (item == null)
                        {
                            item = (StardewValley.Object)Automation.GetItemFromChestsByCategory(chests, -75, -1);
                        }

                        if (item != null)
                        {
                            if (item.category == -79)
                            {
                                obj.heldObject        = new StardewValley.Object(Vector2.Zero, 348, item.Name + " Wine", false, true, false, false);
                                obj.heldObject.Price  = item.Price * 3;
                                obj.heldObject.Name   = item.Name + " Wine";
                                obj.minutesUntilReady = 10000;
                                Automation.RemoveItemFromChestsCategory(chests, -79, -1);
                            }
                            if (item.category == -75)
                            {
                                obj.heldObject        = new StardewValley.Object(Vector2.Zero, 350, item.Name + " Juice", false, true, false, false);
                                obj.heldObject.Price  = (int)(item.price * 2.25d);
                                obj.heldObject.Name   = item.Name + " Juice";
                                obj.minutesUntilReady = 6000;
                                Automation.RemoveItemFromChestsCategory(chests, -75, -1);
                            }
                        }
                    }
                }
            }
            else if (obj.name.Equals("Charcoal Kiln"))
            {
                List <Chest> chests = Automation.GetChestsFromSurroundingLocation(gLoc, objLoc);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest != null)
                        {
                            if (chest.addItem(obj.heldObject) == null)
                            {
                                obj.heldObject      = null;
                                obj.readyForHarvest = false;
                                break;
                            }
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    if (Automation.RemoveItemFromChests(chests, 388, 10))
                    {
                        obj.heldObject        = new StardewValley.Object(382, 1, false, -1, 0);
                        obj.minutesUntilReady = 30;
                        obj.showNextIndex     = true;
                    }
                }
            }
            else if (obj.name.Equals("Cheese Press"))
            {
                List <Chest> chests = Automation.GetChestsFromSurroundingLocation(gLoc, objLoc);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest != null)
                        {
                            if (chest.addItem(obj.heldObject) == null)
                            {
                                obj.heldObject      = null;
                                obj.readyForHarvest = false;
                                break;
                            }
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    if (Automation.RemoveItemFromChests(chests, 184))
                    {
                        obj.heldObject        = new StardewValley.Object(Vector2.Zero, 424, null, false, true, false, false);
                        obj.minutesUntilReady = 200;
                    }
                    else if (Automation.RemoveItemFromChests(chests, 186))
                    {
                        obj.heldObject = new StardewValley.Object(Vector2.Zero, 424, "Cheese (=)", false, true, false, false)
                        {
                            quality = 2
                        };
                        obj.minutesUntilReady = 200;
                    }
                    else if (Automation.RemoveItemFromChests(chests, 436))
                    {
                        obj.heldObject        = new StardewValley.Object(Vector2.Zero, 426, null, false, true, false, false);
                        obj.minutesUntilReady = 200;
                    }
                    else if (Automation.RemoveItemFromChests(chests, 438))
                    {
                        obj.heldObject = new StardewValley.Object(Vector2.Zero, 426, null, false, true, false, false)
                        {
                            quality = 2
                        };
                        obj.minutesUntilReady = 200;
                    }
                }
            }
            else if (obj.name.Equals("Preserves Jar"))
            {
                List <Chest> chests = Automation.GetChestsFromSurroundingLocation(gLoc, objLoc);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest != null)
                        {
                            if (chest.addItem(obj.heldObject) == null)
                            {
                                obj.heldObject      = null;
                                obj.readyForHarvest = false;
                                break;
                            }
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    StardewValley.Object item = (StardewValley.Object)Automation.GetItemFromChestsByCategory(chests, -79, -1);
                    if (item == null)
                    {
                        item = (StardewValley.Object)Automation.GetItemFromChestsByCategory(chests, -75, -1);
                    }

                    if (item != null)
                    {
                        if (item.category == -79)
                        {
                            obj.heldObject        = new StardewValley.Object(Vector2.Zero, 344, item.Name + " Jelly", false, true, false, false);
                            obj.heldObject.Price  = 50 + item.Price * 2;
                            obj.heldObject.Name   = item.Name + " Jelly";
                            obj.minutesUntilReady = 4000;
                            Automation.RemoveItemFromChestsCategory(chests, -79, -1);
                        }
                        if (item.category == -75)
                        {
                            obj.heldObject        = new StardewValley.Object(Vector2.Zero, 342, "Pickled " + item.Name, false, true, false, false);
                            obj.heldObject.Price  = 50 + item.Price * 2;
                            obj.heldObject.Name   = "Pickled " + item.Name;
                            obj.minutesUntilReady = 4000;
                            Automation.RemoveItemFromChestsCategory(chests, -75, -1);
                        }
                    }
                }
            }
            else if (obj.name.Equals("Loom"))
            {
                List <Chest> chests = Automation.GetChestsFromSurroundingLocation(gLoc, objLoc);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest != null)
                        {
                            if (chest.addItem(obj.heldObject) == null)
                            {
                                obj.heldObject      = null;
                                obj.readyForHarvest = false;
                                obj.showNextIndex   = false;
                                break;
                            }
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    if (Automation.RemoveItemFromChests(chests, 440))
                    {
                        obj.heldObject        = new StardewValley.Object(Vector2.Zero, 428, null, false, true, false, false);
                        obj.minutesUntilReady = 240;
                        obj.showNextIndex     = true;
                    }
                }
            }
            else if (obj.name.Equals("Bee House") && !Game1.currentSeason.Equals("winter"))
            {
                List <Chest> chests = Automation.GetChestsFromSurroundingLocation(gLoc, objLoc);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest != null)
                        {
                            if (chest.items.Count < 36)
                            {
                                string str   = "Wild";
                                int    price = 0;
                                if (gLoc is Farm)
                                {
                                    Crop crop = Utility.findCloseFlower(obj.tileLocation);
                                    if (crop != null)
                                    {
                                        str   = Game1.objectInformation[crop.indexOfHarvest].Split(new char[] { '/' })[0];
                                        price = Convert.ToInt32(Game1.objectInformation[crop.indexOfHarvest].Split(new char[] { '/' })[1]) * 2;
                                    }
                                }
                                obj.heldObject.name   = str + " Honey";
                                obj.heldObject.price += price;
                                if (chest.addItem(obj.heldObject) == null)
                                {
                                    obj.heldObject = new StardewValley.Object(Vector2.Zero, 340, null, false, true, false, false);
                                    if (Game1.currentSeason.Equals("winter"))
                                    {
                                        obj.heldObject = null;
                                    }
                                    obj.minutesUntilReady = 2400 - Game1.timeOfDay + 4320;
                                    obj.readyForHarvest   = false;
                                    obj.showNextIndex     = false;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else if (obj.name.Equals("Worm Bin"))
            {
                List <Chest> chests = Automation.GetChestsFromSurroundingLocation(gLoc, objLoc);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest != null)
                        {
                            if (chest.addItem(obj.heldObject) == null)
                            {
                                obj.heldObject        = new StardewValley.Object(685, Game1.random.Next(2, 6), false, -1, 0);
                                obj.minutesUntilReady = 2400 - Game1.timeOfDay;
                                obj.readyForHarvest   = false;
                                obj.showNextIndex     = false;
                                break;
                            }
                        }
                    }
                }
            }
            else if (obj.name.Equals("Seed Maker"))
            {
                List <Chest> chests = Automation.GetChestsFromSurroundingLocation(gLoc, objLoc);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest != null)
                        {
                            if (chest.addItem(obj.heldObject) == null)
                            {
                                obj.heldObject      = null;
                                obj.readyForHarvest = false;
                                break;
                            }
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    int seedId = Automation.RemoveItemFromChestsIfCrop(chests);
                    if (seedId != -1)
                    {
                        Random random = new Random((int)(Game1.stats.DaysPlayed + (uint)((int)Game1.uniqueIDForThisGame / 2) + (uint)((int)obj.tileLocation.X) + (uint)((int)obj.tileLocation.Y * 77) + (uint)Game1.timeOfDay));
                        obj.heldObject = new StardewValley.Object(seedId, random.Next(1, 4), false, -1, 0);
                        if (random.NextDouble() < 0.005)
                        {
                            obj.heldObject = new StardewValley.Object(499, 1, false, -1, 0);
                        }
                        else if (random.NextDouble() < 0.02)
                        {
                            obj.heldObject = new StardewValley.Object(770, random.Next(1, 5), false, -1, 0);
                        }
                        obj.minutesUntilReady = 20;
                    }
                }
            }
            else if (obj.name.Equals("Recycling Machine"))
            {
                List <Chest> chests = Automation.GetChestsFromSurroundingLocation(gLoc, objLoc);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest != null)
                        {
                            if (chest.addItem(obj.heldObject) == null)
                            {
                                obj.heldObject      = null;
                                obj.readyForHarvest = false;
                                break;
                            }
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    Random random2 = new Random((int)Game1.uniqueIDForThisGame / 2 + (int)Game1.stats.DaysPlayed + Game1.timeOfDay + (int)obj.tileLocation.X * 200 + (int)obj.tileLocation.Y);
                    if (Automation.RemoveItemFromChests(chests, 168))
                    {
                        obj.heldObject                     = new StardewValley.Object((random2.NextDouble() < 0.3) ? 382 : ((random2.NextDouble() < 0.3) ? 380 : 390), random2.Next(1, 4), false, -1, 0);
                        obj.minutesUntilReady              = 60;
                        Game1.stats.PiecesOfTrashRecycled += 1u;
                    }
                    else if (Automation.RemoveItemFromChests(chests, 169))
                    {
                        obj.heldObject                     = new StardewValley.Object((random2.NextDouble() < 0.25) ? 382 : 388, random2.Next(1, 4), false, -1, 0);
                        obj.minutesUntilReady              = 60;
                        Game1.stats.PiecesOfTrashRecycled += 1u;
                    }
                    else if (Automation.RemoveItemFromChests(chests, 170) || Automation.RemoveItemFromChests(chests, 171))
                    {
                        obj.heldObject                     = new StardewValley.Object(338, 1, false, -1, 0);
                        obj.minutesUntilReady              = 60;
                        Game1.stats.PiecesOfTrashRecycled += 1u;
                    }
                    else if (Automation.RemoveItemFromChests(chests, 172))
                    {
                        obj.heldObject                     = ((random2.NextDouble() < 0.1) ? new StardewValley.Object(428, 1, false, -1, 0) : new Torch(Vector2.Zero, 3));
                        obj.minutesUntilReady              = 60;
                        Game1.stats.PiecesOfTrashRecycled += 1u;
                    }
                }
            }
            else if (obj.name.Equals("Oil Maker"))
            {
                List <Chest> chests = Automation.GetChestsFromSurroundingLocation(gLoc, objLoc);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest != null)
                        {
                            if (chest.addItem(obj.heldObject) == null)
                            {
                                obj.heldObject      = null;
                                obj.readyForHarvest = false;
                                break;
                            }
                        }
                    }
                }
                if (obj.heldObject == null && !obj.readyForHarvest)
                {
                    if (Automation.RemoveItemFromChests(chests, 270))
                    {
                        obj.heldObject        = new StardewValley.Object(Vector2.Zero, 247, null, false, true, false, false);
                        obj.minutesUntilReady = 1000;
                    }
                    else if (Automation.RemoveItemFromChests(chests, 421))
                    {
                        obj.heldObject        = new StardewValley.Object(Vector2.Zero, 247, null, false, true, false, false);
                        obj.minutesUntilReady = 60;
                    }
                    else if (Automation.RemoveItemFromChests(chests, 430))
                    {
                        obj.heldObject        = new StardewValley.Object(Vector2.Zero, 432, null, false, true, false, false);
                        obj.minutesUntilReady = 360;
                    }
                    else if (Automation.RemoveItemFromChests(chests, 431))
                    {
                        obj.heldObject        = new StardewValley.Object(247, 1, false, -1, 0);
                        obj.minutesUntilReady = 3200;
                    }
                }
            }
            else if (obj.name.Equals("Tapper"))
            {
                List <Chest> chests = Automation.GetChestsFromSurroundingLocation(gLoc, objLoc);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest != null)
                        {
                            if (chest.addItem(obj.heldObject) == null)
                            {
                                int id = obj.heldObject.parentSheetIndex;

                                if (id == 724)
                                {
                                    obj.minutesUntilReady = 16000 - Game1.timeOfDay;
                                }
                                else if (id == 725)
                                {
                                    obj.minutesUntilReady = 13000 - Game1.timeOfDay;
                                }
                                else if (id == 726)
                                {
                                    obj.minutesUntilReady = 10000 - Game1.timeOfDay;
                                }
                                else if (id == 422)
                                {
                                    obj.minutesUntilReady = 3000 - Game1.timeOfDay;
                                    obj.heldObject        = new StardewValley.Object(420, 1, false, -1, 0);
                                }
                                else if (id == 404 || id == 420)
                                {
                                    obj.minutesUntilReady = 3000 - Game1.timeOfDay;
                                    if (!Game1.currentSeason.Equals("fall"))
                                    {
                                        obj.heldObject        = new StardewValley.Object(404, 1, false, -1, 0);
                                        obj.minutesUntilReady = 6000 - Game1.timeOfDay;
                                    }
                                    if (Game1.dayOfMonth % 10 == 0)
                                    {
                                        obj.heldObject = new StardewValley.Object(422, 1, false, -1, 0);
                                    }
                                    if (Game1.currentSeason.Equals("winter"))
                                    {
                                        obj.minutesUntilReady = 80000 - Game1.timeOfDay;
                                    }
                                }
                                if (obj.heldObject != null)
                                {
                                    obj.heldObject = (StardewValley.Object)obj.heldObject.getOne();
                                }
                                obj.readyForHarvest = false;
                                break;
                            }
                        }
                    }
                }
            }
            else if (obj.name.Equals("Lightning Rod"))
            {
                List <Chest> chests = Automation.GetChestsFromSurroundingLocation(gLoc, objLoc);
                if (obj.heldObject != null && obj.readyForHarvest)
                {
                    foreach (Chest chest in chests)
                    {
                        if (chest != null)
                        {
                            if (chest.addItem(obj.heldObject.getOne()) == null)
                            {
                                obj.heldObject      = null;
                                obj.readyForHarvest = false;
                                break;
                            }
                        }
                    }
                }
            }
            // end
        }
示例#14
0
        public static bool Object_PerformObjectDropInAction(ref SObject __instance, ref bool __result, ref Item dropInItem, bool probe, Farmer who)
        {
            if (!(dropInItem is SObject object1))
            {
                return(false);
            }

            if (object1.ParentSheetIndex != 74)
            {
                return(true);
            }

            if (__instance.name.Equals("Furnace"))
            {
                if (who.IsLocalPlayer && who.getTallyOfObject(382, false) == 666666)
                {
                    if (!probe && who.IsLocalPlayer)
                    {
                        Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:Object.cs.12772"));
                    }
                    return(false);
                }
                if (__instance.heldObject.Value == null && !probe)
                {
                    __instance.heldObject.Value  = new SObject(910, 5);
                    __instance.MinutesUntilReady = 2400;
                    who.currentLocation.playSound("furnace");
                    __instance.initializeLightSource(__instance.TileLocation);
                    __instance.showNextIndex.Value = true;

                    Multiplayer multiplayer = ModEntry.ModHelper.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer").GetValue();
                    multiplayer.broadcastSprites(who.currentLocation, new TemporaryAnimatedSprite(30, __instance.TileLocation * 64f + new Vector2(0.0f, -16f), Color.White, 4, false, 50f, 10, 64, (float)((__instance.TileLocation.Y + 1.0) * 64.0 / 10000.0 + 9.99999974737875E-05))
                    {
                        alphaFade = 0.005f
                    });
                    for (int index = who.Items.Count - 1; index >= 0; --index)
                    {
                        if (who.Items[index] is SObject obj && obj.ParentSheetIndex == 382)
                        {
                            --who.Items[index].Stack;
                            if (who.Items[index].Stack <= 0)
                            {
                                who.Items[index] = null;
                                break;
                            }
                            break;
                        }
                    }
                    object1.Stack -= 1;
                    __result       = object1.Stack <= 0;
                    return(false);
                }
                if (__instance.heldObject.Value == null & probe)
                {
                    if (object1.ParentSheetIndex == 74)
                    {
                        __instance.heldObject.Value = new SObject();
                        __result = true;
                        return(false);
                    }
                }
            }
            __result = false;
            return(false);
        }
示例#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;

            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);
        }