internal void UpdateLocationTokens(IMonitor monitor, PerScreen <PlayerData> data) { // Get current location as a MineShaft var mineShaft = Game1.currentLocation as MineShaft; // Get current location as a VolcanoDungeon var VolcanoShaft = Game1.currentLocation as VolcanoDungeon; // Test to see if current location is a MineShaft if (!(mineShaft is null)) { // Yes, update tracker with new data // Display trace information in SMAPI log if (mineShaft.mineLevel < 121) { monitor.Log($"{Game1.player.Name} is on level {mineShaft.mineLevel} of the mine."); } else if (mineShaft.mineLevel == 77377) { monitor.Log($"{Game1.player.Name} is in the Quarry Mine."); } else { monitor.Log($"{Game1.player.Name} on level {mineShaft.mineLevel} (level {mineShaft.mineLevel - 120} of the Skull Cavern)."); } // Update trackers data.Value.CurrentMineLevel = mineShaft.mineLevel; data.Value.DeepestMineLevel = Game1.player.deepestMineLevel; monitor.Log($"Deepest mine level reached by {Game1.player.Name} is {data.Value.DeepestMineLevel}"); }
public CustomBoardController(IModEvents events) { events.Player.Warped += this.OnPlayerWarped; events.Display.RenderedWorld += this.OnWorldRendered; this._customBoardTriggers = new PerScreen <List <CustomBoardTrigger> >(() => new List <CustomBoardTrigger>()); this._currentLocationBoardTriggers = new PerScreen <CustomBoardTrigger[]>(); }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="screenManager">Manages state for each screen.</param> /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="contentPacks">The loaded content packs.</param> /// <param name="getContext">Get the current token context.</param> /// <param name="updateContext">A callback which immediately updates the current condition context.</param> public CommandHandler(PerScreen <ScreenManager> screenManager, IMonitor monitor, LoadedContentPack[] contentPacks, Func <string, IContext> getContext, Action updateContext) { this.ScreenManager = screenManager; this.Monitor = monitor; this.ContentPacks = contentPacks; this.GetContext = getContext; this.UpdateContext = updateContext; }
public static float GetAlpha(object instance, float changeToApply) { if (alphas.TryGetValue(instance, out PerScreen <float> alpha)) //if this instance already has stored alpha values { alpha.Value = Utility.Clamp(alpha.Value + changeToApply, 0.4f, 1f); //calculate and set new alpha (min 40%, max 100%) return(alpha.Value); } else { alpha = new PerScreen <float>(); //create new storage for this instance's alpha values alpha.Value = Utility.Clamp(1f + changeToApply, 0.4f, 1f); //calculate and set new alpha (min 40%, max 100%; default value 100%) alphas.Add(instance, alpha); //store this instance's alpha values return(alpha.Value); } }
public NpcOfferController(QuestOfferManager offerManager, QuestManager questmanager, IModEvents modEvents, IQuestFrameworkEvents qfEvents, IMonitor monitor) { this._npcQuestOffers = new PerScreen <List <QuestOffer <NpcOfferAttributes> > >(CreateOfferList); this._activeIndicators = new PerScreen <HashSet <string> >(CreateActiveIndicatorList); this._offerManager = offerManager; this._questManager = questmanager; this._monitor = monitor; modEvents.GameLoop.DayStarted += this.OnDayStarted; modEvents.GameLoop.TimeChanged += this.OnTimeChanged; modEvents.Player.Warped += this.OnPlayerWarped; modEvents.GameLoop.ReturnedToTitle += this.OnReturnedToTitle; modEvents.Display.RenderedWorld += this.OnRenderedWorld; qfEvents.QuestAccepted += this.OnQuestAccepted; }
internal void CheckForCompletedSpecialOrders(PerScreen <PlayerData> data, IMonitor monitor) { var order = Game1.player.team.completedSpecialOrders; // Check for completed special orders if (data.Value.SpecialOrdersCompleted.Count < order.Count()) { foreach (string questkey in new List <string>(order.Keys)) { if (data.Value.SpecialOrdersCompleted.Contains(questkey) == false) { data.Value.SpecialOrdersCompleted.Add(questkey); monitor.Log($"Special Order with key {questkey} has been completed"); } } } }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="screenManager">Manages state for each screen.</param> /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="contentHelper">Provides an API for managing content assets.</param> /// <param name="contentPacks">The loaded content packs.</param> /// <param name="getContext">Get the current token context.</param> /// <param name="updateContext">A callback which immediately updates the current condition context.</param> public CommandHandler(PerScreen <ScreenManager> screenManager, IMonitor monitor, IContentHelper contentHelper, LoadedContentPack[] contentPacks, Func <string, IContext> getContext, Action updateContext) { this.Monitor = monitor; this.Commands = new InvariantDictionary <ICommand>( new ICommand[] { new DumpCommand( monitor: this.Monitor, getPatchManager: () => screenManager.Value.PatchManager ), new ExportCommand( monitor: this.Monitor ), new HelpCommand( monitor: this.Monitor, getCommands: () => this.Commands ), new InvalidateCommand( monitor: this.Monitor, contentHelper: contentHelper ), new ParseCommand( monitor: this.Monitor, getContext: getContext ), new ReloadCommand( monitor: this.Monitor, getPatchLoader: () => screenManager.Value.PatchLoader, contentPacks: contentPacks, updateContext: updateContext ), new SummaryCommand( monitor: this.Monitor, getPatchManager: () => screenManager.Value.PatchManager, getTokenManager: () => screenManager.Value.TokenManager, getCustomLocationLoader: () => screenManager.Value.CustomLocationManager ), new UpdateCommand( monitor: this.Monitor, updateContext: updateContext ) } .ToDictionary(p => p.Name) ); }
/********* ** Public methods *********/ /// <summary>The mod entry point, called after the mod is first loaded.</summary> /// <param name="helper">Provides simplified APIs for writing mods.</param> public override void Entry(IModHelper helper) { // read config this.Config = helper.ReadConfig <ModConfig>(); // init I18n.Init(helper.Translation); this.TextureManager = new( directoryPath : this.Helper.DirectoryPath, publicAssetBasePath : this.PublicAssetBasePath, contentHelper : helper.ModContent, monitor : this.Monitor ); this.TractorManagerImpl = new(() => { var manager = new TractorManager(this.Config, this.Keys, this.Helper.Reflection); this.UpdateConfigFor(manager); return(manager); }); this.UpdateConfig(); // hook events IModEvents events = helper.Events; events.Content.AssetRequested += this.OnAssetRequested; events.GameLoop.GameLaunched += this.OnGameLaunched; events.GameLoop.SaveLoaded += this.OnSaveLoaded; events.GameLoop.DayStarted += this.OnDayStarted; events.GameLoop.DayEnding += this.OnDayEnding; events.GameLoop.Saved += this.OnSaved; events.Display.RenderedWorld += this.OnRenderedWorld; events.Display.MenuChanged += this.OnMenuChanged; events.Input.ButtonsChanged += this.OnButtonsChanged; events.World.NpcListChanged += this.OnNpcListChanged; events.World.LocationListChanged += this.OnLocationListChanged; events.GameLoop.UpdateTicked += this.OnUpdateTicked; events.Multiplayer.ModMessageReceived += this.OnModMessageReceived; events.Player.Warped += this.OnWarped; // validate translations if (!helper.Translation.GetTranslations().Any()) { this.Monitor.Log("The translation files in this mod's i18n folder seem to be missing. The mod will still work, but you'll see 'missing translation' messages. Try reinstalling the mod to fix this.", LogLevel.Warn); } }
/********* ** Private methods *********/ /**** ** Event handlers ****/ /// <summary>The method invoked on the first update tick, once all mods are initialized.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event data.</param> private void OnGameLaunched(object sender, GameLaunchedEventArgs e) { if (!this.IsDataValid) { return; } // get mod APIs JsonAssetsIntegration jsonAssets = new JsonAssetsIntegration(this.Helper.ModRegistry, this.Monitor); // initialize functionality var customFarming = new CustomFarmingReduxIntegration(this.Helper.ModRegistry, this.Monitor); var producerFramework = new ProducerFrameworkModIntegration(this.Helper.ModRegistry, this.Monitor); this.GameHelper = new GameHelper(customFarming, producerFramework, this.Metadata, this.Helper.Reflection); this.TargetFactory = new TargetFactory(this.Helper.Reflection, this.GameHelper, this.Config, jsonAssets, () => this.Config.EnableTileLookups); this.DebugInterface = new PerScreen <DebugInterface>(() => new DebugInterface(this.GameHelper, this.TargetFactory, this.Config, this.Monitor)); }
/********* ** Public methods *********/ /// <summary>The mod entry point, called after the mod is first loaded.</summary> /// <param name="helper">Provides simplified APIs for writing mods.</param> public override void Entry(IModHelper helper) { // load config this.Config = helper.ReadConfig <ModConfig>(); this.Monitor.Log($"Started with menu key {this.Config.OpenMenuKey}."); // init translations I18n.Init(helper.Translation); // load warps try { this.Warps = helper.Data.ReadJsonFile <ModData>("assets/warps.json"); if (this.Warps == null) { this.Monitor.Log("Some of the mod files are missing (assets/warps.json); try reinstalling this mod.", LogLevel.Error); return; } } catch (Exception ex) { this.Monitor.Log($"Some of the mod files are broken or corrupted (assets/warps.json); try reinstalling this mod.\n{ex}", LogLevel.Error); } // load cheats this.ResetLocationCache(); this.Cheats = new PerScreen <CheatManager>(() => new CheatManager(this.Config, this.Helper.Reflection, () => this.Locations.Value.Value, this.Warps)); // hook events helper.Events.Display.Rendered += this.OnRendered; helper.Events.Display.MenuChanged += this.OnMenuChanged; helper.Events.GameLoop.ReturnedToTitle += this.OnReturnedToTitle; helper.Events.GameLoop.SaveLoaded += this.OnSaveLoaded; helper.Events.GameLoop.UpdateTicked += this.OnUpdateTicked; helper.Events.Input.ButtonPressed += this.OnButtonPressed; helper.Events.Input.ButtonReleased += this.OnButtonReleased; helper.Events.World.LocationListChanged += this.OnLocationListChanged; }
public void OnSaveLoaded(object sender, SaveLoadedEventArgs e) { if (Context.IsMultiplayer) { if (!Context.IsMainPlayer) { Monitor.Log("Connected as non-host player. Only the host's PauseMode config setting will be used.", LogLevel.Info); } else { Monitor.Log($"Connected as host player. PauseMode set to \"{PauseMode}\"", LogLevel.Info); } } IsPaused = InitialPauseState; PlayerStates.Value = new Dictionary <long, PlayerState>(); var state = GetPlayerState(Game1.player.UniqueMultiplayerID); state.IsHost = Context.IsMainPlayer; state.ConfigPauseMode = PauseMode.Value; }
/********* ** Private methods *********/ /// <summary>Build the available commands.</summary> /// <param name="screenManager">Manages state for each screen.</param> /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="contentHelper">Provides an API for managing content assets.</param> /// <param name="contentPacks">The loaded content packs.</param> /// <param name="getContext">Get the current token context.</param> /// <param name="updateContext">A callback which immediately updates the current condition context.</param> private static ICommand[] BuildCommands(PerScreen <ScreenManager> screenManager, IMonitor monitor, IGameContentHelper contentHelper, LoadedContentPack[] contentPacks, Func <string?, IContext> getContext, Action updateContext) { return(new ICommand[] { new DumpCommand( monitor: monitor, getPatchManager: () => screenManager.Value.PatchManager ), new ExportCommand( monitor: monitor, contentHelper: contentHelper ), new InvalidateCommand( monitor: monitor, contentHelper: contentHelper ), new ParseCommand( monitor: monitor, getContext: getContext ), new ReloadCommand( monitor: monitor, getPatchLoader: () => screenManager.Value.PatchLoader, contentPacks: contentPacks, updateContext: updateContext ), new SummaryCommand( monitor: monitor, getPatchManager: () => screenManager.Value.PatchManager, getTokenManager: () => screenManager.Value.TokenManager, getCustomLocationLoader: () => screenManager.Value.CustomLocationManager ), new UpdateCommand( monitor: monitor, updateContext: updateContext ) }); }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="parse">Get parsed conditions for the currently active screen.</param> public ApiManagedConditions(Func <IManagedConditions> parse) { this.Conditions = new PerScreen <IManagedConditions>(parse); }
public QuestManager(IMonitor monitor) { this.monitor = monitor; this._quests = new PerScreen <List <CustomQuest> >(() => new List <CustomQuest>()); this.Factories = new Dictionary <string, Func <CustomQuest> >(); }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="screenManager">Manages state for each screen.</param> /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="contentHelper">Provides an API for managing content assets.</param> /// <param name="contentPacks">The loaded content packs.</param> /// <param name="getContext">Get the current token context.</param> /// <param name="updateContext">A callback which immediately updates the current condition context.</param> public CommandHandler(PerScreen <ScreenManager> screenManager, IMonitor monitor, IGameContentHelper contentHelper, LoadedContentPack[] contentPacks, Func <string?, IContext> getContext, Action updateContext) : base("patch", "Content Patcher", CommandHandler.BuildCommands(screenManager, monitor, contentHelper, contentPacks, getContext, updateContext), monitor) { }
internal void UpdateDeathAndExhaustionTokens(IModHelper helper, IMonitor monitor, PerScreen <PlayerData> data, ModConfig config) { // Update tracker if player died, is married and tracker should update if (Game1.killScreen == true && Game1.player.isMarried() == true && updatedeath == true) { // Increment tracker data.Value.DeathCountMarried++; // Already updated, ensures tracker won't repeatedly increment updatedeath = false; // Display trace information in SMAPI log if (config.ResetDeathCountMarriedWhenDivorced == true) { monitor.Log($"{Game1.player.Name} has died {data.Value.DeathCountMarried} time(s) since last marriage."); } else { monitor.Log($"{Game1.player.Name} has died {data.Value.DeathCountMarried} time(s) whilst married."); } } else if (Game1.killScreen == false && updatedeath == false) { // Tracker should be updated next death updatedeath = true; } // Has player passed out? else if (updatepassout == true && (Game1.timeOfDay == 2600 || Game1.player.stamina <= -15)) { // Yes, update tracker // Increment tracker data.Value.PassOutCount++; // Already updated, ensures tracker won't repeatedly increment updatepassout = false; // Display trace information in SMAPI log if (data.Value.PassOutCount > 20) { monitor.Log($"{Game1.player.Name} has passed out {data.Value.PassOutCount} time(s). Maybe you should go to bed earlier."); } else { monitor.Log($"{Game1.player.Name} has passed out {data.Value.PassOutCount} time(s)."); } } else if (Game1.timeOfDay == 2610 && updatepassout == false) { // Decrement tracker, player can stay up later data.Value.PassOutCount--; // Already updated, ensures tracker won't repeatedly decrement updatepassout = true; // Display trace information in SMAPI log monitor.Log($"Nevermind, {Game1.player.Name} has actually passed out {data.Value.PassOutCount} time(s). Aren't you getting tired?"); } }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="screenManager">Manages state for each screen.</param> public AssetInterceptor(PerScreen <ScreenManager> screenManager) { this.ScreenManager = screenManager; }
public QuestOfferManager(ConditionManager conditionManager, QuestManager questManager) { this._offers = new PerScreen <List <QuestOffer> >(() => new List <QuestOffer>()); this.conditionManager = conditionManager; this.questManager = questManager; }
ColorData() { currentSet_ = new (() => initialSet); }