Add bomb support

This commit is contained in:
ZaneYork 2020-04-08 16:06:14 +08:00
parent 98cb63b6fb
commit 35a5a1d422
6 changed files with 46 additions and 1 deletions

View File

@ -47,6 +47,7 @@
<Compile Include="ModConfig.cs" /> <Compile Include="ModConfig.cs" />
<Compile Include="ModEntry.cs" /> <Compile Include="ModEntry.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Rewrites\TemporaryAnimatedSpriteRewrites.cs" />
<Compile Include="Rewrites\ResourceClumpRewrites.cs" /> <Compile Include="Rewrites\ResourceClumpRewrites.cs" />
<Compile Include="Rewrites\PickaxeRewrites.cs" /> <Compile Include="Rewrites\PickaxeRewrites.cs" />
<Compile Include="Rewrites\FruitTreeRewrites.cs" /> <Compile Include="Rewrites\FruitTreeRewrites.cs" />

View File

@ -36,6 +36,12 @@ namespace CustomToolEffect
{3, new RangeDefine(new Range(3, 3)) }, {3, new RangeDefine(new Range(3, 3)) },
{4, new RangeDefine(new Range(5, 5)) } {4, new RangeDefine(new Range(5, 5)) }
}; };
public Dictionary<int, PowerDefine> BombDefine { get; set; } = new Dictionary<int, PowerDefine>
{
{286, new PowerDefine(1.4f) },
{287, new PowerDefine(1.4f) },
{288, new PowerDefine(1.5f) },
};
public class PowerDefine public class PowerDefine
{ {
public PowerDefine(float power) public PowerDefine(float power)

View File

@ -35,6 +35,13 @@ namespace CustomToolEffect
original: AccessTools.DeclaredMethod(typeof(Tool), "tilesAffected"), original: AccessTools.DeclaredMethod(typeof(Tool), "tilesAffected"),
prefix: new HarmonyMethod(typeof(ToolRewrites.TilesAffectedRewrite), nameof(ToolRewrites.TilesAffectedRewrite.Prefix)) prefix: new HarmonyMethod(typeof(ToolRewrites.TilesAffectedRewrite), nameof(ToolRewrites.TilesAffectedRewrite.Prefix))
); );
AccessTools.GetDeclaredConstructors(typeof(TemporaryAnimatedSprite)).ForEach(ctor =>
{
harmony.Patch(
original: ctor,
postfix: new HarmonyMethod(typeof(ToolRewrites.TilesAffectedRewrite), nameof(TemporaryAnimatedSpriteRewrites.ConstructorRewrite.Postfix))
);
});
} }
} }
} }

View File

@ -0,0 +1,30 @@
using CustomToolEffect;
using Microsoft.Xna.Framework;
using StardewValley;
using StardewValley.TerrainFeatures;
using StardewValley.Tools;
using System;
namespace StardewModdingAPI.Mods.CustomLocalization.Rewrites
{
public class TemporaryAnimatedSpriteRewrites
{
public class ConstructorRewrite
{
public static void Postfix(TemporaryAnimatedSprite __instance)
{
if(__instance.bombRadius > 0)
{
if (ModEntry.ModConfig.BombDefine.TryGetValue(__instance.initialParentTileIndex, out ModConfig.PowerDefine define))
{
if (define.Power < 0)
{
define.Power = 1f;
}
__instance.bombRadius = (int)(__instance.bombRadius * define.Power);
}
}
}
}
}
}

View File

@ -1,7 +1,7 @@
{ {
"Name": "Custom Tool Effect", "Name": "Custom Tool Effect",
"Author": "ZaneYork", "Author": "ZaneYork",
"Version": "1.0.2", "Version": "1.1.0",
"Description": "Custom tool effect range and power", "Description": "Custom tool effect range and power",
"UniqueID": "ZaneYork.CustomToolEffect", "UniqueID": "ZaneYork.CustomToolEffect",
"EntryDll": "CustomToolEffect.dll", "EntryDll": "CustomToolEffect.dll",

View File

@ -11,6 +11,7 @@ Mod's config file instructions:
| PickaxeDefine | Define an pickaxe's effect | | PickaxeDefine | Define an pickaxe's effect |
| HoeDefine | Define an hoe's effect | | HoeDefine | Define an hoe's effect |
| WateringCanDefine | Define an watering can's effect | | WateringCanDefine | Define an watering can's effect |
| BombDefine | Define an bomb's effect, id as key(286 Cherry Bomb/287 Bomb/288 Mega Bomb) |
| Power | The power of this tool when break items, 1.3 means modify to 130% of the origin power | | Power | The power of this tool when break items, 1.3 means modify to 130% of the origin power |
| Range.Length | The length of effect range | | Range.Length | The length of effect range |
| Range.Width | The width of effect range | | Range.Width | The width of effect range |