Decompiled source of Shaun Eello the Trickster v1.0.0

BepInEx/plugins/com.binbin.thetrickster.dll

Decompiled 4 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Obeliskial_Content;
using Obeliskial_Essentials;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.binbin.thetrickster")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Shaun Eello, The Trickster")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+646f4850173fcdedd936efe2a803488002a283bd")]
[assembly: AssemblyProduct("TheMagician")]
[assembly: AssemblyTitle("com.binbin.thetrickster")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 TheMagician
{
	[BepInPlugin("com.binbin.thetrickster", "TheMagician", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("AcrossTheObelisk.exe")]
	public class Plugin : BaseUnityPlugin
	{
		internal int ModDate = int.Parse(DateTime.Today.ToString("yyyyMMdd"));

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

		internal static ManualLogSource Log;

		public static string characterName = "Shaun";

		public static string subclassName = "Trickster";

		public static string debugBase = "Binbin - Testing " + characterName + " ";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"com.binbin.thetrickster 1.0.0 has loaded!");
			Essentials.RegisterMod("TheMagician", "binbin", characterName + ", The " + subclassName, "1.0.0", ModDate, "https://github.com/binbinmods/magician", (string[])null, characterName, 100, new string[3] { "content", "hero", "trait" }, "", true);
			harmony.PatchAll();
		}

		internal static void LogDebug(string msg)
		{
			Log.LogDebug((object)(debugBase + msg));
		}

		internal static void LogInfo(string msg)
		{
			Log.LogInfo((object)(debugBase + msg));
		}

		internal static void LogError(string msg)
		{
			Log.LogError((object)(debugBase + msg));
		}
	}
	public class CustomFunctions
	{
		public enum AppliesTo
		{
			None,
			Global,
			Monsters,
			Heroes,
			ThisHero
		}

		public enum CharacterHas
		{
			Perk,
			Item,
			Trait
		}

		public enum IsAuraOrCurse
		{
			Aura,
			Curse,
			Both
		}

		public static string perkBase = "<RenameThisForPerks>";

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

		public static void TraitHeal(ref Character _character, Character _target, int healAmount, string traitName)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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 WhenYouGainXGainY(string ACGained, string targetAC, string ACtoApply, int nGained, int nToApply, float multiplier, ref Character _character, string traitName)
		{
			if ((!((Object)(object)MatchManager.Instance == (Object)null) || ACGained != null || IsLivingHero(_character)) && !(targetAC == ACtoApply) && ACGained == targetAC)
			{
				int num = Mathf.RoundToInt((float)(nGained + nToApply) * multiplier);
				_character.SetAuraTrait(_character, ACtoApply, 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 nCharges, 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) / nCharges));
			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 ReduceCardTypeCostUntilDiscarded(CardType cardType, int amountToReduce, ref Character _character, ref List<string> heroHand, ref List<CardData> cardDataList, string traitName)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (_character.HeroData == null)
			{
				return;
			}
			if (amountToReduce <= 0)
			{
				return;
			}
			for (int i = 0; i < heroHand.Count; i++)
			{
				CardData cardData = MatchManager.Instance.GetCardData(heroHand[i]);
				if (cardData != null && cardData.GetCardFinalCost() > 0 && cardData.HasCardType(cardType))
				{
					cardDataList.Add(cardData);
				}
			}
			for (int j = 0; j < cardDataList.Count; j++)
			{
				CardData val = cardDataList[j];
				if (val != null)
				{
					val.EnergyReductionTemporal += amountToReduce;
					MatchManager.Instance.UpdateHandCards();
					CardItem cardFromTableByIndex = MatchManager.Instance.GetCardFromTableByIndex(val.InternalId);
					cardFromTableByIndex.PlayDissolveParticle();
					cardFromTableByIndex.ShowEnergyModification(-amountToReduce);
					((CharacterItem)_character.HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_" + traitName, ""), (CombatScrollEffectType)7);
					MatchManager.Instance.CreateLogCardModification(val.InternalId, MatchManager.Instance.GetHero(_character.HeroIndex));
				}
			}
		}

		public static void AddImmunityToHero(string immunity, ref Hero _character)
		{
			if (_character != null && !((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)
		{
			int auraCharges = _character.GetAuraCharges(auraCurseDependent);
			int num = Mathf.FloorToInt((float)auraCharges / stacks_per_bonus);
			_character.ModifyAuraCurseQuantity(auraCurseToModify, num);
		}

		public static AuraCurseData GetAuraCurseData(string auraCurse)
		{
			return Globals.Instance.GetAuraCurseData(auraCurse);
		}

		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 _trait)
		{
			//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(_trait);
			if (MatchManager.Instance.activatedTraits != null && MatchManager.Instance.activatedTraits.ContainsKey(_trait) && MatchManager.Instance.activatedTraits[_trait] > 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(_trait))
					{
						MatchManager.Instance.activatedTraits.Add(_trait, 1);
					}
					else
					{
						Dictionary<string, int> activatedTraits = MatchManager.Instance.activatedTraits;
						int value = activatedTraits[_trait] + 1;
						activatedTraits[_trait] = 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_" + traitData.TraitName, "") + TextChargesLeft(MatchManager.Instance.activatedTraits[_trait], 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 _trait)
		{
			//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(_trait);
			if ((MatchManager.Instance.activatedTraits != null && MatchManager.Instance.activatedTraits.ContainsKey(_trait) && MatchManager.Instance.activatedTraits[_trait] > 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(_trait))
			{
				MatchManager.Instance.activatedTraits.Add(_trait, 1);
			}
			else
			{
				Dictionary<string, int> activatedTraits = MatchManager.Instance.activatedTraits;
				int value = activatedTraits[_trait] + 1;
				activatedTraits[_trait] = 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_" + _trait, "") + TextChargesLeft(MatchManager.Instance.activatedTraits[_trait], traitData.TimesPerTurn), (CombatScrollEffectType)7);
			MatchManager.Instance.CreateLogCardModification(val.InternalId, MatchManager.Instance.GetHero(_character.HeroIndex));
		}

		public static int CountAllStacks(string auraCurse, Hero[] teamHero = null, NPC[] teamNpc = null, bool includeHeroes = true, bool includeNpcs = true)
		{
			if ((Object)(object)MatchManager.Instance == (Object)null)
			{
				return 0;
			}
			if (teamHero == null)
			{
				teamHero = MatchManager.Instance.GetTeamHero();
			}
			if (teamNpc == null)
			{
				teamNpc = MatchManager.Instance.GetTeamNPC();
			}
			int num = 0;
			if (includeHeroes)
			{
				for (int i = 0; i < teamHero.Length; i++)
				{
					if (IsLivingHero((Character)(object)teamHero[i]))
					{
						num += ((Character)teamHero[i]).GetAuraCharges(auraCurse);
					}
				}
			}
			if (includeNpcs)
			{
				for (int j = 0; j < teamNpc.Length; j++)
				{
					if (IsLivingNPC((Character)(object)teamNpc[j]))
					{
						num += ((Character)teamNpc[j]).GetAuraCharges(auraCurse);
					}
				}
			}
			return num;
		}

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

		public static List<int> GetValidCharacters(Character[] characters)
		{
			Plugin.LogDebug("GetValidCharacters");
			List<string> list = new List<string>();
			foreach (Character val in characters)
			{
				list.Append(val.SourceName);
			}
			Plugin.LogDebug("characterList" + string.Join(",", list));
			List<int> list2 = new List<int>();
			for (int j = 0; j < characters.Length; j++)
			{
				if (characters[j].Alive && characters[j] != null)
				{
					list2.Add(j);
				}
			}
			Plugin.LogDebug("GetValidCharacters END");
			return list2;
		}

		public static Character GetFrontCharacter(Character[] characters)
		{
			List<int> validCharacters = GetValidCharacters(characters);
			Plugin.LogDebug("Front Character - Valid Character indices: " + string.Join(",", validCharacters));
			int num = validCharacters.First();
			Character val = characters[num];
			Plugin.LogDebug("Front Character - Front Character: " + val.SourceName);
			return val;
		}

		public static Character GetBackCharacter(Character[] characters)
		{
			List<int> validCharacters = GetValidCharacters(characters);
			int num = validCharacters.Last();
			return characters[num];
		}

		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, perkBase + perkName);
		}

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

		public static bool TeamHasPerk(string perkName)
		{
			if ((Object)(object)AtOManager.Instance == (Object)null)
			{
				return false;
			}
			return AtOManager.Instance.TeamHavePerk(perkBase + perkName) || AtOManager.Instance.TeamHavePerk(perkName);
		}

		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, perkBase + id) || AtOManager.Instance.CharacterHaveItem(characterOfInterest.SubclassName, id);
					break;
				case CharacterHas.Perk:
					flag2 = AtOManager.Instance.CharacterHavePerk(characterOfInterest.SubclassName, perkBase + id) || AtOManager.Instance.CharacterHavePerk(characterOfInterest.SubclassName, id);
					break;
				case CharacterHas.Trait:
					flag2 = AtOManager.Instance.CharacterHaveTrait(characterOfInterest.SubclassName, perkBase + id) || AtOManager.Instance.CharacterHaveTrait(characterOfInterest.SubclassName, id);
					break;
				}
			}
			else
			{
				switch (characterHas)
				{
				case CharacterHas.Item:
					flag2 = AtOManager.Instance.TeamHaveItem(perkBase + id, -1, false) || AtOManager.Instance.TeamHaveItem(id, -1, false);
					break;
				case CharacterHas.Perk:
					flag2 = AtOManager.Instance.TeamHavePerk(perkBase + id) || AtOManager.Instance.TeamHavePerk(id);
					break;
				case CharacterHas.Trait:
					flag2 = AtOManager.Instance.TeamHaveTrait(perkBase + id) || AtOManager.Instance.TeamHaveTrait(id);
					break;
				}
			}
			return flag2 && flag;
		}

		public static bool TeamHasPerkGACM(Character characterOfInterest, string perkName, 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;
			bool flag2 = AtOManager.Instance.TeamHavePerk(perkBase + perkName) || AtOManager.Instance.TeamHavePerk(perkName);
			return flag2 && flag;
		}

		public static bool CharacterHasPerkGACM(Character characterOfInterest, string perkName, AppliesTo appliesTo = AppliesTo.Global)
		{
			if (appliesTo == AppliesTo.None || characterOfInterest == null || (Object)(object)AtOManager.Instance == (Object)null)
			{
				return false;
			}
			bool flag = (characterOfInterest.IsHero && appliesTo == AppliesTo.Heroes) || (!characterOfInterest.IsHero && appliesTo == AppliesTo.Monsters) || appliesTo == AppliesTo.Global;
			bool flag2 = AtOManager.Instance.CharacterHavePerk(characterOfInterest.SubclassName, perkBase + perkName) || AtOManager.Instance.CharacterHavePerk(characterOfInterest.SubclassName, perkName);
			return flag2 && flag;
		}

		public static bool TeamHasTraitGACM(Character characterOfInterest, string perkName, 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;
			bool flag2 = AtOManager.Instance.TeamHaveTrait(perkBase + perkName) || AtOManager.Instance.TeamHavePerk(perkName);
			return flag2 && flag;
		}

		public static bool CharacterHasTraitGACM(Character characterOfInterest, string perkName, 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;
			bool flag2 = AtOManager.Instance.CharacterHaveTrait(characterOfInterest.SubclassName, perkBase + perkName) || AtOManager.Instance.TeamHavePerk(perkName);
			return flag2 && flag;
		}

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

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

		public static bool CharacterObjectHavePerk(Character _character, string _perkID)
		{
			if (_character == null || (Object)(object)AtOManager.Instance == (Object)null)
			{
				return false;
			}
			return AtOManager.Instance.CharacterHavePerk(_character.SubclassName, perkBase + _perkID) || AtOManager.Instance.CharacterHavePerk(_character.SubclassName, _perkID);
		}

		public static void PlayCardForFree(string cardToCast)
		{
			if (cardToCast != null && !((Object)(object)Globals.Instance == (Object)null))
			{
				CardData cardData = Globals.Instance.GetCardData(cardToCast, true);
				if ((Object)(object)cardData == (Object)null)
				{
					PLog("Invalid CardName");
				}
				else
				{
					((MonoBehaviour)MatchManager.Instance).StartCoroutine(MatchManager.Instance.CastCard((CardItem)null, true, cardData, 0, -1, true));
				}
			}
		}

		public static void PlaySoundEffect(Character _character, string ACeffect)
		{
			if ((Object)(object)_character.HeroItem != (Object)null)
			{
				EffectsManager.Instance.PlayEffectAC(ACeffect, true, ((CharacterItem)_character.HeroItem).CharImageT, false, 0f);
			}
		}

		public static void DisplayRemainingChargesForTrait(ref Character _character, TraitData traitData)
		{
			if ((Object)(object)_character.HeroItem != (Object)null)
			{
				((CharacterItem)_character.HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_" + traitData.TraitName, "") + TextChargesLeft(MatchManager.Instance.activatedTraits[traitData.TraitName], traitData.TimesPerTurn), (CombatScrollEffectType)7);
			}
		}

		public static void IncrementTraitActivations(TraitData traitData)
		{
			string id = traitData.Id;
			if (!MatchManager.Instance.activatedTraits.ContainsKey(id))
			{
				MatchManager.Instance.activatedTraits.Add(id, 1);
			}
			else
			{
				MatchManager.Instance.activatedTraits[id]++;
			}
			MatchManager.Instance.SetTraitInfoText();
		}

		public static void IncrementTraitActivations(string traitId)
		{
			TraitData traitData = Globals.Instance.GetTraitData(traitId);
			IncrementTraitActivations(traitData);
		}

		public static bool CanIncrementTraitActivations(TraitData traitData)
		{
			Plugin.LogDebug("canIncrementTraitActivations");
			if ((Object)(object)traitData == (Object)null)
			{
				return false;
			}
			string id = traitData.Id;
			if ((Object)(object)MatchManager.Instance == (Object)null)
			{
				return false;
			}
			if (MatchManager.Instance.activatedTraits == null)
			{
				return false;
			}
			if (MatchManager.Instance.activatedTraits.ContainsKey(id) && MatchManager.Instance.activatedTraits[id] > traitData.TimesPerTurn - 1)
			{
				return false;
			}
			if (!MatchManager.Instance.activatedTraits.ContainsKey(id))
			{
				MatchManager.Instance.activatedTraits.Add(id, 0);
			}
			return true;
		}

		public static bool CanIncrementTraitActivations(string traitId)
		{
			TraitData traitData = Globals.Instance.GetTraitData(traitId);
			return CanIncrementTraitActivations(traitData);
		}

		public static void ModifyAllAurasOrCursesByPercent(int percentToModify, IsAuraOrCurse isAuraOrCurse, Character _characterTarget, Character _characterCaster)
		{
			if (percentToModify == 0 || _characterTarget == null || !_characterTarget.Alive)
			{
				return;
			}
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			if ((isAuraOrCurse == IsAuraOrCurse.Aura || isAuraOrCurse == IsAuraOrCurse.Both) && percentToModify > 0)
			{
				num = percentToModify;
			}
			if ((isAuraOrCurse == IsAuraOrCurse.Aura || isAuraOrCurse == IsAuraOrCurse.Both) && percentToModify < 0)
			{
				num2 = Math.Abs(percentToModify);
			}
			if ((isAuraOrCurse == IsAuraOrCurse.Curse || isAuraOrCurse == IsAuraOrCurse.Both) && percentToModify > 0)
			{
				num3 = percentToModify;
			}
			if ((isAuraOrCurse == IsAuraOrCurse.Curse || isAuraOrCurse == IsAuraOrCurse.Both) && percentToModify < 0)
			{
				num4 = Math.Abs(percentToModify);
			}
			if (_characterTarget == null || !_characterTarget.Alive)
			{
				return;
			}
			for (int i = 0; i < 4; i++)
			{
				if ((i == 0 && num <= 0) || (i == 1 && num3 <= 0) || (i == 2 && num2 <= 0) || (i == 3 && num4 <= 0))
				{
					continue;
				}
				List<string> list = new List<string>();
				List<int> list2 = new List<int>();
				for (int j = 0; j < _characterTarget.AuraList.Count; j++)
				{
					if (_characterTarget.AuraList[j] != null && (Object)(object)_characterTarget.AuraList[j].ACData != (Object)null && _characterTarget.AuraList[j].GetCharges() > 0 && !(_characterTarget.AuraList[j].ACData.Id == "furnace"))
					{
						bool flag = false;
						if ((i == 0 || i == 2) && _characterTarget.AuraList[j].ACData.IsAura)
						{
							flag = true;
						}
						else if ((i == 1 || i == 3) && !_characterTarget.AuraList[j].ACData.IsAura)
						{
							flag = true;
						}
						if (flag)
						{
							list.Add(_characterTarget.AuraList[j].ACData.Id);
							list2.Add(_characterTarget.AuraList[j].GetCharges());
						}
					}
				}
				if (list.Count <= 0)
				{
					continue;
				}
				for (int k = 0; k < list.Count; k++)
				{
					int num5 = i switch
					{
						0 => Functions.FuncRoundToInt((float)((double)list2[k] * (double)num / 100.0)), 
						1 => Functions.FuncRoundToInt((float)((double)list2[k] * (double)num3 / 100.0)), 
						2 => list2[k] - Functions.FuncRoundToInt((float)((double)list2[k] * (double)num2 / 100.0)), 
						_ => list2[k] - Functions.FuncRoundToInt((float)((double)list2[k] * (double)num4 / 100.0)), 
					};
					switch (i)
					{
					case 0:
					case 1:
					{
						AuraCurseData val = AtOManager.Instance.GlobalAuraCurseModificationByTraitsAndItems("set", list[k], _characterCaster, _characterTarget);
						if ((Object)(object)val != (Object)null)
						{
							int maxCharges = val.GetMaxCharges();
							if (maxCharges > -1 && list2[k] + num5 > maxCharges)
							{
								num5 = maxCharges - list2[k];
							}
							_characterTarget.SetAura(_characterCaster, val, num5, false, (CardClass)11, false, false);
						}
						break;
					}
					case 2:
					case 3:
						if (num5 <= 0)
						{
							num5 = 1;
						}
						_characterTarget.ModifyAuraCurseCharges(list[k], num5);
						_characterTarget.UpdateAuraCurseFunctions((AuraCurseData)null, 0, -1);
						break;
					}
				}
			}
		}

		public static void ApplyAuraCurseToAll(string acToApply, int nToApply, AppliesTo appliesTo, Character sourceCharacter = null, bool useCharacterMods = false, bool isPreventable = true)
		{
			Plugin.LogInfo("ApplyAuraCurseToAll");
			if ((Object)(object)MatchManager.Instance == (Object)null)
			{
				Plugin.LogError("No MatchManager");
				return;
			}
			if (sourceCharacter == null && useCharacterMods)
			{
				Plugin.LogError("No Source Character");
				return;
			}
			AuraCurseData auraCurseData = GetAuraCurseData(acToApply);
			if ((Object)(object)auraCurseData == (Object)null)
			{
				Plugin.LogError("Improper AuraCurse");
				return;
			}
			Hero[] teamHero = MatchManager.Instance.GetTeamHero();
			NPC[] teamNPC = MatchManager.Instance.GetTeamNPC();
			switch (appliesTo)
			{
			case AppliesTo.Heroes:
			{
				Hero[] array2 = teamHero;
				foreach (Hero val2 in array2)
				{
					if (IsLivingHero((Character)(object)val2))
					{
						((Character)val2).SetAura(sourceCharacter, auraCurseData, nToApply, false, (CardClass)11, useCharacterMods, isPreventable);
					}
				}
				break;
			}
			case AppliesTo.Global:
			{
				Hero[] array3 = teamHero;
				foreach (Hero val3 in array3)
				{
					if (IsLivingHero((Character)(object)val3))
					{
						((Character)val3).SetAura(sourceCharacter, auraCurseData, nToApply, false, (CardClass)11, useCharacterMods, isPreventable);
					}
				}
				NPC[] array4 = teamNPC;
				foreach (NPC val4 in array4)
				{
					if (IsLivingNPC((Character)(object)val4))
					{
						((Character)val4).SetAura(sourceCharacter, auraCurseData, nToApply, false, (CardClass)11, useCharacterMods, isPreventable);
					}
				}
				break;
			}
			case AppliesTo.Monsters:
			{
				NPC[] array = teamNPC;
				foreach (NPC val in array)
				{
					if (IsLivingNPC((Character)(object)val))
					{
						((Character)val).SetAura(sourceCharacter, auraCurseData, nToApply, false, (CardClass)11, useCharacterMods, isPreventable);
					}
				}
				break;
			}
			}
		}

		public static string CollectionToString(Collection<object> values)
		{
			return string.Join(",", values);
		}

		public static string CollectionToString(Dictionary<string, int> dictionary)
		{
			return "{" + string.Join(",", dictionary.Select((KeyValuePair<string, int> kv) => kv.Key + "=" + kv.Value).ToArray()) + "}";
		}

		public static void DrawCards(int numToDraw)
		{
			MatchManager.Instance.NewCard(numToDraw, (CardFrom)0, "");
		}

		public static void GainEnergy(Character _character, int energyToGain, TraitData traitData = null)
		{
			if (!IsLivingHero(_character))
			{
				Plugin.LogDebug("GainEnergy - Invalid Character");
				return;
			}
			Plugin.LogDebug("GainEnergy - Modifying Energy");
			_character.ModifyEnergy(energyToGain, true);
			if (_character.HeroItem != null)
			{
				Plugin.LogDebug("GainEnergy - Setting Effect AC");
				EffectsManager.Instance.PlayEffectAC("energy", true, ((CharacterItem)_character.HeroItem).CharImageT, false, 0f);
				if (!((Object)(object)traitData == (Object)null))
				{
				}
			}
		}

		public static void StealAuraCurses(ref Character characterStealing, ref Character characterToStealFrom, int nToSteal, IsAuraOrCurse isAuraOrCurse = IsAuraOrCurse.Aura)
		{
			if (isAuraOrCurse == IsAuraOrCurse.Both)
			{
				Plugin.LogDebug("Must Specify Aura or Curse to Steal");
				return;
			}
			if (characterStealing == null || characterToStealFrom == null || !characterStealing.Alive || !characterToStealFrom.Alive)
			{
				Plugin.LogDebug("Character to Steal from or Character Stealing is not a valid living character");
				return;
			}
			List<string> list = new List<string>();
			List<int> list2 = new List<int>();
			int num = 0;
			if (characterToStealFrom != null)
			{
				for (int i = 0; i < characterToStealFrom.AuraList.Count; i++)
				{
					if (num >= nToSteal)
					{
						break;
					}
					bool flag = characterToStealFrom.AuraList[i] != null && (Object)(object)characterToStealFrom.AuraList[i].ACData != (Object)null;
					bool flag2 = ((isAuraOrCurse == IsAuraOrCurse.Aura) ? characterToStealFrom.AuraList[i].ACData.IsAura : (!characterToStealFrom.AuraList[i].ACData.IsAura));
					bool flag3 = characterToStealFrom.AuraList[i].ACData.Removable && characterToStealFrom.AuraList[i].GetCharges() > 0;
					if (flag && flag2 && flag3)
					{
						list.Add(characterToStealFrom.AuraList[i].ACData.Id);
						list2.Add(characterToStealFrom.AuraList[i].GetCharges());
						num++;
					}
				}
			}
			if (num <= 0)
			{
				return;
			}
			characterToStealFrom.HealCursesName(list, "");
			for (int j = 0; j < list.Count; j++)
			{
				if (characterStealing != null && characterStealing.Alive)
				{
					characterStealing.SetAura(characterToStealFrom, Globals.Instance.GetAuraCurseData(list[j]), list2[j], false, (CardClass)11, true, true);
				}
			}
		}

		public static List<string> GetDeck(Character character)
		{
			return character.Cards;
		}

		public static List<CardData> GetDeckCardData(Character character)
		{
			List<CardData> list = new List<CardData>();
			foreach (string card in character.Cards)
			{
				list.Add(Globals.Instance.GetCardData(card, true));
			}
			return list;
		}

		public static int CountAllACOnCharacter(Character character, IsAuraOrCurse isAuraOrCurse)
		{
			int num = 0;
			foreach (Aura aura in character.AuraList)
			{
				bool flag = true;
				switch (isAuraOrCurse)
				{
				case IsAuraOrCurse.Aura:
					flag = aura.ACData.IsAura;
					break;
				case IsAuraOrCurse.Curse:
					flag = !aura.ACData.IsAura;
					break;
				case IsAuraOrCurse.Both:
					flag = true;
					break;
				}
				if (flag)
				{
					num += aura.AuraCharges;
				}
			}
			return num;
		}

		public static void ReduceCardCost(ref CardData cardData, Character currentCharacter = null, int amountToReduce = 1, bool isPermanent = false)
		{
			if ((Object)(object)MatchManager.Instance == (Object)null)
			{
				Plugin.LogError("Null MatchManager");
			}
			else if (!((Object)(object)cardData == (Object)null))
			{
				if (currentCharacter == null)
				{
					currentCharacter = (Character)(object)MatchManager.Instance.GetHeroHeroActive();
				}
				if (isPermanent)
				{
					CardData obj = cardData;
					obj.EnergyReductionPermanent += amountToReduce;
				}
				else
				{
					CardData obj2 = cardData;
					obj2.EnergyReductionTemporal += amountToReduce;
				}
				MatchManager.Instance.GetCardFromTableByIndex(cardData.InternalId).ShowEnergyModification(-amountToReduce);
				MatchManager.Instance.UpdateHandCards();
				MatchManager.Instance.CreateLogCardModification(cardData.InternalId, MatchManager.Instance.GetHero(currentCharacter.HeroIndex));
			}
		}

		public static CardData GetRandomHighestCostCard(CardType cardType, List<string> heroHand = null)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)MatchManager.Instance == (Object)null)
			{
				Plugin.LogError("Null MatchManager");
				return null;
			}
			if (heroHand == null)
			{
				heroHand = MatchManager.Instance.GetHeroHand(MatchManager.Instance.GetHeroActive());
			}
			int num = 0;
			List<CardData> list = new List<CardData>();
			for (int i = 0; i < heroHand.Count; i++)
			{
				CardData cardData = MatchManager.Instance.GetCardData(heroHand[i]);
				if (cardData != null && cardData.GetCardTypes().Contains(cardType) && cardData.GetCardFinalCost() > num)
				{
					num = cardData.GetCardFinalCost();
				}
			}
			if (num <= 0)
			{
				return null;
			}
			for (int j = 0; j < heroHand.Count; j++)
			{
				CardData cardData2 = MatchManager.Instance.GetCardData(heroHand[j]);
				if (cardData2 != null && cardData2.GetCardTypes().Contains(cardType) && cardData2.GetCardFinalCost() >= num)
				{
					list.Add(cardData2);
				}
			}
			if (list.Count <= 0)
			{
				return null;
			}
			return (list.Count != 1) ? list[MatchManager.Instance.GetRandomIntRange(0, list.Count, "default", "")] : list[0];
		}

		public static List<CardData> GetCardsFromHand(CardType cardType = 0, int equalOrAboveCertainCost = 0, int lessThanOrEqualToThisCost = 100)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			Character heroHeroActive = (Character)(object)MatchManager.Instance.GetHeroHeroActive();
			List<string> heroHand = MatchManager.Instance.GetHeroHand(heroHeroActive.HeroIndex);
			List<CardData> list = new List<CardData>();
			for (int i = 0; i < heroHand.Count; i++)
			{
				CardData cardData = MatchManager.Instance.GetCardData(heroHand[i]);
				if ((Object)(object)cardData != (Object)null && cardData.GetCardFinalCost() > 0 && (cardData.GetCardTypes().Contains(cardType) || (int)cardType == 0) && cardData.GetCardFinalCost() >= equalOrAboveCertainCost && cardData.GetCardFinalCost() <= lessThanOrEqualToThisCost)
				{
					list.Add(cardData);
				}
			}
			return list;
		}

		public static List<CardData> GetCardsFromHand(List<string> heroHand, CardType cardType = 0, int equalOrAboveCertainCost = 0, int lessThanOrEqualToThisCost = 100)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			Plugin.LogDebug("GetCardsFromHand");
			List<CardData> list = new List<CardData>();
			for (int i = 0; i < heroHand.Count; i++)
			{
				CardData cardData = MatchManager.Instance.GetCardData(heroHand[i]);
				if ((Object)(object)cardData != (Object)null && cardData.GetCardFinalCost() > 0 && (cardData.GetCardTypes().Contains(cardType) || (int)cardType == 0) && cardData.GetCardFinalCost() >= equalOrAboveCertainCost && cardData.GetCardFinalCost() <= lessThanOrEqualToThisCost)
				{
					list.Add(cardData);
				}
			}
			return list;
		}

		public static CardData GetRightmostCard(List<string> heroHand)
		{
			Plugin.LogDebug("GetRightmostCard");
			return MatchManager.Instance.GetCardData(heroHand.Last());
		}
	}
	[HarmonyPatch]
	internal class Traits
	{
		public static string heroName = "shaun eello";

		public static string subclassname = "trickster";

		public static string debugBase = "Binbin - Testing " + heroName + " ";

		public static string[] myTraitList = new string[9] { "trickstermagictrick", "tricksterpractice", "tricksterstudy", "trickstertrickupyoursleeve", "tricksterlearnrealmagic", "trickstersecretpocket", "tricksterimprovise", "tricksterdistractingact", "tricksterdrawpower" };

		public static int cardsPlayedPerTurn = 0;

		public static string trait0 = "trickstermagictrick";

		public static string trait2a = "trickstertrickupyoursleeve";

		public static string trait2b = "tricksterlearnrealmagic";

		public static string trait4a = "tricksterdistractingact";

		public static string trait4b = "tricksterdrawpower";

		public static void DoCustomTrait(string _trait, ref Trait __instance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			EventActivation value = Traverse.Create((object)__instance).Field("theEvent").GetValue<EventActivation>();
			Character value2 = Traverse.Create((object)__instance).Field("character").GetValue<Character>();
			Character value3 = Traverse.Create((object)__instance).Field("target").GetValue<Character>();
			int value4 = Traverse.Create((object)__instance).Field("auxInt").GetValue<int>();
			string value5 = Traverse.Create((object)__instance).Field("auxString").GetValue<string>();
			CardData value6 = Traverse.Create((object)__instance).Field("castedCard").GetValue<CardData>();
			Traverse.Create((object)__instance).Field("character").SetValue((object)value2);
			Traverse.Create((object)__instance).Field("target").SetValue((object)value3);
			Traverse.Create((object)__instance).Field("theEvent").SetValue((object)value);
			Traverse.Create((object)__instance).Field("auxInt").SetValue((object)value4);
			Traverse.Create((object)__instance).Field("auxString").SetValue((object)value5);
			Traverse.Create((object)__instance).Field("castedCard").SetValue((object)value6);
			TraitData traitData = Globals.Instance.GetTraitData(_trait);
			List<CardData> list = new List<CardData>();
			List<string> heroHand = MatchManager.Instance.GetHeroHand(value2.HeroIndex);
			Hero[] teamHero = MatchManager.Instance.GetTeamHero();
			NPC[] teamNPC = MatchManager.Instance.GetTeamNPC();
			if (_trait == trait0)
			{
				Plugin.LogDebug(_trait);
				Character val = (Character)(object)teamHero.First();
				Plugin.LogDebug("Trait: " + _trait + " - Front hero: " + val.SourceName);
				val.SetAuraTrait(value2, "evasion", 1);
				Plugin.LogDebug("Trait: " + _trait + " - Evasion set");
				((CharacterItem)value2.HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_" + _trait, ""), (CombatScrollEffectType)7);
			}
			else if (_trait == trait2a)
			{
				Plugin.LogDebug(_trait);
				if (CustomFunctions.CanIncrementTraitActivations(_trait) && value6.HasCardType((CardType)14))
				{
					Plugin.LogDebug($"Trait: {_trait} Casted Card - {value6.Id}. IsSmallWeap - {value6.HasCardType((CardType)14)}");
					CustomFunctions.PlayCardForFree("tricksterspecialdraw");
					MatchManager instance = MatchManager.Instance;
					if ((Object)(object)instance != (Object)null)
					{
						Plugin.LogDebug("Decrement globalVanishCardsNum - draw");
						int value7 = Traverse.Create((object)instance).Field("GlobalVanishCardsNum").GetValue<int>();
						value7--;
						Traverse.Create((object)instance).Field("GlobalVanishCardsNum").SetValue((object)value7);
					}
					CustomFunctions.IncrementTraitActivations(_trait);
					((CharacterItem)value2.HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_" + _trait, ""), (CombatScrollEffectType)7);
				}
			}
			else if (_trait == trait2b)
			{
				Plugin.LogDebug(_trait);
				CardData cardData = CustomFunctions.GetRandomHighestCostCard((CardType)16, heroHand);
				CardData cardData2 = CustomFunctions.GetRandomHighestCostCard((CardType)20, heroHand);
				CardData cardData3 = CustomFunctions.GetRandomHighestCostCard((CardType)13);
				CustomFunctions.ReduceCardCost(ref cardData, value2);
				CustomFunctions.ReduceCardCost(ref cardData2, value2);
				CustomFunctions.ReduceCardCost(ref cardData3, value2);
				((CharacterItem)value2.HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_" + _trait, ""), (CombatScrollEffectType)7);
			}
			else if (_trait == trait4a)
			{
				Plugin.LogDebug(_trait);
				Plugin.LogDebug(string.Format("{0} nStealth = {1}", _trait, value2.GetAuraCharges("stealth")));
				if ((Object)(object)value6 != (Object)null && value2.GetAuraCharges("stealth") <= 0 && value6.Id != "tricksterspecialstealth" && value6.Id != "tricksterspecialdraw")
				{
					Plugin.LogDebug(string.Format("Trait: {0} Gaining Stealth - {1}", _trait, value2.GetAuraCharges("stealth")));
					CustomFunctions.PlayCardForFree("tricksterspecialstealth");
					MatchManager instance2 = MatchManager.Instance;
					if ((Object)(object)instance2 != (Object)null)
					{
						Plugin.LogDebug("Decrement globalVanishCardsNum - stealth");
						int value8 = Traverse.Create((object)instance2).Field("GlobalVanishCardsNum").GetValue<int>();
						value8--;
						Traverse.Create((object)instance2).Field("GlobalVanishCardsNum").SetValue((object)value8);
					}
					((CharacterItem)value2.HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_" + _trait, ""), (CombatScrollEffectType)7);
				}
			}
			else if (_trait == trait4b)
			{
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MatchManager), "NewCard")]
		public static void NewCardPostfix(MatchManager __instance, int numCards, CardFrom fromPlace, string comingFromCardId = "")
		{
			Hero heroHeroActive = __instance.GetHeroHeroActive();
			if (CustomFunctions.IsLivingHero((Character)(object)heroHeroActive) && ((Character)heroHeroActive).HaveTrait(trait4b))
			{
				Plugin.LogDebug(string.Format("Trait: {0} Gaining Powerful - {1}", trait4a, ((Character)heroHeroActive).GetAuraCharges("powerful")));
				((Character)heroHeroActive).SetAura((Character)(object)heroHeroActive, CustomFunctions.GetAuraCurseData("powerful"), 1, true, (CardClass)11, true, true);
				((CharacterItem)((Character)heroHeroActive).HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_" + trait4b, ""), (CombatScrollEffectType)7);
			}
		}

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

		public static void UnsetMage(AtOManager __instance)
		{
			if ((Object)(object)__instance == (Object)null || !Globals.Instance.SubClass.ContainsKey("trickster"))
			{
				return;
			}
			Hero[] value = Traverse.Create((object)__instance).Field("teamAtO").GetValue<Hero[]>();
			if (value == null)
			{
				Plugin.LogError("null teamAtO");
				return;
			}
			int num = -1;
			for (int i = 0; i < 4; i++)
			{
				if (((Character)value[i]).SubclassName == "trickster")
				{
					num = i;
				}
			}
			if (num == -1)
			{
				Plugin.LogDebug("trickster not found");
				return;
			}
			Plugin.LogDebug("Unsetting mage subclass inside conditions");
			Globals.Instance.SubClass["trickster"].HeroClassSecondary = (HeroClass)(((Character)value[num]).HaveTrait("tricksterlearnrealmagic") ? 1 : 6);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AtOManager), "BeginAdventure")]
		public static void BeginAdventurePostfix(AtOManager __instance)
		{
			UnsetMage(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AtOManager), "Instantiate")]
		public static void HeroSelectionManagerInstantiatePostfix(HeroSelectionManager __instance)
		{
			UnsetMage(AtOManager.Instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AtOManager), "SaveGame")]
		public static void SaveGamePostfix(AtOManager __instance)
		{
			UnsetMage(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AtOManager), "LoadGame")]
		public static void LoadGamePostfix(AtOManager __instance)
		{
			UnsetMage(__instance);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(AtOManager), "HeroLevelUp")]
		public static bool HeroLevelUpPrefix(ref AtOManager __instance, int heroIndex, string traitId)
		{
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			Plugin.LogDebug("HeroLevelUpPrefix");
			Hero[] value = Traverse.Create((object)__instance).Field("teamAtO").GetValue<Hero[]>();
			if (value == null)
			{
				Plugin.LogError("null teamAtO");
				return true;
			}
			Hero val = value[heroIndex];
			Plugin.LogDebug("Level up before conditions for subclass " + ((Character)val).SubclassName + " trait id " + traitId);
			string text = trait2b;
			if (((Character)val).SubclassName == subclassname && traitId == trait2b)
			{
				TraitData traitData = Globals.Instance.GetTraitData(traitId);
				if ((Object)(object)traitData != (Object)null && traitId == text)
				{
					Plugin.LogDebug("Setting mage subclass inside conditions");
					Globals.Instance.SubClass[((Character)val).SubclassName].HeroClassSecondary = (HeroClass)1;
				}
			}
			HeroClass heroClassSecondary = Globals.Instance.SubClass[((Character)val).SubclassName].HeroClassSecondary;
			Plugin.LogDebug("Hopefully finished setting mage subclass - " + ((object)(HeroClass)(ref heroClassSecondary)).ToString());
			return true;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AtOManager), "GlobalAuraCurseModificationByTraitsAndItems")]
		public static void GlobalAuraCurseModificationByTraitsAndItemsPostfix(ref AtOManager __instance, ref AuraCurseData __result, string _type, string _acId, Character _characterCaster, Character _characterTarget)
		{
			Plugin.LogInfo("GACM");
			Character characterOfInterest = ((_type == "set") ? _characterTarget : _characterCaster);
			if (_acId == "powerful" && CustomFunctions.IfCharacterHas(characterOfInterest, CustomFunctions.CharacterHas.Trait, trait4b, CustomFunctions.AppliesTo.ThisHero))
			{
				Plugin.LogInfo("Shaun has " + trait4b);
				AuraCurseData obj = __result;
				obj.MaxCharges += 5;
				AuraCurseData obj2 = __result;
				obj2.MaxMadnessCharges += 5;
				AuraCurseData obj3 = __result;
				obj3.AuraConsumed += 2;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(CharacterItem), "fOnMouseUp")]
		public static void fOnMouseUpPrefix()
		{
			Plugin.LogDebug("fOnMouseUpPrefix - PRE");
			if (MatchManager.Instance.justCasted && (Object)(object)MatchManager.Instance != (Object)null)
			{
				Plugin.LogDebug("fOnMouseUpPrefix - POST");
				Character heroHeroActive = (Character)(object)MatchManager.Instance.GetHeroHeroActive();
				if (heroHeroActive.GetAuraCharges("stealth") <= 0)
				{
					Plugin.LogDebug(string.Format("Trait: {0} Gaining Stealth - {1}", trait4a, heroHeroActive.GetAuraCharges("stealth")));
					heroHeroActive.SetAuraTrait(heroHeroActive, "stealth", 1);
					((CharacterItem)heroHeroActive.HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_" + trait4a, ""), (CombatScrollEffectType)7);
				}
				Plugin.LogDebug("fOnMouseUpPrefix - POST Stealth");
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MatchManager), "JustCastedCo")]
		public static IEnumerator JustCastedCoWrapper(IEnumerator result)
		{
			Plugin.LogDebug("JustCastedCoWrapper - PRE");
			while (result.MoveNext())
			{
				Plugin.LogDebug("JustCastedCoWrapper - Inside1");
				yield return result.Current;
				Plugin.LogDebug("JustCastedCoWrapper - Inside2");
			}
			Plugin.LogDebug("JustCastedCoWrapper - POST");
			Character _character = (Character)(object)MatchManager.Instance.GetHeroHeroActive();
			if (_character.GetAuraCharges("stealth") <= 0)
			{
				Plugin.LogDebug(string.Format("Trait: {0} Gaining Stealth - {1}", trait4a, _character.GetAuraCharges("stealth")));
				_character.SetAuraTrait(_character, "stealth", 1);
				((CharacterItem)_character.HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_" + trait4a, ""), (CombatScrollEffectType)7);
			}
			Plugin.LogDebug("JustCastedCoWrapper - POST Stealth");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.binbin.thetrickster";

		public const string PLUGIN_NAME = "TheMagician";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}