Decompiled source of Ursur The Tyrant v1.0.19

BepInEx/plugins/com.binbin.TheTyrant.dll

Decompiled 2 months 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Obeliskial_Content;
using Obeliskial_Essentials;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.binbin.TheTyrant")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Ursur, The Tyrant")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4+ca4a5cdf38bc9e1ba972c2dcf54b382a6122a8f5")]
[assembly: AssemblyProduct("The Tyrant")]
[assembly: AssemblyTitle("com.binbin.TheTyrant")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 TheTyrant
{
	[BepInPlugin("com.binbin.TheTyrant", "The Tyrant", "1.0.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("AcrossTheObelisk.exe")]
	public class Plugin : BaseUnityPlugin
	{
		internal const int ModDate = 20240925;

		private readonly Harmony harmony = new Harmony("com.binbin.TheTyrant");

		public static ManualLogSource Log;

		public static string characterName = "Ursur";

		public static string subclassName = "tyrant";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"com.binbin.TheTyrant 1.0.4 has loaded!");
			Essentials.RegisterMod("The Tyrant", "binbin", "Ursur, The Tyrant.", "1.0.4", 20240925, "https://github.com/binbinmods/Ursur", (string[])null, "Ursur", 100, new string[3] { "content", "hero", "trait" }, "", true);
			Essentials.medsTexts["trait_Ursine Blood"] = "Testing String";
			harmony.PatchAll();
		}
	}
	[HarmonyPatch]
	internal class Traits
	{
		public static string[] myTraitList = new string[9] { "ursurursineblood", "ursurresilience", "ursurbellowingblows", "ursurbristlyhide", "ursurbearwithit", "ursurgrizzledclaws", "ursurbestdefense", "ursurunbearable", "ursurbearlynoticeable" };

		public static void DoCustomTrait(string _trait, ref Trait __instance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			EventActivation value = Traverse.Create((object)__instance).Field("theEvent").GetValue<EventActivation>();
			Character _character = Traverse.Create((object)__instance).Field("character").GetValue<Character>();
			Character value2 = Traverse.Create((object)__instance).Field("target").GetValue<Character>();
			int value3 = Traverse.Create((object)__instance).Field("auxInt").GetValue<int>();
			string value4 = Traverse.Create((object)__instance).Field("auxString").GetValue<string>();
			CardData value5 = Traverse.Create((object)__instance).Field("castedCard").GetValue<CardData>();
			Traverse.Create((object)__instance).Field("character").SetValue((object)_character);
			Traverse.Create((object)__instance).Field("target").SetValue((object)value2);
			Traverse.Create((object)__instance).Field("theEvent").SetValue((object)value);
			Traverse.Create((object)__instance).Field("auxInt").SetValue((object)value3);
			Traverse.Create((object)__instance).Field("auxString").SetValue((object)value4);
			Traverse.Create((object)__instance).Field("castedCard").SetValue((object)value5);
			TraitData traitData = Globals.Instance.GetTraitData(_trait);
			List<CardData> cardDataList = new List<CardData>();
			List<string> heroHand = MatchManager.Instance.GetHeroHand(_character.HeroIndex);
			Hero[] teamHero = MatchManager.Instance.GetTeamHero();
			NPC[] teamNPC = MatchManager.Instance.GetTeamNPC();
			Plugin.Log.LogDebug((object)"Ursur CustomTrait");
			Plugin.Log.LogDebug((object)("Ursur: " + _trait));
			switch (_trait)
			{
			case "ursurursineblood":
				if ((Object)(object)value5 != (Object)null && (Object)(object)_character.HeroData != (Object)null)
				{
					string traitName = "Ursine Blood";
					WhenYouPlayXGainY((CardType)19, "chill", 2, value5, ref _character, traitName);
					WhenYouPlayXGainY((CardType)4, "bleed", 2, value5, ref _character, traitName);
				}
				break;
			case "ursurbristlyhide":
				Plugin.Log.LogInfo((object)"Found Bristly Hide");
				if ((Object)(object)_character.HeroData != (Object)null)
				{
					string traitName2 = "Bristly Hide";
					int auracurseBonusValue = Mathf.FloorToInt((float)_character.GetAuraCharges("bleed") / 16f);
					int auracurseBonusValue2 = Mathf.FloorToInt((float)_character.GetAuraCharges("chill") / 20f);
					traitData.AuracurseBonusValue1 = auracurseBonusValue;
					traitData.AuracurseBonusValue2 = auracurseBonusValue2;
					Plugin.Log.LogInfo((object)("Bristly Hide - bonus taunt = " + auracurseBonusValue2 + " actual =" + traitData.AuracurseBonusValue2));
					WhenYouGainXGainY(value4, "taunt", "thorns", value3, 0, 2f, ref _character, traitName2);
					WhenYouGainXGainY(value4, "fortify", "thorns", value3, 0, 2f, ref _character, traitName2);
				}
				break;
			case "ursurbearwithit":
				if ((Object)(object)_character.HeroData != (Object)null)
				{
					Plugin.Log.LogInfo((object)"bearwithit 1");
					string traitName3 = "Bear With It";
					bool applyToAllCards = false;
					ReduceCostByStacks((CardType)19, "bleed", 16, ref _character, ref heroHand, ref cardDataList, traitName3, applyToAllCards);
					ReduceCostByStacks((CardType)4, "chill", 20, ref _character, ref heroHand, ref cardDataList, traitName3, applyToAllCards);
				}
				break;
			case "ursurunbearable":
			{
				string text = "Unbearable";
				Plugin.Log.LogInfo((object)(text + " 1"));
				if ((Object)(object)value5 != (Object)null && (Object)(object)_character.HeroData != (Object)null)
				{
					WhenYouPlayXGainY((CardType)19, "thorns", 2, value5, ref _character, text);
					WhenYouPlayXGainY((CardType)4, "fury", 1, value5, ref _character, text);
				}
				break;
			}
			case "ursurbearlynoticeable":
				break;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Trait), "DoTrait")]
		public static bool DoTrait(EventActivation _theEvent, string _trait, Character _character, Character _target, int _auxInt, string _auxString, CardData _castedCard, ref Trait __instance)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)MatchManager.Instance == (Object)null)
			{
				return false;
			}
			Traverse.Create((object)__instance).Field("character").SetValue((object)_character);
			Traverse.Create((object)__instance).Field("target").SetValue((object)_target);
			Traverse.Create((object)__instance).Field("theEvent").SetValue((object)_theEvent);
			Traverse.Create((object)__instance).Field("auxInt").SetValue((object)_auxInt);
			Traverse.Create((object)__instance).Field("auxString").SetValue((object)_auxString);
			Traverse.Create((object)__instance).Field("castedCard").SetValue((object)_castedCard);
			if (Content.medsCustomTraitsSource.Contains(_trait) && myTraitList.Contains(_trait))
			{
				DoCustomTrait(_trait, ref __instance);
				Plugin.Log.LogDebug((object)("Ursur DoTrait inside conditions " + _trait));
				return false;
			}
			return true;
		}

		public static void TraitHeal(ref Character _character, ref Character _target, int healAmount, string traitName)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			int num = healAmount;
			if (_target.GetHpLeftForMax() < healAmount)
			{
				num = _target.GetHpLeftForMax();
			}
			if (num > 0)
			{
				_target.ModifyHp(num, true, true);
				CastResolutionForCombatText val = new CastResolutionForCombatText();
				val.heal = num;
				if ((Object)(object)_target.HeroItem != (Object)null)
				{
					((CharacterItem)_target.HeroItem).ScrollCombatTextDamageNew(val);
					EffectsManager.Instance.PlayEffectAC("healimpactsmall", true, ((CharacterItem)_target.HeroItem).CharImageT, false, 0f);
				}
				else
				{
					((CharacterItem)_target.NPCItem).ScrollCombatTextDamageNew(val);
					EffectsManager.Instance.PlayEffectAC("healimpactsmall", true, ((CharacterItem)_target.NPCItem).CharImageT, false, 0f);
				}
				_target.SetEvent((EventActivation)15, (Character)null, 0, "");
				_character.SetEvent((EventActivation)14, _target, 0, "");
				((CharacterItem)_character.HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_" + traitName, ""), (CombatScrollEffectType)7);
			}
		}

		public static void WhenYouGainXGainY(string gainedAuraCurse, string desiredAuraCurse, string appliedAuraCurse, int n_charges_incoming, int n_bonus_charges, float multiplier, ref Character _character, string traitName)
		{
			Plugin.Log.LogDebug((object)"WhenYouGainXGainY Debug Start");
			if ((Object)(object)MatchManager.Instance != (Object)null && gainedAuraCurse != null && (Object)(object)_character.HeroData != (Object)null)
			{
				Plugin.Log.LogDebug((object)"WhenYouGainXGainY inside conditions 1");
				if (gainedAuraCurse == desiredAuraCurse)
				{
					Plugin.Log.LogDebug((object)"WhenYouGainXGainY inside conditions 2");
					int num = Mathf.RoundToInt((float)(n_charges_incoming + n_bonus_charges) * multiplier);
					_character.SetAuraTrait(_character, appliedAuraCurse, num);
					((CharacterItem)_character.HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_" + traitName, ""), (CombatScrollEffectType)7);
				}
			}
		}

		public static void WhenYouPlayXGainY(CardType desiredCardType, string desiredAuraCurse, int n_charges, CardData castedCard, ref Character _character, string traitName)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)MatchManager.Instance != (Object)null && (Object)(object)castedCard != (Object)null && (Object)(object)_character.HeroData != (Object)null && castedCard.GetCardTypes().Contains(desiredCardType))
			{
				_character.SetAuraTrait(_character, desiredAuraCurse, n_charges);
				((CharacterItem)_character.HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_" + traitName, ""), (CombatScrollEffectType)7);
			}
		}

		public static void ReduceCostByStacks(CardType cardType, string auraCurseName, int n_charges, ref Character _character, ref List<string> heroHand, ref List<CardData> cardDataList, string traitName, bool applyToAllCards)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_character.HeroData != (Object)null))
			{
				return;
			}
			int num = Mathf.FloorToInt((float)(_character.EffectCharges(auraCurseName) / n_charges));
			if (num <= 0)
			{
				return;
			}
			for (int i = 0; i < heroHand.Count; i++)
			{
				CardData cardData = MatchManager.Instance.GetCardData(heroHand[i]);
				if (cardData.GetCardFinalCost() > 0 && (cardData.GetCardTypes().Contains(cardType) || applyToAllCards))
				{
					cardDataList.Add(cardData);
				}
			}
			for (int j = 0; j < cardDataList.Count; j++)
			{
				CardData obj = cardDataList[j];
				obj.EnergyReductionTemporal += num;
				MatchManager.Instance.UpdateHandCards();
				CardItem cardFromTableByIndex = MatchManager.Instance.GetCardFromTableByIndex(cardDataList[j].InternalId);
				cardFromTableByIndex.PlayDissolveParticle();
				cardFromTableByIndex.ShowEnergyModification(-num);
				((CharacterItem)_character.HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_" + traitName, ""), (CombatScrollEffectType)7);
				MatchManager.Instance.CreateLogCardModification(cardDataList[j].InternalId, MatchManager.Instance.GetHero(_character.HeroIndex));
			}
		}

		public static void IncreaseChargesByStacks(string auraCurseToModify, float stacks_per_bonus, string auraCurseDependent, ref Character _character, string traitName)
		{
			int auraCharges = _character.GetAuraCharges(auraCurseDependent);
			int num = Mathf.FloorToInt((float)auraCharges / stacks_per_bonus);
			_character.ModifyAuraCurseQuantity(auraCurseToModify, num);
		}

		public static string TextChargesLeft(int currentCharges, int chargesTotal)
		{
			int num = currentCharges;
			int num2 = chargesTotal;
			return "<br><color=#FFF>" + num + "/" + num2 + "</color>";
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AtOManager), "GlobalAuraCurseModificationByTraitsAndItems")]
		public static void GlobalAuraCurseModificationByTraitsAndItemsPostfix(ref AtOManager __instance, ref AuraCurseData __result, string _type, string _acId, Character _characterCaster, Character _characterTarget)
		{
			AuraCurseData val = Object.Instantiate<AuraCurseData>(Globals.Instance.GetAuraCurseData(_acId));
			bool flag = false;
			if (_characterTarget != null && _characterTarget.IsHero)
			{
				flag = true;
			}
			if (_acId == "bleed" && flag && _type == "set")
			{
				if (_characterTarget != null && __instance.CharacterHaveTrait(_characterTarget.SubclassName, "ursurbearlynoticeable"))
				{
					__result.AuraDamageType2 = (DamageType)10;
					__result.AuraDamageIncreasedPercentPerStack2 = 1.5f;
					__result.ProduceDamageWhenConsumed = false;
					__result.DamageWhenConsumedPerCharge = 0f;
				}
				if (_type == "consume" && _characterCaster != null && __instance.CharacterHaveTrait(_characterCaster.SubclassName, "ursurbearlynoticeable"))
				{
					__result.ProduceDamageWhenConsumed = false;
					__result.DamageWhenConsumedPerCharge = 0f;
				}
			}
			if (!(_acId == "chill"))
			{
				return;
			}
			if (_type == "set")
			{
				if (_characterTarget != null && __instance.CharacterHaveTrait(_characterTarget.SubclassName, "ursurbearlynoticeable"))
				{
					__result.ResistModified = (DamageType)10;
					__result.ResistModifiedPercentagePerStack = 0.25f;
				}
				if (_characterTarget != null && __instance.CharacterHaveTrait(_characterTarget.SubclassName, "ursurunbearable"))
				{
					__result.CharacterStatModified = (CharacterStat)0;
					__result.CharacterStatChargesMultiplierNeededForOne = 0;
				}
			}
			if (_type == "consume" && _characterCaster != null && __instance.CharacterHaveTrait(_characterCaster.SubclassName, "ursurunbearable"))
			{
				__result.CharacterStatModified = (CharacterStat)0;
				__result.CharacterStatChargesMultiplierNeededForOne = 0;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Character), "GetTraitAuraCurseModifiers")]
		public static void GetTraitAuraCurseModifiersPostfix(ref Character __instance)
		{
			if ((Object)(object)__instance.HeroData != (Object)null)
			{
				int num = __instance.EffectCharges("chill");
				int num2 = __instance.EffectCharges("bleed");
				int num3 = Mathf.FloorToInt((float)num2 / 16f);
				int num4 = Mathf.FloorToInt((float)num / 20f);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "SetEvent")]
		public static void SetEventPrefix(ref Character __instance, ref EventActivation theEvent, Character target = null)
		{
			if (__instance.IsHero && (int)theEvent == 3 && __instance.Traits.Contains("ursurbristlyhide"))
			{
				Plugin.Log.LogDebug((object)"Binbin -- Bristly Hide calc values");
				int auracurseBonusValue = Mathf.FloorToInt((float)__instance.GetAuraCharges("bleed") / 16f);
				int auracurseBonusValue2 = Mathf.FloorToInt((float)__instance.GetAuraCharges("chill") / 20f);
				TraitData traitData = Globals.Instance.GetTraitData("ursurbristlyhide");
				traitData.AuracurseBonusValue1 = auracurseBonusValue2;
				traitData.AuracurseBonusValue2 = auracurseBonusValue;
			}
			if (__instance.IsHero && (int)theEvent == 17 && __instance.Traits.Contains("ursurbristlyhide"))
			{
				Plugin.Log.LogDebug((object)"Binbin -- Bristly Hide inside end turn");
				TraitData traitData2 = Globals.Instance.GetTraitData("ursurbristlyhide");
				traitData2.AuracurseBonusValue1 = 0;
				traitData2.AuracurseBonusValue2 = 0;
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.binbin.TheTyrant";

		public const string PLUGIN_NAME = "The Tyrant";

		public const string PLUGIN_VERSION = "1.0.4";
	}
}