internal static bool IsOrphan(Character follower, GameLocation location) { if (follower != null && follower is MapCompanion) { MapCompanion mapCompanion = follower as MapCompanion; var companionTile = mapCompanion.targetTile.Value / 64f; var targetLayer = location.map.GetLayer("Back"); if (location is FarmHouse) { targetLayer = location.map.GetLayer("Front"); } if (targetLayer.Tiles.Array.GetLength(0) < companionTile.X || targetLayer.Tiles.Array.GetLength(1) < companionTile.Y) { return(true); } var mapTile = targetLayer.Tiles[(int)companionTile.X, (int)companionTile.Y]; if (mapTile is null || !mapTile.Properties.ContainsKey("CustomCompanions")) { return(true); } if (String.IsNullOrEmpty(mapTile.Properties["CustomCompanions"])) { return(true); } string command = mapTile.Properties["CustomCompanions"].ToString(); if (command.Split(' ')[0].ToUpper() != "SPAWN") { return(true); } string companionKey = command.Substring(command.IndexOf(' ') + 2).TrimStart(); if (!Int32.TryParse(command.Split(' ')[1], out int amountToSummon)) { amountToSummon = 1; companionKey = command.Substring(command.IndexOf(' ') + 1); } var companion = companionModels.FirstOrDefault(c => String.Concat(c.Owner, ".", c.Name) == companionKey); if (companion is null) { return(true); } if (companion.GetId() != mapCompanion.companionKey) { return(true); } return(false); } return(false); }
internal static void RefreshLights(GameLocation location) { foreach (var companion in location.characters.Where(c => IsSceneryCompanion(c) && (c as MapCompanion).light != null)) { MapCompanion mapCompanion = companion as MapCompanion; if (!Game1.currentLightSources.Contains(mapCompanion.light)) { Game1.currentLightSources.Add(mapCompanion.light); } } }
internal static void SummonCompanions(CompanionModel model, int numberToSummon, Vector2 tile, GameLocation location) { if (location.characters is null) { CustomCompanions.monitor.Log($"Unable to summon {model.Name} due to the location {location.Name} not having an instantiated GameLocation.characters!"); return; } List <Companion> companions = new List <Companion>(); for (int x = 0; x < numberToSummon; x++) { MapCompanion companion = new MapCompanion(model, tile, location); companions.Add(companion); } var sceneryCompanion = new SceneryCompanions(location, tile, companions); if (sceneryCompanions.Any(s => s.Tile == tile && s.Location == location)) { // Clear out old companions, add in the new ones foreach (var scenery in sceneryCompanions.Where(s => s.Tile == tile && s.Location == location)) { scenery.ReplaceAssociatedCompanions(companions, location); } } else { sceneryCompanions.Add(sceneryCompanion); } // Ensures each collision based companion is moved to an empty tile companions.ForEach(c => location.characters.Add(c)); foreach (var companion in companions.Where(c => c.collidesWithOtherCharacters)) { companion.PlaceInEmptyTile(); } }