Decompiled source of TimbnInfusionRack v1.0.0

Timbn.GraveyardKeeperTwo.InfusionRack/Timbn.GraveyardKeeperTwo.InfusionRack.dll

Decompiled 5 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using LazyBearTechnology;
using Microsoft.CodeAnalysis;
using Timbn.GraveyardKeeperTwo.Core.Framework;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Timbn.GraveyardKeeperTwo.InfusionRack")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Give your zombies tech points. Make Spirit Solutions from organs, lay zombies in infusion stands and run an infusion on the infusion machine to pay each one the full points.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+5a3e77ccf353a1c19e928c6f3552d0b10e981092")]
[assembly: AssemblyProduct("Timbn Infusion Rack")]
[assembly: AssemblyTitle("Timbn.GraveyardKeeperTwo.InfusionRack")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Timbn.GraveyardKeeperTwo.InfusionRack
{
	internal static class InfusionMachine
	{
		public const string StationId = "timbn_infusion_machine";

		private const string _buildIcon = "infusion_machine_build";

		private const string _skullTalent = "talent_blue";

		private const string _template = "pocket_extract_item_craft";

		private const int _ticks = 8;

		private const int _mastery = 4;

		public static void Register(TimbnFrameworkPlugin plugin)
		{
			TimbnModel model = plugin.Models.Build("InfusionMachine", (Action<TimbnModelFaces>)delegate(TimbnModelFaces faces)
			{
				faces.Block("infusion_machine_table", 0, 0, 1, 24).Top("infusion_machine_basin", 5, 17, 5);
			});
			plugin.Sprites.AddEmbeddedPng("infusion_machine_build");
			TimbnStation machine = plugin.Stations.Add("timbn_infusion_machine", (Action<TimbnStationBuilder>)delegate(TimbnStationBuilder station)
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				station.Model(model, new Vector3(0.64f, 0.5f, 0.6f)).Slot("timbn_infusion_slot", new Vector3(-0.64f, 0f, 0.15f), InfusionStand.Size).Slot("timbn_infusion_slot", new Vector3(0.64f, 0f, 0.15f), InfusionStand.Size)
					.Icon("infusion_machine_build")
					.BasedOn("kitchen_oven")
					.Talent("talent_blue")
					.NoFuel()
					.TakesZombie(false)
					.BuiltAt("builder_morgue", (string)null)
					.BuildTab("")
					.UnlockedBy("timbn_infusion_rack")
					.Cost(new(string, int)[3]
					{
						("stone_plate_1", 8),
						("nails_iron", 6),
						("detail_1_iron", 4)
					})
					.Limit(1)
					.Extensions("timbn_infusion_stand", Array.Empty<string>());
			});
			foreach (TechColor color in SpiritSolution.Colors)
			{
				string solution = SpiritSolution.ItemId(color);
				string text = color.ToString().ToLowerInvariant();
				plugin.Crafts.Add("timbn_infusion_machine_" + text, (Action<TimbnCraftBuilder>)delegate(TimbnCraftBuilder craft)
				{
					craft.In(machine).BasedOn("pocket_extract_item_craft").Needs(new(string, int)[2]
					{
						(solution, 1),
						("crystal_goddess", 1)
					})
						.Mastery(4)
						.Icon(solution)
						.DurationTicks(8)
						.AutoFinish()
						.Requires((Func<WgoData, bool>)((WgoData machine2) => InfusionStand.OccupiedStands(machine2).Any()))
						.OnStarted((Action<TimbnCraftEvent>)delegate(TimbnCraftEvent infusion)
						{
							StartOnStands(plugin, infusion.Station);
						})
						.OnFinished((Action<TimbnCraftEvent>)delegate(TimbnCraftEvent infusion)
						{
							Infuse(plugin, infusion.Station, color);
						});
				});
			}
		}

		private static void StartOnStands(TimbnFrameworkPlugin plugin, WgoData machine)
		{
			foreach (WgoData item in InfusionStand.IdleStands(machine))
			{
				if (!plugin.Crafts.Start(item, "timbn_infusion_stand_infusion"))
				{
					TimbnFrameworkPlugin<Plugin>.Logger.LogWarning((object)("Could not start the stand infusion on " + ((ObjectLinkedToDefinition<WGODef>)(object)item).id + "."));
				}
			}
		}

		private static void Infuse(TimbnFrameworkPlugin plugin, WgoData machine, TechColor color)
		{
			foreach (WgoData item in InfusionStand.InfusionStands(machine).ToList())
			{
				ZombieWgoData val = TimbnZombies.AtStation(item);
				if (val != null)
				{
					SpiritSolution.GiveTo(val, machine, color);
				}
				plugin.Crafts.Finish(item);
			}
		}
	}
	internal static class InfusionStand
	{
		public const string StationId = "timbn_infusion_stand";

		public const string InfusionId = "timbn_infusion_stand_infusion";

		public const string SlotId = "timbn_infusion_slot";

		public static readonly Vector3 Size = new Vector3(0.64f, 0.5f, 0.9f);

		private const string _buildIcon = "infusion_stand_build";

		private const string _infusedFlag = "timbn_infusion_done";

		private const string _buildingTalent = "talent_orange";

		private const string _template = "pocket_extract_item_craft";

		private const int _infusionTicks = 600;

		public static void Register(TimbnFrameworkPlugin plugin)
		{
			TimbnModel open = plugin.Models.Build("InfusionStandOpen", (Action<TimbnModelFaces>)delegate(TimbnModelFaces faces)
			{
				faces.Block("infusion_stand_box", 0, 0, 1, 36).Top("infusion_stand_floor", 4, 6, 5).Front("infusion_stand_backwall", 4, 6, 33);
			});
			TimbnModel lid = plugin.Models.Build("InfusionStandLid", (Action<TimbnModelFaces>)delegate(TimbnModelFaces faces)
			{
				faces.Block("infusion_stand_lying_lid", 2, 16, 4, 30);
			});
			TimbnModel glow = plugin.Models.Build("InfusionStandGlow", (Action<TimbnModelFaces>)delegate(TimbnModelFaces faces)
			{
				faces.Front("infusion_stand_working_gemglow", 8, 7, 0).Top("infusion_stand_working_lidlines", 2, 20, 4).Front("infusion_stand_working_lidedge", 2, 17, 3);
			});
			plugin.Sprites.AddEmbeddedPng("infusion_stand_build");
			TimbnStation stand = plugin.Stations.Add("timbn_infusion_stand", (Action<TimbnStationBuilder>)delegate(TimbnStationBuilder station)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				station.Model(open, Size).Icon("infusion_stand_build").BasedOn("resurrection_table_1")
					.HoldsZombie()
					.Talent("talent_orange")
					.ShowWhen(TimbnLook.HoldsGroup("zombie", 1), lid, false)
					.ShowWhen(TimbnLook.Resource("timbn_infusion_done", (TimbnComparison)3, 1), glow, false)
					.Edit((Action<WGODef>)delegate(WGODef def)
					{
						def.customInteraction2.execution.Add(TimbnBalance.Expression("SetWGOPar(\"timbn_infusion_done\", 0)"));
					})
					.BuildsInSlot("timbn_infusion_slot")
					.BuiltAt("builder_morgue", (string)null)
					.BuildTab("")
					.UnlockedBy("timbn_infusion_rack")
					.Cost(new(string, int)[3]
					{
						("stone_plate_1", 6),
						("nails_iron", 4),
						("detail_1_iron", 2)
					});
			});
			plugin.Events.SaveReady((Action)RepairEmptyStands);
			plugin.Crafts.Add("timbn_infusion_stand_infusion", (Action<TimbnCraftBuilder>)delegate(TimbnCraftBuilder craft)
			{
				craft.In(stand).BasedOn("pocket_extract_item_craft").Mastery(1)
					.DurationTicks(600)
					.AutoFinish()
					.Hidden()
					.OnStarted((Action<TimbnCraftEvent>)delegate(TimbnCraftEvent infusion)
					{
						SetGlow(infusion.Station, 0);
					})
					.OnFinished((Action<TimbnCraftEvent>)delegate(TimbnCraftEvent infusion)
					{
						SetGlow(infusion.Station, (TimbnZombies.AtStation(infusion.Station) != null) ? 1 : 0);
					});
			});
		}

		private static void SetGlow(WgoData stand, int value)
		{
			stand.SetGameRes("timbn_infusion_done", value);
		}

		private static void RepairEmptyStands()
		{
			foreach (WgoData item in TimbnWorld.FindAll("timbn_infusion_stand"))
			{
				if (TimbnZombies.AtStation(item) == null && !IsInfusing(item))
				{
					SetGlow(item, 0);
				}
			}
		}

		public static IEnumerable<WgoData> StandsOf(WgoData machine)
		{
			return from stand in TimbnWorld.Extensions(machine)
				where ((ObjectLinkedToDefinition<WGODef>)(object)stand).id == "timbn_infusion_stand"
				select stand;
		}

		public static IEnumerable<WgoData> InfusionStands(WgoData machine)
		{
			return StandsOf(machine).Where(IsInfusing);
		}

		public static IEnumerable<WgoData> OccupiedStands(WgoData machine)
		{
			return from stand in StandsOf(machine)
				where TimbnZombies.AtStation(stand) != null && !IsInfusing(stand)
				select stand;
		}

		public static IEnumerable<WgoData> IdleStands(WgoData machine)
		{
			return from stand in StandsOf(machine)
				where !IsInfusing(stand)
				select stand;
		}

		private static bool IsInfusing(WgoData stand)
		{
			return TimbnWorld.RunningCraft(stand) == "timbn_infusion_stand_infusion";
		}
	}
	internal static class InfusionTech
	{
		public const string Id = "timbn_infusion_rack";

		public static void Register(TimbnFrameworkPlugin plugin)
		{
			plugin.Techs.Add("timbn_infusion_rack", "", (Action<TimbnTechBuilder>)delegate(TimbnTechBuilder tech)
			{
				tech.Tab((TechTreeTab)4).At(8f, 2f).After("body_places_2", Array.Empty<string>())
					.Cost(50, 50, 20)
					.Shows(SpiritSolution.ItemId(TechColor.Red), new string[2] { "timbn_infusion_machine", "timbn_infusion_stand" });
			});
		}
	}
	[BepInPlugin("Timbn.GraveyardKeeperTwo.InfusionRack", "Timbn Infusion Rack", "1.0.0")]
	[BepInDependency("Timbn.GraveyardKeeperTwo.Core", "2.0.0")]
	public class Plugin : TimbnFrameworkPlugin<Plugin>
	{
		protected override void BindConfig(ConfigFile config)
		{
			PluginConfig.Bind(config);
		}

		protected override void OnAwake()
		{
			InfusionTech.Register((TimbnFrameworkPlugin)(object)this);
			SpiritSolution.Register((TimbnFrameworkPlugin)(object)this);
			SpiritRecipes.Register((TimbnFrameworkPlugin)(object)this);
			InfusionStand.Register((TimbnFrameworkPlugin)(object)this);
			InfusionMachine.Register((TimbnFrameworkPlugin)(object)this);
		}
	}
	internal static class PluginConfig
	{
		public static ConfigEntry<int> PointsPerSolution { get; private set; }

		public static void Bind(ConfigFile config)
		{
			PointsPerSolution = TimbnConfig.BindRange<int>(config, "Infusion Rack", "PointsPerSolution", 50, "Tech points each zombie lying in a stand gets from one spirit solution. The distillation cube makes one solution for each white skull on the organ.", 1, 500);
		}
	}
	internal static class SpiritRecipes
	{
		private const int _firePerCraft = 20;

		private static readonly (string Organ, TechColor Color, int Skulls)[] _organs = new(string, TechColor, int)[14]
		{
			("heart_0_1:1", TechColor.Red, 1),
			("heart_1_1:1", TechColor.Red, 1),
			("heart_3_1:3", TechColor.Red, 1),
			("heart_1_2:2", TechColor.Red, 2),
			("heart_2_2:2", TechColor.Red, 2),
			("heart_0_3:3", TechColor.Red, 3),
			("guts_2_1:2", TechColor.Green, 1),
			("guts_2_2:2", TechColor.Green, 1),
			("guts_1_3:3", TechColor.Green, 3),
			("brain_0_1:1", TechColor.Blue, 1),
			("brain_2_1:2", TechColor.Blue, 1),
			("brain_3_1:3", TechColor.Blue, 1),
			("brain_0_2:2", TechColor.Blue, 2),
			("brain_0_3:3", TechColor.Blue, 3)
		};

		public static void Register(TimbnFrameworkPlugin plugin)
		{
			(string, TechColor, int)[] organs = _organs;
			for (int i = 0; i < organs.Length; i++)
			{
				(string, TechColor, int) tuple = organs[i];
				string organ = tuple.Item1;
				TechColor item = tuple.Item2;
				int skulls = tuple.Item3;
				string solution = SpiritSolution.ItemId(item);
				plugin.Crafts.Add("timbn_spirit_" + organ.Replace(':', '_'), (Action<TimbnCraftBuilder>)delegate(TimbnCraftBuilder craft)
				{
					craft.In("distillation_cube").BasedOn("fragrance").Needs(new(string, int)[3]
					{
						(organ, 1),
						("fire", 20),
						("alchemy_bottle_1", 1)
					})
						.Makes(solution, skulls)
						.Mastery(1)
						.Icon(solution)
						.UnlockedBy("timbn_infusion_rack");
				});
			}
		}
	}
	internal enum TechColor
	{
		Red,
		Green,
		Blue
	}
	internal static class SpiritSolution
	{
		private const string _itemTemplate = "embalm_white:1";

		public static IEnumerable<TechColor> Colors => Enum.GetValues(typeof(TechColor)).Cast<TechColor>();

		public static string ItemId(TechColor color)
		{
			return "timbn_spirit_solution_" + color.ToString().ToLowerInvariant();
		}

		public static void Register(TimbnFrameworkPlugin plugin)
		{
			foreach (TechColor color in Colors)
			{
				string text = ItemId(color);
				plugin.Sprites.AddEmbeddedPng(text);
				plugin.Balance.AddItem("embalm_white:1", text, "", "", text, (Action<ItemDef>)delegate(ItemDef item)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_001e: Unknown result type (might be due to invalid IL or missing references)
					item.type = (ItemType)0;
					item.whiteSkulls = 0;
					item.redSkulls = 0;
					item.quality = 0;
					item.qualityType = (QualityType)0;
				});
			}
		}

		public static void GiveTo(ZombieWgoData zombie, WgoData table, TechColor color)
		{
			int value = PluginConfig.PointsPerSolution.Value;
			zombie.DoTechPointsReward(table, (color == TechColor.Red) ? value : 0, (color == TechColor.Green) ? value : 0, (color == TechColor.Blue) ? value : 0);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Timbn.GraveyardKeeperTwo.InfusionRack";

		public const string PLUGIN_NAME = "Timbn Infusion Rack";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}