Ejemplo n.º 1
0
        private void HarvestAllItemsInBuilding(Building building)
        {
            var buildingInfo = new BuildingContentsInfo(building, _supportedContainerTypes);

            Common.Utility.Log($"  {buildingInfo.Containers.Count()} containers found in building.");
            Common.Utility.Log($"  Of these containers, {buildingInfo.ReadyToHarvestContainers.Count()} are ready for harvest.");
            Common.Utility.Log($"  Of these containers, {buildingInfo.ReadyToLoadContainers.Count()} are empty and ready to be loaded.");

            var buildingHandler   = new BuildingContentsHandler(buildingInfo);
            int numItemsHarvested = 0;
            int numItemsLoaded    = 0;


            //Harvest all containers in building that are ready and place contents in player's inventory.
            try
            {
                numItemsHarvested = buildingHandler.HarvestContents(Game1.player);
            }
            catch (InventoryFullException)
            {
                Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:Crop.cs.588"));
            }
            catch (Exception ex)
            {
                Common.Utility.Log($"Exception while harvesting contents in BitwiseJonMods.OneClickShedReloader.HarvestAllItemsInBuilding: {ex.Message}", LogLevel.Error);
            }

            if (numItemsHarvested > 0)
            {
                Game1.playSound("coin");
                Game1.showGlobalMessage(string.Format("Harvested {0} {1}!", numItemsHarvested, numItemsHarvested == 1 ? "item" : "items"));
            }
            else
            {
                Game1.playSound("trashcan");
                Game1.showGlobalMessage("No items harvested.");
            }


            //If player is holding an object that can go into a container in the building, load as many as possible into any empty containers in building.
            try
            {
                numItemsLoaded = buildingHandler.LoadContents(Game1.player);
            }
            catch (Exception ex)
            {
                Common.Utility.Log($"Exception while loading contents in BitwiseJonMods.OneClickShedReloader.HarvestAllItemsInBuilding: {ex.Message}", LogLevel.Error);
            }

            if (numItemsLoaded > 0)
            {
                Game1.playSound("Ship");
                Game1.showGlobalMessage(string.Format("Loaded {0} {1}!", numItemsLoaded, numItemsLoaded == 1 ? "item" : "items"));
            }
            else
            {
                Game1.playSound("trashcan");
                Game1.showGlobalMessage("No items loaded.");
            }
        }
Ejemplo n.º 2
0
        private string GetToolTipInstructions(BuildingContentsInfo buildingInfo)
        {
            string instructions = "";

            //Let's see if player is close enough to harvest/load
            var tileLocation        = GetCursorTileLocation();
            var isPlayerClose       = StardewValley.Utility.tileWithinRadiusOfPlayer((int)tileLocation.X, (int)tileLocation.Y, 4, Game1.player);
            var isPlayerHoldingItem = (Game1.player.ActiveObject != null);
            var anyItemsToHarvest   = buildingInfo.NumberReadyToHarvest > 0;
            var anyItemsToLoad      = buildingInfo.NumberReadyToLoad > 0;

            //Only show instructions if there is anything to load or harvest.
            if (anyItemsToHarvest || anyItemsToLoad)
            {
                if (!isPlayerClose)
                {
                    if (anyItemsToHarvest && anyItemsToLoad && isPlayerHoldingItem)
                    {
                        instructions = "Move closer to harvest and load items.";
                    }
                    else if (anyItemsToLoad && isPlayerHoldingItem)
                    {
                        instructions = "Move closer to load items.";
                    }
                    else if (anyItemsToHarvest)
                    {
                        instructions = "Move closer to harvest items.";
                    }
                    else if (anyItemsToLoad && !isPlayerHoldingItem)
                    {
                        instructions = "Move closer and hold an item to load.";
                    }
                }
                else
                {
                    if (anyItemsToHarvest && anyItemsToLoad && isPlayerHoldingItem)
                    {
                        instructions = "Left click to harvest and load items.";
                    }
                    else if (anyItemsToLoad && isPlayerHoldingItem)
                    {
                        instructions = "Left click to load items.";
                    }
                    else if (anyItemsToHarvest)
                    {
                        instructions = "Left click to harvest items.";
                    }
                    else if (anyItemsToLoad && !isPlayerHoldingItem)
                    {
                        instructions = "Hold an item and click to load.";
                    }
                }

                instructions = string.Format("{0}{0}{1}", Environment.NewLine, instructions);
            }

            return(instructions);
        }
Ejemplo n.º 3
0
        private void DrawHoverTooltip(object sender, RenderingHudEventArgs e)
        {
            //If the building is a supported building, show a tooltip with info about the containers inside. Make sure no menu is showing.
            if (_currentTileLocation != null && Game1.activeClickableMenu == null)
            {
                //Get info about location contents
                var buildingInfo = new BuildingContentsInfo(_currentTileLocation, _supportedContainerTypes);

                //Building instructions depending on proximity to building and if player is holding an item.
                var instructions = GetToolTipInstructions(buildingInfo);

                //Build and display tooltip
                string readyToHarvestTip = buildingInfo.NumberReadyToHarvest != buildingInfo.NumberOfItems ? string.Format("{0} ready to harvest with {1} total {2}", buildingInfo.NumberReadyToHarvest, buildingInfo.NumberOfItems, buildingInfo.NumberOfItems == 1 ? "item" : "items") : string.Format("{0} ready to harvest", buildingInfo.NumberReadyToHarvest);
                string tooltip           = string.Format("{0} total containers{1}{2}{1}{3} ready to load{4}", buildingInfo.NumberOfContainers, Environment.NewLine, readyToHarvestTip, buildingInfo.NumberReadyToLoad, instructions);
                IClickableMenu.drawHoverText(Game1.spriteBatch, tooltip, Game1.smallFont);
            }
        }
Ejemplo n.º 4
0
        private void DrawHoverTooltip(object sender, RenderingHudEventArgs e)
        {
            //If the building is a shed or barn, show a tooltip with info about the containers inside. Make sure no menu is showing.
            if (_currentTileBuilding != null && Game1.activeClickableMenu == null)
            {
                if (_supportedBuildingTypes.Any(b => _currentTileBuilding.buildingType.Contains(b)) && _currentTileBuilding.indoors.Value != null)
                {
                    //Get info about building contents
                    var buildingInfo = new BuildingContentsInfo(_currentTileBuilding, _supportedContainerTypes);

                    //Building instructions depending on proximity to building and if player is holding an item.
                    var instructions = GetToolTipInstructions(buildingInfo);

                    //Build and display tooltip
                    string tooltip = string.Format("{0} total containers{1}{2} ready to harvest{1}{3} ready to load{4}", buildingInfo.NumberOfContainers, Environment.NewLine, buildingInfo.NumberReadyToHarvest, buildingInfo.NumberReadyToLoad, instructions);
                    IClickableMenu.drawHoverText(Game1.spriteBatch, tooltip, Game1.smallFont);
                }
            }
        }
 public BuildingContentsHandler(BuildingContentsInfo buildingInfo)
 {
     _buildingInfo = buildingInfo;
 }