/// <summary>Apply the mod configuration to a tractor manager instance.</summary> /// <param name="manager">The tractor manager to update.</param> private void UpdateConfigFor(TractorManager manager) { var modRegistry = this.Helper.ModRegistry; var reflection = this.Helper.Reflection; var toolConfig = this.Config.StandardAttachments; manager.UpdateConfig(this.Config, this.Keys, new IAttachment[] { new CustomAttachment(this.Config.CustomAttachments, modRegistry, reflection), // should be first so it can override default attachments new AxeAttachment(toolConfig.Axe, modRegistry, reflection), new FertilizerAttachment(toolConfig.Fertilizer, modRegistry, reflection), new GrassStarterAttachment(toolConfig.GrassStarter, modRegistry, reflection), new HoeAttachment(toolConfig.Hoe, modRegistry, reflection), new MeleeBluntAttachment(toolConfig.MeleeBlunt, modRegistry, reflection), new MeleeDaggerAttachment(toolConfig.MeleeDagger, modRegistry, reflection), new MeleeSwordAttachment(toolConfig.MeleeSword, modRegistry, reflection), new MilkPailAttachment(toolConfig.MilkPail, modRegistry, reflection), new PickaxeAttachment(toolConfig.PickAxe, modRegistry, reflection), new ScytheAttachment(toolConfig.Scythe, modRegistry, reflection), new SeedAttachment(toolConfig.Seeds, modRegistry, reflection), modRegistry.IsLoaded(SeedBagAttachment.ModId) ? new SeedBagAttachment(toolConfig.SeedBagMod, modRegistry, reflection) : null, new ShearsAttachment(toolConfig.Shears, modRegistry, reflection), new SlingshotAttachment(toolConfig.Slingshot, modRegistry, reflection), new WateringCanAttachment(toolConfig.WateringCan, modRegistry, reflection) }); }
/**** ** State methods ****/ /// <summary>Detect and fix tractor garages that started construction today.</summary> private void ProcessNewConstruction() { foreach (GarageMetadata metadata in this.GetGarages().ToArray()) { this.HasAnyGarages = true; Building garage = metadata.Building; BuildableGameLocation location = metadata.Location; // skip if not built today if (garage is TractorGarage) { continue; } // set construction days after it's placed if (!this.GaragesStartedToday.Contains(garage)) { garage.daysOfConstructionLeft = this.GarageConstructionDays; this.GaragesStartedToday.Add(garage); } // spawn tractor if built instantly by a mod if (!garage.isUnderConstruction()) { this.GaragesStartedToday.Remove(garage); location.destroyStructure(garage); location.buildings.Add(new TractorGarage(this.GetBlueprint(), new Vector2(garage.tileX, garage.tileY), 0)); if (this.Tractor == null) { this.Tractor = this.SpawnTractor(location, garage.tileX + 1, garage.tileY + 1); } } } }
/********* ** 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>(); this.Keys = this.Config.Controls.ParseControls(helper.Input, this.Monitor); // init I18n.Init(helper.Translation); this.TractorManager = new TractorManager(this.Config, this.Keys, this.Helper.Reflection); this.UpdateConfig(); // hook events IModEvents events = helper.Events; events.GameLoop.GameLaunched += this.OnGameLaunched; events.GameLoop.SaveLoaded += this.OnSaveLoaded; events.GameLoop.DayStarted += this.OnDayStarted; events.GameLoop.DayEnding += this.OnDayEnding; events.GameLoop.Saving += this.OnSaving; events.Display.Rendered += this.OnRendered; events.Display.MenuChanged += this.OnMenuChanged; events.Input.ButtonPressed += this.OnButtonPressed; 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); } }
/// <summary>Spawn a new tractor.</summary> /// <param name="location">The location in which to spawn a tractor.</param> /// <param name="tileX">The tile X position at which to spawn it.</param> /// <param name="tileY">The tile Y position at which to spawn it.</param> private TractorManager SpawnTractor(BuildableGameLocation location, int tileX, int tileY) { TractorManager tractor = new TractorManager(tileX, tileY, this.Config, this.Attachments, this.GetTexture("tractor"), this.Helper.Translation, this.Helper.Reflection); tractor.SetLocation(location, new Vector2(tileX, tileY)); tractor.SetPixelPosition(new Vector2(tractor.Current.Position.X + 20, tractor.Current.Position.Y)); return(tractor); }
/********* ** Private methods *********/ /**** ** Event handlers ****/ /// <summary>The event called when a new day begins.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void TimeEvents_AfterDayStarted(object sender, EventArgs e) { // set up for new day this.Tractor = null; this.GaragesStartedToday.Clear(); this.RestoreCustomData(); this.HasAnyGarages = this.GetGarages().Any(); }
/// <summary>Restore tractor and garage data removed by <see cref="StashCustomData"/>.</summary> /// <remarks>The Robin construction logic is derived from <see cref="NPC.reloadSprite"/> and <see cref="StardewValley.Farm.resetForPlayerEntry"/>.</remarks> private void RestoreCustomData() { // get save data CustomSaveData saveData = this.Helper.ReadJsonFile <CustomSaveData>(this.GetDataPath(Constants.SaveFolderName)); if (saveData?.Buildings == null) { return; } // add tractor + garages BluePrint blueprint = this.GetBlueprint(); BuildableGameLocation[] locations = CommonHelper.GetLocations().OfType <BuildableGameLocation>().ToArray(); foreach (CustomSaveBuilding garageData in saveData.Buildings) { // get location BuildableGameLocation location = locations.FirstOrDefault(p => this.GetMapName(p) == (garageData.Map ?? "Farm")); if (location == null) { this.Monitor.Log($"Ignored tractor garage in unknown location '{garageData.Map}'."); continue; } // add garage TractorGarage garage = new TractorGarage(blueprint, garageData.Tile, Math.Max(0, garageData.DaysOfConstructionLeft - 1)); location.buildings.Add(garage); // add Robin construction if (garage.isUnderConstruction() && !this.IsRobinBusy) { this.IsRobinBusy = true; NPC robin = Game1.getCharacterFromName("Robin"); // update Robin robin.ignoreMultiplayerUpdates = true; robin.sprite.setCurrentAnimation(new List <FarmerSprite.AnimationFrame> { new FarmerSprite.AnimationFrame(24, 75), new FarmerSprite.AnimationFrame(25, 75), new FarmerSprite.AnimationFrame(26, 300, false, false, farmer => this.Helper.Reflection.GetPrivateMethod(robin, "robinHammerSound").Invoke(farmer)), new FarmerSprite.AnimationFrame(27, 1000, false, false, farmer => this.Helper.Reflection.GetPrivateMethod(robin, "robinVariablePause").Invoke(farmer)) }); robin.ignoreScheduleToday = true; Game1.warpCharacter(robin, location.Name, new Vector2(garage.tileX + garage.tilesWide / 2, garage.tileY + garage.tilesHigh / 2), false, false); robin.position.X += Game1.tileSize / 4; robin.position.Y -= Game1.tileSize / 2; robin.CurrentDialogue.Clear(); robin.CurrentDialogue.Push(new Dialogue(Game1.content.LoadString("Strings\\StringsFromCSFiles:NPC.cs.3926"), robin)); } // spawn tractor if (this.Tractor == null && !garage.isUnderConstruction()) { this.Tractor = this.SpawnTractor(location, garage.tileX + 1, garage.tileY + 1); } } }
/********* ** 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>(); this.Keys = this.Config.Controls.ParseControls(helper.Input, this.Monitor); // init tractor logic { IModRegistry modRegistry = this.Helper.ModRegistry; IReflectionHelper reflection = this.Helper.Reflection; StandardAttachmentsConfig toolConfig = this.Config.StandardAttachments; this.TractorManager = new TractorManager(this.Config, this.Keys, this.Helper.Translation, this.Helper.Reflection, attachments: new IAttachment[] { new CustomAttachment(this.Config.CustomAttachments, modRegistry, reflection), // should be first so it can override default attachments new AxeAttachment(toolConfig.Axe, modRegistry, reflection), new FertilizerAttachment(toolConfig.Fertilizer, modRegistry, reflection), new GrassStarterAttachment(toolConfig.GrassStarter, modRegistry, reflection), new HoeAttachment(toolConfig.Hoe, modRegistry, reflection), new MeleeWeaponAttachment(toolConfig.MeleeWeapon, modRegistry, reflection), new MilkPailAttachment(toolConfig.MilkPail, modRegistry, reflection), new PickaxeAttachment(toolConfig.PickAxe, modRegistry, reflection), new ScytheAttachment(toolConfig.Scythe, modRegistry, reflection), new SeedAttachment(toolConfig.Seeds, modRegistry, reflection), new SeedBagAttachment(toolConfig.SeedBagMod, modRegistry, reflection), new ShearsAttachment(toolConfig.Shears, modRegistry, reflection), new SlingshotAttachment(toolConfig.Slingshot, modRegistry, reflection), new WateringCanAttachment(toolConfig.WateringCan, modRegistry, reflection) }); } // hook events IModEvents events = helper.Events; events.GameLoop.GameLaunched += this.OnGameLaunched; events.GameLoop.SaveLoaded += this.OnSaveLoaded; events.GameLoop.DayStarted += this.OnDayStarted; events.GameLoop.DayEnding += this.OnDayEnding; events.GameLoop.Saving += this.OnSaving; if (this.Config.HighlightRadius) { events.Display.Rendered += this.OnRendered; } events.Display.MenuChanged += this.OnMenuChanged; events.Input.ButtonPressed += this.OnButtonPressed; events.World.NpcListChanged += this.OnNpcListChanged; events.World.LocationListChanged += this.OnLocationListChanged; events.GameLoop.UpdateTicked += this.OnUpdateTicked; events.Multiplayer.ModMessageReceived += this.OnModMessageReceived; // 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); } }
public void Start() { bool keepRunning = true; MyTractorManager = new TractorManager(); int userKey = -1; ConsoleIO.WriteWelcome(); do { ConsoleIO.PrintMenu(); switch (ConsoleIO.GetSelection()) { case 1: Console.Clear(); Dictionary <int, Tractor> tractorDictionary = MyTractorManager.GetAllTractors(); ConsoleIO.WriteAllTractors(tractorDictionary); break; case 2: int key = ConsoleIO.GetTractorKeyFromUser(); Tractor current = MyTractorManager.GetATractorByKey(key); ConsoleIO.WriteTractor(current); ConsoleIO.PressAnyKey(); break; case 3: Tractor newTractor = ConsoleIO.GetTractorFromUser(); MyTractorManager.AddTractor(newTractor); break; case 4: userKey = ConsoleIO.GetTractorKeyFromUser(); Tractor updatedTractor = ConsoleIO.GetTractorFromUser(MyTractorManager.GetATractorByKey(userKey)); MyTractorManager.UpdateTractor(userKey, updatedTractor); break; case 5: userKey = ConsoleIO.GetTractorKeyFromUser(); Tractor deletedTractor = MyTractorManager.DeleteTractor(userKey); ConsoleIO.ConfirmDelete(deletedTractor); break; default: keepRunning = false; break; } } while (keepRunning); MyTractorManager.CloseManager(); }
/********* ** 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); } }