Stardew_Valley_Mods/GeneralMods/AutoSpeed/AutoSpeed.cs

71 lines
2.2 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
using Omegasis.AutoSpeed.Framework;
2017-07-28 08:28:39 +08:00
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
2017-07-28 08:28:39 +08:00
namespace Omegasis.AutoSpeed
{
/// <summary>The mod entry point.</summary>
public class AutoSpeed : Mod
{
/*********
**Static Fields
*********/
/// <summary>
/// All of the speed that is added together for auto speed. This is used for mod authors to hook in their speed boosts before auto speed applies the default speed boost.
/// </summary>
public Dictionary<string, int> combinedAddedSpeed;
/*********
2019-01-06 15:23:07 +08:00
** Fields
*********/
/// <summary>The mod configuration.</summary>
private ModConfig Config;
/// <summary>
/// A static reference to expose public fields.
/// </summary>
public static AutoSpeed Instance;
/*********
** 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)
{
2019-01-06 15:21:06 +08:00
helper.Events.GameLoop.UpdateTicked += this.OnUpdateTicked;
this.Config = helper.ReadConfig<ModConfig>();
this.combinedAddedSpeed = new Dictionary<string, int>();
Instance = this;
}
/// <summary>
/// Returns a copy of the mods' api.
/// </summary>
/// <returns></returns>
public override object GetApi()
{
return new AutoSpeedAPI();
}
/*********
** Private methods
*********/
2019-01-06 15:21:06 +08:00
/// <summary>Raised after the game state is updated (≈60 times per second).</summary>
/// <param name="sender">The event sender.</param>
2019-01-06 15:21:06 +08:00
/// <param name="e">The event arguments.</param>
private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
{
if (Context.IsPlayerFree)
{
int addedSpeed = this.combinedAddedSpeed.Values.Sum();
Game1.player.addedSpeed = this.Config.Speed+addedSpeed;
}
}
}
}