Decompiled source of Too Many Perks v1.1.8

BepInEx/plugins/com.binbin.PerkManager.dll

Decompiled 12 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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.PerkManager")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.7.0")]
[assembly: AssemblyInformationalVersion("1.1.7+b02dbb26337a746df12aaf9e04f682f9c594c8b2")]
[assembly: AssemblyProduct("Custom Perks")]
[assembly: AssemblyTitle("com.binbin.PerkManager")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.7.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 PerkManager
{
	public class CustomFunctions
	{
		public enum AppliesTo
		{
			None,
			Global,
			Monsters,
			Heroes,
			ThisHero
		}

		public enum CharacterHas
		{
			Perk,
			Item,
			Trait
		}

		public static void PLog(string s)
		{
			Plugin.Log.LogDebug((object)(Plugin.debugBase + s));
		}

		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 (_target.HeroItem != 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 TraitHealHero(ref Character _character, ref Hero _target, int healAmount, string traitName)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			if (_target == null || !((Character)_target).IsHero || !((Character)_target).Alive)
			{
				return;
			}
			int num = healAmount;
			if (((Character)_target).GetHpLeftForMax() < healAmount)
			{
				num = ((Character)_target).GetHpLeftForMax();
			}
			if (num > 0)
			{
				((Character)_target).ModifyHp(num, true, true);
				CastResolutionForCombatText val = new CastResolutionForCombatText();
				val.heal = num;
				if (((Character)_target).HeroItem != null)
				{
					((CharacterItem)((Character)_target).HeroItem).ScrollCombatTextDamageNew(val);
					EffectsManager.Instance.PlayEffectAC("healimpactsmall", true, ((CharacterItem)((Character)_target).HeroItem).CharImageT, false, 0f);
				}
				else
				{
					((CharacterItem)((Character)_target).NPCItem).ScrollCombatTextDamageNew(val);
					EffectsManager.Instance.PlayEffectAC("healimpactsmall", true, ((CharacterItem)((Character)_target).NPCItem).CharImageT, false, 0f);
				}
				((Character)_target).SetEvent((EventActivation)15, (Character)null, 0, "");
				_character.SetEvent((EventActivation)14, (Character)(object)_target, 0, "");
				((CharacterItem)_character.HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_" + traitName, ""), (CombatScrollEffectType)7);
			}
		}

		public static void WhenYouPlayXRefund1Energy(CardType cardType, ref Character _character, string traitName, string traitID)
		{
		}

		public static void ApplyAuraCurseTo(string auraCurse, int amount, bool allHeroFlag, bool allNpcFlag, bool randomHeroFlag, bool randomNpcFlag, ref Character _character, ref Hero[] teamHeroes, ref NPC[] teamNpc, string traitName, string soundEffect)
		{
			if (allNpcFlag)
			{
				for (int i = 0; i < teamNpc.Length; i++)
				{
					if (teamNpc[i] != null && ((Character)teamNpc[i]).Alive)
					{
						((Character)teamNpc[i]).SetAuraTrait(_character, auraCurse, amount);
						if (((Character)teamNpc[i]).NPCItem != null)
						{
							((CharacterItem)((Character)teamNpc[i]).NPCItem).ScrollCombatText(Texts.Instance.GetText("traits_" + traitName, ""), (CombatScrollEffectType)7);
							EffectsManager.Instance.PlayEffectAC(soundEffect, true, ((CharacterItem)((Character)teamNpc[i]).NPCItem).CharImageT, false, 0f);
						}
					}
				}
			}
			if (!allHeroFlag)
			{
				return;
			}
			for (int j = 0; j < teamHeroes.Length; j++)
			{
				if (teamHeroes[j] != null && ((Character)teamHeroes[j]).Alive)
				{
					((Character)teamHeroes[j]).SetAuraTrait(_character, auraCurse, amount);
					if (((Character)teamHeroes[j]).NPCItem != null)
					{
						((CharacterItem)((Character)teamHeroes[j]).HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_" + traitName, ""), (CombatScrollEffectType)7);
						EffectsManager.Instance.PlayEffectAC(soundEffect, true, ((CharacterItem)((Character)teamHeroes[j]).NPCItem).CharImageT, false, 0f);
					}
				}
			}
		}

		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)
		{
			if ((Object)(object)MatchManager.Instance != (Object)null && gainedAuraCurse != null && (Object)(object)_character.HeroData != (Object)null && gainedAuraCurse == desiredAuraCurse)
			{
				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 AddImmunityToHero(string immunity, ref Hero _character)
		{
			if (!((Character)_character).AuracurseImmune.Contains(immunity))
			{
				((Character)_character).AuracurseImmune.Add(immunity);
			}
		}

		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 AuraCurseData GetAuraCurseData(string ac)
		{
			return Globals.Instance.GetAuraCurseData(ac);
		}

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

		public static void Duality(ref Character _character, ref CardData _castedCard, CardClass class1, CardClass class2, string traitName)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			if (MatchManager.Instance == null || _castedCard == null)
			{
				return;
			}
			TraitData traitData = Globals.Instance.GetTraitData(traitName);
			if (MatchManager.Instance.activatedTraits != null && MatchManager.Instance.activatedTraits.ContainsKey(traitName) && MatchManager.Instance.activatedTraits[traitName] > traitData.TimesPerTurn - 1)
			{
				return;
			}
			for (int i = 0; i < 2; i++)
			{
				CardClass val;
				CardClass val2;
				if (i == 0)
				{
					val = class1;
					val2 = class2;
				}
				else
				{
					val = class2;
					val2 = class1;
				}
				if (_castedCard.CardClass != val)
				{
					continue;
				}
				if (MatchManager.Instance.CountHeroHand(-1) == 0 || _character.HeroData == null)
				{
					break;
				}
				List<CardData> list = new List<CardData>();
				List<string> heroHand = MatchManager.Instance.GetHeroHand(_character.HeroIndex);
				int num = 0;
				for (int j = 0; j < heroHand.Count; j++)
				{
					CardData cardData = MatchManager.Instance.GetCardData(heroHand[j]);
					if (cardData != null && cardData.CardClass == val2 && _character.GetCardFinalCost(cardData) > num)
					{
						num = _character.GetCardFinalCost(cardData);
					}
				}
				if (num <= 0)
				{
					break;
				}
				for (int k = 0; k < heroHand.Count; k++)
				{
					CardData cardData2 = MatchManager.Instance.GetCardData(heroHand[k]);
					if (cardData2 != null && cardData2.CardClass == val2 && _character.GetCardFinalCost(cardData2) >= num)
					{
						list.Add(cardData2);
					}
				}
				if (list.Count <= 0)
				{
					break;
				}
				CardData val3 = ((list.Count != 1) ? list[MatchManager.Instance.GetRandomIntRange(0, list.Count, "trait", "")] : list[0]);
				if (val3 != null)
				{
					if (!MatchManager.Instance.activatedTraits.ContainsKey(traitName))
					{
						MatchManager.Instance.activatedTraits.Add(traitName, 1);
					}
					else
					{
						Dictionary<string, int> activatedTraits = MatchManager.Instance.activatedTraits;
						int value = activatedTraits[traitName] + 1;
						activatedTraits[traitName] = value;
					}
					MatchManager.Instance.SetTraitInfoText();
					int num2 = 1;
					val3.EnergyReductionTemporal += num2;
					MatchManager.Instance.GetCardFromTableByIndex(val3.InternalId).ShowEnergyModification(-num2);
					MatchManager.Instance.UpdateHandCards();
					((CharacterItem)_character.HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_" + traitName, "") + TextChargesLeft(MatchManager.Instance.activatedTraits[traitName], traitData.TimesPerTurn), (CombatScrollEffectType)7);
					MatchManager.Instance.CreateLogCardModification(val3.InternalId, MatchManager.Instance.GetHero(_character.HeroIndex));
				}
				break;
			}
		}

		public static void PermanentyReduceXWhenYouPlayY(ref Character _character, ref CardData _castedCard, CardType reduceThis, CardType whenYouPlayThis, int amountToReduce, string traitName)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Invalid comparison between Unknown and I4
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			if (MatchManager.Instance == null || _castedCard == null)
			{
				return;
			}
			TraitData traitData = Globals.Instance.GetTraitData(traitName);
			if ((MatchManager.Instance.activatedTraits != null && MatchManager.Instance.activatedTraits.ContainsKey(traitName) && MatchManager.Instance.activatedTraits[traitName] > traitData.TimesPerTurn - 1) || !_castedCard.GetCardTypes().Contains(whenYouPlayThis) || MatchManager.Instance.CountHeroHand(-1) == 0 || _character.HeroData == null)
			{
				return;
			}
			List<CardData> list = new List<CardData>();
			List<string> heroHand = MatchManager.Instance.GetHeroHand(_character.HeroIndex);
			if ((int)reduceThis == 0)
			{
				for (int i = 0; i < heroHand.Count; i++)
				{
					CardData cardData = MatchManager.Instance.GetCardData(heroHand[i]);
					if (cardData != null)
					{
						list.Add(cardData);
					}
				}
			}
			else
			{
				for (int j = 0; j < heroHand.Count; j++)
				{
					CardData cardData2 = MatchManager.Instance.GetCardData(heroHand[j]);
					if (cardData2 != null && cardData2.GetCardTypes().Contains(reduceThis))
					{
						list.Add(cardData2);
					}
				}
			}
			if (!MatchManager.Instance.activatedTraits.ContainsKey(traitName))
			{
				MatchManager.Instance.activatedTraits.Add(traitName, 1);
			}
			else
			{
				Dictionary<string, int> activatedTraits = MatchManager.Instance.activatedTraits;
				int value = activatedTraits[traitName] + 1;
				activatedTraits[traitName] = value;
			}
			CardData val = list[MatchManager.Instance.GetRandomIntRange(0, list.Count, "trait", "")];
			val.EnergyReductionPermanent += amountToReduce;
			MatchManager.Instance.GetCardFromTableByIndex(val.InternalId).ShowEnergyModification(-amountToReduce);
			MatchManager.Instance.UpdateHandCards();
			((CharacterItem)_character.HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_" + traitName, "") + TextChargesLeft(MatchManager.Instance.activatedTraits[traitName], traitData.TimesPerTurn), (CombatScrollEffectType)7);
			MatchManager.Instance.CreateLogCardModification(val.InternalId, MatchManager.Instance.GetHero(_character.HeroIndex));
		}

		public static int CountAllStacks(string auraCurse, Hero[] teamHero, NPC[] teamNpc)
		{
			int num = 0;
			for (int i = 0; i < teamHero.Length; i++)
			{
				if (teamHero[i] != null && (Object)(object)((Character)teamHero[i]).HeroData != (Object)null && ((Character)teamHero[i]).Alive)
				{
					num += ((Character)teamHero[i]).GetAuraCharges(auraCurse);
				}
			}
			for (int j = 0; j < teamNpc.Length; j++)
			{
				if (teamNpc[j] != null && ((Character)teamNpc[j]).Alive)
				{
					num += ((Character)teamNpc[j]).GetAuraCharges(auraCurse);
				}
			}
			return num;
		}

		public static void DealIndirectDamageToAllMonsters(DamageType damageType, int amount)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			Plugin.Log.LogDebug((object)(Plugin.debugBase + "Dealing Indirect Damage"));
			NPC[] teamNPC = MatchManager.Instance.GetTeamNPC();
			foreach (NPC val in teamNPC)
			{
				if (val != null && ((Character)val).Alive && !((Character)val).IsHero)
				{
					((Character)val).IndirectDamage(damageType, amount, (AudioClip)null, "", "", "");
				}
			}
		}

		public static Character GetRandomCharacter(Character[] array)
		{
			if (array == null)
			{
				Plugin.Log.LogDebug((object)(Plugin.debugBase + "Null Array"));
			}
			List<Character> list = new List<Character>();
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i] == null)
				{
					Plugin.Log.LogDebug((object)(Plugin.debugBase + "Null index"));
					continue;
				}
				Character val = array[i];
				if (val.Alive && val != null)
				{
					list.Add(val);
				}
			}
			if (list.Count == 0)
			{
				return null;
			}
			int randomIntRange = MatchManager.Instance.GetRandomIntRange(0, list.Count, "default", "");
			if (randomIntRange < list.Count)
			{
				return list[randomIntRange];
			}
			if (list[randomIntRange] == null)
			{
				return null;
			}
			return list[0];
		}

		public static bool IsLivingHero(Character _character)
		{
			return _character != null && _character.Alive && _character.IsHero;
		}

		public static bool IsLivingNPC(Character _character)
		{
			return _character != null && _character.Alive && !_character.IsHero;
		}

		public static bool CharacterHasPerkForSet(string perkName, bool flag, AtOManager __instance, Character _characterTarget)
		{
			return flag && _characterTarget != null && __instance.CharacterHavePerk(_characterTarget.SubclassName, Plugin.perkBase + perkName);
		}

		public static bool CharacterHasPerkForConsume(string perkName, bool flag, AtOManager __instance, Character _characterCaster)
		{
			return flag && _characterCaster != null && __instance.CharacterHavePerk(_characterCaster.SubclassName, Plugin.perkBase + perkName);
		}

		public static bool TeamHasPerkForSet(string perkName, bool flag, AtOManager __instance, Character _characterTarget)
		{
			return _characterTarget != null && __instance.TeamHavePerk(Plugin.perkBase + perkName) && flag;
		}

		public static bool TeamHasPerk(string perkName)
		{
			return AtOManager.Instance.TeamHavePerk(Plugin.perkBase + perkName);
		}

		public static bool TeamHasPerkForConsume(string perkName, bool flag, AtOManager __instance, Character _characterCaster)
		{
			return _characterCaster != null && __instance.TeamHavePerk(Plugin.perkBase + perkName) && flag;
		}

		public static bool CharacterObjectHavePerk(Character _character, string _perk_id)
		{
			if (_character == null)
			{
				return false;
			}
			if (_perk_id.StartsWith(Plugin.perkBase))
			{
				AtOManager.Instance.CharacterHavePerk(_character.SubclassName, _perk_id);
			}
			return AtOManager.Instance.CharacterHavePerk(_character.SubclassName, Plugin.perkBase + _perk_id);
		}

		public static void CastTargetCard(string cardToCast)
		{
			CardData cardData = Globals.Instance.GetCardData(cardToCast, true);
			((MonoBehaviour)MatchManager.Instance).StartCoroutine(MatchManager.Instance.CastCard((CardItem)null, true, cardData, 0, -1, true));
		}

		public static bool IfCharacterHas(Character characterOfInterest, CharacterHas characterHas, string id, AppliesTo appliesTo = AppliesTo.Global, string _type = "", string onlyThisType = "")
		{
			if (appliesTo == AppliesTo.None || characterOfInterest == null || (Object)(object)AtOManager.Instance == (Object)null)
			{
				return false;
			}
			if (_type != "" && onlyThisType != _type)
			{
				return false;
			}
			bool flag = (characterOfInterest.IsHero && appliesTo == AppliesTo.Heroes) || (!characterOfInterest.IsHero && appliesTo == AppliesTo.Monsters) || appliesTo == AppliesTo.Global || (appliesTo == AppliesTo.ThisHero && characterOfInterest.IsHero);
			bool flag2 = false;
			if (appliesTo == AppliesTo.ThisHero)
			{
				switch (characterHas)
				{
				case CharacterHas.Item:
					flag2 = AtOManager.Instance.CharacterHaveItem(characterOfInterest.SubclassName, Plugin.perkBase + id) || AtOManager.Instance.CharacterHaveItem(characterOfInterest.SubclassName, id);
					break;
				case CharacterHas.Perk:
					flag2 = AtOManager.Instance.CharacterHavePerk(characterOfInterest.SubclassName, Plugin.perkBase + id) || AtOManager.Instance.CharacterHavePerk(characterOfInterest.SubclassName, id);
					break;
				case CharacterHas.Trait:
					flag2 = AtOManager.Instance.CharacterHaveTrait(characterOfInterest.SubclassName, Plugin.perkBase + id) || AtOManager.Instance.CharacterHaveTrait(characterOfInterest.SubclassName, id);
					break;
				}
			}
			else
			{
				switch (characterHas)
				{
				case CharacterHas.Item:
					flag2 = AtOManager.Instance.TeamHaveItem(Plugin.perkBase + id, -1, false) || AtOManager.Instance.TeamHaveItem(id, -1, false);
					break;
				case CharacterHas.Perk:
					flag2 = AtOManager.Instance.TeamHavePerk(Plugin.perkBase + id) || AtOManager.Instance.TeamHavePerk(id);
					break;
				case CharacterHas.Trait:
					flag2 = AtOManager.Instance.TeamHaveTrait(Plugin.perkBase + id) || AtOManager.Instance.TeamHaveTrait(id);
					break;
				}
			}
			return flag2 && flag;
		}
	}
	[HarmonyPatch]
	public class PerkBackgroundExtension
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(PerkNodeAmplify), "SetForNodes")]
		public static bool SetForNodesPrefix(PerkNodeAmplify __instance, int _numNodes)
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			Plugin.Log.LogDebug((object)(Plugin.debugBase + "Extending Clickbox for Perks"));
			PolygonCollider2D component = ((Component)__instance).GetComponent<PolygonCollider2D>();
			float num = -0.7f * (float)(_numNodes - 1);
			switch (_numNodes)
			{
			case 2:
				((Component)__instance.bg2).gameObject.SetActive(true);
				((Component)__instance.bg3).gameObject.SetActive(false);
				((Component)__instance.bg4).gameObject.SetActive(false);
				__instance.amplifyNodes.localPosition = new Vector3(num, __instance.amplifyNodes.localPosition.y, __instance.amplifyNodes.localPosition.z);
				component.points = ((Component)__instance.bg2).GetComponent<PolygonCollider2D>().points;
				break;
			case 3:
				((Component)__instance.bg2).gameObject.SetActive(false);
				((Component)__instance.bg3).gameObject.SetActive(true);
				((Component)__instance.bg4).gameObject.SetActive(false);
				__instance.amplifyNodes.localPosition = new Vector3(num, __instance.amplifyNodes.localPosition.y, __instance.amplifyNodes.localPosition.z);
				component.points = ((Component)__instance.bg3).GetComponent<PolygonCollider2D>().points;
				break;
			default:
			{
				((Component)__instance.bg2).gameObject.SetActive(false);
				((Component)__instance.bg3).gameObject.SetActive(false);
				((Component)__instance.bg4).gameObject.SetActive(true);
				__instance.amplifyNodes.localPosition = new Vector3(num, __instance.amplifyNodes.localPosition.y, __instance.amplifyNodes.localPosition.z);
				float num2 = (float)_numNodes / 4f;
				((Component)__instance.bg4).transform.localScale = new Vector3(num2, 1f, 1f);
				PolygonCollider2D component2 = ((Component)__instance.bg4).GetComponent<PolygonCollider2D>();
				Vector2[] points = component2.points;
				for (int i = 0; i < points.Length; i++)
				{
					points[i] = new Vector2(points[i].x * num2, points[i].y);
				}
				component.points = points;
				break;
			}
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PerkTree), "DrawTree")]
		public static void DrawTreePrefix()
		{
			Plugin.Log.LogDebug((object)(Plugin.debugBase + "Draw Tree"));
		}
	}
	[HarmonyPatch]
	public class PerkPatches
	{
		public static int[] paralyzeCounters = new int[4];

		public static bool blockShieldFlag = false;

		public static int blockCount = 0;

		public static int shieldCount = 0;

		public static bool mark1dFlag = true;

		public static bool poison2gFlag = true;

		public static bool bleed2gFlag = true;

		public static bool thorns1eFlag = true;

		public static bool isDamagePreviewActive = false;

		public static bool isCalculateDamageActive = false;

		public static int infiniteProctection = 0;

		public static int infiniteProctectionPowerful = 0;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AtOManager), "BeginAdventure")]
		public static void BeginAdventurePostfix(ref AtOManager __instance)
		{
			Hero[] value = Traverse.Create((object)__instance).Field("teamAtO").GetValue<Hero[]>();
			foreach (Hero hero in value)
			{
				HandleExpPerks(hero);
			}
		}

		public static void HandleExpPerks(Hero _hero)
		{
			int num = 0;
			int num2 = 10;
			int num3 = 40;
			if (CustomFunctions.CharacterObjectHavePerk((Character)(object)_hero, "exp0"))
			{
				num += num2;
			}
			if (CustomFunctions.CharacterObjectHavePerk((Character)(object)_hero, "exp1"))
			{
				num += num2;
			}
			if (CustomFunctions.CharacterObjectHavePerk((Character)(object)_hero, "exp2"))
			{
				num += num2;
			}
			if (CustomFunctions.CharacterObjectHavePerk((Character)(object)_hero, "exp3"))
			{
				num += num3;
			}
			((Character)_hero).GrantExperience(num);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(AtOManager), "HeroLevelUp")]
		public static void HeroLevelUpPrefix(ref AtOManager __instance, int heroIndex, string traitId)
		{
			Hero[] value = Traverse.Create((object)__instance).Field("teamAtO").GetValue<Hero[]>();
			Hero val = value[heroIndex];
			if (CustomFunctions.CharacterObjectHavePerk((Character)(object)val, "health6b"))
			{
				int num = 12;
				((Character)value[heroIndex]).ModifyMaxHP(num);
			}
			if (CustomFunctions.CharacterObjectHavePerk((Character)(object)val, "health6c"))
			{
				int num2 = -14;
				((Character)value[heroIndex]).ModifyMaxHP(num2);
			}
			if (CustomFunctions.CharacterObjectHavePerk((Character)(object)val, "shards5b"))
			{
				int num3 = 125;
				AtOManager.Instance.GivePlayer(1, num3, "", "", true, false);
			}
			if (CustomFunctions.CharacterObjectHavePerk((Character)(object)val, "currency6b"))
			{
				int num4 = 125;
				AtOManager.Instance.GivePlayer(0, num4, "", "", true, false);
			}
			if (CustomFunctions.CharacterObjectHavePerk((Character)(object)val, "resistance5b"))
			{
				CustomFunctions.PLog(Plugin.debugBase + "Attempting to add resistances");
				int num5 = 4;
				string text = Plugin.perkBase + "resistance5b";
				PerkData perkData = Globals.Instance.GetPerkData(text);
				perkData.ResistModified = (DamageType)10;
				perkData.ResistModifiedValue += num5;
				Dictionary<string, PerkData> value2 = Traverse.Create((object)Globals.Instance).Field("_PerksSource").GetValue<Dictionary<string, PerkData>>();
				if (value2.ContainsKey(text))
				{
					CustomFunctions.PLog(Plugin.debugBase + "Setting perk dictionary");
					value2[text] = perkData;
				}
				Traverse.Create((object)Globals.Instance).Field("_PerksSource").SetValue((object)value2);
			}
			if (CustomFunctions.CharacterObjectHavePerk((Character)(object)val, "resistance5c"))
			{
				CustomFunctions.PLog(Plugin.debugBase + "Attempting to add resistances");
				int num6 = -4;
				string text2 = Plugin.perkBase + "resistance5b";
				PerkData perkData2 = Globals.Instance.GetPerkData(text2);
				perkData2.ResistModified = (DamageType)10;
				perkData2.ResistModifiedValue += num6;
				Dictionary<string, PerkData> value3 = Traverse.Create((object)Globals.Instance).Field("_PerksSource").GetValue<Dictionary<string, PerkData>>();
				if (value3.ContainsKey(text2))
				{
					CustomFunctions.PLog(Plugin.debugBase + "Setting perk dictionary");
					value3[text2] = perkData2;
				}
				Traverse.Create((object)Globals.Instance).Field("_PerksSource").SetValue((object)value3);
			}
			HandleExpPerks(val);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MatchManager), "GenerateHeroes")]
		public static void GenerateHeroesPostfix(ref MatchManager __instance)
		{
			Hero[] teamHero = MatchManager.Instance.GetTeamHero();
			for (int i = 0; i < teamHero.Length; i++)
			{
				if (teamHero[i] != null)
				{
					Hero _character = teamHero[i];
					if (CustomFunctions.CharacterObjectHavePerk((Character)(object)_character, "mitigate1d"))
					{
						CustomFunctions.PLog(Plugin.debugBase + "Hero has mitigate1d");
					}
					CustomFunctions.PLog(Plugin.debugBase + "Adding Immunities weak1d and more");
					if (CustomFunctions.CharacterObjectHavePerk((Character)(object)_character, "weak1d"))
					{
						CustomFunctions.PLog(Plugin.debugBase + "Adding Immunities, has weak1d");
						CustomFunctions.AddImmunityToHero("weak", ref _character);
					}
					if (CustomFunctions.CharacterObjectHavePerk((Character)(object)_character, "disarm1a"))
					{
						CustomFunctions.PLog(Plugin.debugBase + "Adding Immunities, has disarm1a");
						CustomFunctions.AddImmunityToHero("disarm", ref _character);
					}
					if (CustomFunctions.CharacterObjectHavePerk((Character)(object)_character, "silence1a"))
					{
						CustomFunctions.AddImmunityToHero("silence", ref _character);
					}
					if (CustomFunctions.CharacterObjectHavePerk((Character)(object)_character, "shackle1b"))
					{
						CustomFunctions.AddImmunityToHero("shackle", ref _character);
					}
					if (CustomFunctions.CharacterObjectHavePerk((Character)(object)_character, "stanza0e"))
					{
						CustomFunctions.AddImmunityToHero("stanzai", ref _character);
						CustomFunctions.AddImmunityToHero("stanzaiii", ref _character);
					}
				}
			}
			Traverse.Create((object)MatchManager.Instance).Field("teamHero").SetValue((object)teamHero);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Globals), "GetCostReroll")]
		public static void GetRerollCostPostfix(ref int __result)
		{
			if (CustomFunctions.TeamHasPerk("currency6d"))
			{
				__result = Mathf.RoundToInt(0.75f * (float)__result);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Globals), "GetDivinationCost")]
		public static void GetDivinationCost(ref Globals __instance, ref int __result)
		{
			if (CustomFunctions.TeamHasPerk("currency6e"))
			{
				__result = Mathf.RoundToInt(0.85f * (float)__result);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Character), "GetTraitHealReceivedPercentBonus")]
		public static void GetTraitHealReceivedPercentBonusPostfix(ref Character __instance, ref float __result)
		{
			if (CustomFunctions.CharacterObjectHavePerk(__instance, "heal5c") && __instance.IsHero && __instance.Alive && __instance != null)
			{
				__result += 35f;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "SetEvent")]
		public static void SetEventPrefix(ref Character __instance, EventActivation theEvent, ref int auxInt, Character target = null, string auxString = "")
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Invalid comparison between Unknown and I4
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Invalid comparison between Unknown and I4
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Invalid comparison between Unknown and I4
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Invalid comparison between Unknown and I4
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Invalid comparison between Unknown and I4
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Invalid comparison between Unknown and I4
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Invalid comparison between Unknown and I4
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Invalid comparison between Unknown and I4
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Invalid comparison between Unknown and I4
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Invalid comparison between Unknown and I4
			//IL_045f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: Invalid comparison between Unknown and I4
			//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fd: Invalid comparison between Unknown and I4
			//IL_0574: Unknown result type (might be due to invalid IL or missing references)
			//IL_0577: Invalid comparison between Unknown and I4
			//IL_0615: Unknown result type (might be due to invalid IL or missing references)
			//IL_0617: Invalid comparison between Unknown and I4
			//IL_066b: Unknown result type (might be due to invalid IL or missing references)
			//IL_066d: Invalid comparison between Unknown and I4
			//IL_06c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c4: Invalid comparison between Unknown and I4
			//IL_078b: Unknown result type (might be due to invalid IL or missing references)
			//IL_078e: Invalid comparison between Unknown and I4
			//IL_0836: Unknown result type (might be due to invalid IL or missing references)
			//IL_0839: Invalid comparison between Unknown and I4
			//IL_08d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d5: Invalid comparison between Unknown and I4
			//IL_093b: Unknown result type (might be due to invalid IL or missing references)
			//IL_093e: Invalid comparison between Unknown and I4
			//IL_0a1a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a1c: Invalid comparison between Unknown and I4
			//IL_0ac8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0acb: Invalid comparison between Unknown and I4
			//IL_0b14: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b19: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b56: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b71: Unknown result type (might be due to invalid IL or missing references)
			if ((int)theEvent == 18 || (int)theEvent == 26)
			{
				return;
			}
			Hero[] teamHeroes = MatchManager.Instance.GetTeamHero();
			NPC[] teamNpc = MatchManager.Instance.GetTeamNPC();
			CustomFunctions.PLog(Plugin.debugBase + "SETEVENTPREFIX");
			if ((int)theEvent == 1)
			{
				infiniteProctection = 0;
				paralyzeCounters = new int[4];
				mark1dFlag = true;
			}
			if ((int)theEvent == 25 && __instance.IsHero && __instance != null && CustomFunctions.CharacterObjectHavePerk(__instance, "zeal1f") && __instance.HasEffect("zeal"))
			{
				CustomFunctions.PLog(Plugin.debugBase + "zeal1f");
				CustomFunctions.PLog(Plugin.debugBase + "Target Charges = " + target.GetAuraCharges("burn"));
				int auraCharges = __instance.GetAuraCharges("burn");
				CustomFunctions.PLog(Plugin.debugBase + "Instance Charges = " + auraCharges);
				int num = Functions.FuncRoundToInt((float)(8 * auraCharges));
				__instance.IndirectDamage((DamageType)7, num, (AudioClip)null, "", "", "");
			}
			if ((int)theEvent == 23 && CustomFunctions.IsLivingNPC(__instance) && CustomFunctions.TeamHasPerk("mark1d") && __instance.HasEffect("mark") && auxString == "mark" && __instance.GetAuraCharges("mark") >= 10 && mark1dFlag)
			{
				CustomFunctions.PLog("mark1d");
				__instance.SetAura(__instance, CustomFunctions.GetAuraCurseData("taunt"), 2, false, (CardClass)11, false, true);
				mark1dFlag = false;
			}
			if ((int)theEvent == 23 && CustomFunctions.IsLivingNPC(target) && CustomFunctions.IsLivingHero(__instance) && CustomFunctions.CharacterObjectHavePerk(__instance, "spark2g") && auxString == "spark")
			{
				target.SetAura(__instance, CustomFunctions.GetAuraCurseData("crack"), 1, false, (CardClass)11, true, true);
			}
			if ((int)theEvent == 23 && auxString == "powerful" && CustomFunctions.IsLivingHero(__instance) && CustomFunctions.TeamHasPerk("powerful1d") && __instance.HasEffect("powerful"))
			{
				AuraCurseData auraCurseData = CustomFunctions.GetAuraCurseData("powerful");
				if ((__instance.GetAuraCharges("powerful") == auraCurseData.MaxCharges || __instance.GetAuraCharges("powerful") == auraCurseData.MaxCharges + 7) && infiniteProctectionPowerful < 10)
				{
					CustomFunctions.PLog("powerful1d");
					__instance.SetAuraTrait(__instance, "vitality", 1);
					infiniteProctectionPowerful++;
				}
			}
			if ((int)theEvent == 23 && auxString == "shackle" && __instance.IsHero && __instance != null && CustomFunctions.CharacterObjectHavePerk(__instance, "shackle1e") && __instance.HasEffect("shackle"))
			{
				CustomFunctions.PLog(Plugin.debugBase + "shackle1e");
				int auraCharges2 = __instance.GetAuraCharges("shackle");
				__instance.ModifyAuraCurseQuantity("dark", auraCharges2);
			}
			if ((int)theEvent == 23 && CustomFunctions.IsLivingHero(__instance) && CustomFunctions.IsLivingNPC(target) && CustomFunctions.CharacterObjectHavePerk(__instance, "poison2h") && auxString == "poison")
			{
				CustomFunctions.PLog(Plugin.debugBase + "poison2h");
				int auraCharges3 = target.GetAuraCharges("poison");
				int num2 = Mathf.RoundToInt((float)auraCharges3 * 0.3f);
				target.IndirectDamage((DamageType)7, num2, (AudioClip)null, "", "", "");
			}
			if ((int)theEvent == 23 && CustomFunctions.IsLivingHero(target) && target.HasEffect("courage") && CustomFunctions.CharacterObjectHavePerk(target, "courage1d") && auxString == "shield")
			{
				int auraCharges4 = target.GetAuraCharges("courage");
				shieldCount++;
				if (shieldCount % 2 == 1 && shieldCount < 100)
				{
					CustomFunctions.PLog(Plugin.debugBase + "courage1d");
					target.SetAura(__instance, CustomFunctions.GetAuraCurseData("shield"), auraCharges4, false, (CardClass)11, false, true);
				}
			}
			if ((int)theEvent == 23 && CustomFunctions.IsLivingHero(target) && target.HasEffect("reinforce") && CustomFunctions.CharacterObjectHavePerk(target, "reinforce1d") && auxString == "block")
			{
				int auraCharges5 = __instance.GetAuraCharges("reinforce");
				blockCount++;
				if (blockCount % 2 == 1 && blockCount < 100)
				{
					CustomFunctions.PLog("reinforce1d");
					target.SetAura(__instance, CustomFunctions.GetAuraCurseData("block"), auraCharges5, false, (CardClass)11, false, true);
				}
			}
			if ((int)theEvent == 23 && CustomFunctions.IsLivingNPC(target) && CustomFunctions.TeamHasPerk("sight1e") && auxString == "sight" && target.HasEffect("sight") && target.GetAuraCharges("sight") >= 100)
			{
				CustomFunctions.PLog("sight1e");
				target.HealCursesName((List<string>)null, "sight");
				target.DispelAuras(3);
			}
			if ((int)theEvent == 23 && __instance != null && CustomFunctions.IsLivingNPC(target) && CustomFunctions.TeamHasPerk("paralyze1c") && auxString == "spark")
			{
				int auraCharges6 = target.GetAuraCharges("spark");
				if (auraCharges6 >= 100 && paralyzeCounters[target.NPCIndex] <= 0)
				{
					CustomFunctions.PLog("paralyze1c");
					AuraCurseData auraCurseData2 = CustomFunctions.GetAuraCurseData("paralyze");
					paralyzeCounters[target.NPCIndex]++;
					target.SetAura(__instance, auraCurseData2, 1, false, (CardClass)11, true, true);
				}
			}
			if ((int)theEvent == 1 && CustomFunctions.IsLivingHero(__instance) && CustomFunctions.CharacterObjectHavePerk(__instance, "block5c"))
			{
				CustomFunctions.PLog("block5c");
				bool allHeroFlag = true;
				bool allNpcFlag = false;
				CustomFunctions.ApplyAuraCurseTo("block", 2, allHeroFlag, allNpcFlag, randomHeroFlag: false, randomNpcFlag: false, ref __instance, ref teamHeroes, ref teamNpc, "", "");
			}
			if ((int)theEvent == 1 && CustomFunctions.IsLivingHero(__instance) && CustomFunctions.CharacterObjectHavePerk(__instance, "shield5c"))
			{
				CustomFunctions.PLog("shield5c");
				bool allHeroFlag2 = true;
				bool allNpcFlag2 = false;
				CustomFunctions.ApplyAuraCurseTo("shield", 4, allHeroFlag2, allNpcFlag2, randomHeroFlag: false, randomNpcFlag: false, ref __instance, ref teamHeroes, ref teamNpc, "", "");
			}
			if ((int)theEvent == 35 && !target.IsHero && target != null && CustomFunctions.TeamHasPerk("poison2g") && target.HasEffect("poison"))
			{
				CustomFunctions.PLog(Plugin.debugBase + "poison2g");
				if (poison2gFlag)
				{
					poison2gFlag = false;
					int auraCharges7 = target.GetAuraCharges("poison");
					CustomFunctions.PLog(Plugin.debugBase + "poison2g - n charges: " + auraCharges7);
					int num3 = Mathf.RoundToInt((float)auraCharges7 * 0.5f);
					Character[] array = (Character[])(object)teamNpc;
					Character randomCharacter = CustomFunctions.GetRandomCharacter(array);
					if (CustomFunctions.IsLivingNPC(randomCharacter))
					{
						randomCharacter.SetAura(__instance, CustomFunctions.GetAuraCurseData("poison"), num3, false, (CardClass)11, false, true);
					}
				}
			}
			if ((int)theEvent == 35 && !target.IsHero && target != null && CustomFunctions.TeamHasPerk("thorns1e") && target.HasEffect("thorns"))
			{
				CustomFunctions.PLog(Plugin.debugBase + "thorns1e");
				if (thorns1eFlag)
				{
					thorns1eFlag = false;
					int auraCharges8 = target.GetAuraCharges("thorns");
					int num4 = Mathf.RoundToInt((float)auraCharges8 * 1f);
					Character[] array = (Character[])(object)teamHeroes;
					Character randomCharacter2 = CustomFunctions.GetRandomCharacter(array);
					if (CustomFunctions.IsLivingHero(randomCharacter2))
					{
						randomCharacter2.SetAura(__instance, CustomFunctions.GetAuraCurseData("thorns"), num4, false, (CardClass)11, false, true);
					}
				}
			}
			if ((int)theEvent == 35 && !target.IsHero && target != null && CustomFunctions.TeamHasPerk("bleed2g") && target.HasEffect("bleed") && bleed2gFlag)
			{
				bleed2gFlag = false;
				CustomFunctions.PLog(Plugin.debugBase + "bleed2g");
				int auraCharges9 = target.GetAuraCharges("bleed");
				CustomFunctions.PLog(Plugin.debugBase + "bleed2g Bleed charges: " + auraCharges9);
				int amount = Mathf.RoundToInt((float)auraCharges9 * 0.25f);
				CustomFunctions.DealIndirectDamageToAllMonsters((DamageType)0, amount);
			}
			if ((int)theEvent == 9 && CustomFunctions.IsLivingNPC(__instance) && CustomFunctions.IsLivingHero(target) && CustomFunctions.CharacterObjectHavePerk(target, "bleed2e"))
			{
				CustomFunctions.PLog("bleed2e");
				int auraCharges10 = __instance.GetAuraCharges("bleed");
				int num5 = Mathf.RoundToInt((float)auraCharges10 * 0.25f);
				target.IndirectHeal(num5, (AudioClip)null, "", "");
			}
			if ((int)theEvent == 9 && CustomFunctions.IsLivingNPC(__instance) && CustomFunctions.IsLivingHero(target) && CustomFunctions.CharacterObjectHavePerk(target, "spark2f"))
			{
				CustomFunctions.PLog(Plugin.debugBase + "spark2f Hitted: " + target.SubclassName);
				int auraCharges11 = __instance.GetAuraCharges("spark");
				int num6 = Mathf.RoundToInt((float)auraCharges11 * 0.2f);
				int nPCIndex = __instance.NPCIndex;
				List<NPC> nPCSides = MatchManager.Instance.GetNPCSides(nPCIndex);
				foreach (NPC item in nPCSides)
				{
					if (item != null && ((Character)item).Alive)
					{
						((Character)item).IndirectDamage((DamageType)6, num6, (AudioClip)null, "", "", "");
					}
				}
			}
			if ((int)theEvent == 7 && CustomFunctions.IsLivingHero(__instance) && CustomFunctions.CharacterObjectHavePerk(__instance, "spellsword1d"))
			{
				CardData value = Traverse.Create((object)__instance).Field("cardCasted").GetValue<CardData>();
				CustomFunctions.PLog(Plugin.debugBase + "spellsword1d Card Types: " + string.Join(",", value.GetCardTypes().ToArray()));
				if ((Object)(object)value != (Object)null && value.EnergyCost >= 4 && (value.HasCardType((CardType)19) || value.HasCardType((CardType)20)))
				{
					__instance.SetAuraTrait(__instance, "spellsword", 1);
				}
			}
			if ((int)theEvent == 23 && auxString == "block" && CustomFunctions.IsLivingHero(target) && CustomFunctions.CharacterObjectHavePerk(target, "block5d"))
			{
				CustomFunctions.PLog(Plugin.debugBase + "block5d");
				int num7 = 1;
				DamageType val = (DamageType)2;
				int num8 = target.DamageWithCharacterBonus(num7, val, (CardClass)11, 0);
				Character[] array = (Character[])(object)teamNpc;
				Character randomCharacter3 = CustomFunctions.GetRandomCharacter(array);
				if (randomCharacter3.Alive && randomCharacter3 != null && target.Alive && target != null)
				{
					randomCharacter3.IndirectDamage(val, num8, (AudioClip)null, "", "", "");
					target.IndirectDamage(val, num8, (AudioClip)null, "", "", "");
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Character), "DamageWithCharacterBonus")]
		public static void DamageWithCharacterBonusPostfix(ref Character __instance, ref int __result, int value, DamageType DT, CardClass CC, int energyCost = 0)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Invalid comparison between Unknown and I4
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Invalid comparison between Unknown and I4
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Invalid comparison between Unknown and I4
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Invalid comparison between Unknown and I4
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Invalid comparison between Unknown and I4
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Invalid comparison between Unknown and I4
			if ((int)CC == 11 || !CustomFunctions.IsLivingHero(__instance) || value == 0 || __result == 0 || (int)DT == 0 || (Object)(object)AtOManager.Instance == (Object)null || (Object)(object)MatchManager.Instance == (Object)null || !CustomFunctions.CharacterObjectHavePerk(__instance, "energy2d"))
			{
				return;
			}
			CustomFunctions.PLog(Plugin.debugBase + "Testing Energy Perk");
			float num = 4f;
			num += (float)__instance.GetAuraCharges("bless") * 0.25f;
			if ((int)DT == 1 || (int)DT == 3 || ((int)DT == 9 && AtOManager.Instance.CharacterHavePerk(__instance.SubclassName, "mainperkSharp1d")) || ((int)DT == 7 && AtOManager.Instance.TeamHaveTrait("shrilltone")))
			{
				num += (float)__instance.GetAuraCharges("sharp") * 0.2f;
			}
			if (((int)DT == 4 || (int)DT == 2) && AtOManager.Instance.CharacterHavePerk(__instance.SubclassName, "mainperkfortify1a"))
			{
				num += (float)__instance.GetAuraCharges("fortify") * 0.2f;
			}
			Dictionary<int, float> dictionary = new Dictionary<int, float>
			{
				{ 0, 0.4f },
				{ 1, 0.7f },
				{ 2, 1f },
				{ 3, 1.4f },
				{ 4, 1.8f },
				{ 5, 2.2f },
				{ 6, 2.7f },
				{ 7, 3.2f },
				{ 8, 3.9f },
				{ 9, 4.8f },
				{ 10, 6f }
			};
			int num2 = __result;
			if (dictionary.ContainsKey(energyCost))
			{
				int val = Mathf.RoundToInt(((float)__result - num * MathF.Sqrt(energyCost)) * dictionary[energyCost] + num);
				if (energyCost < 2)
				{
					__result = Math.Min(val, Mathf.RoundToInt((float)num2 * dictionary[energyCost]));
				}
				else
				{
					__result = Math.Max(val, num2);
				}
				if (__result < 0)
				{
					__result = 0;
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "SetAura")]
		public static void SetAuraPrefix(ref Character __instance, Character theCaster, AuraCurseData _acData, ref int charges, bool fromTrait = false, CardClass CC = 11, bool useCharacterMods = true, bool canBePreventable = true)
		{
			if (CustomFunctions.TeamHasPerk("weak1b") && __instance != null && __instance.Alive && CustomFunctions.IsLivingNPC(theCaster))
			{
				CustomFunctions.PLog(Plugin.debugBase + "weak1b");
				if (theCaster.HasEffect("weak"))
				{
					charges = Functions.FuncRoundToInt(0.8f * (float)charges);
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "BeginTurn")]
		public static void BeginTurnPrefix(ref Character __instance)
		{
			poison2gFlag = true;
			bleed2gFlag = true;
			thorns1eFlag = true;
			infiniteProctection = 0;
			infiniteProctectionPowerful = 0;
			if (!__instance.Alive || __instance == null || (Object)(object)MatchManager.Instance == (Object)null)
			{
				return;
			}
			Hero[] teamHero = MatchManager.Instance.GetTeamHero();
			NPC[] teamNPC = MatchManager.Instance.GetTeamNPC();
			if (CustomFunctions.CharacterObjectHavePerk(__instance, "shackle1d"))
			{
				int auraCharges = __instance.GetAuraCharges("shackle");
				__instance.SetAuraTrait(__instance, "fortify", auraCharges);
			}
			if (CustomFunctions.CharacterObjectHavePerk(__instance, "mitigate1a"))
			{
				int num = 2;
				__instance.SetAuraTrait(__instance, "mitigate", num);
			}
			if (CustomFunctions.CharacterObjectHavePerk(__instance, "mitigate1c"))
			{
				int num2 = 7 * __instance.GetAuraCharges("mitigate");
				__instance.SetAuraTrait(__instance, "block", num2);
			}
			if (CustomFunctions.CharacterObjectHavePerk(__instance, "health6c"))
			{
				CustomFunctions.PLog("Health6c current: " + __instance.HpCurrent + " Max: " + __instance.GetMaxHP());
				if (__instance.GetMaxHP() <= __instance.HpCurrent || __instance.GetHpLeftForMax() <= 0)
				{
					int num3 = 2;
					__instance.SetAuraTrait(__instance, "vitality", num3);
				}
			}
			if (CustomFunctions.CharacterObjectHavePerk(__instance, "chill2f"))
			{
				int num4 = 3;
				__instance.SetAuraTrait(__instance, "chill", num4);
			}
			if (CustomFunctions.CharacterObjectHavePerk(__instance, "sight1d"))
			{
				int num5 = 0;
				NPC[] array = teamNPC;
				foreach (NPC val in array)
				{
					if (CustomFunctions.IsLivingNPC((Character)(object)val) && ((Character)val).GetAuraCharges("sight") >= 100)
					{
						num5++;
					}
				}
				__instance.SetAuraTrait(__instance, "evasion", num5);
			}
			if (CustomFunctions.CharacterObjectHavePerk(__instance, "energize1a") && MatchManager.Instance.GetCurrentRound() == 1)
			{
				__instance.SetAuraTrait(__instance, "energize", 1);
			}
			if (CustomFunctions.CharacterObjectHavePerk(__instance, "spellsword1c"))
			{
				Hero[] array2 = teamHero;
				foreach (Hero val2 in array2)
				{
					if (CustomFunctions.IsLivingHero((Character)(object)val2) && (!(((Character)val2).SubclassName == "queen") || ((Character)val2).GetAuraCharges("spellsword") != 4))
					{
						((Character)val2).SetAuraTrait(__instance, "spellsword", 1);
					}
				}
				NPC[] array3 = teamNPC;
				foreach (NPC val3 in array3)
				{
					if (CustomFunctions.IsLivingNPC((Character)(object)val3))
					{
						((Character)val3).SetAuraTrait(__instance, "spellsword", 1);
					}
				}
			}
			if (CustomFunctions.TeamHasPerk("sanctify2e") && __instance.IsHero && __instance.HasEffect("sanctify"))
			{
				int auraCharges2 = __instance.GetAuraCharges("sanctify");
				int num6 = Mathf.FloorToInt((float)auraCharges2 * 0.05f);
				AuraCurseData auraCurseData = CustomFunctions.GetAuraCurseData("zeal");
				__instance.SetAura(__instance, auraCurseData, num6, false, (CardClass)11, false, true);
			}
			if (CustomFunctions.TeamHasPerk("insane2f") && __instance.HasEffect("insane"))
			{
				int num7 = Mathf.FloorToInt((float)(__instance.GetAuraCharges("insane") / 30));
				__instance.SetAuraTrait(__instance, "scourge", num7);
			}
			if (CustomFunctions.CharacterObjectHavePerk(__instance, "stealh1d") && __instance.IsHero && !__instance.HasEffect("stealth"))
			{
				__instance.SetAura(__instance, CustomFunctions.GetAuraCurseData("stealth"), 1, false, (CardClass)11, false, true);
			}
			if (CustomFunctions.CharacterObjectHavePerk(__instance, "stanza0d") && __instance.IsHero && MatchManager.Instance.GetCurrentRound() == 1)
			{
				__instance.SetAura(__instance, CustomFunctions.GetAuraCurseData("stanzai"), 1, false, (CardClass)11, false, true);
			}
			if (CustomFunctions.CharacterObjectHavePerk(__instance, "stanza0e") && __instance.IsHero && MatchManager.Instance.GetCurrentRound() == 1)
			{
				__instance.SetAura(__instance, CustomFunctions.GetAuraCurseData("stanzaii"), 1, false, (CardClass)11, false, true);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Character), "GetTraitDamagePercentModifiers")]
		public static void GetTraitDamagePercentModifiersPostfix(ref Character __instance, ref float __result)
		{
			if (CustomFunctions.CharacterObjectHavePerk(__instance, "currency6d"))
			{
				int playerGold = AtOManager.Instance.GetPlayerGold();
				int num = Mathf.FloorToInt((float)(10 * playerGold / 2000));
				__result += num;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(MatchManager), "EndTurn")]
		public static void MatchManagerEndTurnPrefix(MatchManager __instance)
		{
			if ((Object)(object)__instance == (Object)null)
			{
				return;
			}
			Character characterActive = __instance.GetCharacterActive();
			if (!CustomFunctions.IsLivingHero(characterActive))
			{
				return;
			}
			if (CustomFunctions.CharacterObjectHavePerk(characterActive, "inspire0d"))
			{
				CustomFunctions.PLog(Plugin.debugBase + "Handsize at End of Turn: " + __instance.CountHeroHand(-1));
				if (__instance.CountHeroHand(-1) >= 4)
				{
					characterActive.SetAuraTrait(characterActive, "inspire", 1);
				}
			}
			if (!CustomFunctions.TeamHasPerk("fury1d") || !characterActive.HasEffect("fury"))
			{
				return;
			}
			CustomFunctions.PLog("fury1d");
			float num = 0.7f;
			if ((Object)(object)characterActive.HeroItem != (Object)null)
			{
				List<Hero> heroSides = MatchManager.Instance.GetHeroSides(characterActive.Position);
				for (int i = 0; i < heroSides.Count; i++)
				{
					((Character)heroSides[i]).SetAura((Character)null, Globals.Instance.GetAuraCurseData("fury"), Functions.FuncRoundToInt((float)characterActive.GetAuraCharges("fury") * num), false, (CardClass)11, true, true);
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(MatchManager), "SetDamagePreview")]
		public static void SetDamagePreviewPrefix()
		{
			isDamagePreviewActive = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MatchManager), "SetDamagePreview")]
		public static void SetDamagePreviewPostfix()
		{
			isDamagePreviewActive = false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(CharacterItem), "CalculateDamagePrePostForThisCharacter")]
		public static void CalculateDamagePrePostForThisCharacterPrefix()
		{
			isCalculateDamageActive = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(CharacterItem), "CalculateDamagePrePostForThisCharacter")]
		public static void CalculateDamagePrePostForThisCharacterPostfix()
		{
			isCalculateDamageActive = false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "HealReceivedFinal")]
		public static void HealReceivedFinalPostfix(Character __instance, int __result, int heal, bool isIndirect = false)
		{
			if (infiniteProctection <= 100 && !isDamagePreviewActive && !isCalculateDamageActive && !((Object)(object)MatchManager.Instance == (Object)null) && CustomFunctions.IsLivingHero(__instance) && MatchManager.Instance.GetHeroHeroActive() != null)
			{
				infiniteProctection++;
				Hero heroHeroActive = MatchManager.Instance.GetHeroHeroActive();
				CustomFunctions.PLog("Inf " + infiniteProctection);
				CustomFunctions.PLog("Active Hero: " + ((Character)heroHeroActive).SubclassName);
				CustomFunctions.PLog("Targeted/Instanced Hero: " + __instance.SubclassName);
				if (__result >= 0 && __instance.GetHpLeftForMax() <= 0 && CustomFunctions.CharacterObjectHavePerk((Character)(object)heroHeroActive, "heal5b") && CustomFunctions.IsLivingHero(__instance) && CustomFunctions.IsLivingHero((Character)(object)heroHeroActive) && heal > 0 && !isIndirect)
				{
					__instance.SetAura(__instance, CustomFunctions.GetAuraCurseData("powerful"), 2, false, (CardClass)11, false, true);
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "EndTurn")]
		public static void CharacterEndTurnPrefix(Character __instance)
		{
			if (!__instance.Alive || __instance == null || (Object)(object)MatchManager.Instance == (Object)null)
			{
				return;
			}
			Hero[] teamHero = MatchManager.Instance.GetTeamHero();
			if (CustomFunctions.CharacterHasPerkForConsume("zeal1e", __instance.IsHero, AtOManager.Instance, __instance))
			{
				CustomFunctions.PLog(Plugin.debugBase + "zeal1e");
				int auraCharges = __instance.GetAuraCharges("zeal");
				AuraCurseData auraCurseData = CustomFunctions.GetAuraCurseData("zeal");
				int num = ((!auraCurseData.ConsumeAll) ? auraCurseData.AuraConsumed : auraCharges);
				int amount = 4 * num;
				CustomFunctions.DealIndirectDamageToAllMonsters((DamageType)8, amount);
				CustomFunctions.DealIndirectDamageToAllMonsters((DamageType)4, amount);
			}
			if (CustomFunctions.CharacterObjectHavePerk(__instance, "paralyze1b"))
			{
				AuraCurseData auraCurseData2 = CustomFunctions.GetAuraCurseData("paralyze");
				Hero[] array = teamHero;
				foreach (Hero val in array)
				{
					if (((Character)val).Alive && val != null)
					{
						((Character)val).HealAuraCurse(auraCurseData2);
					}
				}
			}
			if (CustomFunctions.CharacterObjectHavePerk(__instance, "energize1d") && __instance.EnergyCurrent >= 4)
			{
				__instance.SetAuraTrait(__instance, "energize", 1);
			}
			if (CustomFunctions.CharacterObjectHavePerk(__instance, "fortify1d"))
			{
				int auraCharges2 = __instance.GetAuraCharges("fortify");
				int num2 = Mathf.RoundToInt((float)auraCharges2 * 0.5f);
				__instance.SetAuraTrait(__instance, "reinforce", num2);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AtOManager), "GlobalAuraCurseModificationByTraitsAndItems")]
		public static void GlobalAuraCurseModificationByTraitsAndItemsPostfixGeneral(ref AtOManager __instance, ref AuraCurseData __result, string _type, string _acId, Character _characterCaster, Character _characterTarget)
		{
			bool flag = false;
			bool flag2 = false;
			bool flag3 = false;
			bool flag4 = false;
			bool flag5 = true;
			if (_characterCaster != null)
			{
				flag = _characterCaster.IsHero;
				flag3 = !_characterCaster.IsHero;
			}
			if (_characterTarget != null)
			{
				flag2 = _characterTarget.IsHero;
				flag4 = !_characterTarget.IsHero;
			}
			Character characterOfInterest = ((_type == "set") ? _characterTarget : _characterCaster);
			switch (_acId)
			{
			case "mark":
				if (CustomFunctions.IfCharacterHas(characterOfInterest, CustomFunctions.CharacterHas.Perk, "mark1e", CustomFunctions.AppliesTo.Monsters))
				{
					__result.IncreasedDamageReceivedType = (DamageType)3;
					__result.IncreasedDirectDamageChargesMultiplierNeededForOne = 2;
					__result.IncreasedDirectDamageReceivedPerStack = 3;
				}
				break;
			case "disarm":
				if (_type == "set" && CustomFunctions.CharacterHasPerkForSet("disarm1b", flag2, __instance, _characterTarget))
				{
					__result.Removable = false;
					__result.ResistModified = (DamageType)10;
					__result.ResistModifiedValue = 10;
				}
				if (_type == "consume" && CustomFunctions.CharacterHasPerkForConsume("disarm1b", flag, __instance, _characterCaster))
				{
					__result.ResistModified = (DamageType)10;
					__result.ResistModifiedValue = 10;
				}
				break;
			case "silence":
				if (_type == "set" && CustomFunctions.CharacterHasPerkForSet("silence1b", flag2, __instance, _characterTarget))
				{
					__result.Removable = false;
					__result.AuraDamageType = (DamageType)10;
					__result.AuraDamageIncreasedTotal = 7;
				}
				if (_type == "consume" && CustomFunctions.CharacterHasPerkForConsume("silence1b", flag, __instance, _characterCaster))
				{
					__result.AuraDamageType = (DamageType)10;
					__result.AuraDamageIncreasedTotal = 7;
				}
				break;
			case "stealth":
				if (_type == "set" && CustomFunctions.CharacterHasPerkForSet("stealth1d", flag2, __instance, _characterTarget))
				{
					__result.AuraDamageIncreasedPercentPerStack = 0f;
				}
				if (_type == "consume" && CustomFunctions.CharacterHasPerkForConsume("stealth1d", flag, __instance, _characterCaster))
				{
					__result.AuraDamageIncreasedPercentPerStack = 0f;
				}
				break;
			case "fast":
				if (_type == "set")
				{
					if (CustomFunctions.CharacterHasPerkForSet("fast0b", flag2, __instance, _characterTarget))
					{
						__result.GainCharges = true;
						__result.ConsumeAll = true;
					}
					if (CustomFunctions.CharacterHasPerkForSet("fast0c", flag2, __instance, _characterTarget))
					{
						__result.ConsumedAtTurn = true;
						__result.ConsumedAtTurnBegin = false;
					}
				}
				if (_type == "consume")
				{
					if (CustomFunctions.CharacterHasPerkForConsume("fast0b", flag, __instance, _characterCaster))
					{
						__result.GainCharges = true;
						__result.ConsumeAll = true;
					}
					if (CustomFunctions.CharacterHasPerkForConsume("fast0c", flag, __instance, _characterCaster))
					{
						__result.ConsumedAtTurn = true;
						__result.ConsumedAtTurnBegin = false;
					}
				}
				break;
			case "slow":
				if (_type == "set")
				{
					if (CustomFunctions.TeamHasPerkForSet("slow0b", flag4, __instance, _characterTarget))
					{
						__result.GainCharges = true;
						__result.MaxCharges = 10;
						__result.MaxMadnessCharges = 10;
						__result.CharacterStatModifiedValuePerStack = -1;
					}
					if (CustomFunctions.TeamHasPerkForSet("slow0c", flag2, __instance, _characterTarget))
					{
						__result.GainCharges = true;
						__result.MaxCharges = 10;
						__result.MaxMadnessCharges = 10;
						__result.CharacterStatModifiedValuePerStack = -1;
					}
				}
				if (_type == "consume")
				{
					if (CustomFunctions.TeamHasPerkForConsume("slow0b", flag3, __instance, _characterCaster))
					{
						__result.GainCharges = true;
						__result.MaxCharges = 10;
						__result.MaxMadnessCharges = 10;
						__result.CharacterStatModifiedValuePerStack = -1;
					}
					if (CustomFunctions.TeamHasPerkForConsume("slow0b", flag, __instance, _characterCaster))
					{
						__result.GainCharges = true;
						__result.MaxCharges = 10;
						__result.MaxMadnessCharges = 10;
						__result.CharacterStatModifiedValuePerStack = -1;
					}
				}
				break;
			case "ac":
				if (!(_type == "set") || CustomFunctions.CharacterHasPerkForSet("", flag5, __instance, _characterTarget))
				{
				}
				if (_type == "consume" && !CustomFunctions.CharacterHasPerkForConsume("", flag5, __instance, _characterCaster))
				{
				}
				break;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AtOManager), "GlobalAuraCurseModificationByTraitsAndItems")]
		public static void GlobalAuraCurseModificationByTraitsAndItemsPostfixPhysical(ref AtOManager __instance, ref AuraCurseData __result, string _type, string _acId, Character _characterCaster, Character _characterTarget)
		{
			bool flag = false;
			bool flag2 = false;
			bool flag3 = false;
			bool flag4 = false;
			bool flag5 = true;
			Character characterOfInterest = ((_type == "set") ? _characterTarget : _characterCaster);
			if (_characterCaster != null)
			{
				flag = _characterCaster.IsHero;
				flag3 = !_characterCaster.IsHero;
			}
			if (_characterTarget != null)
			{
				flag2 = _characterTarget.IsHero;
				flag4 = !_characterTarget.IsHero;
			}
			switch (_acId)
			{
			case "ac":
				if (!(_type == "set") || CustomFunctions.CharacterHasPerkForSet("", flag5, __instance, _characterTarget))
				{
				}
				if (_type == "consume" && !CustomFunctions.CharacterHasPerkForConsume("", flag5, __instance, _characterCaster))
				{
				}
				break;
			case "fury":
				if (_type == "set")
				{
				}
				if (_type == "consume" && CustomFunctions.TeamHasPerkForConsume("fury1d", flag, __instance, _characterCaster))
				{
					CustomFunctions.PLog("fury1d Consume");
					__result.ConsumeAll = true;
				}
				break;
			case "sharp":
				if (_type == "set")
				{
					if (CustomFunctions.CharacterHasPerkForSet("sharp1e", flag2, __instance, _characterTarget))
					{
						__result.MaxCharges = 25;
						__result.MaxMadnessCharges = 25;
						__result.AuraDamageIncreasedPerStack = 1.5f;
						__result.AuraDamageIncreasedPerStack2 = 1.5f;
						__result.AuraDamageIncreasedPerStack3 = 1.5f;
						__result.AuraDamageIncreasedPerStack4 = 1.5f;
					}
					if (CustomFunctions.CharacterHasPerkForSet("insane2e", flag5, __instance, _characterTarget) && _characterTarget.HasEffect("insane"))
					{
						int auraCharges5 = _characterTarget.GetAuraCharges("insane");
						AuraCurseData obj3 = __result;
						obj3.AuraDamageIncreasedPerStack *= 1f + 0.01f * (float)auraCharges5;
						AuraCurseData obj4 = __result;
						obj4.AuraDamageIncreasedPerStack2 *= 1f + 0.01f * (float)auraCharges5;
						AuraCurseData obj5 = __result;
						obj5.AuraDamageIncreasedPerStack3 *= 1f + 0.01f * (float)auraCharges5;
					}
				}
				if (_type == "consume")
				{
					if (CustomFunctions.CharacterHasPerkForSet("sharp1e", flag, __instance, _characterCaster))
					{
						__result.MaxCharges = 25;
						__result.MaxMadnessCharges = 25;
						__result.AuraDamageIncreasedPerStack = 1.5f;
						__result.AuraDamageIncreasedPerStack2 = 1.5f;
						__result.AuraDamageIncreasedPerStack3 = 1.5f;
						__result.AuraDamageIncreasedPerStack4 = 1.5f;
					}
					if (CustomFunctions.CharacterHasPerkForConsume("insane2e", flag5, __instance, _characterCaster) && _characterCaster.HasEffect("insane"))
					{
						int auraCharges6 = _characterCaster.GetAuraCharges("insane");
						AuraCurseData obj6 = __result;
						obj6.AuraDamageIncreasedPerStack *= 1f + 0.01f * (float)auraCharges6;
						AuraCurseData obj7 = __result;
						obj7.AuraDamageIncreasedPerStack2 *= 1f + 0.01f * (float)auraCharges6;
						AuraCurseData obj8 = __result;
						obj8.AuraDamageIncreasedPerStack3 *= 1f + 0.01f * (float)auraCharges6;
					}
				}
				break;
			case "crack":
				if (CustomFunctions.IfCharacterHas(characterOfInterest, CustomFunctions.CharacterHas.Perk, "crack2f", CustomFunctions.AppliesTo.Monsters))
				{
					__result.IncreasedDamageReceivedType2 = (DamageType)4;
					__result.IncreasedDirectDamageReceivedPerStack2 = 1;
				}
				if (_type == "set")
				{
					if (CustomFunctions.TeamHasPerkForSet("insane2d", flag4, __instance, _characterTarget) && _characterTarget.HasEffect("insane"))
					{
						int auraCharges8 = _characterTarget.GetAuraCharges("insane");
						AuraCurseData obj9 = __result;
						obj9.IncreasedDirectDamageReceivedPerStack += Mathf.FloorToInt(0.025f * (float)auraCharges8);
					}
					if (CustomFunctions.TeamHasPerkForSet("crack2d", flag4, __instance, _characterTarget))
					{
						__result.CharacterStatModified = (CharacterStat)2;
						__result.CharacterStatModifiedValue = -1;
						__result.CharacterStatChargesMultiplierNeededForOne = 5;
					}
					if (CustomFunctions.TeamHasPerkForSet("crack2e", flag4, __instance, _characterTarget))
					{
						__result.ResistModified = (DamageType)6;
						__result.ResistModifiedPercentagePerStack = -0.3f;
					}
				}
				if (_type == "consume")
				{
					if (CustomFunctions.TeamHasPerkForConsume("insane2d", flag3, __instance, _characterCaster) && _characterCaster.HasEffect("insane"))
					{
						int auraCharges9 = _characterCaster.GetAuraCharges("insane");
						AuraCurseData obj10 = __result;
						obj10.IncreasedDirectDamageReceivedPerStack += Mathf.FloorToInt(0.025f * (float)auraCharges9);
					}
					if (CustomFunctions.TeamHasPerkForConsume("crack2d", flag3, __instance, _characterCaster))
					{
						__result.CharacterStatModified = (CharacterStat)2;
						__result.CharacterStatModifiedValue = -1;
						__result.CharacterStatChargesMultiplierNeededForOne = 5;
					}
					if (CustomFunctions.TeamHasPerkForConsume("crack2e", flag3, __instance, _characterCaster))
					{
						__result.ResistModified = (DamageType)6;
						__result.ResistModifiedPercentagePerStack = -0.3f;
					}
				}
				break;
			case "shackle":
				if (_type == "set")
				{
					if (CustomFunctions.TeamHasPerkForSet("shackle1c", flag5, __instance, _characterTarget))
					{
						__result.Preventable = false;
					}
					if (CustomFunctions.TeamHasPerkForSet("shackle1f", flag4, __instance, _characterTarget))
					{
						int num3 = _characterTarget.GetSpeed()[1];
						__result.IncreasedDamageReceivedType = (DamageType)10;
						__result.IncreasedDirectDamageReceivedPerStack = Mathf.RoundToInt((float)num3 * 0.5f);
					}
				}
				if (_type == "consume")
				{
					if (CustomFunctions.TeamHasPerkForConsume("shackle1c", flag5, __instance, _characterCaster))
					{
						__result.Preventable = false;
					}
					if (CustomFunctions.TeamHasPerkForConsume("shackle1f", flag3, __instance, _characterCaster))
					{
						int num4 = _characterCaster.GetSpeed()[1];
						int auraCharges7 = _characterCaster.GetAuraCharges("shackle");
						__result.IncreasedDamageReceivedType = (DamageType)10;
						__result.IncreasedDirectDamageReceivedPerStack = Mathf.RoundToInt((float)num4 * 0.5f);
					}
				}
				break;
			case "mitigate":
				if (_type == "set")
				{
					if (CustomFunctions.CharacterHasPerkForSet("mitigate1a", flag2, __instance, _characterTarget))
					{
						__result.MaxCharges = 5;
						__result.MaxMadnessCharges = 5;
					}
					if (CustomFunctions.CharacterHasPerkForSet("mitigate1b", flag2, __instance, _characterTarget))
					{
						__result.ConsumedAtTurnBegin = false;
						__result.MaxCharges = 12;
						__result.MaxMadnessCharges = 12;
					}
					if (CustomFunctions.CharacterHasPerkForSet("mitigate1d", flag5, __instance, _characterTarget))
					{
						__result.ConsumeAll = true;
						__result.IncreasedDirectDamageReceivedPerStack = -2;
						CustomFunctions.PLog(Plugin.debugBase + "Mitigate1d: set");
						__result.ChargesMultiplierDescription = 2;
					}
					if (CustomFunctions.TeamHasPerkForSet("mitigate1e", flag5, __instance, _characterTarget))
					{
						__result.AuraDamageType = (DamageType)10;
						__result.AuraDamageIncreasedPercentPerStack = 10f;
					}
				}
				if (_type == "consume")
				{
					if (CustomFunctions.CharacterHasPerkForConsume("mitigate1a", flag, __instance, _characterCaster))
					{
						__result.MaxCharges = 5;
						__result.MaxMadnessCharges = 5;
					}
					if (CustomFunctions.CharacterHasPerkForConsume("mitigate1b", flag, __instance, _characterCaster))
					{
						__result.ConsumedAtTurnBegin = false;
						__result.MaxCharges = 12;
						__result.MaxMadnessCharges = 12;
					}
					if (CustomFunctions.CharacterHasPerkForConsume("mitigate1d", flag5, __instance, _characterCaster))
					{
						__result.IncreasedDirectDamageReceivedPerStack = -2;
						__result.ConsumeAll = true;
						__result.ChargesMultiplierDescription = 2;
					}
					if (CustomFunctions.TeamHasPerkForConsume("mitigate1e", flag5, __instance, _characterCaster))
					{
						__result.AuraDamageType = (DamageType)10;
						__result.AuraDamageIncreasedPercentPerStack = 10f;
					}
				}
				break;
			case "poison":
				if (_type == "set")
				{
					if (CustomFunctions.TeamHasPerkForSet("poison2d", flag5, __instance, _characterTarget))
					{
						__result.MaxMadnessCharges = 300;
					}
					if (CustomFunctions.TeamHasPerkForSet("poison2e", flag5, __instance, _characterTarget))
					{
						__result.ResistModified3 = (DamageType)1;
						__result.ResistModifiedPercentagePerStack3 = -0.25f;
					}
					if (CustomFunctions.TeamHasPerkForSet("poison2f", flag4, __instance, _characterTarget))
					{
						__result.ResistModified2 = (DamageType)10;
						int auraCharges = _characterTarget.GetAuraCharges("poison");
						__result.ResistModifiedValue2 = Mathf.FloorToInt(0.01f * (float)auraCharges);
					}
					if (CustomFunctions.TeamHasPerkForSet("decay1e", flag5, __instance, _characterTarget) && _characterTarget.HasEffect("decay"))
					{
						int auraCharges2 = _characterTarget.GetAuraCharges("decay");
						float num = 1f + 0.2f * (float)auraCharges2;
						AuraCurseData obj = __result;
						obj.DamageWhenConsumedPerCharge *= num;
					}
				}
				if (_type == "consume")
				{
					if (CustomFunctions.TeamHasPerkForConsume("poison2d", flag5, __instance, _characterCaster))
					{
						__result.MaxMadnessCharges = 300;
					}
					if (CustomFunctions.TeamHasPerkForConsume("poison2e", flag5, __instance, _characterCaster))
					{
						__result.ResistModified3 = (DamageType)1;
						__result.ResistModifiedPercentagePerStack3 = -0.25f;
					}
					if (CustomFunctions.TeamHasPerkForConsume("poison2f", flag3, __instance, _characterCaster))
					{
						__result.ResistModified2 = (DamageType)10;
						int auraCharges3 = _characterCaster.GetAuraCharges("poison");
						__result.ResistModifiedValue2 = Mathf.FloorToInt(0.01f * (float)auraCharges3);
					}
					if (CustomFunctions.TeamHasPerkForConsume("decay1e", flag5, __instance, _characterCaster) && _characterCaster.HasEffect("decay"))
					{
						int auraCharges4 = _characterCaster.GetAuraCharges("decay");
						float num2 = 1f + 0.2f * (float)auraCharges4;
						AuraCurseData obj2 = __result;
						obj2.DamageWhenConsumedPerCharge *= num2;
					}
				}
				break;
			case "bleed":
				if (_type == "set")
				{
					if (CustomFunctions.TeamHasPerkForSet("bleed2d", flag5, __instance, _characterTarget))
					{
						__result.MaxMadnessCharges = 300;
					}
					if (CustomFunctions.TeamHasPerkForSet("bleed2f", flag5, __instance, _characterTarget))
					{
						__result.ResistModified3 = (DamageType)3;
						__result.ResistModifiedPercentagePerStack3 = -0.25f;
					}
				}
				if (_type == "consume")
				{
					if (CustomFunctions.TeamHasPerkForConsume("bleed2d", flag5, __instance, _characterCaster))
					{
						__result.MaxMadnessCharges = 300;
					}
					if (CustomFunctions.TeamHasPerkForConsume("bleed2f", flag5, __instance, _characterCaster))
					{
						__result.ResistModified3 = (DamageType)3;
						__result.ResistModifiedPercentagePerStack3 = -0.25f;
					}
				}
				break;
			case "thorns":
				if (_type == "set" && CustomFunctions.TeamHasPerkForSet("thorns1d", flag5, __instance, _characterTarget))
				{
					__result.Removable = false;
				}
				if (_type == "consume" && CustomFunctions.TeamHasPerkForConsume("", flag5, __instance, _characterCaster))
				{
					__result.Removable = false;
				}
				break;
			case "reinforce":
				if (!(_type == "set") || CustomFunctions.CharacterHasPerkForSet("", flag5, __instance, _characterTarget))
				{
				}
				if (_type == "consume" && !CustomFunctions.CharacterHasPerkForConsume("", flag5, __instance, _characterCaster))
				{
				}
				break;
			case "block":
				if (_type == "set" && CustomFunctions.TeamHasPerkForSet("block5b", flag5, __instance, _characterTarget))
				{
					__result.MaxMadnessCharges = 600;
				}
				if (_type == "consume" && CustomFunctions.TeamHasPerkForConsume("block5b", flag5, __instance, _characterCaster))
				{
					__result.MaxMadnessCharges = 600;
				}
				break;
			case "taunt":
				if (_type == "set" && CustomFunctions.CharacterHasPerkForSet("taunt1e", flag2, __instance, _characterTarget))
				{
					__result.GainCharges = true;
					__result.AuraDamageType = (DamageType)10;
					__result.AuraDamageIncreasedPerStack = 1f;
				}
				if (_type == "consume" && CustomFunctions.CharacterHasPerkForConsume("taunt1e", flag, __instance, _characterCaster))
				{
					__result.GainCharges = true;
					__result.AuraDamageType = (DamageType)10;
					__result.AuraDamageIncreasedPerStack = 1f;
				}
				break;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AtOManager), "GlobalAuraCurseModificationByTraitsAndItems")]
		public static void GlobalAuraCurseModificationByTraitsAndItemsPostfixElemental(ref AtOManager __instance, ref AuraCurseData __result, string _type, string _acId, Character _characterCaster, Character _characterTarget)
		{
			bool flag = false;
			bool flag2 = false;
			bool flag3 = false;
			bool flag4 = false;
			bool flag5 = true;
			if (_characterCaster != null)
			{
				flag = _characterCaster.IsHero;
				flag3 = !_characterCaster.IsHero;
			}
			if (_characterTarget != null)
			{
				flag2 = _characterTarget.IsHero;
				flag4 = !_characterTarget.IsHero;
			}
			if ((Object)(object)__result == (Object)null || (_characterCaster == null && _type == "consume") || (_characterTarget == null && _type == "set"))
			{
				return;
			}
			switch (_acId)
			{
			case "insulate":
				if (_type == "set" && CustomFunctions.CharacterHasPerkForSet("insulate1e", flag5, __instance, _characterTarget))
				{
					CustomFunctions.PLog("Insulate1e");
					__result.AuraDamageType = (DamageType)4;
					__result.AuraDamageType2 = (DamageType)5;
					__result.AuraDamageType3 = (DamageType)6;
					__result.AuraDamageIncreasedPercentPerStack = 10f;
					__result.AuraDamageIncreasedPercentPerStack2 = 10f;
					__result.AuraDamageIncreasedPercentPerStack3 = 10f;
					__result.ResistModifiedValue = 15;
					__result.ResistModifiedValue2 = 15;
					__result.ResistModifiedValue3 = 15;
					__result.GainCharges = true;
					__result.MaxCharges = 15;
					__result.MaxMadnessCharges = 15;
				}
				if (_type == "consume" && CustomFunctions.CharacterHasPerkForConsume("insulate1e", flag5, __instance, _characterCaster))
				{
					CustomFunctions.PLog("Insulate1e consume");
					__result.AuraDamageType = (DamageType)4;
					__result.AuraDamageType2 = (DamageType)5;
					__result.AuraDamageType3 = (DamageType)6;
					__result.AuraDamageIncreasedPercentPerStack = 10f;
					__result.AuraDamageIncreasedPercentPerStack2 = 10f;
					__result.AuraDamageIncreasedPercentPerStack3 = 10f;
					__result.ResistModifiedValue = 15;
					__result.ResistModifiedValue2 = 15;
					__result.ResistModifiedValue3 = 15;
					__result.GainCharges = true;
					__result.MaxCharges = 15;
					__result.MaxMadnessCharges = 15;
				}
				break;
			case "spellsword":
				if (_type == "set")
				{
					if (CustomFunctions.CharacterHasPerkForSet("spellsword1a", flag5, __instance, _characterTarget))
					{
						AuraCurseData obj = __result;
						obj.MaxCharges += 2;
						if (__result.MaxMadnessCharges != -1)
						{
							AuraCurseData obj2 = __result;
							obj2.MaxMadnessCharges += 2;
						}
					}
					if (CustomFunctions.TeamHasPerkForSet("spellsword1b", flag2, __instance, _characterTarget))
					{
						__result.AuraDamageType = (DamageType)0;
						__result.AuraDamageIncreasedPerStack = 0f;
						__result.IncreasedDirectDamageReceivedPerStack = -2;
						__result.ChargesMultiplierDescription = 2;
					}
				}
				if (!(_type == "consume"))
				{
					break;
				}
				if (CustomFunctions.CharacterHasPerkForConsume("spellsword1a", flag5, __instance, _characterCaster))
				{
					AuraCurseData obj3 = __result;
					obj3.MaxCharges += 2;
					if (__result.MaxMadnessCharges != -1)
					{
						AuraCurseData obj4 = __result;
						obj4.MaxMadnessCharges += 2;
					}
				}
				if (CustomFunctions.TeamHasPerkForConsume("spellsword1b", flag, __instance, _characterCaster))
				{
					__result.AuraDamageType = (DamageType)0;
					__result.AuraDamageIncreasedPerStack = 0f;
					__result.IncreasedDirectDamageReceivedPerStack = -2;
					__result.ChargesMultiplierDescription = 2;
				}
				break;
			case "energize":
				if (_type == "set")
				{
					if (CustomFunctions.CharacterHasPerkForSet("energize1b", flag2, __instance, _characterTarget))
					{
						__result.MaxCharges = 1;
						__result.MaxMadnessCharges = 1;
						__result.CharacterStatModifiedValuePerStack = 2;
					}
					if (CustomFunctions.CharacterHasPerkForSet("energize1c", flag2, __instance, _characterTarget))
					{
						__result.AuraDamageType = (DamageType)10;
						__result.AuraDamageIncreasedPerStack = 1f;
					}
				}
				if (_type == "consume")
				{
					if (CustomFunctions.CharacterHasPerkForConsume("energize1b", flag, __instance, _characterCaster))
					{
						__result.MaxCharges = 1;
						__result.MaxMadnessCharges = 1;
						__result.CharacterStatModifiedValuePerStack = 2;
					}
					if (CustomFunctions.CharacterHasPerkForConsume("energize1c", flag, __instance, _characterCaster))
					{
						__result.AuraDamageType = (DamageType)10;
						__result.AuraDamageIncreasedPerStack = 1f;
					}
				}
				break;
			case "burn":
				if (_type == "set" && CustomFunctions.TeamHasPerkForSet("scourge1e", flag4, __instance, _characterTarget) && _characterTarget.HasEffect("scourge"))
				{
					int auraCharges = _characterTarget.GetAuraCharges("scourge");
					float num = 0.15f * (float)auraCharges + 1f;
					AuraCurseData obj5 = __result;
					obj5.DamageWhenConsumedPerCharge *= num;
				}
				if (_type == "consume" && CustomFunctions.TeamHasPerkForConsume("scourge1e", flag3, __instance, _characterCaster) && _characterCaster.HasEffect("scourge"))
				{
					int auraCharges2 = _characterCaster.GetAuraCharges("scourge");
					float num2 = 1f + 0.15f * (float)auraCharges2;
					AuraCurseData obj6 = __result;
					obj6.DamageWhenConsumedPerCharge *= num2;
				}
				break;
			case "chill":
				if (_type == "set")
				{
					if (CustomFunctions.TeamHasPerkForSet("chill2e", flag4, __instance, _characterTarget))
					{
						__result.ResistModified = (DamageType)5;
						__result.ResistModified2 = (DamageType)7;
						__result.ResistModifiedPercentagePerStack = -0.5f;
						__result.ResistModifiedPercentagePerStack2 = -0.5f;
					}
					if (CustomFunctions.CharacterHasPerkForSet("chill2f", flag2, __instance, _characterTarget))
					{
						__result.CharacterStatChargesMultiplierNeededForOne = 10;
					}
					if (CustomFunctions.CharacterHasPerkForSet("insulate1d", flag2, __instance, _characterTarget) && _characterTarget.HasEffect("insulate"))
					{
						__result.CharacterStatModified = (CharacterStat)0;
						__result.CharacterStatAbsoluteValuePerStack = 0;
					}
					if (CustomFunctions.CharacterHasPerkForSet("chill2g", flag2, __instance, _characterTarget))
					{
						__result.CharacterStatChargesMultiplierNeededForOne = 3;
						__result.ResistModified = (DamageType)0;
						__result.ResistModifiedPercentagePerStack = 0f;
					}
				}
				if (_type == "consume")
				{
					if (CustomFunctions.TeamHasPerkForConsume("chill2e", flag3, __instance, _characterCaster))
					{
						__result.ResistModified = (DamageType)5;
						__result.ResistModified2 = (DamageType)7;
						__result.ResistModifiedPercentagePerStack = 0.5f;
						__result.ResistModifiedPercentagePerStack2 = 0.5f;
					}
					if (CustomFunctions.CharacterHasPerkForSet("chill2f", flag, __instance, _characterCaster))
					{
						__result.CharacterStatChargesMultiplierNeededForOne = 10;
					}
					if (CustomFunctions.CharacterHasPerkForConsume("chill2g", flag, __instance, _characterCaster))
					{
						__result.CharacterStatChargesMultiplierNeededForOne = 3;
						__result.ResistModified = (DamageType)0;
						__result.ResistModifiedPercentagePerStack = 0f;
					}
					if (CustomFunctions.CharacterHasPerkForConsume("insulate1d", flag, __instance, _characterCaster) && _characterCaster.HasEffect("insulate"))
					{
						__result.CharacterStatModified = (CharacterStat)0;
						__result.CharacterStatAbsoluteValuePerStack = 0;
					}
				}
				break;
			case "wet":
				if (_type == "set")
				{
					if (CustomFunctions.TeamHasPerkForSet("zeal1d", flag2, __instance, _characterTarget) && _characterTarget.HasEffect("zeal"))
					{
						CustomFunctions.PLog(Plugin.debugBase + "zeal1d");
						__result.ResistModified3 = (DamageType)10;
						__result = __instance.GlobalAuraCurseModifyResist(__result, (DamageType)10, 0, 0.5f);
					}
					if (CustomFunctions.TeamHasPerkForSet("wet1d", flag5, __instance, _characterTarget))
					{
						AuraCurseData auraCurseData = CustomFunctions.GetAuraCurseData("None");
						__result.PreventedAuraCurse = null;
						__result.PreventedAuraCurseStackPerStack = 0;
						__result.RemoveAuraCurse = null;
					}
				}
				if (_type == "consume")
				{
					if (CustomFunctions.TeamHasPerkForConsume("zeal1d", flag, __instance, _characterCaster) && _characterCaster.HasEffect("zeal"))
					{
						CustomFunctions.PLog(Plugin.debugBase + "zeal1d");
						__result.ResistModified3 = (DamageType)10;
						__result = __instance.GlobalAuraCurseModifyResist(__result, (DamageType)10, 0, 0.5f);
					}
					if (CustomFunctions.TeamHasPerkForConsume("wet1d", flag5, __instance, _characterCaster))
					{
						AuraCurseData auraCurseData2 = CustomFunctions.GetAuraCurseData("None");
						__result.PreventedAuraCurse = auraCurseData2;
						__result.PreventedAuraCurseStackPerStack = 0;
						__result.RemoveAuraCurse = auraCurseData2;
					}
				}
				break;
			case "spark":
				if (_type == "set")
				{
					if (CustomFunctions.CharacterHasPerkForSet("spark2d", flag2, __instance, _characterTarget))
					{
						__result.AuraDamageType = (DamageType)6;
						__result.AuraDamageIncreasedPerStack = 1f;
						__result.ChargesAuxNeedForOne1 = 5;
					}
					if (CustomFunctions.TeamHasPerkForSet("spark2e", flag2, __instance, _characterTarget))
					{
						__result.DamageTypeWhenConsumed = (DamageType)4;
						__result.ResistModified = (DamageType)6;
						__result.ResistModified2 = (DamageType)4;
						__result.ResistModifiedPercentagePerStack = -0.5f;
						__result.ResistModifiedPercentagePerStack2 = -0.5f;
					}
				}
				if (_type == "consume")
				{
					if (CustomFunctions.CharacterHasPerkForConsume("spark2d", flag, __instance, _characterCaster))
					{
						__result.AuraDamageType = (DamageType)6;
						__result.AuraDamageIncreasedPerStack = 0.2f;
					}
					if (CustomFunctions.TeamHasPerkForConsume("spark2e", flag, __instance, _characterCaster))
					{
						__result.DamageTypeWhenConsumed = (DamageType)4;
						__result.ResistModified = (DamageType)6;
						__result.ResistModified2 = (DamageType)4;
						__result.ResistModifiedPercentagePerStack = -0.5f;
						__result.ResistModifiedPercentagePerStack2 = -0.5f;
					}
				}
				break;
			case "shield":
				if (_type == "set" && CustomFunctions.CharacterHasPerkForSet("shield5b", flag5, __instance, _characterTarget))
				{
					__result.MaxCharges = 300;
				}
				if (_type == "consume" && CustomFunctions.CharacterHasPerkForConsume("shield5b", flag5, __instance, _characterCaster))
				{
					__result.MaxCharges = 300;
				}
				break;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AtOManager), "GlobalAuraCurseModificationByTraitsAndItems")]
		public static void GlobalAuraCurseModificationByTraitsAndItemsPostfixMystical(ref AtOManager __instance, ref AuraCurseData __result, string _type, string _acId, Character _characterCaster, Character _characterTarget)
		{
			bool flag = false;
			bool flag2 = false;
			bool flag3 = false;
			bool flag4 = false;
			bool flag5 = true;
			if (_characterCaster != null)
			{
				flag = _characterCaster.IsHero;
				flag3 = !_characterCaster.IsHero;
			}
			if (_characterTarget != null)
			{
				flag2 = _characterTarget.IsHero;
				flag4 = !_characterTarget.IsHero;
			}
			switch (_acId)
			{
			case "regeneration":
				if (_type == "set" && CustomFunctions.TeamHasPerkForSet("regeneration1d", flag2, __instance, _characterTarget))
				{
					__result.PreventedAuraCurse = CustomFunctions.GetAuraCurseData("vulnerable");
					__result.PreventedAuraCurseStackPerStack = 1;
				}
				if (_type == "consume" && CustomFunctions.TeamHasPerkForConsume("regeneration1d", flag, __instance, _characterCaster))
				{
					__result.PreventedAuraCurse = CustomFunctions.GetAuraCurseData("vulnerable");
					__result.PreventedAuraCurseStackPerStack = 1;
				}
				break;
			case "dark":
				if (_type == "set")
				{
					if (CustomFunctions.TeamHasPerkForSet("dark2e", flag5, __instance, _characterTarget))
					{
						__result.DamageTypeWhenConsumed = (DamageType)4;
						__result.ResistModified2 = (DamageType)4;
						__result.ResistModifiedPercentagePerStack2 = -0.5f;
					}
					if (CustomFunctions.TeamHasPerkForSet("sanctify2d", flag5, __instance, _characterTarget) && _characterTarget.HasEffect("sanctify"))
					{
						int auraCharges = _characterTarget.GetAuraCharges("sanctify");
						AuraCurseData obj = __result;
						obj.ExplodeAtStacks += Mathf.FloorToInt(0.2f * (float)auraCharges);
					}
					if (CustomFunctions.TeamHasPerkForSet("burn2e", flag5, __instance, _characterTarget) && _characterTarget.HasEffect("burn"))
					{
						int auraCharges2 = _characterTarget.GetAuraCharges("burn");
						float num = 1f + 0.05f * (float)auraCharges2;
						AuraCurseData obj2 = __result;
						obj2.DamageWhenConsumedPerCharge *= num;
					}
				}
				if (_type == "consume")
				{
					if (CustomFunctions.TeamHasPerkForConsume("burn2e", flag5, __instance, _characterCaster))
					{
						int auraCharges3 = _characterCaster.GetAuraCharges("burn");
						float num2 = 1f + 0.05f * (float)auraCharges3;
						AuraCurseData obj3 = __result;
						obj3.DamageWhenConsumedPerCharge *= num2;
					}
					if (CustomFunctions.TeamHasPerkForConsume("sanctify2d", flag5, __instance, _characterCaster) && _characterCaster.HasEffect("sanctify"))
					{
						int auraCharges4 = _characterCaster.GetAuraCharges("sanctify");
						AuraCurseData obj4 = __result;
						obj4.ExplodeAtStacks += Mathf.FloorToInt(0.2f * (float)auraCharges4);
					}
					if (CustomFunctions.TeamHasPerkForConsume("dark2e", flag5, __instance, _characterCaster))
					{
						__result.DamageTypeWhenConsumed = (DamageType)4;
						__result.ResistModified2 = (DamageType)4;
						__result.ResistModifiedPercentagePerStack2 = -0.5f;
					}
				}
				break;
			case "decay":
				if (_type == "set" && CustomFunctions.TeamHasPerkForSet("decay1d", flag5, __instance, _characterTarget))
				{
					__result.RemoveAuraCurse = CustomFunctions.GetAuraCurseData("reinforce");
				}
				break;
			case "zeal":
				if (_type == "set")
				{
					if (CustomFunctions.CharacterHasPerkForSet("zeal1b", flag2, __instance, _characterTarget))
					{
						CustomFunctions.PLog(Plugin.debugBase + "zeal1b");
						__result.ConsumeAll = false;
						__result.AuraConsumed = 3;
					}
					if (CustomFunctions.TeamHasPerkForSet("zeal1c", flag2, __instance, _characterTarget))
					{
						CustomFunctions.PLog(Plugin.debugBase + "zeal1c");
						__result.GainCharges = true;
						__result.MaxCharges = Plugin.ZealCap.Value;
						__result.MaxMadnessCharges = Plugin.ZealCap.Value;
						__result.CharacterStatModified = (CharacterStat)2;
						__result.CharacterStatModifiedValuePerStack = -2;
						__result.AuraDamageType = (DamageType)10;
						__result.AuraDamageIncreasedPerStack = -2f;
					}
				}
				if (_type == "consume")
				{
					if (CustomFunctions.CharacterHasPerkForConsume("zeal1b", flag, __instance, _characterCaster))
					{
						CustomFunctions.PLog(Plugin.debugBase + "zeal1b");
						__result.ConsumeAll = false;
						__result.AuraConsumed = 3;
					}
					if (CustomFunctions.TeamHasPerkForConsume("zeal1c", flag, __instance, _characterCaster))
					{
						CustomFunctions.PLog(Plugin.debugBase + "zeal1c");
						__result.GainCharges = true;
						__result.MaxCharges = Plugin.ZealCap.Value;
						__result.MaxMadnessCharges = Plugin.ZealCap.Value;
						__result.CharacterStatModified = (CharacterStat)2;
						__result.CharacterStatModifiedValuePerStack = -2;
						__result.AuraDamageType = (DamageType)10;
						__result.AuraDamageIncreasedPerStack = -2f;
					}
				}
				break;
			case "scourge":
				if (_type == "set")
				{
					if (CustomFunctions.TeamHasPerkForSet("scourge1b", flag5, __instance, _characterTarget))
					{
						__result.ConsumeAll = false;
						__result.AuraConsumed = 3;
					}
					if (CustomFunctions.TeamHasPerkForSet("scourge1c", flag4, __instance, _characterTarget))
					{
						__result.GainCharges = true;
						__result.ResistModified2 = (DamageType)10;
						__result.ResistModifiedPercentagePerStack2 = 3f;
					}
					if (CustomFunctions.TeamHasPerkForSet("scourge1d", flag5, __instance, _characterTarget))
					{
						__result.ConsumedDamageChargesBasedOnACCharges = CustomFunctions.GetAuraCurseData("sight");
						__result.DamageWhenConsumedPerCharge = 2f;
					}
				}
				if (_type == "consume")
				{
					if (CustomFunctions.TeamHasPerkForConsume("scourge1b", flag5, __instance, _characterCaster))
					{
						__result.ConsumeAll = false;
						__result.AuraConsumed = 3;
					}
					if (CustomFunctions.TeamHasPerkForConsume("scourge1c", flag3, __instance, _characterCaster))
					{
						__result.GainCharges = true;
						__result.ResistModified2 = (DamageType)10;
						__result.ResistModifiedPercentagePerStack2 = 3f;
					}
					if (CustomFunctions.TeamHasPerkForConsume("scourge1d", flag5, __instance, _characterCaster))
					{
						__result.ConsumedDamageChargesBasedOnACCharges = CustomFunctions.GetAuraCurseData("sight");
						__result.DamageWhenConsumedPerCharge = 2f;
					}
				}
				break;
			case "weak":
				if (_type == "set" && CustomFunctions.TeamHasPerkForSet("weak1c", flag4, __instance, _characterTarget))
				{
					__result.Preventable = false;
					__result.AuraDamageIncreasedPercent = -25;
					__result.HealDonePercent = -25;
				}
				if (_type == "consume" && CustomFunctions.TeamHasPerkForConsume("weak1c", flag3, __instance, _characterCaster))
				{
					__result.Preventable = false;
					__result.AuraDamageIncreasedPercent = -25;
					__result.HealDonePercent = -25;
				}
				break;
			case "vitality":
				if (_type == "set" && CustomFunctions.CharacterHasPerkForSet("vitality1d", flag2, __instance, _characterTarget))
				{
					__result.RemoveAuraCurse = CustomFunctions.GetAuraCurseData("poison");
				}
				break;
			case "bless":
				if (_type == "set" && CustomFunctions.TeamHasPerkForSet("bless1d", flag2, __instance, _characterTarget))
				{
					__result.AuraDamageType = (DamageType)1;
					__result.AuraDamageType2 = (DamageType)4;
					__result.AuraDamageType3 = (DamageType)8;
					__result.AuraDamageIncreasedPercentPerStack = 3f;
					__result.AuraDamageIncreasedPercentPerStack2 = 3f;
					__result.AuraDamageIncreasedPercentPerStack3 = 3f;
					__result.AuraDamageIncreasedPerStack = 0f;
				}
				if (_type == "consume" && CustomFunctions.TeamHasPerkForConsume("bless1d", flag, __instance, _characterCaster))
				{
					__result.AuraDamageType = (DamageType)1;
					__result.AuraDamageType2 = (DamageType)4;
					__result.AuraDamageType3 = (DamageType)8;
					__result.AuraDamageIncreasedPercentPerStack = 3f;
					__result.AuraDamageIncreasedPercentPerStack2 = 3f;
					__result.AuraDamageIncreasedPercentPerStack3 = 3f;
					__result.AuraDamageIncreasedPerStack = 0f;
				}
				break;
			}
		}
	}
	[HarmonyPatch]
	public class PerkRewrites
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Functions), "GetCardByRarity")]
		public static bool GetCardByRarityPrefix(ref string __result, int rarity, CardData _cardData, bool isChallenge = false)
		{
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Invalid comparison between Unknown and I4
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Invalid comparison between Unknown and I4
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Invalid comparison between Unknown and I4
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Invalid comparison between Unknown and I4
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Invalid comparison between Unknown and I4
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			int num = 78;
			int num2 = 88;
			int num3 = 98;
			int num4;
			if (!GameManager.Instance.IsObeliskChallenge())
			{
				num4 = AtOManager.Instance.GetMadnessDifficulty();
				if (num4 > 0)
				{
					num = 75;
					num2 = 85;
					num3 = 95;
				}
			}
			else
			{
				num4 = AtOManager.Instance.GetObeliskMadness();
			}
			Plugin.Log.LogDebug((object)(Plugin.debugBase + "Testing Perk shards5c: Original Corruption odds" + num3));
			if (AtOManager.Instance.TeamHavePerk(Plugin.perkBase + "shards5c"))
			{
				int num5 = 2;
				num -= num5;
				num2 -= num5;
				num3 -= num5;
				Plugin.Log.LogDebug((object)(Plugin.debugBase + "Testing Perk shards5c: Modified value " + num3));
			}
			if (num4 > 0)
			{
				num -= num4;
				num2 -= Functions.FuncRoundToInt((float)num4 * 0.5f);
			}
			if (rarity < num)
			{
				__result = (((int)_cardData.CardUpgraded == 0 || !(_cardData.UpgradedFrom != "")) ? _cardData.Id.ToLower() : _cardData.UpgradedFrom.ToLower());
				return false;
			}
			if (rarity >= num && rarity < num2)
			{
				if ((int)_cardData.CardUpgraded == 1)
				{
					__result = _cardData.Id.ToLower();
					return false;
				}
				if ((int)_cardData.CardUpgraded == 0)
				{
					__result = _cardData.UpgradesTo1.ToLower();
					return false;
				}
				if ((int)_cardData.CardUpgraded == 2)
				{
					__result = (_cardData.UpgradedFrom + "A").ToLower();
					return false;
				}
			}
			else
			{
				if (rarity >= num2 && rarity < num3)
				{
					if ((int)_cardData.CardUpgraded == 2)
					{
						__result = _cardData.Id.ToLower();
						return false;
					}
					__result = (((int)_cardData.CardUpgraded == 0) ? _cardData.UpgradesTo2.ToLower() : (_cardData.UpgradedFrom + "B").ToLower());
					return false;
				}
				if ((int)_cardData.CardUpgraded == 0)
				{
					__result = (((Object)(object)_cardData.UpgradesToRare != (Object)null) ? _cardData.UpgradesToRare.Id.ToLower() : _cardData.Id.ToLower());
					return false;
				}
				CardData cardData = Globals.Instance.GetCardData(_cardData.UpgradedFrom, false);
				if ((Object)(object)cardData != (Object)null && (Object)(object)cardData.UpgradesToRare != (Object)null)
				{
					__result = cardData.UpgradesToRare.Id.ToLower();
					return false;
				}
			}
			__result = _cardData.Id.ToLower();
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "BonusResists")]
		public static bool BonusResistsPrefix(ref Character __instance, ref int __result, DamageType damageType, string acId = "", bool countChargesConsumedPre = false, bool countChargesConsumedPost = false)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected I4, but got Unknown
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0423: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			switch (damageType - 1)
			{
			case 0:
				if (__instance.IsImmune((DamageType)1))
				{
					num = 1000;
					break;
				}
				num += Traverse.Create((object)__instance).Field("resistSlashing").GetValue<int>();
				if (!__instance.IsHero && AtOManager.Instance.IsChallengeTraitActive("reinforcedmonsters"))
				{
					num += 10;
				}
				break;
			case 1:
				if (__instance.IsImmune((DamageType)2))
				{
					num = 1000;
					break;
				}
				num += Traverse.Create((object)__instance).Field("resistBlunt").GetValue<int>();
				if (!__instance.IsHero && AtOManager.Instance.IsChallengeTraitActive("reinforcedmonsters"))
				{
					num += 10;
				}
				break;
			case 2:
				if (__instance.IsImmune((DamageType