コード例 #1
0
ファイル: Horses.cs プロジェクト: Pathoschild/smapi-mod-dump
        public void Update(object o, object e)
        {
            var opened = unopenedChests.Where(c => c.StardewChest.mutex.IsLocked() || c.StardewChest.mutex.IsLockHeld()).ToArray();

            foreach (var l in opened)
            {
                GameLocation location             = l.Location;
                StardewValley.Objects.Chest chest = l.StardewChest;
                Vector2 tile = l.TilePosition;

                Console.WriteLine($"Opened chest, is outdoors = {location.IsOutdoors}");
                unopenedChests.Remove(l);
                if (location.IsOutdoors && Game1.random.NextDouble() <= horseChance && !l.BeenOpened)
                {
                    Console.WriteLine($"Spawning horse at {location.Name} @ ({tile.X}, {tile.Y})");

                    var horse = new StardewValley.Characters.Horse(Guid.NewGuid(), (int)tile.X, (int)tile.Y);
                    location.addCharacter(horse);
                }
                l.BeenOpened = true;
            }

            if (unopenedChests.Count == 0)
            {
                ModEntry.Events.GameLoop.UpdateTicked -= Update;
            }
        }
コード例 #2
0
 private void LogChestContents(StardewValley.Objects.Chest chest)
 {
     foreach (var item in chest.items)
     {
         this.Monitor.Log($" - {item.Stack,3} x {item.DisplayName}", LogLevel.Debug);
     }
 }
コード例 #3
0
        internal static StardewValley.Objects.Chest GetCommunityCentreFridge(StardewValley.Locations.CommunityCenter cc)
        {
            StardewValley.Objects.Chest chest = null;

            Type kitchen = Type.GetType("CommunityKitchen.Kitchen, CommunityKitchen");

            if (kitchen != null)
            {
                chest = Helper.Reflection
                        .GetMethod(type: kitchen, name: "GetKitchenFridge")
                        .Invoke <StardewValley.Objects.Chest>(cc);
            }

            return(chest);
        }
コード例 #4
0
        static void StashUp()
        {
            List <Item> PlayerInventory = Game1.player.items;

            StardewValley.Objects.Chest OpenChest = getOpenChest();

            if (OpenChest == null)
            {
                return;
            }

            if (OpenChest.isEmpty())
            {
                return;
            }

            Game1.playSound("coin");

            foreach (Item playerItem in PlayerInventory.ToArray())
            {
                if (playerItem == null)
                {
                    continue;
                }

                foreach (Item chestItem in OpenChest.items.ToArray())
                {
                    if (chestItem == null)
                    {
                        continue;
                    }

                    if (playerItem.canStackWith(chestItem))
                    {
                        if (isChestFull(OpenChest) && chestItem.getStack() + playerItem.getStack() > chestItem.maximumStackSize())
                        {
                            continue;
                        }

                        OpenChest.grabItemFromInventory(playerItem, Game1.player);
                        break;
                    }
                }
            }
        }
コード例 #5
0
        void EventUpdateTick(object sender, EventArgs e)
        {
            if (Game1.currentLocation == null)
            {
                return;
            }
            hoverChestName = null;
            if (lastMenu == null || Game1.activeClickableMenu == null || lastMenu != Game1.activeClickableMenu)
            {
                if (chestNameBox != null && Game1.keyboardDispatcher.Subscriber == chestNameBox)
                {
                    Game1.keyboardDispatcher.Subscriber = null;
                }
                labelButton      = null;
                leftClickWasDown = false;
                chestNameBox     = null;
                if (oldMenuButton != null)
                {
                    Game1.options.menuButton = oldMenuButton;
                    oldMenuButton            = null;
                }
            }
            GameLocation currentLocation = Game1.currentLocation;

            StardewValley.Objects.Chest openChest = null;

            foreach (KeyValuePair <Vector2, StardewValley.Object> keyPair in currentLocation.Objects.Pairs)
            {
                if (keyPair.Value is StardewValley.Objects.Chest)
                {
                    openChest = keyPair.Value as StardewValley.Objects.Chest;
                    if (openChest.mutex.IsLocked() && Game1.activeClickableMenu is ItemGrabMenu)
                    {
                        lastMenu = Game1.activeClickableMenu;
                        chestKey = keyPair.Key;
                        break;
                    }
                    if (openChest.getBoundingBox(keyPair.Key).Contains(Game1.getMouseX() + Game1.viewport.X, Game1.getMouseY() + Game1.viewport.Y))
                    {
                        hoverChestName = openChest.name;
                    }

                    openChest = null;
                }
            }

            if (openChest == null)
            {
                return;
            }

            if (labelButton == null)
            {
                chestNameBox       = new SpeederSDVUIUtils.TextBox(Game1.content.Load <Texture2D>("LooseSprites\\textBox"), null, Game1.smallFont, Game1.textColor);
                chestNameBox.Text  = openChest.name;
                chestNameBox.X     = lastMenu.xPositionOnScreen;
                chestNameBox.Y     = lastMenu.yPositionOnScreen + lastMenu.height - Game1.tileSize * 2;
                chestNameBox.Width = Game1.tileSize * 5;
                labelButton        = new ClickableTextureComponent("label-chest", new Rectangle(chestNameBox.X + chestNameBox.Width + Game1.tileSize / 2, chestNameBox.Y, Game1.tileSize, Game1.tileSize), "", "Label Chest", Game1.mouseCursors, new Rectangle(128, 256, 64, 64), (float)Game1.pixelZoom / 6f);
            }

            int  mouseX            = Game1.getOldMouseX();
            int  mouseY            = Game1.getOldMouseY();
            bool mouseJustReleased = false;

            if (leftClickWasDown == true && Mouse.GetState().LeftButton == ButtonState.Released)
            {
                mouseJustReleased = true;
            }

            labelButton.tryHover(mouseX, mouseY);

            Rectangle chestNameBoxBoundingBox = new Rectangle(chestNameBox.X, chestNameBox.Y, chestNameBox.Width, chestNameBox.Height);

            if (chestNameBoxBoundingBox.Contains(mouseX, mouseY))
            {
                if (Mouse.GetState().LeftButton == ButtonState.Pressed)
                {
                    leftClickWasDown = true;
                }
                else
                {
                    leftClickWasDown = false;
                }

                chestNameBox.Highlighted = true;

                if (mouseJustReleased)
                {
                    chestNameBox.SelectMe();
                    if (oldMenuButton == null)
                    {
                        oldMenuButton            = Game1.options.menuButton;
                        Game1.options.menuButton = new InputButton[] { };
                    }
                    //Game1.freezeControls = true;
                }
            }
            else if (chestNameBox.Selected == false)
            {
                chestNameBox.Highlighted = false;
            }

            if (labelButton.containsPoint(mouseX, mouseY))
            {
                if (Mouse.GetState().LeftButton == ButtonState.Pressed)
                {
                    leftClickWasDown = true;
                }
                else
                {
                    leftClickWasDown = false;
                }
                hovered = true;

                if (mouseJustReleased && chestNameBox.Selected)
                {
                    chestNameBox.Selected                  = false;
                    chestNameBox.Highlighted               = false;
                    Game1.keyboardDispatcher.Subscriber    = null;
                    currentLocation.objects[chestKey].name = chestNameBox.Text;
                    Game1.playSound("smallSelect");
                    Game1.options.menuButton = oldMenuButton;
                    oldMenuButton            = null;
                }
            }
            else
            {
                hovered = false;
            }
        }
コード例 #6
0
ファイル: ModEntry.cs プロジェクト: mjSurber/FarmHouseRedone
        internal void fixVoidObjects(FarmHouse house)
        {
            FarmHouseStates.fixObjectsOnMap(house);
            //Todo: Find all loose items and put them in a gift box
            List <Item> itemsToStore = new List <Item>();

            //for(int x = 0; x < house.map.GetLayer("Back").LayerWidth; x++)
            //{
            //    for(int y = 0; y < house.map.GetLayer("Back").LayerHeight; y++)
            //    {

            //    }
            //}
            Logger.Log("Fixing void objects...");
            Dictionary <Vector2, Vector2> replacementCoordinates = new Dictionary <Vector2, Vector2>();
            List <Vector2> deadObjects = new List <Vector2>();

            foreach (KeyValuePair <Vector2, StardewValley.Object> objectPair in house.objects.Pairs)
            {
                bool canBePlaced = isObjectSpotValid(objectPair.Value, objectPair.Key, house);
                Logger.Log("Tile blocked? " + (house.isTileOnMap(objectPair.Key) && !canBePlaced).ToString());
                if (house.isTileOnMap(objectPair.Key) && !canBePlaced)
                {
                    Logger.Log("Tile " + objectPair.Key.ToString() + " was not placeable!  Moving object...");
                    Point newSpot  = house.getRandomOpenPointInHouse(Game1.random);
                    int   attempts = 0;
                    while ((newSpot == Point.Zero || !objectPair.Value.canBePlacedHere(house, new Vector2(newSpot.X, newSpot.Y))) && attempts < 20)
                    {
                        newSpot = house.getRandomOpenPointInHouse(Game1.random);
                        attempts++;
                        Logger.Log("Failed to find empty open spot in the farmhouse for an object.  Attempt #" + attempts);
                    }
                    Logger.Log("Finished selecting spots.");
                    if (newSpot == Point.Zero)
                    {
                        Logger.Log("Could not find a suitable location for an object.  Storing it in a gift box.");
                        if (objectPair.Value is StardewValley.Objects.Chest)
                        {
                            StardewValley.Objects.Chest chest = (objectPair.Value as StardewValley.Objects.Chest);
                            Logger.Log("Object to be stored is a chest, so the contents will be stored separately.");
                            foreach (Item item in chest.items)
                            {
                                itemsToStore.Add(item);
                            }
                        }
                        itemsToStore.Add(objectPair.Value);
                        deadObjects.Add(objectPair.Key);
                    }
                    else
                    {
                        Vector2 tileLocation = new Vector2(newSpot.X, newSpot.Y);
                        replacementCoordinates[tileLocation] = objectPair.Key;
                        objectPair.Value.tileLocation.Value  = tileLocation;
                        deadObjects.Add(objectPair.Key);
                        Logger.Log("Placing object at " + tileLocation.ToString());
                    }
                }
                else
                {
                    Logger.Log("Skipping " + objectPair.Key.ToString() + " because it " + (house.isTileOnMap(objectPair.Key) ? "was on the map, and " : "was not on the map, and ") + (!canBePlaced ? "was not placeable." : "was placeable."));
                }
            }
            foreach (KeyValuePair <Vector2, Vector2> replacementPair in replacementCoordinates)
            {
                if (!house.objects.ContainsKey(replacementPair.Key))
                {
                    house.objects.Add(replacementPair.Key, house.objects[replacementPair.Value]);
                }
            }
            foreach (Vector2 deadObject in deadObjects)
            {
                house.objects.Remove(deadObject);
            }

            List <StardewValley.Objects.Furniture> deadFurniture = new List <StardewValley.Objects.Furniture>();

            foreach (StardewValley.Objects.Furniture furniture in house.furniture)
            {
                bool canBePlaced = isFurnitureSpotValid(furniture, house);
                Logger.Log("Tile blocked? " + (!house.isTileOnMap(furniture.tileLocation) || !canBePlaced).ToString());
                fixFurniture(furniture, house, ref deadFurniture, ref itemsToStore);
            }
            foreach (StardewValley.Objects.Furniture furniture in deadFurniture)
            {
                house.furniture.Remove(furniture);
            }

            Point chestSpot = house.getRandomOpenPointInHouse(Game1.random);

            StardewValley.Objects.Chest giftBox = new StardewValley.Objects.Chest(0, itemsToStore, new Vector2(chestSpot.X, chestSpot.Y), true);
        }
コード例 #7
0
        internal void fixVoidObjects(FarmHouse house)
        {
            //Todo: Find all loose items and put them in a gift box
            List <Item> itemsToStore = new List <Item>();

            //for(int x = 0; x < house.map.GetLayer("Back").LayerWidth; x++)
            //{
            //    for(int y = 0; y < house.map.GetLayer("Back").LayerHeight; y++)
            //    {

            //    }
            //}
            Logger.Log("Fixing void objects...");
            Dictionary <Vector2, Vector2> replacementCoordinates = new Dictionary <Vector2, Vector2>();
            List <Vector2> deadObjects = new List <Vector2>();

            foreach (KeyValuePair <Vector2, StardewValley.Object> objectPair in house.objects.Pairs)
            {
                bool canBePlaced = isObjectSpotValid(objectPair.Value, objectPair.Key, house);
                Logger.Log("Tile blocked? " + (house.isTileOnMap(objectPair.Key) && !canBePlaced).ToString());
                if (house.isTileOnMap(objectPair.Key) && !canBePlaced)
                {
                    Logger.Log("Tile " + objectPair.Key.ToString() + " was not placeable!  Moving object...");
                    Point newSpot  = house.getRandomOpenPointInHouse(Game1.random);
                    int   attempts = 0;
                    while ((newSpot == Point.Zero || !objectPair.Value.canBePlacedHere(house, new Vector2(newSpot.X, newSpot.Y))) && attempts < 20)
                    {
                        newSpot = house.getRandomOpenPointInHouse(Game1.random);
                        attempts++;
                        Logger.Log("Failed to find empty open spot in the farmhouse for an object.  Attempt #" + attempts);
                    }
                    Logger.Log("Finished selecting spots.");
                    if (newSpot == Point.Zero)
                    {
                        Logger.Log("Could not find a suitable location for an object.  Storing it in a gift box.");
                        if (objectPair.Value is StardewValley.Objects.Chest)
                        {
                            StardewValley.Objects.Chest chest = (objectPair.Value as StardewValley.Objects.Chest);
                            Logger.Log("Object to be stored is a chest, so the contents will be stored separately.");
                            foreach (Item item in chest.items)
                            {
                                itemsToStore.Add(item);
                            }
                        }
                        itemsToStore.Add(objectPair.Value);
                        deadObjects.Add(objectPair.Key);
                    }
                    else
                    {
                        Vector2 tileLocation = new Vector2(newSpot.X, newSpot.Y);
                        replacementCoordinates[tileLocation] = objectPair.Key;
                        objectPair.Value.tileLocation.Value  = tileLocation;
                        deadObjects.Add(objectPair.Key);
                        Logger.Log("Placing object at " + tileLocation.ToString());
                    }
                }
                else
                {
                    Logger.Log("Skipping " + objectPair.Key.ToString() + " because it " + (house.isTileOnMap(objectPair.Key) ? "was on the map, and " : "was not on the map, and ") + (!canBePlaced ? "was not placeable." : "was placeable."));
                }
            }
            foreach (KeyValuePair <Vector2, Vector2> replacementPair in replacementCoordinates)
            {
                if (!house.objects.ContainsKey(replacementPair.Key))
                {
                    house.objects.Add(replacementPair.Key, house.objects[replacementPair.Value]);
                }
            }
            foreach (Vector2 deadObject in deadObjects)
            {
                house.objects.Remove(deadObject);
            }

            List <StardewValley.Objects.Furniture> deadFurniture = new List <StardewValley.Objects.Furniture>();

            foreach (StardewValley.Objects.Furniture furniture in house.furniture)
            {
                bool canBePlaced = isFurnitureSpotValid(furniture, house);
                Logger.Log("Tile blocked? " + (!house.isTileOnMap(furniture.tileLocation) || !canBePlaced).ToString());
                if (house.isTileOnMap(furniture.tileLocation) && (furniture.furniture_type == StardewValley.Objects.Furniture.window || furniture.furniture_type == StardewValley.Objects.Furniture.painting))
                {
                    bool wasOnWall = false;
                    foreach (Rectangle wall in house.getWalls())
                    {
                        if (wall.Contains(new Point((int)furniture.tileLocation.X, (int)furniture.tileLocation.Y)))
                        {
                            wasOnWall = true;
                            break;
                        }
                    }
                    if (!wasOnWall)
                    {
                        Logger.Log("Wall furniture was not on a wall!  Moving...");
                        List <Rectangle> walls = house.getWalls();
                        int     wallToPlace    = Game1.random.Next(walls.Count);
                        Vector2 placeSpot      = Vector2.Zero;
                        int     attempts       = 0;
                        while (placeSpot == Vector2.Zero && attempts < 20)
                        {
                            int     wallX    = Game1.random.Next(walls[wallToPlace].Width) + walls[wallToPlace].X;
                            Vector2 testSpot = new Vector2(wallX, walls[wallToPlace].Y);
                            if (!house.isTileOccupiedForPlacement(testSpot, furniture))
                            {
                                placeSpot = testSpot;
                            }
                            attempts++;
                            Logger.Log("Suitable wall location not found!  Trying again...  Attempt #" + attempts);
                        }
                        if (placeSpot == Vector2.Zero)
                        {
                            Logger.Log("Could not find a suitable location for a piece of furniture.  Storing it in a gift box.");
                            itemsToStore.Add(furniture);
                            deadFurniture.Add(furniture);
                        }
                        else
                        {
                            furniture.tileLocation.Value = new Vector2(placeSpot.X, placeSpot.Y);
                            reclaculateFurniture(furniture);
                            Logger.Log("Placing furniture at " + furniture.tileLocation.ToString());
                        }
                    }
                }
                else if (!house.isTileOnMap(furniture.tileLocation) || !canBePlaced)
                {
                    Logger.Log("Furniture was stuck, moving...");
                    Point newSpot  = house.getRandomOpenPointInHouse(Game1.random);
                    int   attempts = 0;
                    while ((newSpot == Point.Zero || !furniture.canBePlacedHere(house, new Vector2(newSpot.X, newSpot.Y)) || !isCompletelyClear(furniture, new Vector2(newSpot.X, newSpot.Y), house) || (furniture.furniture_type == StardewValley.Objects.Furniture.window)) && attempts < 20)
                    {
                        newSpot = house.getRandomOpenPointInHouse(Game1.random);
                        attempts++;
                        Logger.Log("Failed to find empty open spot in the farmhouse for a piece of furniture.  Attempt #" + attempts);
                    }
                    if (newSpot == Point.Zero)
                    {
                        Logger.Log("Could not find a suitable location for a piece of furniture.  Storing it in a gift box.");
                        itemsToStore.Add(furniture);
                        deadFurniture.Add(furniture);
                    }
                    else
                    {
                        furniture.tileLocation.Value = new Vector2(newSpot.X, newSpot.Y);
                        reclaculateFurniture(furniture);
                        Logger.Log("Placing furniture at " + furniture.tileLocation.ToString());
                    }
                }
                else
                {
                    Logger.Log("Skipping " + furniture.tileLocation.ToString() + " because it " + (house.isTileOnMap(furniture.tileLocation) ? "was on the map, and " : "was not on the map, and ") + (!canBePlaced ? "was not placeable." : "was placeable."));
                }
            }
            foreach (StardewValley.Objects.Furniture furniture in deadFurniture)
            {
                house.furniture.Remove(furniture);
            }

            Point chestSpot = house.getRandomOpenPointInHouse(Game1.random);

            StardewValley.Objects.Chest giftBox = new StardewValley.Objects.Chest(0, itemsToStore, new Vector2(chestSpot.X, chestSpot.Y), true);
        }
コード例 #8
0
 static bool isChestFull(StardewValley.Objects.Chest inputChest)
 {
     return(inputChest.items.Count >= StardewValley.Objects.Chest.capacity);
 }