// Handles customizations for NPCs // Custom NPCs and custom names or sprites for existing NPCs private void LoadCustomNpcs() { foreach (var npc in ModMain.GetVillagers()) { GetNpcCrop(npc); GetCustomName(npc); } // For farmhands, custom NPCs can't be found so rely on config if (Context.IsMultiplayer && !Context.IsMainPlayer) { var CustomNpcMarkerOffsets = ModMain.Globals.CustomNpcMarkerOffsets; if (CustomNpcMarkerOffsets != null && CustomNpcMarkerOffsets.Count > 0) { foreach (var villager in CustomNpcMarkerOffsets) { NpcMarkerOffsets[villager.Key] = villager.Value; } } } // Handle duplicate displayName -- custom NPCs that replaces villagers Dictionary <string, string> dupes = Names .Where(n1 => Names.Any(n2 => n2.Key != n1.Key && n2.Value == n1.Value)) .ToDictionary(n => n.Key, n => n.Value); // Properly replace the villager with custom NPC foreach (var dupe in dupes) { if (dupe.Key != dupe.Value) { Names[dupe.Key] = dupe.Value; } else { Names.Remove(dupe.Key); } } if (NpcCustomizations.Count != 0) { var names = "Adjusted markers for "; foreach (var name in NpcCustomizations) { names += name + ", "; } ModMain.IMonitor.Log(names.Substring(0, names.Length - 2), LogLevel.Debug); } ModMain.Helper.Data.WriteJsonFile($"config/{Constants.SaveFolderName}.json", ModMain.Config); }
// Handles customizations for NPCs // Custom NPCs and custom names or sprites for existing NPCs private void LoadCustomNpcs() { foreach (var npc in ModMain.GetVillagers()) { GetNpcCrop(npc); GetCustomName(npc); } // Handle duplicate displayName -- custom NPCs that replaces villagers Dictionary <string, string> dupes = Names .Where(n1 => Names.Any(n2 => n2.Key != n1.Key && n2.Value == n1.Value)) .ToDictionary(n => n.Key, n => n.Value); // Properly replace the villager with custom NPC foreach (var dupe in dupes) { if (dupe.Key != dupe.Value) { Names[dupe.Key] = dupe.Value; } else { Names.Remove(dupe.Key); } } if (NpcCustomizations.Count != 0) { var names = "Adjusted markers for "; foreach (var name in NpcCustomizations) { names += name + ", "; } ModMain.IMonitor.Log(names.Substring(0, names.Length - 2), LogLevel.Debug); } ModMain.Helper.Data.WriteJsonFile($"config/{Constants.SaveFolderName}.json", ModMain.Config); }