예제 #1
0
        private void GameLoop_TimeChanged(object sender, StardewModdingAPI.Events.TimeChangedEventArgs e)
        {
            if (Game1.currentLocation != null && Game1.currentLocation is Farm f)
            {
                foreach (var v in f.buildings)
                {
                    if (v is FishPond fp)
                    {
                        if (Game1.random.NextDouble() <= ModConfig.JumpChance)
                        {
                            NetEvent0 animateHappyFishEvent = this.Helper.Reflection
                                                              .GetField <NetEvent0>(fp, "animateHappyFishEvent").GetValue();
                            animateHappyFishEvent.Fire();
                        }
                    }
                }
            }

            if (Game1.currentLocation != null && Game1.currentLocation.IsOutdoors && _validFishLocations.Count >= ModConfig.NumberOfJumpingFish)
            {
                //get fish
                Dictionary <int, int> fishLocation = SDVUtilities.GetFishListing(Game1.currentLocation);

                if (fishLocation.Keys.Count <= 0)
                {
                    return;
                }

                //legendaries!
                List <int> legendaryFishAdded = new List <int>();
                if (ModConfig.LegendariesJumpAfterCatch)
                {
                    switch (Game1.currentLocation.Name)
                    {
                    case "ExteriorMuseum":
                        foreach (var v in Game1.objectInformation)
                        {
                            if (v.Value.Split('/')[0] == "Pufferchick" && Game1.player.fishCaught.ContainsKey(v.Key))
                            {
                                legendaryFishAdded.Add(v.Key);
                                fishLocation.Add(v.Key, -1);
                            }
                        }
                        break;

                    case "Mountain":
                        if (Game1.currentSeason == "spring" && Game1.player.fishCaught.ContainsKey(163))
                        {
                            legendaryFishAdded.Add(163);
                            fishLocation.Add(163, -1);
                        }
                        break;

                    case "Beach":
                        if (Game1.currentSeason == "summer" && Game1.player.fishCaught.ContainsKey(159))
                        {
                            legendaryFishAdded.Add(159);
                            fishLocation.Add(159, -1);
                        }
                        break;

                    case "Forest":
                        if (Game1.currentSeason == "winter" && Game1.player.fishCaught.ContainsKey(775))
                        {
                            legendaryFishAdded.Add(775);
                            fishLocation.Add(775, 0);
                        }
                        break;

                    case "Town":
                        if (Game1.currentSeason == "fall" && Game1.player.fishCaught.ContainsKey(160))
                        {
                            fishLocation.Add(160, -1);
                        }
                        break;

                    case "Sewer":
                        if (Game1.player.fishCaught.ContainsKey(682))
                        {
                            fishLocation.Add(682, -1);
                        }
                        break;
                    }
                }

                int[]     fishIDs   = fishLocation.Keys.ToArray();
                Vector2[] validLocs = _validFishLocations.Keys.ToArray();

                for (int i = 0; i < ModConfig.NumberOfJumpingFish; i++)
                {
                    if (Game1.random.NextDouble() > ModConfig.JumpChance)
                    {
                        continue;
                    }

                    int rndFish = Game1.random.Next(0, fishIDs.Count() - 1);

                    if (legendaryFishAdded.Contains(rndFish) && Game1.random.NextDouble() < ModConfig.LegendaryJumpChance)
                    {
                        int loopCheck = 0;
                        do
                        {
                            rndFish = Game1.random.Next(0, fishIDs.Count() - 1);
                            i++;
                        } while (legendaryFishAdded.Contains(rndFish) && loopCheck < 12000);
                    }

                    int rndLoc = Game1.random.Next(0, validLocs.Count() - 1);
                    if (fishLocation[fishIDs[rndFish]] == -1 ||
                        fishLocation[fishIDs[rndFish]] == _validFishLocations[validLocs[rndLoc]] && rndFish != 0)
                    {
                        StardewValley.Object fish = new StardewValley.Object(fishIDs[rndFish], 1, false, -1, 0);
                        var startPosition         = validLocs[rndLoc];
                        var endPosition           = new Vector2(startPosition.X + 1.5f, startPosition.Y + 1.5f);
                        if (ValidFishForJumping(fish.ParentSheetIndex))
                        {
                            this._jumpingFish.Add(new JumpFish(fish, startPosition * Game1.tileSize,
                                                               endPosition * Game1.tileSize));
                        }
                    }
                }
            }
        }