Skip to content

Commit

Permalink
etc
Browse files Browse the repository at this point in the history
  • Loading branch information
aedenthorn committed Sep 11, 2023
1 parent b86afc8 commit e5bbc34
Show file tree
Hide file tree
Showing 20 changed files with 772 additions and 47 deletions.
15 changes: 15 additions & 0 deletions BuffFramework/BuffFrameworkAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace BuffFramework
{
public interface IBuffFrameworkAPI
{
public void UpdateBuffs();
}

public class BuffFrameworkAPI : IBuffFrameworkAPI
{
public void UpdateBuffs()
{
ModEntry.UpdateBuffs();
}
}
}
12 changes: 6 additions & 6 deletions BuffFramework/CodePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,32 +154,32 @@ public static void Postfix(Farmer __instance)
__instance.rightRing.fieldChangeEvent += RightRing_fieldChangeEvent;
}

private static void RightRing_fieldChangeEvent(Netcode.NetRef<StardewValley.Objects.Ring> field, StardewValley.Objects.Ring oldValue, StardewValley.Objects.Ring newValue)
public static void RightRing_fieldChangeEvent(Netcode.NetRef<StardewValley.Objects.Ring> field, StardewValley.Objects.Ring oldValue, StardewValley.Objects.Ring newValue)
{
UpdateBuffs();
}

private static void LeftRing_fieldChangeEvent(Netcode.NetRef<StardewValley.Objects.Ring> field, StardewValley.Objects.Ring oldValue, StardewValley.Objects.Ring newValue)
public static void LeftRing_fieldChangeEvent(Netcode.NetRef<StardewValley.Objects.Ring> field, StardewValley.Objects.Ring oldValue, StardewValley.Objects.Ring newValue)
{
UpdateBuffs();
}

private static void Boots_fieldChangeEvent(Netcode.NetRef<StardewValley.Objects.Boots> field, StardewValley.Objects.Boots oldValue, StardewValley.Objects.Boots newValue)
public static void Boots_fieldChangeEvent(Netcode.NetRef<StardewValley.Objects.Boots> field, StardewValley.Objects.Boots oldValue, StardewValley.Objects.Boots newValue)
{
UpdateBuffs();
}

private static void PantsItem_fieldChangeEvent(Netcode.NetRef<StardewValley.Objects.Clothing> field, StardewValley.Objects.Clothing oldValue, StardewValley.Objects.Clothing newValue)
public static void PantsItem_fieldChangeEvent(Netcode.NetRef<StardewValley.Objects.Clothing> field, StardewValley.Objects.Clothing oldValue, StardewValley.Objects.Clothing newValue)
{
UpdateBuffs();
}

private static void ShirtItem_fieldChangeEvent(Netcode.NetRef<StardewValley.Objects.Clothing> field, StardewValley.Objects.Clothing oldValue, StardewValley.Objects.Clothing newValue)
public static void ShirtItem_fieldChangeEvent(Netcode.NetRef<StardewValley.Objects.Clothing> field, StardewValley.Objects.Clothing oldValue, StardewValley.Objects.Clothing newValue)
{
UpdateBuffs();
}

private static void Hat_fieldChangeEvent(Netcode.NetRef<StardewValley.Objects.Hat> field, StardewValley.Objects.Hat oldValue, StardewValley.Objects.Hat newValue)
public static void Hat_fieldChangeEvent(Netcode.NetRef<StardewValley.Objects.Hat> field, StardewValley.Objects.Hat oldValue, StardewValley.Objects.Hat newValue)
{
UpdateBuffs();
}
Expand Down
19 changes: 13 additions & 6 deletions BuffFramework/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Object = StardewValley.Object;

namespace BuffFramework
{
public partial class ModEntry
{
private static float CheckGlowRate(Buff buff, float rate)
public static float CheckGlowRate(Buff buff, float rate)
{
if (!Config.ModEnabled)
return rate;
Expand All @@ -25,7 +26,7 @@ private static float CheckGlowRate(Buff buff, float rate)
}


private static void UpdateBuffs()
public static void UpdateBuffs()
{
if (farmerBuffs.Value is null)
farmerBuffs.Value = new();
Expand All @@ -42,7 +43,13 @@ private static void UpdateBuffs()
int duration = 50;
var b = kvp.Value;
if (b.ContainsKey("consume"))
{
if (farmerBuffs.Value.TryGetValue(kvp.Key, out var eatBuff))
{
newBuffDict.Add(kvp.Key, eatBuff);
}
continue;
}
if (b.TryGetValue("hat", out var hat) && Game1.player.hat.Value?.Name != (string)hat)
continue;
if (b.TryGetValue("shirt", out var shirt) && Game1.player.shirtItem.Value?.Name != (string)shirt)
Expand Down Expand Up @@ -111,7 +118,7 @@ private static void UpdateBuffs()
farmerBuffs.Value = newBuffDict;
}

private static Buff CreateBuff(string key, Dictionary<string, object> b, object food, int duration)
public static Buff CreateBuff(string key, Dictionary<string, object> b, object food, int duration)
{

Buff buff;
Expand Down Expand Up @@ -208,7 +215,7 @@ private static Buff CreateBuff(string key, Dictionary<string, object> b, object
return buff;
}

private static int GetInt(object value)
public static int GetInt(object value)
{
if(value is long)
{
Expand All @@ -228,7 +235,7 @@ private static int GetInt(object value)
}

}
private static float GetFloat(object r)
public static float GetFloat(object r)
{
if (r is float)
return (float)r;
Expand All @@ -240,7 +247,7 @@ private static float GetFloat(object r)
}


private static void ClearCues()
public static void ClearCues()
{
foreach (var cue in cues)
{
Expand Down
24 changes: 15 additions & 9 deletions BuffFramework/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ public override void Entry(IModHelper helper)
File.WriteAllText(Path.Combine(SHelper.DirectoryPath, "out2.json"), JsonConvert.SerializeObject(dict, Formatting.Indented));
}

private void GameLoop_OneSecondUpdateTicked(object sender, StardewModdingAPI.Events.OneSecondUpdateTickedEventArgs e)
public override object GetApi()
{
return new BuffFrameworkAPI();
}

public void GameLoop_OneSecondUpdateTicked(object sender, StardewModdingAPI.Events.OneSecondUpdateTickedEventArgs e)
{
if(!Config.ModEnabled || !Context.IsPlayerFree)
return;
Expand All @@ -84,45 +89,46 @@ private void GameLoop_OneSecondUpdateTicked(object sender, StardewModdingAPI.Eve
}
}

private void GameLoop_ReturnedToTitle(object sender, StardewModdingAPI.Events.ReturnedToTitleEventArgs e)
public void GameLoop_ReturnedToTitle(object sender, StardewModdingAPI.Events.ReturnedToTitleEventArgs e)
{
ClearCues();
}

private void GameLoop_TimeChanged(object sender, StardewModdingAPI.Events.TimeChangedEventArgs e)
public void GameLoop_TimeChanged(object sender, StardewModdingAPI.Events.TimeChangedEventArgs e)
{
Helper.Events.GameLoop.UpdateTicking += GameLoop_UpdateTicking;
}

private void Player_Warped(object sender, StardewModdingAPI.Events.WarpedEventArgs e)
public void Player_Warped(object sender, StardewModdingAPI.Events.WarpedEventArgs e)
{
Helper.Events.GameLoop.UpdateTicking += GameLoop_UpdateTicking;
}
private void GameLoop_DayStarted(object sender, StardewModdingAPI.Events.DayStartedEventArgs e)

public void GameLoop_DayStarted(object sender, StardewModdingAPI.Events.DayStartedEventArgs e)
{
Helper.Events.GameLoop.UpdateTicking += GameLoop_UpdateTicking;
}

private void GameLoop_UpdateTicking(object sender, StardewModdingAPI.Events.UpdateTickingEventArgs e)
public void GameLoop_UpdateTicking(object sender, StardewModdingAPI.Events.UpdateTickingEventArgs e)
{
UpdateBuffs();
Helper.Events.GameLoop.UpdateTicking -= GameLoop_UpdateTicking;
}

private void Content_AssetRequested(object sender, StardewModdingAPI.Events.AssetRequestedEventArgs e)
public void Content_AssetRequested(object sender, StardewModdingAPI.Events.AssetRequestedEventArgs e)
{
if (e.NameWithoutLocale.IsEquivalentTo(dictKey))
{
e.LoadFrom(() => new Dictionary<string, Dictionary<string, object>>(), StardewModdingAPI.Events.AssetLoadPriority.Exclusive);
}
}

private void GameLoop_SaveLoaded(object sender, StardewModdingAPI.Events.SaveLoadedEventArgs e)
public void GameLoop_SaveLoaded(object sender, StardewModdingAPI.Events.SaveLoadedEventArgs e)
{
farmerBuffs.Value = new();
}

private void GameLoop_GameLaunched(object sender, StardewModdingAPI.Events.GameLaunchedEventArgs e)
public void GameLoop_GameLaunched(object sender, StardewModdingAPI.Events.GameLaunchedEventArgs e)
{


Expand Down
2 changes: 1 addition & 1 deletion BuffFramework/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "Buff Framework",
"Author": "aedenthorn",
"Version": "0.5.1",
"Version": "0.6.0",
"Description": "Buff Framework.",
"UniqueID": "aedenthorn.BuffFramework",
"EntryDll": "BuffFramework.dll",
Expand Down
2 changes: 1 addition & 1 deletion ContentPatcherEditor/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "Content Patcher Editor",
"Author": "aedenthorn",
"Version": "0.5.0",
"Version": "0.5.1",
"Description": "Content Patcher Editor.",
"UniqueID": "aedenthorn.ContentPatcherEditor",
"EntryDll": "ContentPatcherEditor.dll",
Expand Down
2 changes: 1 addition & 1 deletion CropWateringBubbles/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "Crop Watering Bubbles",
"Author": "aedenthorn",
"Version": "0.2.3",
"Version": "0.2.4",
"Description": "Crop Harvest Bubbles.",
"UniqueID": "aedenthorn.CropWateringBubbles",
"EntryDll": "CropWateringBubbles.dll",
Expand Down
128 changes: 128 additions & 0 deletions DinoForm/CodePatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
using HarmonyLib;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewValley;
using StardewValley.Network;
using Object = StardewValley.Object;

namespace DinoForm
{
public partial class ModEntry
{
public static int buffId = 3885251;
public static int consumeBuffId = 3885252;

[HarmonyPatch(typeof(Farmer), nameof(Farmer.draw))]
public class Farmer_draw_Patch
{
public static bool Prefix(Farmer __instance, SpriteBatch b)
{
if (!Config.ModEnabled || __instance != Game1.player || DinoFormStatus(Game1.player) == DinoForm.Inactive)
return true;
var drawLayer = __instance.getDrawLayer();
Texture2D texture = SHelper.GameContent.Load<Texture2D>("Characters\\Monsters\\Pepper Rex");
b.Draw(texture, Game1.player.getLocalPosition(Game1.viewport) + new Vector2(28, 0), new Rectangle?(GetSourceRect(Game1.player)), Color.White, 0f, new Vector2(16f, 16f), 4f, SpriteEffects.None, drawLayer + 0.001f);
var chance = Game1.random.NextDouble();
if (chance < 0.001 && Game1.soundBank != null && (dinoSound.Value is null || !dinoSound.Value.IsPlaying) && Game1.player.currentLocation == Game1.currentLocation)
{
dinoSound.Value = Game1.soundBank.GetCue("croak");
dinoSound.Value.Play();
}
return false;
}
}

[HarmonyPatch(typeof(FarmerSprite), "checkForFootstep")]
public class FarmerSprite_checkForFootstep_Patch
{
public static bool Prefix(FarmerSprite __instance, Farmer ___owner)
{
if (!Config.ModEnabled || DinoFormStatus(Game1.player) == DinoForm.Inactive || ___owner != Game1.player)
return true;
return false;
}
}

[HarmonyPatch(typeof(Farmer), nameof(Farmer.GetBoundingBox))]
public class Farmer_GetBoundingBox_Patch
{
public static void Postfix(Farmer __instance, ref Rectangle __result)
{
if (!Config.ModEnabled || __instance.mount is not null || __instance != Game1.player || DinoFormStatus(Game1.player) == DinoForm.Inactive)
return;
__result.Inflate(16, 0);
}
}

[HarmonyPatch(typeof(Farmer), nameof(Farmer.MovePosition))]
public class Farmer_MovePosition_Patch
{
public static bool Prefix(Farmer __instance, GameLocation currentLocation)
{
if (!Config.ModEnabled || __instance.mount is not null || __instance != Game1.player || DinoFormStatus(Game1.player) == DinoForm.Inactive)
return true;

if (breathingFire.Value)
return false;
if(__instance.movementDirections.Count == 0)
{
frameOffset.Value = 0;
}
else
{
frameOffset.Value++;
}
foreach(var d in __instance.movementDirections)
{
var nextPosition = __instance.nextPosition(d);
foreach (var kvp in currentLocation.Objects.Pairs)
{
if (nextPosition.Intersects(kvp.Value.getBoundingBox(kvp.Key)))
{
if (kvp.Value.Name.Equals("Weeds"))
{
AccessTools.Method(typeof(Object), "cutWeed").Invoke(kvp.Value, new object[] { __instance, currentLocation });
currentLocation.Objects.Remove(kvp.Key);
}
else if(kvp.Value.Name.Contains("Stone") && !kvp.Value.bigCraftable.Value && kvp.Value is not Fence)
{
currentLocation.playSound("hammer", NetAudio.SoundContext.Default);
currentLocation.destroyObject(kvp.Key, __instance);
}
else if(kvp.Value.Name.Contains("Twig"))
{
kvp.Value.Fragility = 2;
currentLocation.playSound("axchop", NetAudio.SoundContext.Default);
Game1.createRadialDebris(currentLocation, 12, (int)kvp.Value.TileLocation.X, (int)kvp.Value.TileLocation.Y, Game1.random.Next(4, 10), false, -1, false, -1);
currentLocation.debris.Add(new Debris(new Object(388, 1, false, -1, 0), kvp.Value.TileLocation * 64f + new Vector2(32f, 32f)));
kvp.Value.performRemoveAction(kvp.Value.TileLocation, Game1.currentLocation);
Game1.currentLocation.Objects.Remove(kvp.Key);
}
}
}
}

return true;
}
}

[HarmonyPatch(typeof(Game1), nameof(Game1.pressUseToolButton))]
public class Game1_pressUseToolButton_Patch
{
public static bool Prefix()
{
return (!Config.ModEnabled || DinoFormStatus(Game1.player) == DinoForm.Inactive);
}
}
[HarmonyPatch(typeof(GameLocation), nameof(GameLocation.isCollidingWithWarp))]
public class GameLocation_isCollidingWithWarp_Patch
{
public static void Prefix(ref Rectangle position, Character character)
{
if (!Config.ModEnabled || character != Game1.player || DinoFormStatus(Game1.player) == DinoForm.Inactive)
return;
position.Inflate(-16, 0);
}
}
}
}
30 changes: 30 additions & 0 deletions DinoForm/DinoForm.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>1.0.0</Version>
<TargetFramework>net5.0</TargetFramework>
<EnableHarmony>true</EnableHarmony>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<None Remove="i18n\default.json" />
</ItemGroup>
<ItemGroup>
<Content Include="i18n\default.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
<None Update="assets\board.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="manifest.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions DinoForm/IBuffFrameworkAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace DinoForm
{
public interface IBuffFrameworkAPI
{
public void UpdateBuffs();
}
}
Loading

0 comments on commit e5bbc34

Please sign in to comment.