// TODO I think you currently make the players invisible if they are not participating

        public static void setUpFestivalMainEvent_Kelly(StardewValley.Event __instance)
        {
            try
            {
                // using the default condition for the method
                if (Monitor is null || __instance is null || !__instance.isSpecificFestival("spring24"))
                {
                    return;
                }

                isMalePosition = true;
                string[] eventCommands = __instance.eventCommands;

                for (int i = 0; i < eventCommands.Length; i++)
                {
                    string curr = eventCommands[i];

                    if (!curr.Contains("farmer"))
                    {
                        continue;
                    }

                    curr             = fixFarmerDance(curr);
                    eventCommands[i] = curr;
                }

                if (!isMalePosition)                // Make the farmer (if they are in the female position) do a final pose with their arms in the air
                {
                    string   farmerFinalPose  = "showFrame 96";
                    string[] newEventCommands = new string[eventCommands.Length + 1];

                    for (int i = 0; i < newEventCommands.Length; i++)
                    {
                        if (i < 291)
                        {
                            newEventCommands[i] = eventCommands[i];
                        }

                        else if (i == 291)
                        {
                            newEventCommands[i] = farmerFinalPose;
                        }

                        else
                        {
                            newEventCommands[i] = eventCommands[i - 1];
                        }
                    }

                    __instance.eventCommands = newEventCommands;
                }
            }
            catch (Exception e)
            {
                Monitor.Log($"Failed in {nameof(EventPatched)}:\n{e}", LogLevel.Error);
            }
        }
Example #2
0
        public static void setUpFestivalMainEvent_Kelly(StardewValley.Event __instance)
        {
            try
            {
                Monitor.Log("Successfully loaded setUpFesticalMainEvent_Kelly", LogLevel.Alert);
            }

            catch (Exception e)
            {
                Monitor.Log("Failed to load setUpFesticalMainEvent_Kelly", LogLevel.Alert);
            }
        }
 private IEnumerable <Character> GetLocationCharacters(GameLocation location, Event currentEvent = null)
 {
     if (location is AnimalHouse)
     {
         return((location as AnimalHouse).animals.Values
                .Cast <Character>()
                .Union(location.getCharacters())
                .Union(location.farmers.Cast <Character>()));
     }
     if (currentEvent != null && Config.displayTooltipDuringEvent)
     {
         return(currentEvent.actors
                .Cast <Character>()
                .Union(currentEvent.farmerActors.Cast <Character>()));
     }
     return(location.getCharacters()
            .Cast <Character>()
            .Union(location.farmers.Cast <Character>()));
 }
Example #4
0
 //3 hours of trying and tears :c
 internal static void StartEvent(StardewValley.Event EventObj, string locationName, int x, int y)
 {
     if (Game1.currentLocation.Name.Equals(locationName))
     {
         Game1.delayedActions.Add(new DelayedAction(500, delegate
         {
             Game1.currentLocation.startEvent(EventObj);
         }));
         Game1.fadeScreenToBlack();
     }
     else
     {
         LocationRequest warpRequest = Game1.getLocationRequest(locationName);
         warpRequest.OnLoad += delegate
         {
             Game1.currentLocation.currentEvent = EventObj;
         };
         Game1.warpFarmer(warpRequest, x, y, Game1.player.FacingDirection);
     }
 }
Example #5
0
        public static void setUpFestivalMainEvent_FDF(StardewValley.Event __instance)
        {
            {
                if (Monitor is null || __instance is null || !__instance.isSpecificFestival("spring24"))
                {
                    return;
                }
                try
                {
                    /*
                     * //Reflection to access protected Game1.Multiplayer
                     * Multiplayer multiplayer = Helper.Reflection.GetField<Multiplayer>(typeof(Game1), "multiplayer").GetValue();
                     */
                    //Sets up random number generation for later use
                    Random rnd  = new Random();
                    Random rnd2 = new Random();

                    //Sets up lists for pair generation
                    List <NetDancePartner> females = new List <NetDancePartner>();
                    List <NetDancePartner> males   = new List <NetDancePartner>();

                    List <string> leftoverFemales = new List <string>();
                    List <string> leftoverMales   = new List <string>();

                    List <NPC> charList = new List <NPC>();
                    Utility.getAllCharacters(charList);

                    //Populates "leftoverGender" lists with all datable NPCs of each respective gender for selection, configurable switch for nonbinary characters
                    foreach (NPC character in charList)
                    {
                        if (character.datable.Equals(true) && character.Age != 2)
                        {
                            int intgender = character.Gender;

                            Monitor.Log($"{character.name}'s gender is evaluated as {intgender}.", LogLevel.Trace);

                            switch (intgender)
                            {
                            case 0:
                                leftoverMales.Add(character.Name);
                                Monitor.Log($"Successfully added {character.Name} to leftoverMales dancer pool.", LogLevel.Trace);
                                break;

                            case 1:
                                leftoverFemales.Add(character.Name);
                                Monitor.Log($"Successfully added {character.Name} to leftoverFemales dancer pool.", LogLevel.Trace);
                                break;

                            case 2:
                                if (Config.AllowNonBinaryPartners.Equals(true))
                                {
                                    try
                                    {
                                        //check to see if nonbinary dance partner has custom FDF sprites
                                        //load custom FDF sprites if available

                                        //add nonbinary partner to random leftoverGender list

                                        // int g = rnd.Next(1);
                                        // if (g == 0)
                                        // {
                                        //     leftoverMales.Add(character.Name);
                                        //     Monitor.Log("Successfully added nonbinary NPC " + character.Name + " randomly to leftoverMales dancer pool.", LogLevel.Trace);
                                        // }
                                        // else
                                        // {
                                        //     leftoverFemales.Add(character.Name);
                                        //     Monitor.Log("Successfully added nonbinary NPC " + character.Name + " randomly to leftoverFemales dancer pool.", LogLevel.Trace);
                                        // }

                                        break;
                                    }
                                    catch (Exception)
                                    {
                                        Monitor.Log($"Failed to find custom FDF sprites for {character.Name} and cannot add that NPC to dancer pools.", LogLevel.Debug);
                                        continue;
                                    }
                                }
                                else
                                {
                                    Monitor.Log($"Failed to add nonbinary NPC {character.Name} to a leftoverGender dancer pool due to config- AllowNonBinaryPartners = false.", LogLevel.Debug);
                                    break;
                                }
                            }
                            continue;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    Monitor.Log("Finished adding NPCs to leftoverGender dancer pools.", LogLevel.Debug);

                    //Removes blacklisted datables from "leftoverGender" lists based on config
                    if (String.IsNullOrEmpty(Config.DancerBlackList).Equals(false))
                    {
                        try
                        {
                            List <string> blackList = new List <string>(Config.DancerBlackList.Split('/').ToList());

                            IEnumerable <string> toRemoveMale = blackList.Intersect(leftoverMales);
                            foreach (string k in toRemoveMale.ToList())
                            {
                                leftoverMales.Remove(k);
                                blackList.Remove(k);
                                Monitor.Log($"Successfully removed blacklisted NPC {k} from dancer pool.", LogLevel.Trace);
                            }

                            IEnumerable <string> toRemoveFemale = blackList.Intersect(leftoverFemales);
                            foreach (string j in toRemoveFemale.ToList())
                            {
                                leftoverFemales.Remove(j);
                                blackList.Remove(j);
                                Monitor.Log($"Successfully removed blacklisted NPC {j} from dancer pool.", LogLevel.Trace);
                            }

                            //Logs blacklisting activity to monitor
                            if (blackList.Any().Equals(false))
                            {
                                Monitor.Log("Successfully removed all blacklisted NPCs from dancer pool.", LogLevel.Trace);
                            }
                            else
                            {
                                string blackListError = string.Join(", ", blackList);
                                Monitor.Log($"Failed to remove the following blacklisted NPCs from dancer pool: {blackListError}. Please check that NPCs are referenced by key, and seperated by a single forward slash.", LogLevel.Debug);
                            }
                        }
                        catch (Exception)
                        {
                            Monitor.Log("Flower Dance Fix failed to parse dancer blacklist. Please check that NPCs are referenced by key, and seperated by a single forward slash.", LogLevel.Debug);
                        }
                    }

                    //Prevents selection of tourist datable characters based on config
                    if (Config.AllowTouristPartners.Equals(false))
                    {
                        foreach (NPC character in charList)
                        {
                            if (character.datable.Equals(true) && !character.homeRegion.Equals(2))
                            {
                                int intgender = character.Gender;
                                switch (intgender)
                                {
                                case 0:
                                    leftoverMales.Remove(character.Name);
                                    Monitor.Log($"Successfully removed tourist NPC {character.Name} from leftoverMales dancer pool. Configurable by AllowTouristPartners.", LogLevel.Trace);
                                    break;

                                case 1:
                                    leftoverFemales.Remove(character.Name);
                                    Monitor.Log($"Successfully removed tourist NPC {character.Name} from leftoverFemales dancer pool. Configurable by AllowTouristPartners.", LogLevel.Alert);
                                    break;

                                case 2:
                                    if (Config.AllowNonBinaryPartners.Equals(true))
                                    {
                                        break;
                                    }
                                    break;
                                }
                            }
                        }
                    }

                    //Adds farmer-farmer and farmer-NPC pairs to dancelist- vanilla code
                    List <Farmer> farmers = (from f in Game1.getOnlineFarmers()
                                             orderby f.UniqueMultiplayerID
                                             select f).ToList();
                    while (farmers.Count > 0)
                    {
                        Farmer f2 = farmers[0];
                        farmers.RemoveAt(0);

                        /*
                         * if (multiplayer.isDisconnecting(f2) || f2.dancePartner.Value == null)
                         * {
                         *  continue;
                         * }
                         */

                        if (f2.dancePartner.GetGender() == 1)
                        {
                            females.Add(f2.dancePartner);
                            if (f2.dancePartner.IsVillager())
                            {
                                leftoverFemales.Remove(f2.dancePartner.TryGetVillager().Name);
                            }
                            males.Add(new NetDancePartner(f2));

                            Monitor.Log($"Made a pair of farmer {f2.displayName} and NPC {f2.dancePartner} and successfully entered pair into NetDancePartner.", LogLevel.Trace);
                        }
                        else if (f2.dancePartner.GetGender() == 0)
                        {
                            males.Add(f2.dancePartner);
                            if (f2.dancePartner.IsVillager())
                            {
                                leftoverMales.Remove(f2.dancePartner.TryGetVillager().Name);
                            }
                            females.Add(new NetDancePartner(f2));

                            Monitor.Log($"Made a pair of farmer {f2.displayName} and NPC {f2.dancePartner} and successfully entered pair into NetDancePartner.", LogLevel.Trace);
                        }
                        else if (f2.dancePartner.IsFarmer())
                        {
                            farmers.Remove(f2.dancePartner.TryGetFarmer());

                            Monitor.Log($"Made a pair of farmer {f2.displayName} and farmer {f2.dancePartner.TryGetFarmer()} and successfully entered pair into NetDancePartner.", LogLevel.Trace);
                        }
                        else
                        {
                            Monitor.Log($"Did not add farmer {f2.displayName} to NetDancePairs because they did not have a partner.", LogLevel.Trace);
                        }
                    }

                    //Generates NPC-NPC pairs
                    while ((females.Count < Config.MaxDancePairs) && leftoverFemales.Any() && leftoverMales.Any())
                    {
                        int    rF     = rnd.Next(leftoverFemales.Count);
                        string female = leftoverFemales[rF];

                        //Random pair generation- config moderated
                        if (Config.NPCsHaveRandomPartners.Equals(true))
                        {
                            try
                            {
                                int    r          = rnd.Next(leftoverMales.Count);
                                string randomMale = leftoverMales[r];

                                females.Add(new NetDancePartner(female));
                                males.Add(new NetDancePartner(randomMale));

                                leftoverFemales.Remove(female);
                                leftoverMales.Remove(randomMale);

                                Monitor.Log($"Randomly made a pair with {female} and {randomMale} and successfully entered pair into NetDancePartner.", LogLevel.Debug);
                            }
                            catch (Exception)
                            {
                                Monitor.Log("Failed to fill NetDancePartner with random M-F pairs.", LogLevel.Debug);
                                break;
                            }
                        }
                        //"Love Interest" pair generation, followed by random pair generation for any remainders
                        else
                        {
                            if (hasVanillaLoveInterest(female).Equals(true) && getCustomLoveInterest(female) != null && Utility.getLoveInterest(female).Equals(getCustomLoveInterest(female)) && leftoverMales.Contains(getCustomLoveInterest(female)))
                            {
                                string loveInterestMale = Utility.getLoveInterest(female);

                                females.Add(new NetDancePartner(female));
                                males.Add(new NetDancePartner(loveInterestMale));
                                leftoverMales.Remove(loveInterestMale);
                                leftoverFemales.Remove(female);

                                Monitor.Log($"Used vanilla \"Love Interest\" method to make a pair with {female} and {loveInterestMale} and successfully entered pair into NetDancePartner.", LogLevel.Debug);
                            }
                            else if (getCustomLoveInterest(female) != null && leftoverMales.Contains(getCustomLoveInterest(female)))
                            {
                                string loveInterestMale = getCustomLoveInterest(female);

                                females.Add(new NetDancePartner(female));
                                males.Add(new NetDancePartner(loveInterestMale));
                                leftoverFemales.Remove(female);
                                leftoverMales.Remove(loveInterestMale);
                                Monitor.Log($"Used custom \"Love Interest\" method to make a pair with {female} and {loveInterestMale} and successfully entered pair into NetDancePartner.", LogLevel.Debug);
                            }
                            else
                            {
                                int    rM         = rnd.Next(leftoverMales.Count);
                                string randomMale = leftoverMales[rM];

                                if (leftoverFemales.Contains(getCustomLoveInterest(randomMale)) && female != getCustomLoveInterest(randomMale))
                                {
                                    Monitor.Log($"Could not make a random pair of {female} and {randomMale} because {randomMale} has a valid love interest partner available for selection. {female} will be shuffled back into selection pool.", LogLevel.Trace);
                                    continue;
                                }
                                else
                                {
                                    females.Add(new NetDancePartner(female));
                                    males.Add(new NetDancePartner(randomMale));

                                    leftoverFemales.Remove(female);
                                    leftoverMales.Remove(randomMale);

                                    Monitor.Log($"Randomly made a pair with {female} and {randomMale} and successfully entered pair into NetDancePartner.", LogLevel.Debug);
                                }
                            }
                        }
                    }

                    if (leftoverFemales.Any())
                    {
                        string unselectedLOFemales = String.Join(", ", leftoverFemales);
                        Monitor.Log($"After pair generation, leftoverFemales contains the following NPCs not selected for dance: {unselectedLOFemales}", LogLevel.Trace);
                    }

                    if (leftoverMales.Any())
                    {
                        string unselectedLOMales = String.Join(", ", leftoverMales);
                        Monitor.Log($"After pair generation, leftoverMales contains the following NPCs not selected for dance: {unselectedLOMales}", LogLevel.Trace);
                    }


                    //Generates spring24.json "mainEvent" value
                    string rawFestivalData = "";
                    try
                    {
                        StringBuilder buildFestivalData = new StringBuilder();

                        buildFestivalData.Append("pause 500/playMusic none/pause 500/globalFade/viewport -1000 -1000/loadActors MainEvent/warp farmer1 5 21/warp farmer2 11 21/warp farmer3 23 21/warp farmer4 12 21/faceDirection farmer1 2/faceDirection farmer3 2/faceDirection farmer4 2/faceDirection farmer 2");
                        buildFestivalData.Append(CustomDance.BuildEventWarpBlock(females));
                        buildFestivalData.Append(CustomDance.BuildShowFrameBlock(females));
                        buildFestivalData.Append("/viewport 14 25 clamp true/pause 2000/playMusic FlowerDance/pause 600");
                        buildFestivalData.Append(CustomDance.BuildAnimateBlock1(females));
                        buildFestivalData.Append(CustomDance.BuildAnimateBlock2(females));
                        buildFestivalData.Append("/pause 9600");
                        buildFestivalData.Append(CustomDance.BuildGiantOffsetBlock(females));
                        buildFestivalData.Append(CustomDance.BuildAnimateBlock3(females));
                        buildFestivalData.Append("/pause 7600");
                        buildFestivalData.Append(CustomDance.BuildStopAnimationBlock(females));
                        buildFestivalData.Append("/pause 3000/globalFade/viewport -1000 -1000/message \"That was fun! Time to go home...\"/waitForOtherPlayers festivalEnd/end");

                        rawFestivalData = buildFestivalData.ToString();
                    }
                    catch (Exception e)
                    {
                        Monitor.Log("Failed to generate a custom Flower Dance template- reverting to vanilla Flower Dance Template. Exception: " + e, LogLevel.Debug);
                        rawFestivalData = __instance.GetFestivalDataForYear("mainEvent");
                    }

                    Monitor.Log(rawFestivalData, LogLevel.Trace);

                    int i = 1;

                    while (i <= Config.MaxDancePairs && i <= females.Count())
                    {
                        string female2 = ((females[i - 1].IsVillager()) ? ("farmer" + Utility.getFarmerNumberFromFarmer(females[i - 1].TryGetFarmer())) : females[i - 1].TryGetVillager().Name);
                        string male    = ((males[i - 1].IsVillager()) ? ("farmer" + Utility.getFarmerNumberFromFarmer(males[i - 1].TryGetFarmer())) : males[i - 1].TryGetVillager().Name);
                        rawFestivalData = rawFestivalData.Replace("Girl" + (i), female2);
                        rawFestivalData = rawFestivalData.Replace("Guy" + (i), male);
                        i++;
                    }

                    Regex regex          = new Regex("showFrame (?<farmerName>farmer\\d) 44");
                    Regex showFrameGirl  = new Regex("showFrame (?<farmerName>farmer\\d) 40");
                    Regex animation1Guy  = new Regex("animate (?<farmerName>farmer\\d) false true 600 44 45");
                    Regex animation1Girl = new Regex("animate (?<farmerName>farmer\\d) false true 600 43 41 43 42");
                    Regex animation2Guy  = new Regex("animate (?<farmerName>farmer\\d) false true 300 46 47");
                    Regex animation2Girl = new Regex("animate (?<farmerName>farmer\\d) false true 600 46 47");
                    rawFestivalData = regex.Replace(rawFestivalData, "showFrame $1 12/faceDirection $1 0");
                    rawFestivalData = showFrameGirl.Replace(rawFestivalData, "showFrame $1 0/faceDirection $1 2");
                    rawFestivalData = animation1Guy.Replace(rawFestivalData, "animate $1 false true 600 12 13 12 14");
                    rawFestivalData = animation1Girl.Replace(rawFestivalData, "animate $1 false true 596 4 0");
                    rawFestivalData = animation2Guy.Replace(rawFestivalData, "animate $1 false true 150 12 13 12 14");
                    rawFestivalData = animation2Girl.Replace(rawFestivalData, "animate $1 false true 600 0 3");

                    Monitor.Log(rawFestivalData, LogLevel.Trace);

                    string[] newCommands = (__instance.eventCommands = rawFestivalData.Split('/'));
                }

                catch (Exception ex)
                {
                    Monitor.Log($"Failed in {nameof(setUpFestivalMainEvent_FDF)}:\n{ex}", LogLevel.Error);
                }
            }
        }
Example #6
0
 public static void SetCurrentEvent(SDV.AnimalHouse animalHouse, SDV.Event currentEvent)
 {
     animalHouse.currentEvent = currentEvent;
 }