Skip to content

Commit

Permalink
crc api
Browse files Browse the repository at this point in the history
  • Loading branch information
aedenthorn committed Mar 16, 2022
1 parent 3a375e4 commit 21a3858
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 120 deletions.
1 change: 1 addition & 0 deletions CustomResourceClumps/CustomResourceClump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace CustomResourceClumps
public class CustomResourceClump
{
public List<DropItem> dropItems = new List<DropItem>();
public string id;
public string clumpDesc;
public int debrisType;
public string[] hitSounds;
Expand Down
37 changes: 37 additions & 0 deletions CustomResourceClumps/CustomResourceClumps.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Microsoft.Xna.Framework;
using StardewValley;
using StardewValley.TerrainFeatures;
using System.Collections.Generic;
using System.Linq;

namespace CustomResourceClumps
{
public class CustomResourceClumps
{
public ResourceClump GetCustomClump(string id, Vector2 tile)
{
var clump = ModEntry.customClumps.Find(n => n.id == id);
if (clump == null)
return null;
return new ResourceClump(clump.index, clump.tileWidth, clump.tileHeight, tile);
}
public bool TryPlaceClump(GameLocation location, string id, Vector2 tile)
{
if (location == null)
return false;
var clump = ModEntry.customClumps.Find(n => n.id == id);
if (clump == null)
return false;
location.resourceClumps.Add(new ResourceClump(clump.index, clump.tileWidth, clump.tileHeight, tile));
return true;
}
public List<object> GetCustomClumpData()
{
return new List<object>(ModEntry.customClumps);
}
public List<string> GetCustomClumpIDs()
{
return ModEntry.customClumps.Select(n => n.id).ToList();
}
}
}
85 changes: 12 additions & 73 deletions CustomResourceClumps/CustomResourceClumps.csproj
Original file line number Diff line number Diff line change
@@ -1,81 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5BE0FDBC-2CCF-406D-B690-B15F15302438}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CustomResourceClumps</RootNamespace>
<AssemblyName>CustomResourceClumps</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<EnableHarmony>true</EnableHarmony>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Version>1.0.0</Version>
<TargetFramework>net5.0</TargetFramework>
<EnableHarmony>true</EnableHarmony>
</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" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
<Compile Include="CustomResourceClumpData.cs" />
<Compile Include="CustomResourceClump.cs" />
<Compile Include="DropItem.cs" />
<Compile Include="ModConfig.cs" />
<Compile Include="ModEntry.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="assets\copper.png" />
<Content Include="assets\diamond.png" />
<Content Include="assets\gold.png" />
<Content Include="assets\iron.png" />
<Content Include="EXAMPLEcustom_resource_clumps.json">
<None Update="i18n\default.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="manifest.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="i18n\default.json" />
<None Include="i18n\ko.json" />
<None Include="manifest.json" />
<None Include="packages.config" />
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Pathoschild.Stardew.ModBuildConfig.4.0.0\build\Pathoschild.Stardew.ModBuildConfig.targets" Condition="Exists('..\packages\Pathoschild.Stardew.ModBuildConfig.4.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.4.0.0\build\Pathoschild.Stardew.ModBuildConfig.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Pathoschild.Stardew.ModBuildConfig.4.0.0\build\Pathoschild.Stardew.ModBuildConfig.targets'))" />
</Target>
</Project>
18 changes: 9 additions & 9 deletions CustomResourceClumps/ModEntry.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Harmony;
using HarmonyLib;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI;
Expand Down Expand Up @@ -50,7 +50,7 @@ public override void Entry(IModHelper helper)
Config = Helper.ReadConfig<ModConfig>();
SMonitor = Monitor;
SHelper = Helper;
var harmony = HarmonyInstance.Create(ModManifest.UniqueID);
var harmony = new Harmony(ModManifest.UniqueID);

harmony.Patch(
original: AccessTools.Method(typeof(MineShaft), "populateLevel"),
Expand Down Expand Up @@ -209,7 +209,7 @@ private static void MineShaft_populateLevel_Postfix(MineShaft __instance)
}
private static bool ResourceClump_draw_prefix(ResourceClump __instance, SpriteBatch spriteBatch, float ___shakeTimer)
{
int indexOfClump = __instance.parentSheetIndex;
int indexOfClump = __instance.parentSheetIndex.Value;
if (indexOfClump >= 0)
{
return true;
Expand All @@ -229,7 +229,7 @@ private static bool ResourceClump_draw_prefix(ResourceClump __instance, SpriteBa

private static bool ResourceClump_performToolAction_prefix(ref ResourceClump __instance, Tool t, Vector2 tileLocation, GameLocation location, ref bool __result)
{
int indexOfClump = __instance.parentSheetIndex;
int indexOfClump = __instance.parentSheetIndex.Value;
if (indexOfClump >= 0)
{
return true;
Expand All @@ -249,7 +249,7 @@ private static bool ResourceClump_performToolAction_prefix(ref ResourceClump __i
return false;
}
SMonitor.Log($"tooltype is correct");
if (t.upgradeLevel < clump.toolMinLevel)
if (t.UpgradeLevel < clump.toolMinLevel)
{
foreach (string sound in clump.failSounds)
location.playSound(sound, NetAudio.SoundContext.Default);
Expand All @@ -260,11 +260,11 @@ private static bool ResourceClump_performToolAction_prefix(ref ResourceClump __i
return false;
}

float power = Math.Max(1f, (float)(t.upgradeLevel + 1) * 0.75f);
float power = Math.Max(1f, (float)(t.UpgradeLevel + 1) * 0.75f);
__instance.health.Value -= power;
Game1.createRadialDebris(Game1.currentLocation, clump.debrisType, (int)tileLocation.X + Game1.random.Next(__instance.width / 2 + 1), (int)tileLocation.Y + Game1.random.Next(__instance.height / 2 + 1), Game1.random.Next(4, 9), false, -1, false, -1);
Game1.createRadialDebris(Game1.currentLocation, clump.debrisType, (int)tileLocation.X + Game1.random.Next(__instance.width.Value / 2 + 1), (int)tileLocation.Y + Game1.random.Next(__instance.height.Value / 2 + 1), Game1.random.Next(4, 9), false, -1, false, -1);

if (__instance.health > 0f)
if (__instance.health.Value > 0f)
{
foreach (string sound in clump.hitSounds)
location.playSound(sound, NetAudio.SoundContext.Default);
Expand Down Expand Up @@ -304,7 +304,7 @@ private static bool ResourceClump_performToolAction_prefix(ref ResourceClump __i
}
}
int amount = addedItems + Game1.random.Next(item.minAmount, Math.Max(item.minAmount + 1, item.maxAmount + 1)) + ((Game1.random.NextDouble() < (double)((float)who.LuckLevel / 100f)) ? item.luckyAmount : 0);
Game1.createMultipleObjectDebris(itemId, (int)tileLocation.X, (int)tileLocation.Y, amount, who.uniqueMultiplayerID, location);
Game1.createMultipleObjectDebris(itemId, (int)tileLocation.X, (int)tileLocation.Y, amount, who.UniqueMultiplayerID, location);
}
}
if (expTypes.ContainsKey(clump.expType))
Expand Down
36 changes: 0 additions & 36 deletions CustomResourceClumps/Properties/AssemblyInfo.cs

This file was deleted.

4 changes: 2 additions & 2 deletions CustomResourceClumps/manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"Name": "Custom Resource Clumps",
"Author": "aedenthorn",
"Version": "0.4.1",
"Version": "0.5.0",
"Description": "Spawns custom resource clumps in mines.",
"UniqueID": "aedenthorn.CustomResourceClumps",
"EntryDll": "CustomResourceClumps.dll",
"MinimumApiVersion": "3.8.0",
"MinimumApiVersion": "3.13.0",
"UpdateKeys": ["Nexus:6669"],
"ModUpdater": {
"Repository": "StardewValleyMods",
Expand Down

0 comments on commit 21a3858

Please sign in to comment.