public NpcCheckActionPatch(CompanionManager manager, IInputHelper input, Config config) { this.Manager = manager; this.Input = input; this.Config = config; Instance = this; }
private void RemoveOrphanCompanions(GameLocation location) { if (location.characters != null) { foreach (var creature in location.characters.Where(c => CompanionManager.IsOrphan(c, location)).ToList()) { Monitor.Log($"Removing orphan scenery companion {creature.Name} from {location.Name}", LogLevel.Trace); location.characters.Remove(creature); } } if (location is BuildableGameLocation) { foreach (Building building in (location as BuildableGameLocation).buildings) { GameLocation indoorLocation = building.indoors.Value; if (indoorLocation is null) { continue; } if (indoorLocation.characters != null) { foreach (var creature in indoorLocation.characters.Where(c => CompanionManager.IsOrphan(c, location)).ToList()) { indoorLocation.characters.Remove(creature); } } } } }
public CompanionStateMachine(CompanionManager manager, NPC companion, IContentLoader loader, IMonitor monitor = null) { this.CompanionManager = manager; this.Companion = companion; this.ContentLoader = loader; this.Monitor = monitor; this.Bag = new Chest(true); }
internal static void Setup(HarmonyInstance harmony, CompanionManager manager) { CompanionSayHiPatch.manager = manager; harmony.Patch( original: AccessTools.Method(typeof(NPC), nameof(NPC.sayHiTo)), prefix: new HarmonyMethod(typeof(CompanionSayHiPatch), nameof(CompanionSayHiPatch.Prefix)) ); }
public CompanionStateMachine(CompanionManager manager, NPC companion, CompanionMetaData metadata, IContentLoader loader, IReflectionHelper reflection, IMonitor monitor = null) { this.CompanionManager = manager; this.Companion = companion; this.Metadata = metadata; this.ContentLoader = loader; this.Monitor = monitor; this.Bag = new Chest(true); this.Reflection = reflection; }
public CompanionStateMachine(CompanionManager manager, NPC companion, CompanionMetaData metadata, IContentLoader loader, IReflectionHelper reflection, IMonitor monitor = null) { this.CompanionManager = manager; this.Companion = companion; this.Metadata = metadata; this.ContentLoader = loader; this.Monitor = monitor; this.Bag = new Chest(); this.Reflection = reflection; this.SpokenDialogues = new HashSet <string>(); this.Dialogues = new DialogueProvider(companion, loader); }
private static void CheckForCharacterInteractionAtTilePostfix(Utility __instance, Vector2 tileLocation, Farmer who) { NPC character = Game1.currentLocation.isCharacterAtTile(tileLocation); if (CompanionManager.IsCustomCompanion(character)) { Companion companion = character as Companion; if (companion.owner is null && companion.model != null && !String.IsNullOrEmpty(companion.model.InspectionDialogue)) { Game1.mouseCursor = 4; Game1.mouseCursorTransparency = Utility.tileWithinRadiusOfPlayer((int)tileLocation.X, (int)tileLocation.Y, 1, who) ? 1f : 0.5f; } } }
private void DebugSpawnCompanion(string command, string[] args) { if (args.Length == 0) { Monitor.Log($"Missing required arguments: [QUANTITY] UNIQUE_ID.COMPANION_NAME [X] [Y]", LogLevel.Warn); return; } int amountToSummon = 1; string companionKey = args[0]; var targetTile = Game1.player.getTileLocation(); if (args.Length > 1 && Int32.TryParse(args[0], out int parsedAmountToSummon)) { amountToSummon = parsedAmountToSummon; companionKey = args[1]; if (args.Length > 3 && Int32.TryParse(args[2], out int xTile) && Int32.TryParse(args[3], out int yTile)) { targetTile += new Vector2(xTile, yTile); } } else if (args.Length > 2 && Int32.TryParse(args[1], out int xTile) && Int32.TryParse(args[2], out int yTile)) { targetTile += new Vector2(xTile, yTile); } if (!CompanionManager.companionModels.Any(c => String.Concat(c.Owner, ".", c.Name) == companionKey) && !CompanionManager.companionModels.Any(c => String.Concat(c.Name) == companionKey)) { Monitor.Log($"No match found for the companion name {companionKey}.", LogLevel.Warn); return; } if (CompanionManager.companionModels.Where(c => String.Concat(c.Name) == companionKey).Count() > 1) { Monitor.Log($"There was more than one match to the companion name {companionKey}. Use exact name (UNIQUE_ID.COMPANION_NAME) to resolve this issue.", LogLevel.Warn); return; } var companion = CompanionManager.companionModels.Where(c => String.Concat(c.Name) == companionKey).Count() > 1 ? CompanionManager.companionModels.FirstOrDefault(c => String.Concat(c.Owner, ".", c.Name) == companionKey) : CompanionManager.companionModels.FirstOrDefault(c => String.Concat(c.Name) == companionKey); if (companion is null) { Monitor.Log($"An error has occured trying to spawn {companionKey}: Command failed!", LogLevel.Warn); return; } Monitor.Log($"Spawning {companionKey} x{amountToSummon} at {Game1.currentLocation.NameOrUniqueName} on tile {Game1.player.getTileLocation()}!", LogLevel.Debug); CompanionManager.SummonCompanions(companion, amountToSummon, targetTile, Game1.currentLocation); }
private static void IsThereAFarmerOrCharacterWithinDistancePostfix(Utility __instance, ref Character __result, Vector2 tileLocation, int tilesAway, GameLocation environment) { if (__result != null && CompanionManager.IsCustomCompanion(__result)) { foreach (NPC c in environment.characters.Where(c => !CompanionManager.IsCustomCompanion(c))) { if (Vector2.Distance(c.getTileLocation(), tileLocation) <= tilesAway) { __result = c; return; } } __result = null; } }
private void OnContentInvalidated(object sender, AssetsInvalidatedEventArgs e) { foreach (var asset in e.Names.Where(a => trackedModels.ContainsKey(a.Name))) { var trackedModel = trackedModels[asset.Name]; var tokenModel = Helper.GameContent.Load <TokenModel>(asset); var updatedModel = JsonParser.GetUpdatedModel(trackedModel, tokenModel.Companion); if (!JsonParser.CompareSerializedObjects(updatedModel, trackedModel)) { // Update the existing model object if (CompanionManager.UpdateCompanionModel(JsonParser.Deserialize <CompanionModel>(updatedModel))) { trackedModels[asset.Name] = updatedModel; } } } }
public static void CompanionAddRelationshipNew(Guid sourceGuid, Guid targetGuid, Axis axis, Guid strengthGuid, bool onlyInParty) { Guid strengthOverrideGuid = CompanionStrengthOverrides.First(x => x.Key == strengthGuid).Value; ChangeStrengthGameData strengthOverride = Scripts.GetGameDataByGuid <ChangeStrengthGameData>(strengthOverrideGuid); sourceGuid = InstanceID.GetObjectID(sourceGuid); targetGuid = InstanceID.GetObjectID(targetGuid); Guid guid = GameState.PlayerCharacter.GetComponent <InstanceID>().Guid; if (onlyInParty && (!SingletonBehavior <PartyManager> .Instance.IsActivePartyMember(sourceGuid) || !SingletonBehavior <PartyManager> .Instance.IsActivePartyMember(targetGuid))) { return; } if (sourceGuid == SpecialCharacterInstanceID.PlayerGuid || sourceGuid == guid) { Debug.LogError("Cannot change the player's relationship towards a companion"); UIDebug.LogOnScreenWarning("Script is trying to use Player's guid as SourceGuid for CompanionAddRelationship", UIDebug.Department.Design, 10f); } else if (targetGuid == SpecialCharacterInstanceID.PlayerGuid || targetGuid == guid) { CompanionGameData sourceCompanion = CompanionManager.GetCompanionData(sourceGuid); SingletonBehavior <PartyManager> .Instance.AddPlayerRelationship(sourceCompanion, strengthOverride.ChangeValue, axis); } else { CompanionGameData sourceCompanion = CompanionManager.GetCompanionData(sourceGuid); CompanionGameData targetCompanion = CompanionManager.GetCompanionData(targetGuid); if (sourceCompanion == null || targetCompanion == null) { Debug.LogError($"Null companion data being used for guid: {((!(sourceCompanion == null)) ? targetGuid : sourceGuid)}"); } else { SingletonBehavior <PartyManager> .Instance.AddRelationship(sourceCompanion, targetCompanion, strengthOverride.ChangeValue, axis); } } }
private void Application_Startup(Object sender, StartupEventArgs e) { DllHelper.RegistDLL(); ResourceDictionary resource = new ResourceDictionary { Source = new Uri(@"Resource\Languages\langs.xaml", UriKind.Relative) }; if (resource.Contains(SettingsHelper.Lang)) { String path = resource[resource[SettingsHelper.Lang].ToString()].ToString(); resource = new ResourceDictionary { Source = new Uri(path, UriKind.Relative) }; } Application.Current.Resources.MergedDictionaries[0] = resource; if (e.Args.Length == 1 && e.Args[0] == "-c") { CompanionManager.StartCompanionThread(); } else { _mutex = new Mutex(true, "PsDownloadTools", out Boolean ret); if (!ret) { new DialogMessage(TryFindResource("StrProgramRunning") as String).ShowDialog(); Environment.Exit(0); } else { ExceptionHelper.InitExceptionHelper(this); CompanionManager.CallCompanionThread(); Current.StartupUri = new Uri("View/ViewMain.xaml", UriKind.Relative); } } }
private void RemoveAllCompanions(string owner = null, GameLocation targetLocation = null) { foreach (GameLocation location in Game1.locations.Where(l => l != null && (targetLocation is null || l == targetLocation))) { if (location.characters != null) { foreach (var creature in location.characters.Where(c => CompanionManager.IsCustomCompanion(c) && (owner is null || (c as Companion).model.Owner.Equals(owner, StringComparison.OrdinalIgnoreCase))).ToList()) { location.characters.Remove(creature); } } if (location is BuildableGameLocation) { foreach (Building building in (location as BuildableGameLocation).buildings) { GameLocation indoorLocation = building.indoors.Value; if (indoorLocation is null) { continue; } if (indoorLocation.characters != null) { foreach (var creature in indoorLocation.characters.Where(c => CompanionManager.IsCustomCompanion(c) && (owner is null || (c as Companion).model.Owner.Equals(owner, StringComparison.OrdinalIgnoreCase))).ToList()) { indoorLocation.characters.Remove(creature); } } } } } this.Reset(); }
public SpouseReturnHomePatch(CompanionManager manager) { this.Manager = manager; Instance = this; }
public GameLocationPerformActionPatch(CompanionManager manager, bool overrideDoorLock) { this.Manager = manager; this.OverriedDoorLock = overrideDoorLock; Instance = this; }
public CompanionSayHiPatch(CompanionManager manager) { this.Manager = manager; Instance = this; }
public GameUseToolPatch(CompanionManager manager) { this.Manager = manager; Instance = this; }
public CompanionCutscenes(IContentLoader contentLoader, CompanionManager companionManager, IConditionsChecker epu) { this.contentLoader = contentLoader; this.companionManager = companionManager; this.epu = epu; }
public CompanionStateMachine(string name, CompanionManager manager, CompanionMetaData metadata, IContentLoader loader, IReflectionHelper reflection, IMonitor monitor = null) : this(manager, null, metadata, loader, reflection, monitor) { this.Name = name; this.isVillager = true; this.ReloadNpc(); }
public GetCharacterPatch(CompanionManager manager) { this.Manager = manager; Instance = this; }
public MonsterBehaviorPatch(CompanionManager manager) { this.Manager = manager; Instance = this; }
public GameLocationPerformActionPatch(CompanionManager manager) { this.Manager = manager; Instance = this; }
public CompanionCutscenes(IContentLoader contentLoader, CompanionManager companionManager) { this.contentLoader = contentLoader; this.companionManager = companionManager; }
private void SpawnSceneryCompanions(GameLocation location, bool spawnOnlyRequiredCompanions = false) { try { var targetLayer = location.map.GetLayer("Back"); if (location is FarmHouse) { targetLayer = location.map.GetLayer("Front"); } for (int x = 0; x < targetLayer.LayerWidth; x++) { for (int y = 0; y < targetLayer.LayerHeight; y++) { var tile = targetLayer.Tiles[x, y]; if (tile is null) { continue; } if (tile.Properties.ContainsKey("CustomCompanions")) { if (String.IsNullOrEmpty(tile.Properties["CustomCompanions"])) { if (CompanionManager.sceneryCompanions.Any(s => s.Location == location && s.Tile == new Vector2(x, y))) { Monitor.Log($"Removing cached SceneryCompanions on tile ({x}, {y}) for map {location.NameOrUniqueName}!", LogLevel.Trace); CompanionManager.RemoveSceneryCompanionsAtTile(location, new Vector2(x, y)); } continue; } string command = tile.Properties["CustomCompanions"].ToString(); if (command.Split(' ')[0].ToUpper() != "SPAWN") { if (!String.IsNullOrEmpty(command)) { Monitor.Log($"Unknown CustomCompanions command ({command.Split(' ')[0]}) given on tile ({x}, {y}) for map {location.NameOrUniqueName}!", LogLevel.Warn); } continue; } 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 = CompanionManager.companionModels.FirstOrDefault(c => String.Concat(c.Owner, ".", c.Name) == companionKey); if (companion is null) { Monitor.Log($"Unable to find companion match for {companionKey} given on tile ({x}, {y}) for map {location.NameOrUniqueName}!", LogLevel.Warn); continue; } if (spawnOnlyRequiredCompanions && !companion.EnableSpawnAtDayStart) { continue; } // Check if it is already spawned if (location.characters.Any(c => CompanionManager.IsSceneryCompanion(c) && (c as MapCompanion).targetTile == new Vector2(x, y) * 64f && (c as MapCompanion).companionKey == companion.GetId())) { continue; } // Check if the companion is allowed to be spawned if (CompanionManager.denyRespawnCompanions.Any(s => s.Location == location && s.Tile == new Vector2(x, y) && s.Companions.Any(c => c.companionKey == companion.GetId()))) { continue; } Monitor.Log($"Spawning [{companionKey}] x{amountToSummon} on tile ({x}, {y}) for map {location.NameOrUniqueName}"); CompanionManager.SummonCompanions(companion, amountToSummon, new Vector2(x, y), location); } } } CompanionManager.RefreshLights(location); } catch (Exception ex) { Monitor.Log($"Unable to spawn companions on {location.NameOrUniqueName}, likely due to a bad map. See log for more details.", LogLevel.Warn); Monitor.Log(ex.ToString()); } }