Exemplo n.º 1
0
        public void DoSearch()
        {
            foreach (var card in Cards)
            {
                card.IsDisplayed = true;
            }

            foreach (var card in Cards)
            {
                var isNameMatch          = string.IsNullOrEmpty(CardNameSearch) ? true : card.Info.Name.ToLower().Contains(CardNameSearch.ToLower());
                var isPatchMatch         = string.IsNullOrEmpty(PatchSearch) ? true : card.Info.Patch.Contains(PatchSearch);
                var isNpcMatch           = string.IsNullOrEmpty(NPCNameSearch) ? true : card.Info.NPCs.FirstOrDefault(n => n.ToLower().Contains(NPCNameSearch.ToLower())) != null;
                var isMinDifficultyMatch = string.IsNullOrEmpty(MinDifficultySearch) ? true : card.Difficulty >= int.Parse(MinDifficultySearch);
                var isMaxDifficultyMatch = string.IsNullOrEmpty(MaxDifficultySearch) ? true : card.Difficulty <= int.Parse(MaxDifficultySearch);
                var isCollectionMatch    = string.IsNullOrEmpty(CollectedSearch) || CollectedSearch == "No Preference" ? true : (CollectedSearch == "Collected" && card.IsCollected) || (CollectedSearch == "Uncollected" && !card.IsCollected);

                card.IsDisplayed = isNameMatch && isPatchMatch && isNpcMatch && isMinDifficultyMatch && isMaxDifficultyMatch && isCollectionMatch;
            }

            // store fields for resetting later
            var cardName = CardNameSearch;
            var patch    = PatchSearch;
            var npcName  = NPCNameSearch;

            CardNames.Clear();
            Patches.Clear();
            NPCNames.Clear();

            var displayedCards = Cards.Where(c => c.IsDisplayed);

            foreach (var displayedCard in displayedCards)
            {
                if (!CardNames.Contains(displayedCard.Info.Name))
                {
                    CardNames.Add(displayedCard.Info.Name);
                }

                if (!Patches.Contains(displayedCard.Info.Patch))
                {
                    Patches.Add(displayedCard.Info.Patch);
                }

                foreach (var npc in displayedCard.Info.NPCs)
                {
                    if (!NPCNames.Contains(npc))
                    {
                        NPCNames.Add(npc);
                    }
                }
            }

            // set fields back after the search
            CardNameSearch = cardName;
            PatchSearch    = patch;
            NPCNameSearch  = npcName;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generate a basic npc based off of all all of the NPC data here.
        /// </summary>
        /// <param name="gender"></param>
        /// <param name="minNumOfAccessories"></param>
        /// <param name="maxNumOfAccessories"></param>
        public ExtendedNPC generateNPC(Genders gender, int minNumOfAccessories, int maxNumOfAccessories, StandardColorCollection DrawColors = null)
        {
            Seasons myseason = Seasons.spring;

            if (Game1.currentSeason == "spring")
            {
                myseason = Seasons.spring;
            }
            if (Game1.currentSeason == "summer")
            {
                myseason = Seasons.summer;
            }
            if (Game1.currentSeason == "fall")
            {
                myseason = Seasons.fall;
            }
            if (Game1.currentSeason == "winter")
            {
                myseason = Seasons.winter;
            }

            List <AssetSheet> bodyList      = new List <AssetSheet>();
            List <AssetSheet> eyesList      = new List <AssetSheet>();
            List <AssetSheet> hairList      = new List <AssetSheet>();
            List <AssetSheet> shirtList     = new List <AssetSheet>();
            List <AssetSheet> shoesList     = new List <AssetSheet>();
            List <AssetSheet> pantsList     = new List <AssetSheet>();
            List <AssetSheet> accessoryList = new List <AssetSheet>();

            //Get all applicable parts from this current asset manager
            foreach (var assetManager in this.assetPool)
            {
                var body = getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.body);
                foreach (var piece in body)
                {
                    bodyList.Add(piece);
                }

                var eyes = getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.eyes);
                foreach (var piece in eyes)
                {
                    eyesList.Add(piece);
                }

                var hair = getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.hair);
                foreach (var piece in hair)
                {
                    hairList.Add(piece);
                }

                var shirt = getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.shirt);
                foreach (var piece in shirt)
                {
                    shirtList.Add(piece);
                }

                var pants = getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.pants);
                foreach (var piece in pants)
                {
                    pantsList.Add(piece);
                }

                var shoes = getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.shoes);
                foreach (var piece in shoes)
                {
                    shoesList.Add(piece);
                }

                var accessory = getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.accessory);
                foreach (var piece in accessory)
                {
                    accessoryList.Add(piece);
                }
            }


            Random r      = new Random(System.DateTime.Now.Millisecond);
            int    amount = 0;

            amount = r.Next(minNumOfAccessories, maxNumOfAccessories + 1); //Necessary since r.next returns a num between min and (max-1)

            int bodyIndex  = 0;
            int eyesIndex  = 0;
            int hairIndex  = 0;
            int shirtIndex = 0;
            int pantsIndex = 0;
            int shoesIndex = 0;

            if (bodyList.Count != 0)
            {
                bodyIndex = r.Next(0, bodyList.Count - 1);
            }
            else
            {
                Class1.ModMonitor.Log("Error: Not enough body templates to generate an npc. Aborting", StardewModdingAPI.LogLevel.Error);
                return(null);
            }

            if (eyesList.Count != 0)
            {
                eyesIndex = r.Next(0, eyesList.Count - 1);
            }
            else
            {
                Class1.ModMonitor.Log("Error: Not enough eyes templates to generate an npc. Aborting", StardewModdingAPI.LogLevel.Error);
                return(null);
            }

            if (hairList.Count != 0)
            {
                hairIndex = r.Next(0, hairList.Count - 1);
            }
            else
            {
                Class1.ModMonitor.Log("Error: Not enough hair templates to generate an npc. Aborting", StardewModdingAPI.LogLevel.Error);
                return(null);
            }

            if (shirtList.Count != 0)
            {
                shirtIndex = r.Next(0, shirtList.Count - 1);
            }
            else
            {
                Class1.ModMonitor.Log("Error: Not enough shirt templates to generate an npc. Aborting", StardewModdingAPI.LogLevel.Error);
                return(null);
            }

            if (pantsList.Count != 0)
            {
                pantsIndex = r.Next(0, pantsList.Count - 1);
            }
            else
            {
                Class1.ModMonitor.Log("Error: Not enough pants templates to generate an npc. Aborting", StardewModdingAPI.LogLevel.Error);
                return(null);
            }

            if (shoesList.Count != 0)
            {
                shoesIndex = r.Next(0, shoesList.Count - 1);
            }
            else
            {
                Class1.ModMonitor.Log("Error: Not enough shoes templates to generate an npc. Aborting", StardewModdingAPI.LogLevel.Error);
                return(null);
            }
            List <int> accIntList = new List <int>();

            if (accessoryList.Count != 0)
            {
                for (int i = 0; i < amount; i++)
                {
                    int acc = r.Next(0, accessoryList.Count - 1);
                    accIntList.Add(acc);
                }
            }

            //Get a single sheet to pull from.
            AssetSheet bodySheet;
            AssetSheet eyesSheet;
            AssetSheet hairSheet;
            AssetSheet shirtSheet;
            AssetSheet shoesSheet;
            AssetSheet pantsSheet;

            bodySheet  = bodyList.ElementAt(bodyIndex);
            eyesSheet  = eyesList.ElementAt(eyesIndex);
            hairSheet  = hairList.ElementAt(hairIndex);
            shirtSheet = shirtList.ElementAt(shirtIndex);
            pantsSheet = pantsList.ElementAt(pantsIndex);
            shoesSheet = shoesList.ElementAt(shoesIndex);


            List <AssetSheet> accessorySheet = new List <AssetSheet>();

            foreach (var v in accIntList)
            {
                accessorySheet.Add(accessoryList.ElementAt(v));
            }
            if (DrawColors == null)
            {
                DrawColors = new StandardColorCollection();
            }
            var         render = generateBasicRenderer(bodySheet, eyesSheet, hairSheet, shirtSheet, pantsSheet, shoesSheet, accessorySheet, DrawColors);
            ExtendedNPC npc    = new ExtendedNPC(new Sprite(getDefaultSpriteImage(bodySheet)), render, new Microsoft.Xna.Framework.Vector2(0, 0) * Game1.tileSize, 2, NPCNames.getRandomNPCName(gender));

            return(npc);
        }