Esempio n. 1
0
        private void DogSpawn(StardewValley.Characters.Pet thePet = null, NPC theNPC = null)
        {
            // Spawn gift

            // Remove old gift if there's still one on the floor
            OverlaidDictionary obs      = Game1.getLocationFromName("Farm").Objects;
            Vector2            spawnPos = new Vector2(tile.X, tile.Y);

            for (int i = 0; i < obs.Count(); i++)
            {
                Vector2 currentPos = obs.Keys.ElementAt(i);

                if (currentPos == spawnPos)
                {
                    obs.Remove(obs.Keys.ElementAt(i));
                }
            }

            Game1.getLocationFromName("Farm").dropObject(new StardewValley.Object(giftId, 1, false, -1, 0), spawnPos * 64f, Game1.viewport, true, (Farmer)null);
            //this.Monitor.Log("Object dropped!");

            // Convert drop location to dirt (if we would do this beforehand, spawn would be impeded)
            Game1.getLocationFromName("Farm").terrainFeatures[tile] = new HoeDirt();

            // Warp dog
            Vector2 warpPos = this.FindSafePosition(tile);

            // If we find a safe location near the treasure, warp the pet
            if (warpPos != tile)
            {
                if (theNPC == null)
                {
                    thePet.Position = warpPos * 64f;
                }
                else if (thePet == null)
                {
                    theNPC.Position = warpPos * 64f;
                }
            }

            this.Monitor.Log("Warped him ... most likely, to " + warpPos.X + "/" + warpPos.Y);
            warpedToday = true;

            Game1.playSound("dog_bark");
        }
Esempio n. 2
0
        // If the cat gave a gift, warp him next to it the first time the player enters the farm
        public void Warped(object sender, EventArgs e)
        {
            if (Game1.currentLocation is Farm && giftToday && !warpedToday)
            {
                foreach (NPC pet in Game1.getLocationFromName("Farm").getCharacters())
                {
                    if (pet is StardewValley.Characters.Cat || pet is StardewValley.Characters.Dog)
                    {
                        //this.Monitor.Log("Found pet for warping.");
                        thePet = (StardewValley.Characters.Pet)pet;
                    }
                }

                if (thePet != null)
                {
                    if (thePet is StardewValley.Characters.Cat)
                    {
                        // Have a chance of Dusty digging up something instead of the cat
                        if (Game1.currentLocation.characters.Contains(Game1.getCharacterFromName("Dusty", true)) && Game1.random.Next(1, 10) > 8)
                        {
                            this.DogSpawn(null, Game1.getCharacterFromName("Dusty", true));
                        }
                        else
                        {
                            int x = (int)Game1.player.Position.X / 64;
                            int y = (int)Game1.player.Position.Y / 64;

                            // Spawn gift

                            // Remove old gift if there's still one on the floor
                            OverlaidDictionary obs      = Game1.getLocationFromName("Farm").Objects;
                            Vector2            spawnPos = new Vector2(x, y + 1);

                            for (int i = 0; i < obs.Count(); i++)
                            {
                                Vector2 currentPos = obs.Keys.ElementAt(i);

                                if (currentPos == spawnPos)
                                {
                                    obs.Remove(obs.Keys.ElementAt(i));
                                }
                            }

                            Game1.getLocationFromName("Farm").dropObject(new StardewValley.Object(giftId, 1, false, -1, 0), spawnPos * 64f, Game1.viewport, true, (Farmer)null);

                            // Warp cat
                            // Check if field is free
                            Vector2 warpPos = new Vector2(x + 1, y + 2);
                            Vector2 safePos = new Vector2(x + 1, y + 2);

                            // If field is free, warp cat there
                            if (Game1.getLocationFromName("Farm").isTileLocationTotallyClearAndPlaceableIgnoreFloors(warpPos))
                            {
                                //this.Monitor.Log(warpPos.X + "/" + warpPos.Y + " is free, warping cat there");
                                thePet.Position = warpPos * 64f;
                            }
                            else
                            {
                                // Otherwise, find a nearby free location. If we find one, warp the cat there. Otherwise, just don't warp.
                                safePos = this.FindSafePosition(warpPos);
                                if (safePos != warpPos)
                                {
                                    thePet.Position = safePos * 64f;
                                }
                            }

                            // this.Monitor.Log("Warped him.");
                            warpedToday = true;

                            Game1.playSound("cat");
                        }
                    }

                    if (thePet is StardewValley.Characters.Dog)
                    {
                        // Have a chance of Dusty digging something up instead of the dog
                        if (Game1.currentLocation.characters.Contains(Game1.getCharacterFromName("Dusty", true)) && Game1.random.Next(1, 10) > 8)
                        {
                            this.DogSpawn(null, Game1.getCharacterFromName("Dusty", true));
                        }
                        else
                        {
                            this.DogSpawn(thePet, null);
                        }
                    }

                    String dog = "";

                    if (thePet is StardewValley.Characters.Dog)
                    {
                        dog   = " Search your farm carefully to find it!";
                        isCat = false;
                    }

                    msgDisplayed = true;
                    Helper.Content.InvalidateCache(@"LooseSprites\Cursors.xnb");
                    HUDMessage msg = new HUDMessage(thePet.Name + " brought you a gift." + dog, 1);
                    Game1.addHUDMessage(msg);
                }
                //else
                //this.Monitor.Log("Didn't find the pet.");
            }
        }