/// <summary> /// Gets the visitor list for a specific day. Explorers can't be visitors, so remove them. /// </summary> /// <param name="random">Random to use to select.</param> /// <param name="capacity">Maximum number of people to allow on the island.</param> /// <returns>Visitor List.</returns> /// <remarks>For a deterministic island list, use a Random seeded with the uniqueID + number of days played.</remarks> private static List <NPC> GenerateVistorList(Random random, int capacity, HashSet <NPC> explorers) { CurrentGroup = null; CurrentVisitingGroup = null; CurrentAdventureGroup = null; CurrentAdventurers = null; List <NPC> visitors = new(); HashSet <NPC> valid_visitors = new(); foreach (NPC npc in Utility.getAllCharacters()) { if (IslandSouth.CanVisitIslandToday(npc) && !explorers.Contains(npc)) { valid_visitors.Add(npc); } } if (Globals.SaveDataModel is not null) { foreach (string npcname in Globals.SaveDataModel.NPCsForTomorrow) { NPC npc = Game1.getCharacterFromName(npcname); visitors.Add(npc); if (!valid_visitors.Contains(npc)) { Globals.ModMonitor.Log($"{npcname} queued for Island DESPITE exclusion!", LogLevel.Warn); } } Globals.SaveDataModel.NPCsForTomorrow.Clear(); } if (random.NextDouble() < Globals.Config.GroupChance) { List <string> groupkeys = new(); foreach (string key in IslandGroups.Keys) { // Filter out groups where one member can't make it or are too big if (IslandGroups[key].Count <= capacity - visitors.Count && IslandGroups[key].All((NPC npc) => valid_visitors.Contains(npc))) { groupkeys.Add(key); } } if (groupkeys.Count > 0) { CurrentGroup = Utility.GetRandom(groupkeys, random); #if DEBUG Globals.ModMonitor.Log($"Group {CurrentGroup} headed to Island.", LogLevel.Debug); #endif HashSet <NPC> possiblegroup = IslandGroups[CurrentGroup]; visitors.AddRange(possiblegroup.Where((npc) => !visitors.Contains(npc))); // limit group size if there's too many people... CurrentVisitingGroup = possiblegroup; valid_visitors.ExceptWith(visitors); } } if (Game1.getCharacterFromName("Gus") is NPC gus && !visitors.Contains(gus) && valid_visitors.Contains(gus) && Globals.Config.GusDayAsShortString().Equals(Game1.shortDayNameFromDayOfSeason(Game1.dayOfMonth), StringComparison.OrdinalIgnoreCase) && Globals.Config.GusChance > random.NextDouble()) { Globals.ModMonitor.DebugOnlyLog($"Forcibly adding Gus."); visitors.Add(gus); valid_visitors.Remove(gus); } // Prevent children and anyone with the neveralone exclusion from going alone. int kidsremoved = valid_visitors.RemoveWhere((NPC npc) => npc.Age == NPC.child && (!IslandSouthPatches.Exclusions.TryGetValue(npc, out string[]? exclusions) || !exclusions.Contains("freerange"))); int neveralone = valid_visitors.RemoveWhere((NPC npc) => IslandSouthPatches.Exclusions.TryGetValue(npc, out string[]? exclusions) && exclusions.Contains("neveralone")); if (Globals.Config.DebugMode) { Globals.ModMonitor.Log($"Excluded {kidsremoved} kids and {neveralone} never alone villagers from the valid villagers list"); } if (visitors.Count < capacity) { #if DEBUG Globals.ModMonitor.Log($"{capacity} not yet reached, attempting to add more.", LogLevel.Debug); #endif visitors.AddRange(valid_visitors.OrderBy(a => random.Next()).Take(capacity - visitors.Count)); } // If George in visitors, add Evelyn. if (visitors.Any((NPC npc) => npc.Name.Equals("George", StringComparison.OrdinalIgnoreCase)) && visitors.All((NPC npc) => !npc.Name.Equals("Evelyn", StringComparison.OrdinalIgnoreCase)) && Game1.getCharacterFromName("Evelyn") is NPC evelyn) { // counting backwards to avoid kicking out a group member. for (int i = visitors.Count - 1; i >= 0; i--) { if (!visitors[i].Name.Equals("Gus", StringComparison.OrdinalIgnoreCase) && !visitors[i].Name.Equals("George", StringComparison.OrdinalIgnoreCase)) { Globals.ModMonitor.DebugOnlyLog($"Replacing one visitor {visitors[i].Name} with Evelyn"); visitors[i] = evelyn; break; } } } for (int i = 0; i < visitors.Count; i++) { visitors[i].scheduleDelaySeconds = Math.Min(i * 0.4f, 7f); } // set schedule Delay for George and Evelyn so they arrive together (in theory)? if (visitors.FirstOrDefault((NPC npc) => npc.Name.Equals("George", StringComparison.OrdinalIgnoreCase)) is NPC george && visitors.FirstOrDefault((NPC npc) => npc.Name.Equals("Evelyn", StringComparison.OrdinalIgnoreCase)) is NPC evelyn2) { george.scheduleDelaySeconds = 7f; evelyn2.scheduleDelaySeconds = 6.8f; } Globals.ModMonitor.DebugOnlyLog($"{visitors.Count} vistors: {string.Join(", ", visitors.Select((NPC npc) => npc.Name))}"); IslandSouthPatches.ClearCache(); return(visitors); }
/// <summary> /// Yields a group of valid explorers. /// </summary> /// <param name="random">Seeded random.</param> /// <returns>An explorer group (of up to three explorers), or an empty hashset if there's no group today.</returns> private static HashSet <NPC> GenerateExplorerGroup(Random random) { if (random.NextDouble() <= Globals.Config.ExplorerChance) { List <string> explorerGroups = ExplorerGroups.Keys.ToList(); if (explorerGroups.Count > 0) { CurrentAdventureGroup = explorerGroups[random.Next(explorerGroups.Count)]; CurrentAdventurers = ExplorerGroups[CurrentAdventureGroup].Where((NPC npc) => IslandSouth.CanVisitIslandToday(npc)).Take(3).ToHashSet(); return(CurrentAdventurers); } } return(new HashSet <NPC>()); // just return an empty hashset. }