Skip to content

Commit

Permalink
etc
Browse files Browse the repository at this point in the history
  • Loading branch information
aedenthorn committed Nov 19, 2022
1 parent 31306b0 commit a18077a
Show file tree
Hide file tree
Showing 15 changed files with 397 additions and 40 deletions.
24 changes: 9 additions & 15 deletions Restauranteer/CodePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static void Postfix(NPC __instance, SpriteBatch b, float alpha, ref bool
__instance.IsEmoting = true;
if (!__instance.modData.TryGetValue(orderKey, out string data))
return;
if(__instance.currentLocation.Name != "Saloon")
if(!Config.RestaurantLocations.Contains(__instance.currentLocation.Name))
{
__instance.modData.Remove(orderKey);
return;
Expand All @@ -60,15 +60,16 @@ public class GameLocation_performAction_Patch
{
public static bool Prefix(GameLocation __instance, string action, Farmer who, Location tileLocation, ref bool __result)
{
if (!Config.ModEnabled || __instance.Name != "Saloon" || (action != "kitchen" && action != "fridge" && (SHelper.Input.IsDown(Config.FridgeModKey) || action != "DropBox GusFridge")))
if (!Config.ModEnabled || !Config.RestaurantLocations.Contains(__instance.Name) || (action != "kitchen" && action != "fridge" && (SHelper.Input.IsDown(Config.FridgeModKey) || action != "DropBox GusFridge")))
return true;
if (!Game1.player.eventsSeen.Contains(980558))
{
Game1.drawObjectDialogue(SHelper.Translation.Get("low-friendship"));
__result = true;
return false;
}
if (Config.AuotFillFridge)
var fridge = GetFridge(__instance);
if (Config.AutoFillFridge)
{
fridge.Value.items.Clear();
foreach (var c in __instance.characters)
Expand Down Expand Up @@ -130,31 +131,24 @@ public class GameLocation_initNetFields_Patch
{
public static void Postfix(GameLocation __instance)
{
if (!Config.ModEnabled || __instance.Name != "Saloon")
if (!Config.ModEnabled || !Config.RestaurantLocations.Contains(__instance.Name))
return;
var fridge = GetFridge(__instance);
__instance.NetFields.AddFields(new INetSerializable[]
{
fridge
});
}
}

[HarmonyPatch(typeof(GameLocation), "drawAboveFrontLayer")]
public class GameLocation_drawAboveFrontLayer_Patch
{
public static void Postfix(GameLocation __instance, SpriteBatch b)
{
if (!Config.ModEnabled || __instance.Name != "Saloon")
return;
}
}
[HarmonyPatch(typeof(GameLocation), nameof(GameLocation.UpdateWhenCurrentLocation))]
public class GameLocation_UpdateWhenCurrentLocation_Patch
{
public static void Postfix(GameLocation __instance, GameTime time)
{
if (!Config.ModEnabled || __instance.Name != "Saloon")
if (!Config.ModEnabled || !Config.RestaurantLocations.Contains(__instance.Name))
return;
var fridge = GetFridge(__instance);
fridge.Value.updateWhenCurrentLocation(time, __instance);
}
}
Expand All @@ -164,7 +158,7 @@ public class NPC_tryToReceiveActiveObject_Patch
{
public static bool Prefix(NPC __instance, Farmer who)
{
if (!Config.ModEnabled || __instance.currentLocation.Name != "Saloon" || !__instance.modData.TryGetValue(orderKey, out string data))
if (!Config.ModEnabled || !Config.RestaurantLocations.Contains(__instance.Name) || !__instance.modData.TryGetValue(orderKey, out string data))
return true;
OrderData orderData = JsonConvert.DeserializeObject<OrderData>(data);
if(who.ActiveObject?.ParentSheetIndex == orderData.dish)
Expand Down
48 changes: 42 additions & 6 deletions Restauranteer/Methods.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
using Newtonsoft.Json;
using HarmonyLib;
using Netcode;
using Newtonsoft.Json;
using StardewValley;
using StardewValley.Locations;
using StardewValley.Menus;
using StardewValley.Objects;
using System;
using System.Collections.Generic;
using System.Linq;
using Object = StardewValley.Object;

namespace Restauranteer
{
Expand All @@ -13,7 +19,7 @@ private void UpdateOrders()
foreach(var c in Game1.player.currentLocation.characters)
{

if (c.isVillager() && c.Name != "Gus" && c.Name != "Emily")
if (c.isVillager() && !Config.IgnoredNPCs.Contains(c.Name))
{
CheckOrder(c);
}
Expand Down Expand Up @@ -53,29 +59,29 @@ private void StartOrder(NPC npc)
List<int> loves = new();
foreach(var str in Game1.NPCGiftTastes["Universal_Love"].Split(' '))
{
if (Game1.objectInformation.TryGetValue(int.Parse(str), out string data) && CraftingRecipe.cookingRecipes.ContainsKey(data.Split('/')[0]))
if (int.TryParse(str, out int i) && Game1.objectInformation.TryGetValue(i, out string data) && CraftingRecipe.cookingRecipes.ContainsKey(data.Split('/')[0]))
{
loves.Add(int.Parse(str));
}
}
foreach(var str in Game1.NPCGiftTastes[npc.Name].Split('/')[1].Split(' '))
{
if (Game1.objectInformation.TryGetValue(int.Parse(str), out string data) && CraftingRecipe.cookingRecipes.ContainsKey(data.Split('/')[0]))
if (int.TryParse(str, out int i) && Game1.objectInformation.TryGetValue(i, out string data) && CraftingRecipe.cookingRecipes.ContainsKey(data.Split('/')[0]))
{
loves.Add(int.Parse(str));
}
}
List<int> likes = new();
foreach(var str in Game1.NPCGiftTastes["Universal_Like"].Split(' '))
{
if (Game1.objectInformation.TryGetValue(int.Parse(str), out string data) && CraftingRecipe.cookingRecipes.ContainsKey(data.Split('/')[0]))
if (int.TryParse(str, out int i) && Game1.objectInformation.TryGetValue(i, out string data) && CraftingRecipe.cookingRecipes.ContainsKey(data.Split('/')[0]))
{
likes.Add(int.Parse(str));
}
}
foreach (var str in Game1.NPCGiftTastes[npc.Name].Split('/')[3].Split(' '))
{
if (Game1.objectInformation.TryGetValue(int.Parse(str), out string data) && CraftingRecipe.cookingRecipes.ContainsKey(data.Split('/')[0]))
if (int.TryParse(str, out int i) && Game1.objectInformation.TryGetValue(i, out string data) && CraftingRecipe.cookingRecipes.ContainsKey(data.Split('/')[0]))
{
likes.Add(int.Parse(str));
}
Expand All @@ -97,5 +103,35 @@ private void StartOrder(NPC npc)
Monitor.Log($"{npc.Name} is going to order {name}");
npc.modData[orderKey] = JsonConvert.SerializeObject(new OrderData(dish, name, loved));
}

private static NetRef<Chest> GetFridge(GameLocation __instance)
{
if(__instance is FarmHouse)
{
return (__instance as FarmHouse).fridge;
}
if(__instance is IslandFarmHouse)
{
return (__instance as IslandFarmHouse).fridge;
}
NetRef<Chest> fridge;
if (__instance.Objects.TryGetValue(fridgeHideTile, out Object value) && value is Chest)
{
fridge = new NetRef<Chest>(value as Chest);

}
else
{
SMonitor.Log($"adding fridge to {__instance.Name}");
fridge = new NetRef<Chest>(new Chest(true, 130));
__instance.Objects.Add(fridgeHideTile, fridge.Value);
}

__instance.NetFields.AddFields(new INetSerializable[]
{
fridge
});
return fridge;
}
}
}
11 changes: 10 additions & 1 deletion Restauranteer/ModConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Restauranteer
public class ModConfig
{
public bool ModEnabled { get; set; } = true;
public bool AuotFillFridge { get; set; } = true;
public bool AutoFillFridge { get; set; } = true;
public bool PatchSaloonMap { get; set; } = true;
public bool RevealGiftTaste { get; set; } = true;
public SButton FridgeModKey { get; set; } = SButton.LeftShift;
Expand All @@ -20,6 +20,15 @@ public class ModConfig
public string EventKey { get; set; } = "980558/t 600 1130/w sunny/f Gus 1250";
public string EventReplacePart { get; set; } = "/pause 500/end";
public string EventReplaceWith { get; set; } = "/pause 200/speak Gus \"{0}\"/pause 500/end";
public List<string> RestaurantLocations { get; set; } = new List<string>()
{
"Saloon"
};
public List<string> IgnoredNPCs { get; set; } = new List<string>()
{
"Gus",
"Emily"
};
public List<Point> KitchenTiles { get; set; } = new List<Point>()
{
};
Expand Down
19 changes: 12 additions & 7 deletions Restauranteer/ModEntry.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using HarmonyLib;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Netcode;
using Newtonsoft.Json;
using StardewModdingAPI;
using StardewModdingAPI.Utilities;
using StardewValley;
Expand All @@ -9,8 +11,11 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using xTile;
using xTile.Dimensions;
using xTile.Tiles;

namespace Restauranteer
{
Expand All @@ -25,9 +30,10 @@ public partial class ModEntry : Mod
public static ModEntry context;

public static string orderKey = "aedenthorn.Restauranteer/order";
public static string fridgeKey = "aedenthorn.Restauranteer/fridge";
public static Texture2D emoteSprite;
public static Vector2 fridgeHideTile = new Vector2(-42000, -42000);
public static PerScreen<Dictionary<string, int>> npcOrderNumbers = new PerScreen<Dictionary<string, int>>();
public static NetRef<Chest> fridge;
public static PerScreen<Location> fridgePosition = new PerScreen<Location>();

/// <summary>The mod entry point, called after the mod is first loaded.</summary>
Expand All @@ -52,17 +58,16 @@ public override void Entry(IModHelper helper)
npcOrderNumbers.Value = new Dictionary<string, int>();
}


private void GameLoop_DayStarted(object sender, StardewModdingAPI.Events.DayStartedEventArgs e)
{
npcOrderNumbers.Value.Clear();
fridge = new NetRef<Chest>(new Chest(true, 130));

emoteSprite = SHelper.ModContent.Load<Texture2D>(Path.Combine("assets", "emote.png"));
}

private void GameLoop_OneSecondUpdateTicked(object sender, StardewModdingAPI.Events.OneSecondUpdateTickedEventArgs e)
{
if(Config.ModEnabled && Context.IsPlayerFree && Game1.player.currentLocation.Name == "Saloon" && Game1.player.eventsSeen.Contains(980558))
if(Config.ModEnabled && Context.IsPlayerFree && Config.RestaurantLocations.Contains(Game1.player.currentLocation.Name) && Game1.player.eventsSeen.Contains(980558))
{
UpdateOrders();
}
Expand All @@ -83,7 +88,7 @@ private void Content_AssetRequested(object sender, StardewModdingAPI.Events.Asse
}
});
}
if (e.NameWithoutLocale.IsEquivalentTo("Maps/Saloon"))
else if (e.NameWithoutLocale.IsEquivalentTo("Maps/Saloon"))
{
e.Edit(delegate (IAssetData data)
{
Expand Down Expand Up @@ -135,8 +140,8 @@ private void GameLoop_GameLaunched(object sender, StardewModdingAPI.Events.GameL
configMenu.AddBoolOption(
mod: ModManifest,
name: () => "Auto Fill Fridge",
getValue: () => Config.AuotFillFridge,
setValue: value => Config.AuotFillFridge = value
getValue: () => Config.AutoFillFridge,
setValue: value => Config.AutoFillFridge = value
);
configMenu.AddBoolOption(
mod: ModManifest,
Expand Down
2 changes: 1 addition & 1 deletion Restauranteer/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "Restauranteer",
"Author": "aedenthorn",
"Version": "0.1.0",
"Version": "0.3.0",
"Description": "Restauranteer.",
"UniqueID": "aedenthorn.Restauranteer",
"EntryDll": "Restauranteer.dll",
Expand Down
10 changes: 0 additions & 10 deletions SmallerCrops/GameLocationPatches.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
using HarmonyLib;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json;
using StardewModdingAPI;
using StardewValley;
using StardewValley.Network;
using StardewValley.Objects;
using StardewValley.TerrainFeatures;
using StardewValley.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using xTile.Dimensions;
using Object = StardewValley.Object;
using Rectangle = Microsoft.Xna.Framework.Rectangle;

namespace SmallerCrops
Expand Down
56 changes: 56 additions & 0 deletions TextureTweaks/CodePatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using HarmonyLib;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;

namespace TextureTweaks
{
public partial class ModEntry
{
[HarmonyPatch(typeof(SpriteBatch), nameof(SpriteBatch.Draw), new Type[] { typeof(Texture2D), typeof(Vector2), typeof(Rectangle?), typeof(Color) })]
public class SpriteBatch_Draw_Patch_1
{
public static void Prefix(ref Texture2D texture, ref Rectangle? sourceRectangle, ref Color color)
{
CheckTexture(ref texture, ref sourceRectangle, ref color);

}
}
[HarmonyPatch(typeof(SpriteBatch), nameof(SpriteBatch.Draw), new Type[] { typeof(Texture2D), typeof(Rectangle), typeof(Rectangle?), typeof(Color) })]
public class SpriteBatch_Draw_Patch_2
{
public static void Prefix(ref Texture2D texture, ref Rectangle? sourceRectangle, ref Color color)
{
CheckTexture(ref texture, ref sourceRectangle, ref color);

}
}
[HarmonyPatch(typeof(SpriteBatch), nameof(SpriteBatch.Draw), new Type[] { typeof(Texture2D), typeof(Rectangle), typeof(Rectangle?), typeof(Color), typeof(float), typeof(Vector2), typeof(SpriteEffects), typeof(float) })]
public class SpriteBatch_Draw_Patch_3
{
public static void Prefix(ref Texture2D texture, ref Rectangle? sourceRectangle, ref Color color)
{
CheckTexture(ref texture, ref sourceRectangle, ref color);

}
}
[HarmonyPatch(typeof(SpriteBatch), nameof(SpriteBatch.Draw), new Type[] { typeof(Texture2D), typeof(Vector2), typeof(Rectangle?), typeof(Color), typeof(float), typeof(Vector2), typeof(Vector2), typeof(SpriteEffects), typeof(float) })]
public class SpriteBatch_Draw_Patch_4
{
public static void Prefix(ref Texture2D texture, ref Rectangle? sourceRectangle, ref Color color, Vector2 scale)
{
CheckScaledTexture(ref texture, ref sourceRectangle, ref color, ref scale);

}
}
[HarmonyPatch(typeof(SpriteBatch), nameof(SpriteBatch.Draw), new Type[] { typeof(Texture2D), typeof(Vector2), typeof(Rectangle?), typeof(Color), typeof(float), typeof(Vector2), typeof(float), typeof(SpriteEffects), typeof(float) })]
public class SpriteBatch_Draw_Patch_5
{
public static void Prefix(ref Texture2D texture, ref Rectangle? sourceRectangle, ref Color color, float scale)
{
CheckScaledTexture(ref texture, ref sourceRectangle, ref color, ref scale);
scale = 1;
}
}
}
}
Loading

0 comments on commit a18077a

Please sign in to comment.