Ejemplo n.º 1
0
        /// <summary>
        /// Checks if the key is only as specific as having a time set. (i.e not location or day specific)
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static bool IsKeyTimeSpecific(string key)
        {
            SongConditionals condition = new SongConditionals(key);

            if (condition.isTimeSpecific())
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public static bool IsKeyGeneric(string key)
        {
            SongConditionals condition = new SongConditionals(key);

            if (condition.isLocationSpecific() == false && condition.isTimeSpecific() == false && condition.isDaySpecific() == false)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Checks to see if a song can be played given a set of conditionals.
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public bool canBePlayed(string key)
 {
     foreach (KeyValuePair <string, SongConditionals> pair in this.songConditionals)
     {
         SongConditionals temp = new SongConditionals(key);
         if (pair.Value.canBePlayed(temp) == true)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Checks if a song can be played provided a given key.
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public bool canBePlayed(SongConditionals other)
        {
            if (this.isLocationSpecific())
            {
                if (!string.IsNullOrEmpty(other.location))
                {
                    if (this.location.Equals(other.location) == false)
                    {
                        return(false);                                             //If there is a check but not the right location return false
                    }
                }
                else
                {
                    return(false); //If there is no check against this then return false;
                }
            }
            if (this.isTimeSpecific())
            {
                if (!string.IsNullOrEmpty(other.time))
                {
                    if (this.time.Equals(other.time) == false)
                    {
                        return(false);                                     //If the two times don't match return false
                    }
                }
                else
                {
                    return(false); //If there is no check against this and this is time specific don't allow it.
                }
            }


            if (this.isDaySpecific())
            {
                //condition specific check
                if (!string.IsNullOrEmpty(other.dayOfWeek))
                {
                    if (this.dayOfWeek.Equals(other.dayOfWeek) == false)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false); //There is no check against this day of the week. Don't allow it.
                }
            }

            //Check for season.
            if (this.isSeasonSpecific())
            {
                if (!string.IsNullOrEmpty(other.season))
                {
                    if (this.season.Equals(other.season) == false)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }

            //Check for weather.
            if (this.isWeatherSpecific())
            {
                if (!string.IsNullOrEmpty(other.weather))
                {
                    if (this.weather.Equals(other.weather) == false)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }


            if (!string.IsNullOrEmpty(this.menu))
            {
                if (!string.IsNullOrEmpty(other.menu))
                {
                    if (this.menu.Equals(other.menu) == false)
                    {
                        return(false);
                    }
                }
            }

            if (!string.IsNullOrEmpty(this.festival))
            {
                if (!string.IsNullOrEmpty(other.festival))
                {
                    if (this.festival.Equals(other.festival) == false)
                    {
                        return(false);
                    }
                }
            }

            if (!string.IsNullOrEmpty(this.eventKey))
            {
                if (!string.IsNullOrEmpty(other.eventKey))
                {
                    if (this.eventKey.Equals(other.eventKey) == false)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>Select the actual song to be played right now based on the selector key. The selector key should be called when the player's location changes.</summary>
        public bool selectMusic(string songListKey, bool warpCheck = false)
        {
            if (this.CurrentMusicPack != null)
            {
                if (this.CurrentMusicPack.IsPlaying() && StardewSymphony.Config.WaitForSongToFinishBeforeMusicSwap)
                {
                    StardewSymphony.ModMonitor.Log("Waiting for music to finish before playing another song.");
                    return(false);
                }
            }
            if (warpCheck == true)
            {
                if (StardewSymphony.Config.LocationsToIgnoreWarpMusicChange.ContainsKey(Game1.player.currentLocation.Name))
                {
                    if (StardewSymphony.Config.LocationsToIgnoreWarpMusicChange[Game1.player.currentLocation.Name] == true)
                    {
                        return(false);
                    }
                }
                return(false);
            }


            //Prevent generic song changes when running about.

            SongConditionals conditional = new SongConditionals(songListKey);

            // stop timer timer when music is selected
            this.Timer.Enabled = false;

            // get applicable music packs
            var listOfValidMusicPacks = this.GetApplicableMusicPacks(songListKey);

            //If the list of valid packs are 0, check if I'm currently at an event or festival or get some location specific music and try to play a generalized song from there.
            if (listOfValidMusicPacks.Count == 0)
            {
                //No valid songs to play at this time.
                if (StardewSymphony.Config.EnableDebugLog)
                {
                    StardewSymphony.ModMonitor.Log("Error: There are no songs to play across any music pack for the song key: " + songListKey + ".7 Are you sure you did this properly?");
                }
                StardewSymphony.menuChangedMusic = false;
                return(false);
            }
            //All music packs that have songs have been taken into acount.
            //Check all songs in all music packs to see if it can be played here.

            List <KeyValuePair <MusicPackV2, string> > packSongNames    = new List <KeyValuePair <MusicPackV2, string> >();
            List <KeyValuePair <MusicPackV2, string> > locpackSongNames = new List <KeyValuePair <MusicPackV2, string> >();

            foreach (var ok in listOfValidMusicPacks)
            {
                foreach (SongInformation song in ok.Key.SongInformation.songs.Values)
                {
                    if (song.canBePlayed(songListKey))
                    {
                        foreach (SongConditionals con in song.songConditionals.Values)
                        {
                            if (con.isLocationSpecific() == false)
                            {
                                //If the key is generic skip over it.
                                if (con.isKeyGeneric())
                                {
                                    if (this.CurrentMusicPack != null)
                                    {
                                        if (this.CurrentMusicPack.IsPlaying())
                                        {
                                            continue;
                                        }
                                    }
                                }
                                //If I have warped and the key only is to be played when time changes prevent a new song from playing.
                                //If the key is more specific (I.E has a location associated with it) then music will change.
                                if (warpCheck == true && con.isTimeSpecific())
                                {
                                    if (this.CurrentMusicPack != null)
                                    {
                                        if (this.CurrentMusicPack.IsPlaying())
                                        {
                                            continue;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                locpackSongNames.Add(new KeyValuePair <MusicPackV2, string>(ok.Key, song.name));
                            }
                        }
                        packSongNames.Add(new KeyValuePair <MusicPackV2, string>(ok.Key, song.name));
                    }
                }
            }

            //If there is a valid key for the place/time/event/festival I am at, play it!

            int randInt = this.Random.Next(0, packSongNames.Count - 1);

            var musicPackPair = packSongNames.ElementAt(randInt);

            /*
             * //Check to see if the only location song was the one I was just playing. If so ignore it and chose more generic music.
             * if (locpackSongNames.Count == 1)
             * {
             *  if (musicPackPair.Key == locpackSongNames[0].Key)
             *  {
             *      if (musicPackPair.Value == locpackSongNames[0].Value)
             *      {
             *          //Don't care
             *      }
             *  }
             * }
             * //If not the try to chose another location specific song.
             * else
             * {
             *  packSongNames = locpackSongNames;
             *  randInt = this.Random.Next(0, packSongNames.Count - 1);
             *  musicPackPair = packSongNames.ElementAt(randInt);
             * }*/

            while (true)
            {
                if (this.CurrentMusicPack != null)
                {
                    if (packSongNames.Count == 0)
                    {
                        return(false);
                    }
                    if (musicPackPair.Key.Name == this.CurrentMusicPack.Name)
                    {
                        if (musicPackPair.Value == this.CurrentMusicPack.CurrentSongName)
                        {
                            if (packSongNames.Count == 1)
                            {
                                return(false);
                            }
                            else
                            {
                                //Used to eliminate chosing the same song from the same pack.
                                packSongNames.Remove(musicPackPair);
                                randInt       = this.Random.Next(0, packSongNames.Count - 1);
                                musicPackPair = packSongNames.ElementAt(randInt);
                            }
                        }
                        else
                        {
                            //Different song from same pack
                            break;
                        }
                    }
                    else
                    {
                        //Different pack so probably different song.
                        break;
                    }
                }
                else
                {
                    break;
                }
            }

            //used to swap the music packs and stop the last playing song.
            this.SwapMusicPacks(musicPackPair.Key.Name);
            string songName = musicPackPair.Value;

            this.CurrentMusicPack.PlaySong(songName);
            return(true);
        }