Skip to content

Commit

Permalink
Version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Bpendragon committed Jan 2, 2021
1 parent cac7d7b commit 2e09a9b
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 91 deletions.
6 changes: 6 additions & 0 deletions GreenhouseSprinklers/GreenhouseSprinklers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{96DF27DA-EA8F-4637-A642-90717C166693}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{96DF27DA-EA8F-4637-A642-90717C166693}.Debug|Any CPU.Build.0 = Debug|Any CPU
{96DF27DA-EA8F-4637-A642-90717C166693}.Debug|x86.ActiveCfg = Debug|x86
{96DF27DA-EA8F-4637-A642-90717C166693}.Debug|x86.Build.0 = Debug|x86
{96DF27DA-EA8F-4637-A642-90717C166693}.Release|Any CPU.ActiveCfg = Release|Any CPU
{96DF27DA-EA8F-4637-A642-90717C166693}.Release|Any CPU.Build.0 = Release|Any CPU
{96DF27DA-EA8F-4637-A642-90717C166693}.Release|x86.ActiveCfg = Release|x86
{96DF27DA-EA8F-4637-A642-90717C166693}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using Bpendragon.GreenhouseSprinklers.Data;
using StardewModdingAPI;
using StardewModdingAPI.Events;

namespace Bpendragon.GreenhouseSprinklers
Expand All @@ -7,13 +9,12 @@ partial class ModEntry
{
internal void OnLoad(object sender, SaveLoadedEventArgs e)
{

throw new NotImplementedException();
Data = Helper.Data.ReadJsonFile<ModData>($"data/{Constants.SaveFolderName}.json") ?? new ModData();
}

internal void OnSave(object sender, SavingEventArgs e)
{
this.Helper.Data.WriteJsonFile("data.json", Data);
Helper.Data.WriteJsonFile($"data/{Constants.SaveFolderName}.json", Data);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,30 @@ partial class ModEntry
private readonly int MaxOccupantsID = -794738;
private void OnMenuChanged(object sender, MenuChangedEventArgs e)
{
if (e.NewMenu == null) return; //if menu was closed this should fix it.
Monitor.Log($"Menu type {e.NewMenu.GetType()} opened");
if (!Context.IsWorldReady) return;
if (!(e.NewMenu is CarpenterMenu)) return;
int level = 1;
if (Data.FirstUpgrade) level = 2;
if (Data.SecondUpgrade) level = 3;
if (Data.FinalUpgrade) return; //we've built the final upgrade,
if (e.NewMenu is CarpenterMenu)
if (Data.FinalUpgrade)
{
Monitor.Log("In the Carpenter Menu, here's hoping");
IList<BluePrint> blueprints = this.Helper.Reflection
.GetField<List<BluePrint>>(e.NewMenu, "blueprints")
.GetValue();

blueprints.Add(this.GetBluePrint(level));
Monitor.Log("Blueprint should be added");
if (!blueprints.Any(p => p.name == "Stable" && p.maxOccupants != this.MaxOccupantsID))
{
Farm farm = Game1.getFarm();

int cabins = farm.getNumberBuildingsConstructed("Cabin");
int stables = farm.getNumberBuildingsConstructed("Stable");
if (stables < cabins + 1)
blueprints.Add(new BluePrint("Stable"));
}
Monitor.Log("We've got the final upgrade, skipping");
return; //we've built the final upgrade,
}
Monitor.Log("In the Carpenter Menu, here's hoping");
IList<BluePrint> blueprints = Helper.Reflection
.GetField<List<BluePrint>>(e.NewMenu, "blueprints")
.GetValue();

blueprints.Add(GetBluePrint(level));
Monitor.Log("Blueprint should be added");
}

private void OnBuildingListChanged(object sender, BuildingListChangedEventArgs e)
{
Monitor.Log("Building list changed");
}

private BluePrint GetBluePrint(int level)
Expand Down Expand Up @@ -76,17 +74,17 @@ private BluePrint GetBluePrint(int level)
buildMats = BuildMaterials3;
days = cost.SecondUpgrade.DaysToConstruct;
}
return new BluePrint("Stable")
return new BluePrint("Silo")
{
displayName = "Sprinkler System Upgrade",
description = desc,
moneyRequired = money,
nameOfBuildingToUpgrade = "Greenhouse",
nameOfBuildingToUpgrade = "Silo",
itemsRequired = buildMats,
daysToConstruct = days,
maxOccupants = this.MaxOccupantsID
maxOccupants = MaxOccupantsID,
blueprintType = "Upgrades"
};
}

}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,53 @@
using StardewModdingAPI.Events;
using System;
using StardewModdingAPI;
using StardewValley;
using System.Linq;

namespace Bpendragon.GreenhouseSprinklers
{
partial class ModEntry
{
internal void OnDayStart(object sender, DayStartedEventArgs e)
{
WaterGreenHouse();
this.Monitor.Log("Day starting");
Monitor.Log("Day starting");
if (Data.FirstUpgrade)
{
this.Monitor.Log("first upgrade owned, watering");

Monitor.Log("first upgrade owned, watering");
WaterGreenHouse();
}
if(Data.FinalUpgrade)
{
Monitor.Log("final ugrade owned, watering entire farm");
WaterFarm();
}
}

internal void OnDayEnding(object sender, DayEndingEventArgs e)
{
this.Monitor.Log("Day ending");
if (Data.SecondUpgrade)
Monitor.Log("Day ending");
if (Data.SecondUpgrade) //run these checks before we check for upgrades
{
this.Monitor.Log("second upgrade owned, watering");
Monitor.Log("second upgrade owned, watering");
WaterGreenHouse();
}
}

internal void OnTimeChanged(object sender, TimeChangedEventArgs e)
{
throw new NotImplementedException();
}


if (Data.FinalUpgrade)
{
Monitor.Log("final ugrade owned, watering entire farm");
WaterFarm();
}
if (!Data.FinalUpgrade)
{
var silo = Game1.getFarm().buildings.Where(x => x.buildingType == "Silo" && x.daysUntilUpgrade == 1).FirstOrDefault();
if (silo != null)
{
Monitor.Log("Silo \"Upgrade\" completed, moving to next level");
silo.daysUntilUpgrade.Value = 0;
if (!Data.FirstUpgrade) Data.FirstUpgrade = true;
else if (!Data.SecondUpgrade) Data.SecondUpgrade = true;
else if (!Data.FinalUpgrade) Data.FinalUpgrade = true;
else Monitor.Log("Tried to Upgrade sprinklers while all upgrades already completed", LogLevel.Error);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,33 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Build" />
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Utilities.v4.0" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -48,7 +72,6 @@
<Compile Include="Models\ModConfig.cs" />
<Compile Include="Models\ModData.cs" />
<Compile Include="Controllers\FileController.cs" />
<Compile Include="Models\Upgrades.cs" />
<Compile Include="ModEntry.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand All @@ -60,16 +83,16 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Pathoschild.Stardew.ModBuildConfig.3.0.0\build\Pathoschild.Stardew.ModBuildConfig.targets" Condition="Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.3.0.0\build\Pathoschild.Stardew.ModBuildConfig.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.3.0.0\build\Pathoschild.Stardew.ModBuildConfig.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Pathoschild.Stardew.ModBuildConfig.3.0.0\build\Pathoschild.Stardew.ModBuildConfig.targets'))" />
</Target>
<ProjectExtensions>
<VisualStudio>
<UserProperties manifest_1json__JsonSchema="" />
</VisualStudio>
</ProjectExtensions>
<Import Project="..\packages\Pathoschild.Stardew.ModBuildConfig.3.2.2\build\Pathoschild.Stardew.ModBuildConfig.targets" Condition="Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.3.2.2\build\Pathoschild.Stardew.ModBuildConfig.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.3.2.2\build\Pathoschild.Stardew.ModBuildConfig.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Pathoschild.Stardew.ModBuildConfig.3.2.2\build\Pathoschild.Stardew.ModBuildConfig.targets'))" />
</Target>
</Project>
72 changes: 55 additions & 17 deletions GreenhouseSprinklers/GreenhouseSprinklers/ModEntry.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using Bpendragon.GreenhouseSprinklers.Data;

using StardewModdingAPI;

using StardewValley;
using StardewValley.Objects;
using StardewValley.TerrainFeatures;

using System.Collections.Generic;
using System.Linq;

Expand All @@ -13,31 +16,34 @@ partial class ModEntry : Mod
private ModConfig Config;
private ModData Data;
public Dictionary<int, int> BuildMaterials1 { get; set; } = new Dictionary<int, int>();
public Dictionary<int, int> BuildMaterials2 { get; set; } = new Dictionary<int, int>();
public Dictionary<int, int> BuildMaterials2 { get; set; } = new Dictionary<int, int>();
public Dictionary<int, int> BuildMaterials3 { get; set; } = new Dictionary<int, int>();
public Difficulty difficulty;

public override void Entry(IModHelper helper)
{
this.Config = this.Helper.ReadConfig<ModConfig>();
Config = Helper.ReadConfig<ModConfig>();


SetBuildMaterials();
Data = this.Helper.Data.ReadJsonFile<ModData>($"data/{Constants.SaveFolderName}.json") ?? new ModData();



helper.Events.GameLoop.DayStarted += OnDayStart;
helper.Events.GameLoop.DayEnding += OnDayEnding;
helper.Events.GameLoop.Saving += OnSave;
//helper.Events.GameLoop.SaveLoaded += OnLoad;
helper.Events.Display.MenuChanged += OnMenuChanged;


helper.Events.GameLoop.DayStarted += OnDayStart;
helper.Events.GameLoop.DayEnding += OnDayEnding;
helper.Events.GameLoop.Saving += OnSave;
helper.Events.GameLoop.SaveLoaded += OnLoad;
helper.Events.Display.MenuChanged += OnMenuChanged;
helper.Events.World.BuildingListChanged += OnBuildingListChanged;
}


private void SetBuildMaterials()
{
var diff = Config.DifficultySettings.First(x => x.Difficulty == Config.SelectedDifficulty);
this.difficulty = Config.SelectedDifficulty;
if(null == diff)
difficulty = Config.SelectedDifficulty;
if (null == diff)
{
Monitor.Log("Difficulty Settings not found or set, mod will not work properly", LogLevel.Error);
}
Expand All @@ -58,15 +64,15 @@ private void WaterGreenHouse()
var gh = Game1.getLocationFromName("Greenhouse");
if (gh != null)
{
this.Monitor.Log("Greenhouse Located");
Monitor.Log("Greenhouse Located");
}
else
{
this.Monitor.Log("No Greenhouse found", StardewModdingAPI.LogLevel.Warn);
Monitor.Log("No Greenhouse found", LogLevel.Warn);
}
int i = 0;
var terrainfeatures = gh.terrainFeatures.Values;
this.Monitor.Log($"Found {terrainfeatures.Count()} terrainfeatures in Greenhouse");
Monitor.Log($"Found {terrainfeatures.Count()} terrainfeatures in Greenhouse");

foreach (var tf in terrainfeatures)
{
Expand All @@ -76,10 +82,10 @@ private void WaterGreenHouse()
i++;
}
}
this.Monitor.Log($"{i} tiles watered.");
Monitor.Log($"{i} tiles watered.");

int j = 0;
this.Monitor.Log("Watering pots in greenhouse");
Monitor.Log("Watering pots in greenhouse");
foreach (IndoorPot pot in gh.objects.Values.OfType<IndoorPot>())
{
if (pot.hoeDirt.Value is HoeDirt dirt)
Expand All @@ -90,7 +96,39 @@ private void WaterGreenHouse()
}
}

this.Monitor.Log($"{j} Pots Watered");
Monitor.Log($"{j} Pots Watered");
}

private void WaterFarm()
{
var farm = Game1.getFarm();
int i = 0;
var terrainFeatures = farm.terrainFeatures.Values;
Monitor.Log($"Found {terrainFeatures.Count()} terrainfeatures in Farm");

foreach (var tf in terrainFeatures)
{
if (tf is HoeDirt dirt)
{
dirt.state.Value = HoeDirt.watered;
i++;
}
}
Monitor.Log($"{i} tiles watered.");

int j = 0;
Monitor.Log("Watering pots on farm");
foreach (IndoorPot pot in farm.objects.Values.OfType<IndoorPot>())
{
if (pot.hoeDirt.Value is HoeDirt dirt)
{
dirt.state.Value = HoeDirt.watered;
pot.showNextIndex.Value = true;
j++;
}
}

Monitor.Log($"{j} Pots Watered");
}
}
}
Loading

0 comments on commit 2e09a9b

Please sign in to comment.