/// <summary> /// Companion initializator. Call it after saved game is loaded /// </summary> /// <param name="loader"></param> /// <param name="gameEvents"></param> /// <param name="reflection"></param> public void InitializeCompanions(IContentLoader loader, IModEvents gameEvents, ISpecialModEvents specialEvents, IReflectionHelper reflection) { Dictionary <string, string> dispositions = loader.LoadData <string, string>("Data/CompanionDispositions"); foreach (string npcName in dispositions.Keys) { NPC companion = Game1.getCharacterFromName(npcName, true); if (companion == null) { this.monitor.Log($"Unable to initialize companion `{npcName}`, because this NPC cannot be found in the game. " + "Are you trying to add a custom NPC as a companion? Check the mod which adds this NPC into the game. " + "Don't report this as a bug to NPC Adventures unless it's a vanilla game NPC.", LogLevel.Error); continue; } CompanionStateMachine csm = new CompanionStateMachine(this, companion, new CompanionMetaData(dispositions[npcName]), loader, reflection, this.monitor); Dictionary <StateFlag, ICompanionState> stateHandlers = new Dictionary <StateFlag, ICompanionState>() { [StateFlag.RESET] = new ResetState(csm, gameEvents, this.monitor), [StateFlag.AVAILABLE] = new AvailableState(csm, gameEvents, this.monitor), [StateFlag.RECRUITED] = new RecruitedState(csm, gameEvents, specialEvents, this.monitor), [StateFlag.UNAVAILABLE] = new UnavailableState(csm, gameEvents, this.monitor), }; csm.Setup(stateHandlers); this.PossibleCompanions.Add(npcName, csm); } this.monitor.Log($"Initalized {this.PossibleCompanions.Count} companions.", LogLevel.Info); }
/// <summary> /// Companion initializator. Call it after saved game is loaded /// </summary> /// <param name="loader"></param> /// <param name="gameEvents"></param> /// <param name="reflection"></param> public void InitializeCompanions(IContentLoader loader, IModEvents gameEvents, ISpecialModEvents specialEvents, IReflectionHelper reflection) { Dictionary <string, string> dispositions = loader.LoadData <string, string>("Data/CompanionDispositions"); foreach (string npcName in dispositions.Keys) { CompanionStateMachine csm = new CompanionStateMachine(npcName, this, new CompanionMetaData(dispositions[npcName]), loader, reflection, this.monitor); Dictionary <StateFlag, ICompanionState> stateHandlers = new Dictionary <StateFlag, ICompanionState>() { [StateFlag.RESET] = new ResetState(csm, gameEvents, this.monitor), [StateFlag.AVAILABLE] = new AvailableState(csm, gameEvents, this.monitor), [StateFlag.RECRUITED] = new RecruitedState(csm, gameEvents, specialEvents, this.monitor), [StateFlag.UNAVAILABLE] = new UnavailableState(csm, gameEvents, this.monitor), }; csm.Setup(stateHandlers); this.PossibleCompanions.Add(npcName, csm); } this.monitor.Log($"Initalized {this.PossibleCompanions.Count} companions.", LogLevel.Info); }