示例#1
0
 internal static void Postfix(CraftingRecipe __instance, Item __result)
 {
     // Intercept machine crafts with a Propagator subclass,
     // rather than a generic nonfunctional craftable.
     if (__instance.name.Equals(Data.PropagatorName))
     {
         __result = new Propagator(Game1.player.getTileLocation());
     }
 }
示例#2
0
 internal static void CraftingRecipe_CreateItem_Postfix(CraftingRecipe __instance, Item __result)
 {
     // Intercept machine crafts with a Propagator subclass,
     // rather than a generic nonfunctional craftable
     if (__instance.name == ModValues.PropagatorInternalName)
     {
         __result = new Propagator(Game1.player.getTileLocation());
     }
 }
示例#3
0
        internal static bool Prefix(
            List <Dictionary <ClickableTextureComponent, CraftingRecipe> > ___pagesOfCraftingRecipes,
            int ___currentCraftingPage, Item ___heldItem,
            ClickableTextureComponent c, bool playSound = true)
        {
            try
            {
                // Fetch an instance of any clicked-on craftable in the crafting menu.
                Item tempItem = ___pagesOfCraftingRecipes[___currentCraftingPage][c]
                                .createItem();

                // Fall through the prefix for any craftables other than the Propagator.
                if (!tempItem.Name.Equals(Data.PropagatorName))
                {
                    return(true);
                }

                // Behaviours as from base method.
                if (___heldItem == null)
                {
                    ___pagesOfCraftingRecipes[___currentCraftingPage][c]
                    .consumeIngredients(null);
                    ___heldItem = tempItem;
                    if (playSound)
                    {
                        Game1.playSound("coin");
                    }
                }
                if (Game1.player.craftingRecipes.ContainsKey(___pagesOfCraftingRecipes[___currentCraftingPage][c].name))
                {
                    Game1.player.craftingRecipes[___pagesOfCraftingRecipes[___currentCraftingPage][c].name]
                        += ___pagesOfCraftingRecipes[___currentCraftingPage][c].numberProducedPerCraft;
                }
                if (___heldItem == null || !Game1.player.couldInventoryAcceptThisItem(___heldItem))
                {
                    return(false);
                }

                // Add the machine to the user's inventory.
                Propagator prop = new Propagator(Game1.player.getTileLocation());
                Game1.player.addItemToInventoryBool(prop, false);
                ___heldItem = null;
                return(false);
            }
            catch (Exception e)
            {
                Log.E($"BlueberryMushroomMachine failed in" +
                      $"{nameof(CraftingPagePatch)}.{nameof(Prefix)}" +
                      $"\n{e}");
                return(true);
            }
        }
示例#4
0
        private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            e.Button.TryGetKeyboard(out Keys keyPressed);

            // Debug functionalities.
            if (Game1.activeClickableMenu == null)
            {
                if (keyPressed.ToSButton().Equals(Config.GivePropagatorKey))
                {
                    Monitor.Log(Game1.player.Name + " cheated in a Propagator.", LogLevel.Trace);

                    Propagator prop = new Propagator(Game1.player.getTileLocation());
                    Game1.player.addItemByMenuIfNecessary(prop);
                }
            }
        }
示例#5
0
        private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            e.Button.TryGetKeyboard(out var keyPressed);

            if (Game1.activeClickableMenu != null)
            {
                return;
            }

            // Debug functionalities.
            if (keyPressed.ToSButton().Equals(Config.GivePropagatorKey))
            {
                var prop = new Propagator(Game1.player.getTileLocation());
                Game1.player.addItemByMenuIfNecessary(prop);
                Log.D($"{Game1.player.Name} spawned in a {Const.PropagatorInternalName} ({prop.DisplayName}).",
                      Config.DebugMode);
            }
        }
示例#6
0
        private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            if (Game1.eventUp && !Game1.currentLocation.currentEvent.playerControlSequence ||
                Game1.currentBillboard != 0 || Game1.activeClickableMenu != null || Game1.menuUp ||
                Game1.nameSelectUp ||
                Game1.IsChatting || Game1.dialogueTyping || Game1.dialogueUp || Game1.fadeToBlack ||
                !Game1.player.CanMove || Game1.eventUp || Game1.isFestival())
            {
                return;
            }

            // Debug spawning for Propagator: Can't be spawned in with CJB Item Spawner as it subclasses Object
            if (e.Button == Config.DebugGivePropagatorKey)
            {
                var prop = new Propagator(Game1.player.getTileLocation());
                Game1.player.addItemByMenuIfNecessary(prop);
                Log.D($"{Game1.player.Name} spawned in a"
                      + $" [{ModValues.PropagatorIndex}] {ModValues.PropagatorInternalName} ({prop.DisplayName}).");
            }
        }
示例#7
0
        /// <summary>
        /// Rebuilds any broken or missing Propagator objects in the player's inventory and throughout game location object lists.
        /// </summary>
        private void RebuildPropagtors()
        {
            if (Data != null && Data.PyTKMigration)
            {
                // Manually rebuild each Propagator in the player's inventory
                var rebuiltItemsCount = 0;
                var items             = Game1.player.Items;
                for (var i = items.Count - 1; i > 0; --i)
                {
                    if (items[i] == null ||
                        !items[i].Name.StartsWith($"PyTK|Item|{ModValues.PackageName}") ||
                        !items[i].Name.Contains($"{ModValues.PropagatorInternalName}"))
                    {
                        continue;
                    }

                    ++rebuiltItemsCount;
                    Log.D($"Found a broken Propagator in {Game1.player.Name}'s inventory slot {i}, rebuilding manually.",
                          Config.DebugMode);

                    var stack = items[i].Stack;
                    Game1.player.removeItemFromInventory(items[i]);
                    Game1.player.addItemToInventory(new Propagator {
                        Stack = stack
                    }, i);
                }

                // Manually rebuild each Propagator in the world
                var rebuiltObjectsCount = 0;
                foreach (var location in Game1.locations)
                {
                    foreach (var key in location.Objects.Keys.ToList())
                    {
                        if (!location.Objects[key].Name.StartsWith($"PyTK|Item|{ModValues.PackageName}"))
                        {
                            continue;
                        }

                        int index = 0, quantity = 0, quality = 0;
                        var days              = 0f;
                        var replacement       = new Propagator();
                        var tileLocation      = Vector2.Zero;
                        var isHoldingMushroom = false;
                        var itemSplit         = location.Objects[key].Name.Substring(location.Objects[key].Name.IndexOf(", ")).Split('|');
                        foreach (var field in itemSplit)
                        {
                            var fieldSplit = field.Split(new[] { '=' }, 2);
                            switch (fieldSplit[0])
                            {
                            case "tileLocationX":
                                tileLocation.X = float.Parse(fieldSplit[1]);
                                break;

                            case "tileLocationY":
                                tileLocation.Y = float.Parse(fieldSplit[1]);
                                break;

                            case "heldObjectIndex":
                                index = int.Parse(fieldSplit[1]);
                                break;

                            case "heldObjectQuality":
                                quality = int.Parse(fieldSplit[1]);
                                break;

                            case "heldObjectQuantity":
                                quantity = int.Parse(fieldSplit[1]);
                                break;

                            case "days":
                                days = float.Parse(fieldSplit[1]);
                                break;

                            case "produceExtra":
                                isHoldingMushroom = true;
                                break;
                            }
                        }
                        replacement.TileLocation = tileLocation;
                        replacement.PutSourceMushroom(new Object(index, quantity)
                        {
                            Quality = quality
                        });
                        if (isHoldingMushroom)
                        {
                            replacement.PutExtraHeldMushroom(daysToMature: days);
                        }

                        ++rebuiltObjectsCount;
                        Log.D($"Found a broken Propagator in {location.Name}'s objects at {key.ToString()}, rebuilding manually.",
                              Config.DebugMode);

                        location.Objects[key] = replacement;
                    }
                }

                Log.D($"Rebuilt {rebuiltItemsCount} inventory items and {rebuiltObjectsCount} world objects.");
                Data.PyTKMigration = false;
            }
        }