Decompiled source of Doremy Sweet v0.5.55

LBoL_Doremy.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AddWatermark;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Cysharp.Threading.Tasks;
using HarmonyLib;
using LBoL.Base;
using LBoL.Base.Extensions;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Battle;
using LBoL.Core.Battle.BattleActions;
using LBoL.Core.Battle.Interactions;
using LBoL.Core.Cards;
using LBoL.Core.Intentions;
using LBoL.Core.Randoms;
using LBoL.Core.SaveData;
using LBoL.Core.StatusEffects;
using LBoL.Core.Units;
using LBoL.EntityLib.Cards.Character.Cirno;
using LBoL.EntityLib.Cards.Character.Marisa;
using LBoL.EntityLib.Cards.Character.Reimu;
using LBoL.EntityLib.Cards.Character.Sakuya;
using LBoL.EntityLib.Cards.Enemy;
using LBoL.EntityLib.Cards.Neutral.Blue;
using LBoL.EntityLib.Cards.Neutral.NoColor;
using LBoL.EntityLib.EnemyUnits.Normal;
using LBoL.EntityLib.Exhibits;
using LBoL.EntityLib.StatusEffects.Cirno;
using LBoL.EntityLib.StatusEffects.ExtraTurn;
using LBoL.EntityLib.StatusEffects.ExtraTurn.Partners;
using LBoL.EntityLib.StatusEffects.Reimu;
using LBoL.EntityLib.StatusEffects.Sakuya;
using LBoL.Presentation;
using LBoL.Presentation.UI;
using LBoL.Presentation.UI.ExtraWidgets;
using LBoL.Presentation.UI.Panels;
using LBoL.Presentation.UI.Widgets;
using LBoL.Presentation.Units;
using LBoLEntitySideloader;
using LBoLEntitySideloader.Attributes;
using LBoLEntitySideloader.CustomHandlers;
using LBoLEntitySideloader.CustomKeywords;
using LBoLEntitySideloader.Entities;
using LBoLEntitySideloader.Resource;
using LBoLEntitySideloader.Utils;
using LBoL_Doremy.Actions;
using LBoL_Doremy.CreatedCardTracking;
using LBoL_Doremy.DoremyChar.Actions;
using LBoL_Doremy.DoremyChar.BattleTracking;
using LBoL_Doremy.DoremyChar.Cards.Rare;
using LBoL_Doremy.DoremyChar.Cards.Rare.DreamTeamates;
using LBoL_Doremy.DoremyChar.Cards.Token;
using LBoL_Doremy.DoremyChar.Cards.Uncommon;
using LBoL_Doremy.DoremyChar.DoremyPU;
using LBoL_Doremy.DoremyChar.DreamManagers;
using LBoL_Doremy.DoremyChar.Keywords;
using LBoL_Doremy.DoremyChar.SE;
using LBoL_Doremy.ExtraAssets;
using LBoL_Doremy.RootTemplates;
using LBoL_Doremy.StaticResources;
using LBoL_Doremy.Utils;
using Spine;
using TMPro;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.UI;

[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: IgnoresAccessChecksTo("LBoL.Base")]
[assembly: IgnoresAccessChecksTo("LBoL.ConfigData")]
[assembly: IgnoresAccessChecksTo("LBoL.Core")]
[assembly: IgnoresAccessChecksTo("LBoL.EntityLib")]
[assembly: IgnoresAccessChecksTo("LBoL.Presentation")]
[assembly: IgnoresAccessChecksTo("Untitled.ConfigDataBuilder.Base")]
[assembly: AssemblyCompany("LBoL_Doremy")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LBoL_Doremy")]
[assembly: AssemblyTitle("LBoL_Doremy")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace LBoL_Doremy
{
	[BepInPlugin("neoCollab.lbol.char.Doremy", "Doremy Player character", "0.5.55")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("LBoL.exe")]
	public class BepinexPlugin : BaseUnityPlugin
	{
		private static readonly Harmony harmony = PInfo.harmony;

		internal static ManualLogSource log;

		private void Awake()
		{
			log = ((BaseUnityPlugin)this).Logger;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			EntityManager.RegisterSelf();
			harmony.PatchAll();
			if (Chainloader.PluginInfos.ContainsKey("neo.lbol.tools.watermark"))
			{
				WatermarkWrapper.ActivateWatermark();
			}
			CardIndexGenerator.PromiseClearIndexSet();
			BattleHistoryHandlers.RegisterAll();
			DreamLayerHandlers.RegisterHandlers();
			AssetManager.DoLoadSync();
		}

		private void OnDestroy()
		{
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal static class Log
	{
		private static ManualLogSource log = BepinexPlugin.log;

		internal static void LogMessage(object data)
		{
			log.LogMessage(data);
		}

		internal static void LogInfo(object data)
		{
			log.LogInfo(data);
		}

		internal static void LogDebug(object data)
		{
			log.LogDebug(data);
		}

		internal static void LogWarning(object data)
		{
			log.LogWarning(data);
		}

		internal static void LogError(object data)
		{
			log.LogError(data);
		}

		internal static void LogFatal(object data)
		{
			log.LogFatal(data);
		}
	}
	public static class ModConfig
	{
		private static string gameplaySection = "Gameplay";

		private static ConfigEntry<bool> autoSaveAfterLucentGenesis;

		public static bool AutoSaveAfterLucentGenesis => autoSaveAfterLucentGenesis.Value;

		public static void DoBinds(ConfigFile configFile)
		{
			autoSaveAfterLucentGenesis = configFile.Bind<bool>(gameplaySection, "AutoSaveAfterLucentGenesis", true, "Save Power committed to use Lucent Genesis to prevent save scumming for favorable outcome.");
		}
	}
	public static class PInfo
	{
		public const string GUID = "neoCollab.lbol.char.Doremy";

		public const string Name = "Doremy Player character";

		public const string version = "0.5.55";

		public static readonly Harmony harmony = new Harmony("neoCollab.lbol.char.Doremy");
	}
	internal class WatermarkWrapper
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static void ActivateWatermark()
		{
			API.ActivateWatermark();
		}
	}
}
namespace LBoL_Doremy.Utils
{
	public static class DColorUtils
	{
		private static string uiBlueHex = ColorUtility.ToHtmlStringRGB(GlobalConfig.UiBlue);

		public const string common = "#a0a1a0";

		public const string uncommon = "#3277d1";

		public const string rare = "#d6cd28";

		public const string basicAndCommon = "#898e89";

		public const string misfortune = "#8a3baf";

		public const string status = "#b25eee";

		public const string tool = "#f8f8ff";

		public static string DL => "<color=#b24ac4>DL</color>";

		public static string LightBlue => "<color=#B2FFFF>";

		public static string UIBlue => "<color=#" + uiBlueHex + ">";

		public static string CC => "</color>";

		public static string ColorName(this Card card, string defaultColor = "#000000")
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Invalid comparison between Unknown and I4
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected I4, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected I4, but got Unknown
			string text = ((GameEntity)card).Name + (card.IsUpgraded ? " +" : "");
			if (card.IsBasic && (int)card.Config.Rarity == 0)
			{
				return text.WrapHex("#898e89");
			}
			CardType cardType = card.CardType;
			CardType val = cardType;
			switch (val - 6)
			{
			case 1:
				return text.WrapHex("#b25eee");
			case 2:
				return text.WrapHex("#8a3baf");
			case 0:
				return text.WrapHex("#f8f8ff");
			default:
			{
				Rarity rarity = card.Config.Rarity;
				Rarity val2 = rarity;
				switch ((int)val2)
				{
				case 0:
					return text.WrapHex("#a0a1a0");
				case 1:
					return text.WrapHex("#3277d1");
				case 2:
				case 3:
				case 4:
					return text.WrapHex("#d6cd28");
				default:
					return text.WrapHex(defaultColor);
				}
			}
			}
		}

		public static string WrapHex(this string text, string hex)
		{
			return "<color=" + hex + ">" + text + "</color>";
		}
	}
	public static class DEntityUtils
	{
		[return: MaybeNull]
		public static GameEntity TrickleDownActionSource(this GameEntity actionSource)
		{
			GameEntity result = actionSource;
			StatusEffect val = (StatusEffect)(object)((actionSource is StatusEffect) ? actionSource : null);
			if (val != null && val.SourceCard != null)
			{
				result = (GameEntity)(object)val.SourceCard;
			}
			return result;
		}
	}
}
namespace LBoL_Doremy.StaticResources
{
	public class Artists
	{
		public const string Deeznuts = "Deeznuts";

		public const string kimmchu = "kimmchu!";

		public const string DC = "GameCavalier";

		public const string Ali = "Ali";
	}
	internal static class Loc
	{
		internal static DirectorySource locSource = Sources.rootDirSource;

		public static string Cards = "Cards";

		public static string Exhibits = "Exhibits";

		public static string PlayerUnit = "PlayerUnit";

		public static string EnemiesUnit = "EnemyUnit";

		public static string UnitModel = "UnitModel";

		public static string UltimateSkills = "UltimateSkills";

		public static string StatusEffects = "StatusEffects";

		public static BatchLocalization CardsBatchLoc = new BatchLocalization((IResourceSource)(object)locSource, typeof(CardTemplate), Cards, (Locale)0, false);

		public static BatchLocalization ExhibitsBatchLoc = new BatchLocalization((IResourceSource)(object)locSource, typeof(ExhibitTemplate), Exhibits, (Locale)0, false);

		public static BatchLocalization PlayerUnitBatchLoc = new BatchLocalization((IResourceSource)(object)locSource, typeof(PlayerUnitTemplate), PlayerUnit, (Locale)0, false);

		public static BatchLocalization EnemiesUnitBatchLoc = new BatchLocalization((IResourceSource)(object)locSource, typeof(EnemyUnitTemplate), EnemiesUnit, (Locale)0, false);

		public static BatchLocalization UnitModelBatchLoc = new BatchLocalization((IResourceSource)(object)locSource, typeof(UnitModelTemplate), UnitModel, (Locale)0, false);

		public static BatchLocalization UltimateSkillsBatchLoc = new BatchLocalization((IResourceSource)(object)locSource, typeof(UltimateSkillTemplate), UltimateSkills, (Locale)0, false);

		public static BatchLocalization StatusEffectsBatchLoc = new BatchLocalization((IResourceSource)(object)locSource, typeof(StatusEffectTemplate), StatusEffects, (Locale)0, false);
	}
	internal class Sources
	{
		private static IResourceSource embeddedSource = (IResourceSource)new EmbeddedSource(Assembly.GetExecutingAssembly());

		private static DirectorySource imgsDirSource = new DirectorySource("neoCollab.lbol.char.Doremy", "imgs");

		internal static DirectorySource rootDirSource = new DirectorySource("neoCollab.lbol.char.Doremy", "");

		internal static DirectorySource playerImgsSource = rootDirSource;

		internal static IResourceSource imgsSource = (IResourceSource)(object)rootDirSource;

		internal static IResourceSource exAndBomb = (IResourceSource)(object)rootDirSource;

		internal static DirectorySource extraImgs = rootDirSource;
	}
}
namespace LBoL_Doremy.RootTemplates
{
	public static class CardIndexGenerator
	{
		private static readonly List<ManaColor> offColors = DoremyCavalierDef.offColors;

		private static int? initial_offset = null;

		private static HashSet<int> uniqueIds = new HashSet<int>();

		public const int milx10 = 10000000;

		public static HashSet<int> UniqueIds
		{
			get
			{
				if (uniqueIds == null)
				{
					uniqueIds = new HashSet<int>();
				}
				return uniqueIds;
			}
		}

		public static int Initial_offset
		{
			get
			{
				if (!initial_offset.HasValue)
				{
					int num = 0;
					if (UniqueTracker.Instance.configIndexes.TryGetValue(typeof(CardConfig), out var value))
					{
						num = value.Where((int i) => i >= 10000000).DefaultIfEmpty().Max() / 10000000;
					}
					num++;
					initial_offset = num * 10000000;
				}
				return initial_offset.Value;
			}
		}

		internal static void PromiseClearIndexSet()
		{
			EntityManager.AddPostLoadAction((Action)delegate
			{
				uniqueIds = null;
			}, (Assembly)null);
		}

		public static int GetUniqueIndex(CardConfig config)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected I4, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			int num = Initial_offset;
			num += (config.Colors.Any((ManaColor x) => offColors.Any((ManaColor y) => y == x)) ? 1000000 : 0);
			num += ((!((Enum)config.Keywords).HasFlag((Enum)(object)(Keyword)2)) ? ((config.Rarity + 1) * 100000) : 0);
			int num2 = ((config.Colors.Count > 1) ? 9 : ((int)config.Colors[0]));
			num += num2 * 10000;
			int num3;
			if (!config.IsXCost && !((Enum)config.Keywords).HasFlag((Enum)(object)(Keyword)32768))
			{
				ManaGroup cost = config.Cost;
				if (((ManaGroup)(ref cost)).Total <= 9)
				{
					cost = config.Cost;
					num3 = ((ManaGroup)(ref cost)).Total;
					goto IL_00df;
				}
			}
			num3 = 9;
			goto IL_00df;
			IL_00df:
			int num4 = num3;
			num += num4 * 1000;
			num += config.Type * 100;
			if (UniqueTracker.Instance.configIndexes.TryGetValue(typeof(CardConfig), out var value))
			{
				for (; value.Contains(num); num++)
				{
				}
			}
			return num;
		}
	}
	public abstract class DCardDef : CardTemplate
	{
		public override IdContainer GetId()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			return IdContainer.op_Implicit(((EntityDefinition)(object)this).SelfId());
		}

		public override CardImages LoadCardImages()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			CardImages val = new CardImages(Sources.imgsSource);
			val.AutoLoad(IdContainer.op_Implicit(((EntityDefinition)this).GetId()), ".png", "", PreConfig().SubIllustrator.ToList(), false);
			return val;
		}

		public override LocalizationOption LoadLocalization()
		{
			return (LocalizationOption)(object)Loc.CardsBatchLoc.AddEntity((EntityDefinition)(object)this);
		}

		public override CardConfig MakeConfig()
		{
			CardConfig val = PreConfig();
			val.Index = CardIndexGenerator.GetUniqueIndex(val);
			return val;
		}

		public CardConfig DefaultConfig()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Expected O, but got Unknown
			return new CardConfig(0, "", 10, true, new string[0][], "", "", 0, false, true, true, false, true, (Rarity)0, (CardType)0, (TargetType?)(TargetType)4, (IReadOnlyList<ManaColor>)new List<ManaColor>(), false, default(ManaGroup), (ManaGroup?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (ManaGroup?)null, (ManaGroup?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (Keyword)0, (Keyword)0, false, (Keyword)0, (Keyword)0, (IReadOnlyList<string>)new List<string>(), (IReadOnlyList<string>)new List<string>(), (IReadOnlyList<string>)new List<string>(), (IReadOnlyList<string>)new List<string>(), "DoremyCavalier", (string)null, (string)null, false, "GameCavalier", (IReadOnlyList<string>)new List<string>());
		}

		public abstract CardConfig PreConfig();
	}
	public abstract class DCard : Card
	{
		public string DL => DColorUtils.DL;

		public string LB => DColorUtils.LightBlue;

		public string UIBlue => DColorUtils.UIBlue;

		public string CC => DColorUtils.CC;

		public string SS => " ";

		public string BrB => StringDecorator.Decorate("|" + (((Card)this).IsUpgraded ? Keywords.GetDisplayWord((Keyword)1024).Name : Keywords.GetDisplayWord((Keyword)512).Name) + "|");

		public int BlockOrShield
		{
			get
			{
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				int result;
				if (!((Card)this).IsUpgraded)
				{
					BlockInfo block = ((Card)this).Block;
					result = ((BlockInfo)(ref block)).Block;
				}
				else
				{
					ShieldInfo shield = ((Card)this).Shield;
					result = ((ShieldInfo)(ref shield)).Shield;
				}
				return result;
			}
		}

		public string DoTimes => (TimesVal > 1) ? RuntimeFormatterExtensions.RuntimeFormat(((GameEntity)this).LocalizeProperty("Times", false, true), ((GameEntity)this).FormatWrapper) : "";

		public virtual int TimesVal => ((Card)this).Value1;

		protected BattleController RealBattle
		{
			[return: MaybeNull]
			get
			{
				object obj = ((Card)this).Battle;
				if (obj == null)
				{
					GameMaster instance = Singleton<GameMaster>.Instance;
					if (instance == null)
					{
						obj = null;
					}
					else
					{
						GameRunController currentGameRun = instance.CurrentGameRun;
						obj = ((currentGameRun != null) ? currentGameRun.Battle : null);
					}
				}
				return (BattleController)obj;
			}
		}

		public override void Initialize()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			((Card)this).Initialize();
			((GameEntity)this).FormatWrapper = (GameEntityFormatWrapper)(object)new DFormatterCard((Card)(object)this, (CardFormatWrapper)((GameEntity)this).FormatWrapper);
		}

		protected void ReactOnCardsAddedEvents(BattleController battle, Func<Card[], GameEventArgs, IEnumerable<BattleAction>> reactor)
		{
			ReactOnCardsAddedEvents(battle, reactor, (GameEventPriority)((Card)this).Config.Order);
		}

		protected void ReactOnCardsAddedEvents(BattleController battle, Func<Card[], GameEventArgs, IEnumerable<BattleAction>> reactor, GameEventPriority priority)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			EventSequencedReactor<CardsAddingToDrawZoneEventArgs> val = (CardsAddingToDrawZoneEventArgs args) => reactor(args.Cards, (GameEventArgs)(object)args);
			EventSequencedReactor<CardsEventArgs> val2 = (CardsEventArgs args) => reactor(args.Cards, (GameEventArgs)(object)args);
			((Card)this).ReactBattleEvent<CardsEventArgs>(battle.CardsAddedToDiscard, val2, priority);
			((Card)this).ReactBattleEvent<CardsAddingToDrawZoneEventArgs>(battle.CardsAddedToDrawZone, val, priority);
			((Card)this).ReactBattleEvent<CardsEventArgs>(battle.CardsAddedToExile, val2, priority);
			((Card)this).ReactBattleEvent<CardsEventArgs>(battle.CardsAddedToHand, val2, priority);
		}

		public NightmareAction NightmareAction(Unit target, NightmareInfo level, float occupationTime = 0.15f)
		{
			return new NightmareAction((Unit)(object)((Card)this).Battle.Player, target, level, occupationTime);
		}

		protected string GetPendingNMDmgDesc(Func<int, int> dmgFunc)
		{
			if (((Card)this).Battle == null)
			{
				return "";
			}
			string text = "";
			DC_NightmareSE dC_NightmareSE = default(DC_NightmareSE);
			text = ((((Card)this).PendingTarget == null) ? "N/A" : ((!((Card)this).PendingTarget.TryGetStatusEffect<DC_NightmareSE>(ref dC_NightmareSE)) ? "0" : dmgFunc(((StatusEffect)dC_NightmareSE).Level).ToString()));
			return StringDecorator.Decorate("(|e:" + text + "|) ");
		}
	}
	public abstract class DExhibitDef : ExhibitTemplate
	{
		public const string inactive = "Inactive";

		public override IdContainer GetId()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			return IdContainer.op_Implicit(((EntityDefinition)(object)this).SelfId());
		}

		public override LocalizationOption LoadLocalization()
		{
			return (LocalizationOption)(object)Loc.ExhibitsBatchLoc.AddEntity((EntityDefinition)(object)this);
		}

		public override ExhibitSprites LoadSprite()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			return new ExhibitSprites(ResourceLoader.LoadSprite(IdContainer.op_Implicit(((EntityDefinition)this).GetId()) + ".png", Sources.exAndBomb, (Rect?)null, 1, (Vector2?)null));
		}
	}
	public struct NightmareInfo
	{
		public float toApply;

		public readonly bool isSelfNightmare;

		public static explicit operator int(NightmareInfo nightmareInfo)
		{
			return MathExtensions.RoundToInt(nightmareInfo.toApply, MidpointRounding.AwayFromZero);
		}

		public static implicit operator float(NightmareInfo nightmareInfo)
		{
			return nightmareInfo.toApply;
		}

		public static implicit operator NightmareInfo(int _int)
		{
			return new NightmareInfo(_int, isSelfNightmare: false);
		}

		public static implicit operator NightmareInfo(float _float)
		{
			return new NightmareInfo(_float, isSelfNightmare: false);
		}

		public NightmareInfo(float toApply, bool isSelfNightmare)
		{
			this.toApply = toApply;
			this.isSelfNightmare = isSelfNightmare;
		}

		public override string ToString()
		{
			return toApply.ToString();
		}
	}
	public class DFormatterCard : GameEntityFormatWrapper
	{
		private readonly CardFormatWrapper cardFormatWrapper = null;

		private readonly Card card;

		private static Unit _fakeUnit;

		public static Unit FakeUnit
		{
			get
			{
				if (_fakeUnit == null)
				{
					_fakeUnit = (Unit)(object)Library.CreateEnemyUnit<WhiteFairy>();
				}
				return _fakeUnit;
			}
		}

		public DFormatterCard(Card card, CardFormatWrapper ogWrapper)
			: base((GameEntity)(object)card)
		{
			cardFormatWrapper = ogWrapper;
			this.card = card;
		}

		public DFormatterCard(Card card)
			: base((GameEntity)(object)card)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			cardFormatWrapper = new CardFormatWrapper(card);
			this.card = card;
		}

		public override string FormatArgument(object arg, string format)
		{
			if (arg is NightmareInfo nightmareInfo)
			{
				BattleController battle = card.Battle;
				if (battle == null)
				{
					return GameEntityFormatWrapper.WrappedFormatNumber((int)nightmareInfo, (int)nightmareInfo, format);
				}
				Unit val = card.PendingTarget;
				if (nightmareInfo.isSelfNightmare)
				{
					val = (Unit)(object)battle.Player;
				}
				if (val == null)
				{
					val = FakeUnit;
				}
				NightmareArgs nightmareArgs = new NightmareArgs(nightmareInfo.isSelfNightmare)
				{
					source = (Unit)(object)battle.Player,
					target = val,
					level = nightmareInfo
				};
				((GameEventArgs)nightmareArgs).ActionSource = (GameEntity)(object)card;
				((GameEventArgs)nightmareArgs).Cause = (ActionCause)20;
				EventManager.GetDoremyEvents(battle).nightmareEvents.nigtmareApplying.Execute(nightmareArgs);
				return GameEntityFormatWrapper.WrappedFormatNumber((int)nightmareInfo, (int)nightmareArgs.level, format);
			}
			return ((GameEntityFormatWrapper)cardFormatWrapper).FormatArgument(arg, format);
		}
	}
	public abstract class DPlayerDef : PlayerUnitTemplate
	{
	}
	public abstract class DPlayer : PlayerUnit
	{
	}
	public abstract class DStatusEffectDef : StatusEffectTemplate
	{
		public override IdContainer GetId()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			return IdContainer.op_Implicit(((EntityDefinition)(object)this).SelfId());
		}

		public override LocalizationOption LoadLocalization()
		{
			return (LocalizationOption)(object)Loc.StatusEffectsBatchLoc.AddEntity((EntityDefinition)(object)this);
		}

		public override Sprite LoadSprite()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return ResourceLoader.LoadSprite(IdContainer.op_Implicit(((EntityDefinition)this).GetId()) + ".png", Sources.imgsSource, (Rect?)null, 1, (Vector2?)null);
		}

		public override StatusEffectConfig MakeConfig()
		{
			return PreConfig();
		}

		public StatusEffectConfig DefaultConfig()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			return new StatusEffectConfig(0, "", 10, (StatusEffectType)0, false, true, (int?)null, true, (StackType?)(StackType)0, false, (StackType?)(StackType)0, (DurationDecreaseTiming)0, false, (StackType?)(StackType)3, (StackType?)(StackType)3, false, (Keyword)0, (IReadOnlyList<string>)new List<string>(), "Default", "Default", "Default");
		}

		public abstract StatusEffectConfig PreConfig();
	}
	public abstract class DStatusEffect : StatusEffect
	{
		public string DL => DColorUtils.DL;

		public string LB => DColorUtils.LightBlue;

		public string UIBlue => DColorUtils.UIBlue;

		public string CC => DColorUtils.CC;

		public string DoTimes => (TimesVal > 1) ? RuntimeFormatterExtensions.RuntimeFormat(((GameEntity)this).LocalizeProperty("Times", false, true), ((GameEntity)this).FormatWrapper) : "";

		public virtual int TimesVal => ((StatusEffect)this).Level;

		protected BattleController RealBattle
		{
			[return: MaybeNull]
			get
			{
				object obj = ((StatusEffect)this).Battle;
				if (obj == null)
				{
					GameMaster instance = Singleton<GameMaster>.Instance;
					if (instance == null)
					{
						obj = null;
					}
					else
					{
						GameRunController currentGameRun = instance.CurrentGameRun;
						obj = ((currentGameRun != null) ? currentGameRun.Battle : null);
					}
				}
				return (BattleController)obj;
			}
		}

		public NightmareAction NightmareAction(Unit target, NightmareInfo level, float occupationTime = 0.15f)
		{
			return new NightmareAction((Unit)(object)((StatusEffect)this).Battle.Player, target, level, occupationTime);
		}

		protected void ReactOnCardsAddedEvents(Func<Card[], GameEventArgs, IEnumerable<BattleAction>> reactor)
		{
			ReactOnCardsAddedEvents(reactor, (GameEventPriority)((StatusEffect)this).Config.Order);
		}

		protected void ReactOnCardsAddedEvents(Func<Card[], GameEventArgs, IEnumerable<BattleAction>> reactor, GameEventPriority priority)
		{
			//IL_0035: 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)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			EventSequencedReactor<CardsAddingToDrawZoneEventArgs> val = (CardsAddingToDrawZoneEventArgs args) => reactor(args.Cards, (GameEventArgs)(object)args);
			EventSequencedReactor<CardsEventArgs> val2 = (CardsEventArgs args) => reactor(args.Cards, (GameEventArgs)(object)args);
			((StatusEffect)this).ReactOwnerEvent<CardsEventArgs>(((StatusEffect)this).Battle.CardsAddedToDiscard, val2, priority);
			((StatusEffect)this).ReactOwnerEvent<CardsAddingToDrawZoneEventArgs>(((StatusEffect)this).Battle.CardsAddedToDrawZone, val, priority);
			((StatusEffect)this).ReactOwnerEvent<CardsEventArgs>(((StatusEffect)this).Battle.CardsAddedToExile, val2, priority);
			((StatusEffect)this).ReactOwnerEvent<CardsEventArgs>(((StatusEffect)this).Battle.CardsAddedToHand, val2, priority);
		}
	}
	public abstract class DUltimateSkillDef : UltimateSkillTemplate
	{
		public override IdContainer GetId()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			return IdContainer.op_Implicit(((EntityDefinition)(object)this).SelfId());
		}

		public override LocalizationOption LoadLocalization()
		{
			return (LocalizationOption)(object)Loc.UltimateSkillsBatchLoc.AddEntity((EntityDefinition)(object)this);
		}

		public override Sprite LoadSprite()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return ResourceLoader.LoadSprite(IdContainer.op_Implicit(((EntityDefinition)this).GetId()) + ".png", Sources.exAndBomb, (Rect?)null, 1, (Vector2?)null);
		}
	}
	internal static class Extensions
	{
		public static string SelfId(this EntityDefinition entityDefinition, string suffix = "Def")
		{
			string name = ((object)entityDefinition).GetType().Name;
			return name.Substring(0, name.Length - suffix.Length);
		}
	}
	public static class DStringUtils
	{
		public static string FirstToLower(this string s)
		{
			string result;
			if (s.Length <= 0)
			{
				result = s;
			}
			else
			{
				result = char.ToLower(s[0]) + s.Substring(1, s.Length - 1);
			}
			return result;
		}
	}
}
namespace LBoL_Doremy.ExtraAssets
{
	public static class AssetManager
	{
		private static DoremyAssets doremyAssets;

		private static bool finishedLoading;

		public static DoremyAssets DoremyAssets
		{
			get
			{
				if (!finishedLoading)
				{
					Log.LogError("Additional Doremy assets did not finish loading.");
				}
				return doremyAssets;
			}
			private set
			{
				doremyAssets = value;
			}
		}

		public static async void DoLoadAsync()
		{
			try
			{
				finishedLoading = false;
				AssetManager.doremyAssets = new DoremyAssets();
				DoremyAssets doremyAssets = AssetManager.doremyAssets;
				doremyAssets.createdIcon = await ResourceLoader.LoadSpriteAsync("CreatedIcon.png", Sources.extraImgs, 100, (GraphicsFormat)4, 1, (FilterMode)1, (SpriteMeshType)1, (Rect?)null, (Vector2?)null, "file://");
				DoremyAssets doremyAssets2 = AssetManager.doremyAssets;
				doremyAssets2.dlTrackerIcon = await ResourceLoader.LoadSpriteAsync("DreamLevel.png", Sources.extraImgs, 100, (GraphicsFormat)4, 1, (FilterMode)1, (SpriteMeshType)1, (Rect?)null, (Vector2?)null, "file://");
				DoremyAssets doremyAssets3 = AssetManager.doremyAssets;
				doremyAssets3.dlCorruptedIcon = await ResourceLoader.LoadSpriteAsync("CorruptedDL.png", Sources.extraImgs, 100, (GraphicsFormat)4, 1, (FilterMode)1, (SpriteMeshType)1, (Rect?)null, (Vector2?)null, "file://");
				DoremyAssets doremyAssets4 = AssetManager.doremyAssets;
				doremyAssets4.purpleBar = await ResourceLoader.LoadSpriteAsync("PurpleBar.png", Sources.extraImgs, 100, (GraphicsFormat)4, 1, (FilterMode)1, (SpriteMeshType)1, (Rect?)null, (Vector2?)null, "file://");
				finishedLoading = true;
			}
			catch (Exception ex2)
			{
				Exception ex = ex2;
				Log.LogError(ex);
			}
		}

		public static void DoLoadSync()
		{
			try
			{
				finishedLoading = false;
				doremyAssets = new DoremyAssets();
				doremyAssets.createdIcon = ResourceLoader.LoadSprite("CreatedIcon.png", (IResourceSource)(object)Sources.extraImgs, (Rect?)null, 1, (Vector2?)null);
				doremyAssets.dlTrackerIcon = ResourceLoader.LoadSprite("DreamLevel.png", (IResourceSource)(object)Sources.extraImgs, (Rect?)null, 1, (Vector2?)null);
				doremyAssets.dlCorruptedIcon = ResourceLoader.LoadSprite("CorruptedDL.png", (IResourceSource)(object)Sources.extraImgs, (Rect?)null, 1, (Vector2?)null);
				doremyAssets.purpleBar = ResourceLoader.LoadSprite("PurpleBar.png", (IResourceSource)(object)Sources.extraImgs, (Rect?)null, 1, (Vector2?)null);
				finishedLoading = true;
			}
			catch (Exception data)
			{
				Log.LogError(data);
			}
		}
	}
	public class DoremyAssets
	{
		public Sprite createdIcon;

		public Sprite dlTrackerIcon;

		public Sprite dlCorruptedIcon;

		public Sprite dreamLevel;

		public Sprite purpleBar;
	}
}
namespace LBoL_Doremy.CreatedCardTracking
{
	public static class CreatedIdTracker
	{
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPriority(0)]
		private class BattleController_Patch
		{
			private static void Postfix(BattleController __instance)
			{
				startingId = __instance._cardInstanceId;
			}
		}

		private static int startingId = 1000;

		public static bool WasGenerated(this Card card)
		{
			return card.InstanceId > startingId || card.IsPlayTwiceToken;
		}
	}
}
namespace LBoL_Doremy.Actions
{
	public class DreamLevelArgs : GameEventArgs
	{
		public Card target;

		public int dreamLevelDelta = 1;

		public bool isEndOfTurnBounce = false;

		public DreamLevelArgs()
		{
		}

		public DreamLevelArgs(bool isEndOfTurnBounce)
		{
			this.isEndOfTurnBounce = isEndOfTurnBounce;
		}

		public override string GetBaseDebugString()
		{
			object arg = dreamLevelDelta;
			Card obj = target;
			return string.Format("Applying {0} Dream Level to {1}", arg, ((obj != null) ? ((GameEntity)obj).Name : null) ?? "many");
		}
	}
}
namespace LBoL_Doremy.DoremyChar.Visuals
{
	[HarmonyPatch(typeof(CardWidget), "LazySetCard")]
	internal class CardWidget_LazySetCard_Patch
	{
		private static void Postfix(CardWidget __instance)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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)
			Card card = __instance.Card;
			if (card != null && card.WasGenerated())
			{
				GameObject val = Object.Instantiate<GameObject>(__instance.baseLoyaltyObj, __instance.baseLoyaltyObj.transform.parent, true);
				((Object)val).name = "CreatedIcon";
				Object.Destroy((Object)(object)((Component)val.transform.Find("BaseLoyaltyText")).gameObject);
				Transform transform = val.transform;
				transform.localPosition += new Vector3(0f, 285f, 0f);
				Image component = val.GetComponent<Image>();
				component.sprite = AssetManager.DoremyAssets.createdIcon;
				val.SetActive(true);
			}
		}
	}
}
namespace LBoL_Doremy.DoremyChar.VanillaTweaks
{
	internal class HatateInit_Patch
	{
		private static void Postfix(Card __instance)
		{
			if (((GameEntity)__instance).Id == "HatateDiscard")
			{
				GameRunController currentGameRun = Singleton<GameMaster>.Instance.CurrentGameRun;
				if (((currentGameRun != null) ? ((GameEntity)currentGameRun.Player).Id : null) == "DoremyCavalier")
				{
					__instance.Config = ObjectExtensions.Copy<CardConfig>(__instance.Config);
					CardConfig config = __instance.Config;
					config.RelativeEffects = config.RelativeEffects.Concat(new string[3] { "DC_VanillaExTooltipSE", "DC_NightmareSE", "DC_SelfNightmareTooltipSE" }).ToList();
					config.UpgradedRelativeEffects = config.RelativeEffects.Concat(new string[3] { "DC_VanillaExTooltipSE", "DC_NightmareSE", "DC_SelfNightmareTooltipSE" }).ToList();
				}
			}
		}
	}
	internal class HatateGetBaseDescription_Patch
	{
		private static void Postfix(Card __instance, ref string __result)
		{
			if (((GameEntity)__instance).Id == "HatateDiscard")
			{
				GameRunController gameRun = ((GameEntity)__instance).GameRun;
				if (((gameRun != null) ? ((GameEntity)gameRun.Player).Id : null) == "DoremyCavalier")
				{
					__result += DC_VanillaLocHelper.GetLoc("NewsFab");
				}
			}
		}
	}
	internal class NewsFab_Patch
	{
		private static IEnumerable<BattleAction> Postfix(IEnumerable<BattleAction> actions, HatateDiscard __instance)
		{
			foreach (BattleAction action in actions)
			{
				yield return action;
			}
			GameRunController gameRun = ((GameEntity)__instance).GameRun;
			if (((gameRun != null) ? ((GameEntity)gameRun.Player).Id : null) == "DoremyCavalier")
			{
				yield return (BattleAction)(object)new NightmareAction((Unit)(object)((Card)__instance).Battle.Player, (Unit)(object)((Card)__instance).Battle.Player, new NightmareInfo(5f, isSelfNightmare: true), 0.15f);
			}
		}
	}
	public sealed class DC_VanillaLocHelperDef : DStatusEffectDef
	{
		public override Sprite LoadSprite()
		{
			return null;
		}

		public override StatusEffectConfig PreConfig()
		{
			return DefaultConfig();
		}
	}
	[EntityLogic(typeof(DC_VanillaLocHelperDef))]
	public sealed class DC_VanillaLocHelper : DStatusEffect
	{
		public static string GetLoc(string key, object[] toFormat = null)
		{
			string text = TypeFactory<StatusEffect>.LocalizeProperty("DC_VanillaLocHelper", key, true, true);
			if (text == null)
			{
				return "";
			}
			if (toFormat != null)
			{
				text = string.Format(text, toFormat);
			}
			return text;
		}
	}
}
namespace LBoL_Doremy.DoremyChar.Ults
{
	public sealed class DoremyCavalierUUltDef : DUltimateSkillDef
	{
		public override UltimateSkillConfig MakeConfig()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			return new UltimateSkillConfig("", 10, 100, 100, 2, (UsRepeatableType)1, 0, 15, 0, (Keyword)256, (IReadOnlyList<string>)new List<string> { "DC_NightmareSE" }, (IReadOnlyList<string>)new List<string>());
		}
	}
	[EntityLogic(typeof(DoremyCavalierUUltDef))]
	public sealed class DoremyCavalierUUlt : UltimateSkill
	{
		public DoremyCavalierUUlt()
		{
			((UltimateSkill)this).TargetType = (TargetType)2;
		}

		protected override IEnumerable<BattleAction> Actions(UnitSelector selector)
		{
			yield return (BattleAction)(object)PerformAction.Spell((Unit)(object)((UltimateSkill)this).Owner, ((GameEntity)this).Id);
			yield return (BattleAction)(object)PerformAction.Gun((Unit)(object)((UltimateSkill)this).Owner, (Unit)(object)((UltimateSkill)this).Battle.AllAliveEnemies.FirstOrDefault(), "Sweet02", 0f);
			EnemyUnit[] enemies = selector.GetEnemies(((UltimateSkill)this).Battle);
			foreach (EnemyUnit e2 in enemies)
			{
				ApplyStatusEffectAction<DC_NightmareSE> obj = new ApplyStatusEffectAction<DC_NightmareSE>((Unit)(object)e2, (int?)((UltimateSkill)this).Value1, (int?)null, (int?)null, (int?)null, 0f, true);
				((BattleAction)obj).Source = (GameEntity)(object)this;
				yield return (BattleAction)(object)obj;
			}
			if (((UltimateSkill)this).Battle.BattleShouldEnd)
			{
				yield break;
			}
			EnemyUnit[] enemies2 = UnitSelector.AllEnemies.GetEnemies(((UltimateSkill)this).Battle);
			DC_NightmareSE nightmare = default(DC_NightmareSE);
			foreach (EnemyUnit e in enemies2)
			{
				if (((Unit)e).TryGetStatusEffect<DC_NightmareSE>(ref nightmare))
				{
					yield return (BattleAction)new DamageAction((Unit)(object)((UltimateSkill)this).Battle.Player, (Unit)(object)e, DamageInfo.Attack((float)((StatusEffect)nightmare).Level / 2f, true), "Instant", (GunType)0);
				}
				nightmare = null;
			}
		}
	}
	public sealed class DoremyCavalierWUltDef : DUltimateSkillDef
	{
		public override UltimateSkillConfig MakeConfig()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			return new UltimateSkillConfig("", 10, 110, 110, 2, (UsRepeatableType)1, 0, 5, 0, (Keyword)0, (IReadOnlyList<string>)new List<string>(), (IReadOnlyList<string>)new List<string>());
		}
	}
	[EntityLogic(typeof(DoremyCavalierWUltDef))]
	public sealed class DoremyCavalierWUlt : UltimateSkill
	{
		private struct PreconditionInfo
		{
			public CardWeightTable cardWeightTable;

			public Predicate<CardConfig> filter;
		}

		private PreconditionInfo? preconditionInfo = null;

		public int MinColours = 1;

		public ManaGroup Mana
		{
			get
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				ManaGroup result = default(ManaGroup);
				((ManaGroup)(ref result)).Philosophy = 2;
				return result;
			}
		}

		public int MinOrigins => 1;

		public int MinTypes => 2;

		public int MaxTypePool => 5;

		public int RollAmount { get; set; }

		public int PoolSize { get; set; }

		public DoremyCavalierWUlt()
		{
			((UltimateSkill)this).TargetType = (TargetType)0;
		}

		public override void Initialize()
		{
			((UltimateSkill)this).Initialize();
			Log.LogDebug("initing " + ((GameEntity)this).Name);
			CHandlerManager.RegisterBattleEventHandler<UsUsingEventArgs>((EventProvider<UsUsingEventArgs, BattleController>)((BattleController b) => b.UsUsing), (GameEventHandler<UsUsingEventArgs>)Precondition, (Predicate<BattleController>)null, (GameEventPriority)10);
		}

		private void Precondition(UsUsingEventArgs args)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			if (args.Us == this)
			{
				((UltimateSkill)this).Battle.React(new Reactor(PreconditionSequence(args)), (GameEntity)(object)this, (ActionCause)4);
			}
		}

		private IEnumerable<BattleAction> PreconditionSequence(UsUsingEventArgs args)
		{
			Action<UsUsingEventArgs> cancelUs = delegate(UsUsingEventArgs args)
			{
				((GameEventArgs)args).CancelBy((GameEntity)(object)this);
				UiManager.GetPanel<PlayBoard>().RewindUs();
				preconditionInfo = null;
			};
			preconditionInfo = null;
			RollAmount = ((UltimateSkill)this).Value1;
			PoolSize = 0;
			IEnumerable<string> originIds = Enumerable.Concat(second: from pu in Library.GetSelectablePlayers()
				select ((GameEntity)pu).Id, first: new string[1]);
			IEnumerable<DC_OriginOption> originOptions = originIds.Select(delegate(string id)
			{
				DC_OriginOption dC_OriginOption = Library.CreateCard<DC_OriginOption>();
				dC_OriginOption.OriginId = id;
				return dC_OriginOption;
			});
			SelectCardInteraction originSelection = new SelectCardInteraction(MinOrigins, originOptions.Count(), (IEnumerable<Card>)originOptions, (SelectedCardHandling)0)
			{
				Source = (GameEntity)(object)this
			};
			yield return (BattleAction)(object)new InteractionActionPlus((Interaction)(object)originSelection, canCancel: true, new ViewSelectCardResolver(delegate
			{
				SelectCardPanel panel3 = UiManager.GetPanel<SelectCardPanel>();
				((TMP_Text)panel3.titleTmp).text = RuntimeFormatterExtensions.RuntimeFormat(((GameEntity)this).LocalizeProperty("ChooseOrigin", true, true), ((GameEntity)this).FormatWrapper);
				CollectionExtensions.Do<SelectCardWidget>((IEnumerable<SelectCardWidget>)panel3._selectCardWidgets, (Action<SelectCardWidget>)delegate(SelectCardWidget w)
				{
					Card card = w.Card;
					DC_OriginOption oo = card as DC_OriginOption;
					if (oo != null && oo.OriginId != null)
					{
						CardConfig val2 = ((IEnumerable<CardConfig>)CardConfig.AllConfig()).FirstOrDefault((Func<CardConfig, bool>)((CardConfig cc) => cc.Owner == oo.OriginId && cc.IsPooled && string.IsNullOrEmpty(cc.ImageId)));
						if (val2 != null)
						{
							Texture val3 = ResourcesHelper.TryGetCardImage(val2.Id);
							if ((Object)(object)val3 != (Object)null)
							{
								w.CardWidget.cardImage.texture = val3;
							}
						}
					}
				});
			}).ExtendEnumerator);
			if (((Interaction)originSelection).IsCanceled)
			{
				cancelUs(args);
				yield break;
			}
			HashSet<string> originFilter = (from DC_OriginOption c in originSelection.SelectedCards
				select c.OriginId).ToHashSet();
			RollAmount += Math.Min(15, Enumerable.Range(1, originSelection.SelectedCards.Count - 1).Sum());
			IEnumerable<DC_TypeOption> cTypes = (from i in Enumerable.Range(1, MaxTypePool)
				select (CardType)i).Select(delegate(CardType t)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				DC_TypeOption dC_TypeOption2 = Library.CreateCard<DC_TypeOption>();
				dC_TypeOption2.CType = t;
				return dC_TypeOption2;
			});
			SelectCardInteraction cTypeSelection = new SelectCardInteraction(MinTypes, cTypes.Count(), (IEnumerable<Card>)cTypes, (SelectedCardHandling)0)
			{
				Source = (GameEntity)(object)this
			};
			yield return (BattleAction)(object)new InteractionActionPlus((Interaction)(object)cTypeSelection, canCancel: true, new ViewSelectCardResolver(delegate
			{
				SelectCardPanel panel2 = UiManager.GetPanel<SelectCardPanel>();
				((TMP_Text)panel2.titleTmp).text = RuntimeFormatterExtensions.RuntimeFormat(((GameEntity)this).LocalizeProperty("ChooseType", true, true), ((GameEntity)this).FormatWrapper);
				CollectionExtensions.Do<SelectCardWidget>((IEnumerable<SelectCardWidget>)panel2._selectCardWidgets, (Action<SelectCardWidget>)delegate(SelectCardWidget w)
				{
					//IL_0017: Unknown result type (might be due to invalid IL or missing references)
					//IL_001d: Invalid comparison between Unknown and I4
					//IL_0065: Unknown result type (might be due to invalid IL or missing references)
					if (w.Card is DC_TypeOption dC_TypeOption)
					{
						if ((int)dC_TypeOption.CType == 5)
						{
							w.CardWidget.SetProperties();
							w.CardWidget._changed = false;
							w.CardWidget.MarginAsFriend = false;
							((TMP_Text)w.CardWidget.descriptionText).ForceMeshUpdate(false, false);
						}
						string text = DC_TypeOption.Type2Img[dC_TypeOption.CType];
						Texture val = ResourcesHelper.TryGetCardImage(text);
						if ((Object)(object)val != (Object)null)
						{
							w.CardWidget.cardImage.texture = val;
						}
					}
				});
			}).ExtendEnumerator);
			if (((Interaction)cTypeSelection).IsCanceled)
			{
				cancelUs(args);
				yield break;
			}
			HashSet<CardType> cTypeFilter = (from DC_TypeOption c in cTypeSelection.SelectedCards
				select c.CType).ToHashSet();
			RollAmount += (from DC_TypeOption to in cTypeSelection.SelectedCards
				select to.RollMod).Sum();
			CardWeightTable weightTable = new CardWeightTable(RarityWeightTable.BattleCard, OwnerWeightTable.AllOnes, CardTypeWeightTable.AllOnes, false);
			Predicate<CardConfig> filter = (CardConfig cc) => (originFilter.Contains(cc.Owner) || (int)cc.Type == 6 || (int)cc.Type == 7 || (int)cc.Type == 8) && cTypeFilter.Contains(cc.Type) && !cc.IsXCost;
			PoolSize = ((IEnumerable<RandomPoolEntry<Type>>)((GameEntity)this).GameRun.CreateValidCardsPool(weightTable, (ManaGroup?)null, false, false, false, filter)).Count();
			SelectCardInteraction confirmation = new SelectCardInteraction(1, 1, (IEnumerable<Card>)(object)new Card[2]
			{
				Library.CreateCard<DC_FinalConfirmationOption>(),
				Library.CreateCard<DC_WUltErrata>()
			}, (SelectedCardHandling)0)
			{
				Source = (GameEntity)(object)this
			};
			yield return (BattleAction)(object)new InteractionActionPlus((Interaction)(object)confirmation, canCancel: true, new ViewSelectCardResolver(delegate
			{
				SelectCardPanel panel = UiManager.GetPanel<SelectCardPanel>();
				((TMP_Text)panel.titleTmp).text = RuntimeFormatterExtensions.RuntimeFormat(((GameEntity)this).LocalizeProperty("FinalChoice", true, true), ((GameEntity)this).FormatWrapper);
				CollectionExtensions.Do<SelectCardWidget>((IEnumerable<SelectCardWidget>)panel._selectCardWidgets, (Action<SelectCardWidget>)delegate(SelectCardWidget w)
				{
					if (w.Card is DC_FinalConfirmationOption dC_FinalConfirmationOption)
					{
						dC_FinalConfirmationOption.RollAmount = RollAmount;
						dC_FinalConfirmationOption.PoolSize = PoolSize;
					}
				});
			}).ExtendEnumerator);
			if (((Interaction)confirmation).IsCanceled)
			{
				cancelUs(args);
				yield break;
			}
			Log.LogDebug(string.Join("|", from c in originFilter
				orderby c
				select c into o
				select (o == null) ? "Neutral" : o));
			Log.LogDebug(string.Join("|", cTypeFilter.OrderBy((CardType c) => c)));
			preconditionInfo = new PreconditionInfo
			{
				cardWeightTable = weightTable,
				filter = filter
			};
		}

		protected override IEnumerable<BattleAction> Actions(UnitSelector selector)
		{
			if (!preconditionInfo.HasValue)
			{
				Log.LogError(((GameEntity)this).Id + " preconditionInfo is empty.");
				yield break;
			}
			CardWeightTable weightTable = preconditionInfo.Value.cardWeightTable;
			Predicate<CardConfig> filter = preconditionInfo.Value.filter;
			new List<Card>();
			List<Card> finalCards = ((GameEntity)this).GameRun.RollCardsWithoutManaLimit(((GameEntity)this).GameRun.BattleCardRng, weightTable, RollAmount, false, false, filter).ToList();
			if (finalCards.Count < RollAmount)
			{
				yield return (BattleAction)(object)PerformAction.Chat((Unit)(object)((UltimateSkill)this).Owner, string.Format(((GameEntity)this).LocalizeProperty("NotEnoughChat", false, true), finalCards.Count), 3f, 0f, 0f, true);
			}
			Log.LogDebug($"total pool {PoolSize}");
			SelectCardInteraction cardSelection = new SelectCardInteraction(1, 1, (IEnumerable<Card>)finalCards, (SelectedCardHandling)0)
			{
				CanCancel = false,
				Source = (GameEntity)(object)this
			};
			if (finalCards.Count > 0)
			{
				GameMaster instance = Singleton<GameMaster>.Instance;
				PlayerSaveData playerData = ((instance == null) ? null : instance.GameRunSaveData?.Player);
				if (playerData != null)
				{
					if (((UltimateSkill)this).Battle.Player.Power < playerData.Power)
					{
						playerData.Power = ((UltimateSkill)this).Battle.Player.Power;
						Singleton<GameMaster>.Instance.SaveGameRun(Singleton<GameMaster>.Instance.GameRunSaveData, false);
					}
				}
				else
				{
					Log.LogWarning("GameRunSaveData is null.");
				}
				yield return (BattleAction)(object)PerformAction.Spell((Unit)(object)((UltimateSkill)this).Owner, ((GameEntity)this).Id);
				yield return (BattleAction)new GainManaAction(Mana);
				yield return (BattleAction)(object)new InteractionActionPlus((Interaction)(object)cardSelection, canCancel: false, new ViewSelectCardResolver(delegate
				{
					SelectCardPanel panel = UiManager.GetPanel<SelectCardPanel>();
					TextMeshProUGUI titleTmp = panel.titleTmp;
					((TMP_Text)titleTmp).text = ((TMP_Text)titleTmp).text + RuntimeFormatterExtensions.RuntimeFormat(((GameEntity)this).LocalizeProperty("RollAmount", true, true), ((GameEntity)this).FormatWrapper);
				}).ExtendEnumerator);
			}
			Card cardChosen = cardSelection.SelectedCards?.FirstOrDefault();
			if (cardChosen != null)
			{
				cardChosen.Config = ObjectExtensions.Copy<CardConfig>(cardChosen.Config);
				CardConfig config = cardChosen.Config;
				ManaGroup val = cardChosen.Config.Cost;
				config.Cost = ManaGroup.Anys(((ManaGroup)(ref val)).Amount);
				if (cardChosen.Config.UpgradedCost.HasValue)
				{
					CardConfig config2 = cardChosen.Config;
					val = cardChosen.Config.UpgradedCost.Value;
					config2.UpgradedCost = ManaGroup.Anys(((ManaGroup)(ref val)).Amount);
				}
				else
				{
					CardConfig config3 = cardChosen.Config;
					val = cardChosen.Config.Cost;
					config3.UpgradedCost = ManaGroup.Anys(((ManaGroup)(ref val)).Amount);
				}
				cardChosen._baseCost = cardChosen.ConfigCost;
				yield return (BattleAction)new AddCardsToHandAction((Card[])(object)new Card[1] { cardChosen });
			}
			PoolSize = 0;
			RollAmount = 0;
		}
	}
	public sealed class DC_ManaOptionDef : OptionCardDef
	{
		public override CardImages LoadCardImages()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			return new CardImages(Sources.imgsSource, (Texture2D)ResourcesHelper.TryGetCardImage("CManaCard"));
		}

		public override CardConfig PreConfig()
		{
			CardConfig val = base.PreConfig();
			val.Rarity = (Rarity)2;
			val.Owner = "";
			return val;
		}
	}
	[EntityLogic(typeof(DC_ManaOptionDef))]
	public sealed class DC_ManaOption : Card
	{
		public static string[] c2img = new string[9] { "", "WManaCard", "UManaCard", "BManaCard", "RManaCard", "GManaCard", "CManaCard", "PManaCard", "" };

		private ManaColor _manaColor;

		public ManaColor ManaColor
		{
			get
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				return _manaColor;
			}
			set
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0003: 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_000f: Invalid comparison between Unknown and I4
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				_manaColor = value;
				if ((int)_manaColor == 7)
				{
					((Card)this).Config.Colors = new List<ManaColor>
					{
						(ManaColor)1,
						(ManaColor)2,
						(ManaColor)3,
						(ManaColor)4,
						(ManaColor)5
					};
				}
				else
				{
					((Card)this).Config.Colors = new List<ManaColor> { value };
				}
			}
		}

		public ManaGroup C2Mana
		{
			get
			{
				//IL_0003: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				ManaGroup result = default(ManaGroup);
				((ManaGroup)(ref result)).SetValue(ManaColor, 1);
				return result;
			}
		}

		public override void Initialize()
		{
			((Card)this).Initialize();
			((Card)this).Config = ObjectExtensions.Copy<CardConfig>(((Card)this).Config);
		}
	}
	public sealed class DC_OriginOptionDef : OptionCardDef
	{
		public override CardImages LoadCardImages()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			return new CardImages(Sources.imgsSource, (Texture2D)ResourcesHelper.TryGetCardImage("SummerFlower"));
		}

		public override CardConfig PreConfig()
		{
			CardConfig val = base.PreConfig();
			val.Rarity = (Rarity)2;
			val.Owner = "";
			return val;
		}
	}
	[EntityLogic(typeof(DC_OriginOptionDef))]
	public sealed class DC_OriginOption : Card
	{
		private string _originId = null;

		public string OriginName => (OriginId == null) ? ((GameEntity)this).LocalizeProperty("Neutral", false, true) : UnitNameTable.GetName(OriginId, PlayerUnitConfig.FromId(OriginId).NarrativeColor).ToString(true, (NounCase)0, (UnitNameStyle)0);

		public string OriginId
		{
			get
			{
				return _originId;
			}
			set
			{
				_originId = value;
				((Card)this).Config.Owner = value;
			}
		}

		public override void Initialize()
		{
			((Card)this).Initialize();
			((Card)this).Config = ObjectExtensions.Copy<CardConfig>(((Card)this).Config);
		}
	}
	public sealed class DC_TypeOptionDef : OptionCardDef
	{
		public override CardImages LoadCardImages()
		{
			return null;
		}

		public override CardConfig PreConfig()
		{
			CardConfig val = base.PreConfig();
			val.Rarity = (Rarity)2;
			val.Owner = "";
			return val;
		}
	}
	[EntityLogic(typeof(DC_TypeOptionDef))]
	public sealed class DC_TypeOption : Card
	{
		public static string[] Type2Img = new string[9] { "", "FinalSpark", "NiuqiDefense", "PerfectServant", "BailianBlack", "MeilingFriend", "ToolHeal", "Nightmare", "Drunk" };

		public static int[] Type2RollMod = new int[9] { 0, 2, 1, 0, -1, -1, -3, 2, 2 };

		private CardType _cType;

		public string RollModDesc => GameEntityFormatWrapper.WrappedFormatNumber(0, RollMod, "");

		public int RollMod { get; set; }

		public string CTypeDesc => StringDecorator.Decorate("|" + LocalizationExtensions.Localize($"CardType.{CType}", true) + "|");

		public CardType CType
		{
			get
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				return _cType;
			}
			set
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				((Card)this).Config.Type = value;
				RollMod = Type2RollMod[value];
				_cType = value;
			}
		}

		public override void Initialize()
		{
			((Card)this).Initialize();
			((Card)this).Config = ObjectExtensions.Copy<CardConfig>(((Card)this).Config);
		}
	}
	public sealed class DC_FinalConfirmationOptionDef : OptionCardDef
	{
		public override CardImages LoadCardImages()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			CardImages val = new CardImages(Sources.imgsSource);
			val.main = ResourceLoader.LoadTexture("DoremyComatoseForm.png", Sources.imgsSource);
			return val;
		}

		public override CardConfig PreConfig()
		{
			CardConfig val = base.PreConfig();
			val.Rarity = (Rarity)2;
			val.Owner = "DoremyCavalier";
			return val;
		}
	}
	[EntityLogic(typeof(DC_FinalConfirmationOptionDef))]
	public sealed class DC_FinalConfirmationOption : Card
	{
		public int RollAmount { get; internal set; } = 0;


		public int PoolSize { get; internal set; } = 0;


		public override void Initialize()
		{
			((Card)this).Initialize();
		}
	}
	public sealed class DC_WUltErrataDef : OptionCardDef
	{
		public override CardImages LoadCardImages()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			CardImages val = new CardImages(Sources.imgsSource);
			val.main = ResourceLoader.LoadTexture("DOBToptionP.png", Sources.imgsSource);
			return val;
		}

		public override CardConfig PreConfig()
		{
			CardConfig val = base.PreConfig();
			val.Rarity = (Rarity)2;
			val.Owner = "";
			return val;
		}
	}
	[EntityLogic(typeof(DC_WUltErrataDef))]
	public sealed class DC_WUltErrata : Card
	{
	}
}
namespace LBoL_Doremy.DoremyChar.SE
{
	public abstract class DC_ExileQueueSE : DStatusEffect
	{
		public const int exileQueuePriority = 12;

		public int maxQDisplay = 13;

		protected override void OnAdded(Unit unit)
		{
			((StatusEffect)this).Count = 0;
		}

		protected string GetQueuedCardsDesc(IEnumerable<Card> queue)
		{
			if (queue.FirstOrDefault() == null)
			{
				return DC_ExileQueueTooltipSE.GetSharedLoc("Nothing");
			}
			string text = string.Join(", ", from c in queue.Take(maxQDisplay)
				select c.ColorName());
			int num = queue.Count();
			if (num > maxQDisplay)
			{
				text += DC_ExileQueueTooltipSE.GetSharedLoc("OverQ", new object[1] { num - maxQDisplay });
			}
			return text;
		}

		protected abstract IEnumerable<Card> UpdateQueueContainer(IEnumerable<Card> queue);

		protected virtual string GetNoTargetCardInBattle()
		{
			return DC_ExileQueueTooltipSE.GetSharedLoc("NotInExile");
		}

		protected virtual void PostProcessCopy(Card copy)
		{
		}

		protected IEnumerable<BattleAction> ProcessQueue(IList<Card> queue)
		{
			if (((StatusEffect)this).Battle.BattleShouldEnd)
			{
				yield break;
			}
			List<Card> bulkCopies = new List<Card>();
			Dictionary<Card, int> potentialRemove = new Dictionary<Card, int>();
			HashSet<int> actuallyToRemove = new HashSet<int>();
			bool moveBroken = false;
			bool copyBroken = false;
			for (int j = 0; j < queue.Count; j++)
			{
				Card card = queue[j];
				if (!card.Config.FindInBattle || card.Config.ToolPlayableTimes.HasValue || ((int)card.CardType == 5 && card.Summoned))
				{
					foreach (BattleAction item in ProcessBulkCopies())
					{
						yield return item;
					}
					if (!moveBroken)
					{
						if (card.Battle != null && (int)card.Zone != 2)
						{
							MoveCardAction moveAction = new MoveCardAction(card, (CardZone)2);
							yield return (BattleAction)(object)moveAction;
							if (((GameEventArgs)((EventBattleAction<CardMovingEventArgs>)(object)moveAction).Args).IsCanceled)
							{
								moveBroken = true;
							}
							else
							{
								PostProcessCopy(((EventBattleAction<CardMovingEventArgs>)(object)moveAction).Args.Card);
								actuallyToRemove.Add(j);
							}
						}
						else
						{
							yield return (BattleAction)(object)PerformAction.Chat(((StatusEffect)this).Owner, string.Format(GetNoTargetCardInBattle(), card.ColorName()), 3f, 0f, 0f, false);
							actuallyToRemove.Add(j);
						}
						UpdateCount(queue, actuallyToRemove.Count);
					}
				}
				else if (!copyBroken)
				{
					Card copy = card.CloneBattleCard();
					copy.IsCopy = false;
					bulkCopies.Add(copy);
					potentialRemove.Add(copy, j);
				}
				if (moveBroken && copyBroken)
				{
					break;
				}
			}
			foreach (BattleAction item2 in ProcessBulkCopies())
			{
				yield return item2;
			}
			UpdateQueueContainer(queue.Where((Card _, int i) => !actuallyToRemove.Contains(i)));
			IEnumerable<BattleAction> ProcessBulkCopies()
			{
				if (bulkCopies.Count > 0 && !copyBroken)
				{
					AddCardsToHandAction addAction = new AddCardsToHandAction((IEnumerable<Card>)bulkCopies, (AddCardsType)0);
					((StatusEffect)this).NotifyActivating();
					yield return (BattleAction)(object)addAction;
					Card[] cards = ((EventBattleAction<CardsEventArgs>)(object)addAction).Args.Cards;
					foreach (Card c in cards)
					{
						PostProcessCopy(c);
						actuallyToRemove.Add(potentialRemove[c]);
					}
					UpdateCount(queue, actuallyToRemove.Count);
					if (!((EventBattleAction<CardsEventArgs>)(object)addAction).Args.Cards.SequenceEqual(bulkCopies))
					{
						copyBroken = true;
					}
					bulkCopies.Clear();
				}
			}
		}

		protected void UpdateCount(ICollection<Card> queue, int toBeRemovedCount = 0)
		{
			((StatusEffect)this).Count = queue.Count - toBeRemovedCount;
			((GameEntity)this).NotifyChanged();
		}
	}
	public sealed class DC_NightmareSEDef : DStatusEffectDef
	{
		public override StatusEffectConfig PreConfig()
		{
			StatusEffectConfig val = DefaultConfig();
			val.Type = (StatusEffectType)2;
			val.HasCount = true;
			val.CountStackType = (StackType)3;
			return val;
		}
	}
	[EntityLogic(typeof(DC_NightmareSEDef))]
	public sealed class DC_NightmareSE : DStatusEffect
	{
		[HarmonyPatch]
		private class MaxHp_Patch
		{
			[HarmonyPatch(typeof(Unit), "SetMaxHp")]
			[HarmonyPostfix]
			private static void EnemyPostfix(Unit __instance)
			{
				CheckNightmare(__instance);
			}

			private static void CheckNightmare(Unit unit)
			{
				DC_NightmareSE dC_NightmareSE = default(DC_NightmareSE);
				if (unit.Battle == null || !unit.TryGetStatusEffect<DC_NightmareSE>(ref dC_NightmareSE))
				{
					return;
				}
				dC_NightmareSE.UpdateOrCreateNightmareBar(((StatusEffect)dC_NightmareSE).Level);
				foreach (BattleAction item in dC_NightmareSE.CheckAndDoKill())
				{
					((StatusEffect)dC_NightmareSE).Battle.RequestDebugAction(item, "Nightmare maxHp check");
				}
			}
		}

		[HarmonyPatch]
		private class UncapCountAndLevel_Patch
		{
			private static IEnumerable<MethodBase> TargetMethods()
			{
				yield return AccessTools.PropertySetter(typeof(StatusEffect), "Count");
				yield return AccessTools.PropertySetter(typeof(StatusEffect), "Level");
				yield return AccessTools.Method(typeof(StatusEffect), "Stack", (Type[])null, (Type[])null);
				yield return AccessTools.Method(typeof(StatusEffect), "ClampMax", (Type[])null, (Type[])null);
			}

			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0003: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Expected O, but got Unknown
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Expected O, but got Unknown
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Expected O, but got Unknown
				CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
				val.Start();
				while (val.IsValid)
				{
					val.MatchEndForward((CodeMatch[])(object)new CodeMatch[1] { CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Ldc_I4, (object)999)) });
					if (val.IsValid)
					{
						val.SetInstruction(new CodeInstruction(OpCodes.Ldc_I4, (object)int.MaxValue));
					}
				}
				return val.InstructionEnumeration();
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private class DeathExplode_DoubleDmgFix_Patch
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
			{
				//IL_0003: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Expected O, but got Unknown
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: Expected O, but got Unknown
				//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bb: Expected O, but got Unknown
				//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d4: Expected O, but got Unknown
				return new CodeMatcher(instructions, (ILGenerator)null).MatchEndForward((CodeMatch[])(object)new CodeMatch[1] { CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Ldstr, (object)"2")) }).MatchEndBackwards((CodeMatch[])(object)new CodeMatch[1] { CodeMatch.op_Implicit(new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.PropertyGetter(typeof(DieEventArgs), "Source"))) }).Advance(1)
					.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
					{
						new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(DeathExplode_DoubleDmgFix_Patch), "CheckSourceType", (Type[])null, (Type[])null))
					})
					.MatchEndForward((CodeMatch[])(object)new CodeMatch[1] { CodeMatch.op_Implicit(OpCodes.Beq) })
					.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
					{
						new CodeInstruction(OpCodes.Pop, (object)null)
					})
					.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
					{
						new CodeInstruction(OpCodes.Ldc_I4_0, (object)null)
					})
					.InstructionEnumeration();
			}

			private static int CheckSourceType(Unit source)
			{
				return (source is EnemyUnit) ? 1 : 0;
			}
		}

		public const int killPriority = int.MaxValue;

		public static readonly string nightmareBarGoName = "NightmareBar";

		private Unit _nightmareSource;

		public Unit NightmareSource
		{
			get
			{
				if (_nightmareSource == null)
				{
					Log.LogWarning(((GameEntity)this).Name + " doesn't have NightmareSource set. Defaulting to PlayerUnit.");
					return (Unit)(object)base.RealBattle.Player;
				}
				return _nightmareSource;
			}
			set
			{
				_nightmareSource = value;
			}
		}

		protected override void OnAdded(Unit unit)
		{
			if (!IsLevelZero())
			{
				((StatusEffect)this).ReactOwnerEvent<DamageEventArgs>(unit.DamageReceived, (EventSequencedReactor<DamageEventArgs>)DamageReceived, (GameEventPriority)int.MaxValue);
				((StatusEffect)this).HandleOwnerEvent<HealEventArgs>(unit.HealingReceived, (GameEventHandler<HealEventArgs>)HealingReceived, (GameEventPriority)int.MaxValue);
				((StatusEffect)this).ReactOwnerEvent<BlockShieldEventArgs>(unit.BlockShieldGained, (EventSequencedReactor<BlockShieldEventArgs>)BlockShieldGained, (GameEventPriority)int.MaxValue);
				((StatusEffect)this).ReactOwnerEvent<BlockShieldEventArgs>(unit.BlockShieldLost, (EventSequencedReactor<BlockShieldEventArgs>)BlockShieldLost, (GameEventPriority)int.MaxValue);
				UpdateOrCreateNightmareBar(((StatusEffect)this).Level);
				((GameEntity)this).React(CheckAndDoKill());
			}
		}

		public void UpdateOrCreateNightmareBar(int targetLevel)
		{
			Unit owner = ((StatusEffect)this).Owner;
			IUnitView obj = ((owner != null) ? owner.View : null);
			UnitView val = (UnitView)(object)((obj is UnitView) ? obj : null);
			if (val == null)
			{
				return;
			}
			UnitStatusWidget statusWidget = val._statusWidget;
			if ((Object)(object)statusWidget == (Object)null)
			{
				return;
			}
			HealthBar hpBar = statusWidget.hpBar;
			if (!((Object)(object)hpBar == (Object)null))
			{
				GameObject gameObject = ((Component)hpBar).gameObject;
				Transform obj2 = gameObject.transform.Find(nightmareBarGoName);
				GameObject val2 = ((obj2 != null) ? ((Component)obj2).gameObject : null);
				if ((Object)(object)val2 == (Object)null)
				{
					val2 = Object.Instantiate<GameObject>(((Component)gameObject.transform.Find("HealthBarHealth")).gameObject, gameObject.transform, true);
					((Object)val2).name = nightmareBarGoName;
					val2.GetComponent<Image>().sprite = AssetManager.DoremyAssets.purpleBar;
				}
				Image component = val2.GetComponent<Image>();
				float num = PrecalculateHpBarFill(hpBar, ((StatusEffect)this).Owner.Hp, ((StatusEffect)this).Owner.MaxHp, ((StatusEffect)this).Owner.Shield, ((StatusEffect)this).Owner.Block);
				component.fillAmount = (float)Math.Clamp(targetLevel, 0, ((StatusEffect)this).Owner.Hp) / (float)((StatusEffect)this).Owner.Hp * num;
			}
		}

		private static float PrecalculateHpBarFill(HealthBar healthBar, int hp, int maxHp, int shield, int block)
		{
			int hp2 = healthBar._hp;
			float num = (float)hp / (float)maxHp;
			float num2 = 0.3f;
			if (1f - num > 0.3f)
			{
				num2 = 1f - num;
			}
			if (1f - num > 0.6f)
			{
				num2 = 0.6f;
			}
			float num3 = num;
			float num4 = 0f;
			float num5 = 0f;
			if (shield + block != 0)
			{
				float num6 = num2 * (float)(shield + block) / ((float)(shield + block) + 20f);
				float num7 = num6 * (float)shield / (float)(shield + block);
				float num8 = num6 * (float)block / (float)(shield + block);
				if (num6 > 1f - num)
				{
					num3 = 1f - num6;
				}
				num4 = num3 + num7;
				num5 = num4 + num8;
			}
			return num3;
		}

		protected override void OnRemoved(Unit unit)
		{
			if (unit.IsAlive)
			{
				UpdateOrCreateNightmareBar(0);
			}
		}

		public override void NotifyChanged()
		{
			((StatusEffect)this).NotifyChanged();
			UpdateOrCreateNightmareBar(((StatusEffect)this).Level);
		}

		public override bool Stack(StatusEffect other)
		{
			bool result = ((StatusEffect)this).Stack(other);
			if (other is DC_NightmareSE dC_NightmareSE)
			{
				NightmareSource = dC_NightmareSE.NightmareSource;
			}
			((GameEntity)this).React(CheckAndDoKill());
			IsLevelZero();
			return result;
		}

		private bool IsLevelZero()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			if (((StatusEffect)this).Level <= 0)
			{
				((GameEntity)this).React(Reactor.op_Implicit((BattleAction)new RemoveStatusEffectAction((StatusEffect)(object)this, true, 0.1f)));
				return true;
			}
			return false;
		}

		public bool CheckKill()
		{
			((StatusEffect)this).Count = Math.Clamp(((StatusEffect)this).Owner.Hp + -((StatusEffect)this).Level, 0, ((StatusEffect)this).Owner.Hp);
			return ((StatusEffect)this).Level >= ((StatusEffect)this).Owner.Hp;
		}

		private IEnumerable<BattleAction> CheckAndDoKill()
		{
			if (CheckKill())
			{
				((StatusEffect)this).NotifyActivating();
				yield return (BattleAction)new ForceKillAction(NightmareSource, ((StatusEffect)this).Owner);
			}
		}

		private void HealingReceived(HealEventArgs args)
		{
			if (((StatusEffect)this).Battle._resolver._reactors == null)
			{
				foreach (BattleAction item in CheckAndDoKill())
				{
					((StatusEffect)this).Battle.RequestDebugAction(item, "Nightmare healing fallback check");
				}
				return;
			}
			((GameEntity)this).React(CheckAndDoKill());
		}

		private IEnumerable<BattleAction> DamageReceived(DamageEventArgs args)
		{
			return CheckAndDoKill();
		}

		private IEnumerable<BattleAction> BlockShieldLost(BlockShieldEventArgs args)
		{
			((GameEntity)this).NotifyChanged();
			yield break;
		}

		private IEnumerable<BattleAction> BlockShieldGained(BlockShieldEventArgs args)
		{
			((GameEntity)this).NotifyChanged();
			yield break;
		}
	}
	public sealed class DoremyExtraDrawSEDef : DStatusEffectDef
	{
		public override StatusEffectConfig PreConfig()
		{
			StatusEffectConfig val = DefaultConfig();
			val.Type = (StatusEffectType)0;
			return val;
		}
	}
	[EntityLogic(typeof(DoremyExtraDrawSEDef))]
	public sealed class DoremyExtraDrawSE : DStatusEffect
	{
		protected override void OnAdded(Unit unit)
		{
			((StatusEffect)this).ReactOwnerEvent<UnitEventArgs>(((Unit)((StatusEffect)this).Battle.Player).TurnStarting, (EventSequencedReactor<UnitEventArgs>)OnTurnStarting, (GameEventPriority)20);
		}

		private IEnumerable<BattleAction> OnTurnStarting(UnitEventArgs args)
		{
			((StatusEffect)this).NotifyActivating();
			yield return (BattleAction)new DrawManyCardAction(((StatusEffect)this).Level);
			yield return (BattleAction)new RemoveStatusEffectAction((StatusEffect)(object)this, true, 0.1f);
		}
	}
}
namespace LBoL_Doremy.DoremyChar.Keywords
{
	public static class DoremyKw
	{
		public const string dreamLayerId = "DC_DreamLayerKeywordSE";

		public const string dLId = "DC_DLKwSE";

		public static CardKeyword NewDreamLayer => new CardKeyword("DC_DreamLayerKeywordSE", false)
		{
			descPos = (KwDescPos)1
		};

		public static DLKeyword NewDLKeyword => new DLKeyword();
	}
	public sealed class DC_DreamLayerKeywordSEDef : DStatusEffectDef
	{
		public override Sprite LoadSprite()
		{
			return null;
		}

		public override StatusEffectConfig PreConfig()
		{
			return DefaultConfig();
		}
	}
	[EntityLogic(typeof(DC_DreamLayerKeywordSEDef))]
	public sealed class DC_DreamLayerKeywordSE : DStatusEffect
	{
	}
	public class DLKeyword : CardKeyword
	{
		private int _dreamLevel = 0;

		public const int maxDL = 10;

		public int DreamLevel
		{
			get
			{
				return _dreamLevel;
			}
			internal set
			{
				_dreamLevel = value;
				_dreamLevel = Math.Clamp(_dreamLevel, 0, 10);
			}
		}

		public DLKeyword(string kwSEid = "DC_DLKwSE", bool isVerbose = false)
			: base(kwSEid, isVerbose)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			base.descPos = (KwDescPos)0;
		}

		[return: MaybeNull]
		public override CardKeyword Clone(CloningMethod cloningMethod)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//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_001b: Expected I4, but got Unknown
			switch ((int)cloningMethod)
			{
			case 0:
			case 2:
			case 3:
			{
				DLKeyword newDLKeyword = DoremyKw.NewDLKeyword;
				newDLKeyword.DreamLevel = DreamLevel;
				return (CardKeyword)(object)newDLKeyword;
			}
			default:
				return null;
			}
		}

		public override void Merge(CardKeyword other)
		{
			if (other is DLKeyword dLKeyword && dLKeyword.DreamLevel > DreamLevel)
			{
				DreamLevel = dLKeyword.DreamLevel;
			}
		}
	}
	public sealed class DC_DLKwSEDef : DStatusEffectDef
	{
		public override Sprite LoadSprite()
		{
			return null;
		}

		public override StatusEffectConfig PreConfig()
		{
			StatusEffectConfig val = DefaultConfig();
			val.RelativeEffects = new List<string> { "DC_SelfNightmareTooltipSE" };
			return val;
		}
	}
	[EntityLogic(typeof(DC_DLKwSEDef))]
	public sealed class DC_DLKwSE : DStatusEffect
	{
		private int dlLevel = 0;

		public string DLMulDesc => 10f.ToString();

		public override string Name => RuntimeFormatterExtensions.RuntimeFormat(((StatusEffect)this).Name, ((GameEntity)this).FormatWrapper);

		public void OnTooltipDisplay(Card card)
		{
			DLKeyword dLKeyword = default(DLKeyword);
			if (KeywordManager.TryGetCustomKeyword<DLKeyword>(card, "DC_DLKwSE", ref dLKeyword))
			{
				dlLevel = dLKeyword.DreamLevel;
			}
		}
	}
	public sealed class DC_SelfNightmareTooltipSEDef : DStatusEffectDef
	{
		public override Sprite LoadSprite()
		{
			return null;
		}

		public override StatusEffectConfig PreConfig()
		{
			return DefaultConfig();
		}
	}
	[EntityLogic(typeof(DC_SelfNightmareTooltipSEDef))]
	public sealed class DC_SelfNightmareTooltipSE : DStatusEffect
	{
	}
	public sealed class DC_CreatedTooltipSEDef : DStatusEffectDef
	{
		public override Sprite LoadSprite()
		{
			return null;
		}

		public override StatusEffectConfig PreConfig()
		{
			return DefaultConfig();
		}
	}
	[EntityLogic(typeof(DC_CreatedTooltipSEDef))]
	public sealed class DC_CreatedTooltipSE : DStatusEffect
	{
	}
	public sealed class DC_ExileQueueTooltipSEDef : DStatusEffectDef
	{
		public override Sprite LoadSprite()
		{
			return null;
		}

		public override StatusEffectConfig PreConfig()
		{
			return DefaultConfig();
		}
	}
	[EntityLogic(typeof(DC_ExileQueueTooltipSEDef))]
	public sealed class DC_ExileQueueTooltipSE : DStatusEffect
	{
		public static string GetSharedLoc(string key, object[] toFormat = null)
		{
			string text = TypeFactory<StatusEffect>.LocalizeProperty("DC_ExileQueueTooltipSE", key, true, true);
			if (text == null)
			{
				return "";
			}
			if (toFormat != null)
			{
				text = string.Format(text, toFormat);
			}
			return text;
		}
	}
	public sealed class DC_VanillaExTooltipSEDef : DStatusEffectDef
	{
		public override Sprite LoadSprite()
		{
			return null;
		}

		public override StatusEffectConfig PreConfig()
		{
			return DefaultConfig();
		}
	}
	[EntityLogic(typeof(DC_VanillaExTooltipSEDef))]
	public sealed class DC_VanillaExTooltipSE : DStatusEffect
	{
		public override string Name => RuntimeFormatterExtensions.RuntimeFormat(StringDecorator.Decorate(((StatusEffect)this).Name), ((GameEntity)this).FormatWrapper);
	}
}
namespace LBoL_Doremy.DoremyChar.Exhibits
{
	public sealed class DoremyCavalierUExDef : DExhibitDef
	{
		public override ExhibitSprites LoadSprite()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			ExhibitSprites val = base.LoadSprite();
			val.customSprites.Add("Inactive", ResourceLoader.LoadSprite("Inactive" + IdContainer.op_Implicit(((EntityDefinition)this).GetId()) + ".png", Sources.exAndBomb, (Rect?)null, 1, (Vector2?)null));
			return val;
		}

		public override ExhibitConfig MakeConfig()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			return new ExhibitConfig(0, "", 10, false, false, false, false, (AppearanceType)0, "Doremy", (ExhibitLosableType)1, (Rarity)3, (int?)4, (int?)null, (int?)null, (ManaGroup?)null, (ManaColor?)null, (ManaColor?)(ManaColor)2, 1, false, (int?)null, (Keyword)1024, (IReadOnlyList<string>)new List<string> { "DC_CreatedTooltipSE" }, (IReadOnlyList<string>)new List<string>());
		}
	}
	[EntityLogic(typeof(DoremyCavalierUExDef))]
	public sealed class DoremyCavalierUEx : ShiningExhibit
	{
		private bool _isActive = true;

		public override string OverrideIconName
		{
			get
			{
				if (IsActive)
				{
					return ((GameEntity)this).Id;
				}
				return ((GameEntity)this).Id + "Inactive";
			}
		}

		public bool IsActive
		{
			get
			{
				return _isActive;
			}
			private set
			{
				_isActive = value;
				((GameEntity)this).NotifyChanged();
			}
		}

		protected override void OnEnterBattle()
		{
			((Exhibit)this).ReactBattleEvent<UnitEventArgs>(((Unit)((Exhibit)this).Owner).TurnEnding, (EventSequencedReactor<UnitEventArgs>)OnTurnEnding);
			((Exhibit)this).HandleBattleEvent<UnitEventArgs>(((Unit)((Exhibit)this).Owner).TurnStarted, (GameEventHandler<UnitEventArgs>)OnTurnStarted, (GameEventPriority)(-199));
			((Exhibit)this).HandleBattleEvent<CardUsingEventArgs>(((Exhibit)this).Battle.CardUsed, (GameEventHandler<CardUsingEventArgs>)OnCardUsed);
			((Exhibit)this).HandleBattleEvent<CardUsingEventArgs>(((Exhibit)this).Battle.CardPlayed, (GameEventHandler<CardUsingEventArgs>)OnCardUsed);
		}

		private void OnTurnStarted(UnitEventArgs args)
		{
			IsActive = true;
		}

		private void OnCardUsed(CardUsingEventArgs args)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Invalid comparison between Unknown and I4
			Card card = args.Card;
			if (card != null && (int)card.CardType == 1)
			{
				IsActive = false;
				((GameEntity)this).NotifyChanged();
			}
		}

		protected override void OnLeaveBattle()
		{
			IsActive = false;
		}

		private IEnumerable<BattleAction> OnTurnEnding(UnitEventArgs args)
		{
			if (IsActive)
			{
				((Exhibit)this).NotifyActivating();
				yield return (BattleAction)new CastBlockShieldAction((Unit)(object)((Exhibit)this).Owner, 0, ((Exhibit)this).Value1, (BlockShieldType)2, true);
			}
		}
	}
	public sealed class DoremyCavalierWExDef : DExhibitDef
	{
		public override ExhibitSprites LoadSprite()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			ExhibitSprites val = base.LoadSprite();
			val.customSprites.Add("Inactive", ResourceLoader.LoadSprite("Inactive" + IdContainer.op_Implicit(((EntityDefinition)this).GetId()) + ".png", Sources.exAndBomb, (Rect?)null, 1, (Vector2?)null));
			return val;
		}

		public override ExhibitConfig MakeConfig()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			return new ExhibitConfig(0, "", 10, false, false, false, false, (AppearanceType)0, "Doremy", (ExhibitLosableType)1, (Rarity)3, (int?)null, (int?)null, (int?)null, (ManaGroup?)ManaGroup.Empty, (ManaColor?)null, (ManaColor?)(ManaColor)1, 1, false, (int?)null, (Keyword)1099511627776L, (IReadOnlyList<string>)new List<string> { "DC_CreatedTooltipSE" }, (IReadOnlyList<string>)new List<string>());
		}
	}
	[EntityLogic(typeof(DoremyCavalierWExDef))]
	public sealed class DoremyCavalierWEx : ShiningExhibit
	{
		private bool _isActive = true;

		public override string OverrideIconName
		{
			get
			{
				if (IsActive)
				{
					return ((GameEntity)this).Id;
				}
				return ((GameEntity)this).Id + "Inactive";
			}
		}

		public bool IsActive
		{
			get
			{
				return _isActive;
			}
			private set
			{
				_isActive = value;
				((GameEntity)this).NotifyChanged();
			}
		}

		protected override void OnEnterBattle()
		{
			IsActive = true;
			((Exhibit)this).ReactBattleEvent<CardsEventArgs>(((Exhibit)this).Battle.CardsAddedToDiscard, (EventSequencedReactor<CardsEventArgs>)OnOtherAdded);
			((Exhibit)this).ReactBattleEvent<CardsAddingToDrawZoneEventArgs>(((Exhibit)this).Battle.CardsAddedToDrawZone, (EventSequencedReactor<CardsAddingToDrawZoneEventArgs>)OnDrawZoneAdded);
			((Exhibit)this).ReactBattleEvent<CardsEventArgs>(((Exhibit)this).Battle.CardsAddedToExile, (EventSequencedReactor<CardsEventArgs>)OnOtherAdded);
			((Exhibit)this).ReactBattleEvent<CardsEventArgs>(((Exhibit)this).Battle.CardsAddedToHand, (EventSequencedReactor<CardsEventArgs>)OnOtherAdded);
		}

		protected override void OnLeaveBattle()
		{
			IsActive = true;
		}

		private IEnumerable<BattleAction> DoDiscount(IEnumerable<Card> cards, GameEventArgs args)
		{
			if (IsActive && cards.FirstOrDefault() != null && args.ActionSource.TrickleDownActionSource() is Card)
			{
				((Exhibit)this).NotifyActivating();
				IsActive = false;
				cards.First().SetTurnCost(((Exhibit)this).Mana);
			}
			yield break;
		}

		private IEnumerable<BattleAction> OnDrawZoneAdded(CardsAddingToDrawZoneEventArgs args)
		{
			return DoDiscount(args.Cards, (GameEventArgs)(object)args);
		}

		private IEnumerable<BattleAction> OnOtherAdded(CardsEventArgs args)
		{
			return DoDiscount(args.Cards, (GameEventArgs)(object)args);
		}
	}
}
namespace LBoL_Doremy.DoremyChar.DreamManagers
{
	internal static class DreamLayerHandlers
	{
		[HarmonyPatch]
		internal class BoostCardWidgetPatch
		{
			public const string DLGoName = "DLStackTracker";

			private static IEnumerable<MethodBase> TargetMethods()
			{
				yield return AccessTools.Method(typeof(CardWidget), "SetProperties", (Type[])null, (Type[])null);
				yield return AccessTools.Method(typeof(CardWidget), "LazySetCard", (Type[])null, (Type[])null);
			}

			private static void Postfix(CardWidget __instance)
			{
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_0094: Unknown result type (might be due to invalid IL or missing references)
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				Transform obj = __instance.baseLoyaltyObj.transform.parent.Find("DLStackTracker");
				GameObject val = ((obj != null) ? ((Component)obj).gameObject : null);
				DLKeyword dLKeyword = default(DLKeyword);
				if (KeywordManager.TryGetCustomKeyword<DLKeyword>(__instance._card, "DC_DLKwSE", ref dLKeyword))
				{
					if ((Object)(object)val == (Object)null)
					{
						val = Object.Instantiate<GameObject>(__instance.baseLoyaltyObj, __instance.baseLoyaltyObj.transform.parent, true);
						((Object)val).name = "DLStackTracker";
						Transform transform = val.transform;
						transform.localPosition += new Vector3(0f, 95f, 0f);
					}
					Image component = val.GetComponent<Image>();
					if (__instance._card.IsDLCorrupted())
					{
						component.sprite = AssetManager.DoremyAssets.dlCorruptedIcon;
					}
					else
					{
						component.sprite = AssetManager.DoremyAssets.dlTrackerIcon;
					}
					TextMeshProUGUI component2 = ((Component)val.transform.Find("BaseLoyaltyText")).gameObject.GetComponent<TextMeshProUGUI>();
					((TMP_Text)component2).text = dLKeyword.DreamLevel.ToString();
					val.SetActive(true);
				}
				else if ((Object)(object)val != (Object)null)
				{
					val.SetActive(false);
				}
			}
		}

		public static int bouncePriority = 10;

		public static GameEvent<UnitEventArgs> GetBounceEvent(BattleController battle)
		{
			return ((Unit)battle.Player).TurnEnding;
		}

		public static void RegisterHandlers()
		{
			CHandlerManager.RegisterBattleEventHandler<UnitEventArgs>((EventProvider<UnitEventArgs, BattleController>)((BattleController b) => GetBounceEvent(b)), (GameEventHandler<UnitEventArgs>)OnPlayerTurnEnd, (Predicate<BattleController>)null, (GameEventPriority)bouncePriority);
			CHandlerManager.RegisterBattleEventHandler<DamageDealingEventArgs>((EventProvider<DamageDealingEventArgs, BattleController>)((BattleController b) => ((Unit)b.Player).DamageDealing), (GameEventHandler<DamageDealingEventArgs>)OnDmgDealing, (Predicate<BattleController>)null, (GameEventPriority)20);
			CHandlerManager.RegisterBattleEventHandler<BlockShieldEventArgs>((EventProvider<BlockShieldEventArgs, BattleController>)((BattleController b) => ((Unit)b.Player).BlockShieldCasting), (GameEventHandler<BlockShieldEventArgs>)OnSBGaining, (Predicate<BattleController>)null, (GameEventPriority)20);
			CHandlerManager.RegisterBattleEventHandler<NightmareArgs>((EventProvider<NightmareArgs, BattleController>)((BattleController b) => EventManager.GetDoremyEvents(b).nightmareEvents.nigtmareApplying), (GameEventHandler<NightmareArgs>)OnNMApplying, (Predicate<BattleController>)null, (GameEventPriority)20);
			CHandlerManager.RegisterBattleEventHandler<CardUsingEventArgs>((EventProvider<CardUsingEventArgs, BattleController>)((BattleController b) => b.CardUsed), (GameEventHandler<CardUsingEventArgs>)OnCardUsed, (Predicate<BattleController>)null, (GameEventPriority)(-999));
			CHandlerManager.RegisterBattleEventHandler<CardUsingEventArgs>((EventProvider<CardUsingEventArgs, BattleController>)((BattleController b) => b.CardPlayed), (GameEventHandler<CardUsingEventArgs>)OnCardUsed, (Predicate<BattleController>)null, (GameEventPriority)(-999));
		}

		public static bool IsDLCorrupted(this Card card)
		{
			return card.IsCopy;
		}

		public static NightmareInfo SelfNM2Apply(int dlLevel)
		{
			return new NightmareInfo(dlLevel, isSelfNightmare: true);
		}

		private static void OnCardUsed(CardUsingEventArgs args)
		{
			CorruptedDLPenalty(args.Card);
		}

		public static void CorruptedDLPenalty(Card card, int levelCap = int.MaxValue)
		{
			BattleController battle = EventManager.Battle;
			DLKeyword dLKeyword = default(DLKeyword);
			if (!battle.BattleShouldEnd && card.IsDLCorrupted() && KeywordManager.TryGetCustomKeyword<DLKeyword>(card, "DC_DLKwSE", ref dLKeyword))
			{
				NightmareInfo level = SelfNM2Apply(Math.Min(dLKeyword.DreamLevel, levelCap));
				if (level.toApply > 0f)
				{
					battle.React(Reactor.op_Implicit((BattleAction)(object)new NightmareAction((Unit)(object)battle.Player, (Unit)(object)battle.Player, level, 0.015f)), (GameEntity)(object)card, (ActionCause)1);
				}
			}
		}

		private static float BoostMultiplier(int dreamLevel)
		{
			return 1f + EventManager.DoremyEvents.DLperLevelMult * (float)dreamLevel;
		}

		private static void OnNMApplying(NightmareArgs args)
		{
			GameEntity actionSource = ((GameEventArgs)args).ActionSource;
			Card val = (Card)(object)((actionSource is Card) ? actionSource : null);
			DLKeyword dLKeyword = default(DLKeyword);
			if (val != null && !args.isSelfNightmare && KeywordManager.TryGetCustomKeyword<DLKeyword>(val, "DC_DLKwSE", ref dLKeyword))
			{
				args.level = (float)args.level * BoostMultiplier(dLKeyword.DreamLevel);
				((GameEventArgs)args).AddModifier((GameEntity)(object)val);
			}
		}

		private static void OnSBGaining(BlockShieldEventArgs args)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			if ((int)args.Type == 1)
			{
				GameEntity actionSource = ((GameEventArgs)args).ActionSource;
				Card val = (Card)(object)((actionSource is Card) ? actionSource : null);
				DLKeyword dLKeyword = default(DLKeyword);
				if (val != null && KeywordManager.TryGetCustomKeyword<DLKeyword>(val, "DC_DLKwSE", ref dLKeyword))
				{
					args.Block *= BoostMultiplier(dLKeyword.DreamLevel);
					args.Shield *= BoostMultiplier(dLKeyword.DreamLevel);
					((GameEventArgs)args).AddModifier((GameEntity)(object)val);
				}
			}
		}

		private static void OnDmgDealing(DamageDealingEventArgs args)
		{
			//IL_0002: 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_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			DamageInfo damageInfo = args.DamageInfo;
			if ((int)((DamageInfo)(ref damageInfo)).DamageType == 2)
			{
				GameEntity actionSource = ((GameEventArgs)args).ActionSource;
				Card val = (Card)(object)((actionSource is Card) ? actionSource : null);
				DLKeyword dLKeyword = default(DLKeyword);
				if (val != null && KeywordManager.TryGetCustomKeyword<DLKeyword>(val, "DC_DLKwSE", ref dLKeyword))
				{
					DamageInfo damageInfo2 = args.DamageInfo;
					damageInfo = args.DamageInfo;
					((DamageInfo)(ref damageInfo2)).Damage = ((DamageInfo)(ref damageInfo)).Amount * BoostMultiplier(dLKeyword.DreamLevel);
					args.DamageInfo = damageInfo2;
					((GameEventArgs)args).AddModifier((GameEntity)(object)val);
				}
			}
		}

		private static void OnPlayerTurnEnd(UnitEventArgs args)
		{
			//IL_007e: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			GameMaster instance = Singleton<GameMaster>.Instance;
			object obj;
			if (instance == null)
			{
				obj = null;
			}
			else
			{
				GameRunController currentGameRun = instance.CurrentGameRun;
				obj = ((currentGameRun != null) ? currentGameRun.Battle : null);
			}
			BattleController val = (BattleController)obj;
			if (val == null)
			{
				return;
			}
			foreach (Card item in val.HandZone.Where((Card c) => KeywordManager.HasCustomKeyword(c, "DC_DreamLayerKeywordSE")))
			{
				val.React(Reactor.op_Implicit((BattleAction)(object)new ApplyDLAction(item, isEndOfTurnBounce: true)), (GameEntity)(object)item, (ActionCause)1);
				DrawZoneTarget val2 = (DrawZoneTarget)2;
				val.React(Reactor.op_Implicit((BattleAction)new MoveCardToDrawZoneAction(item, val2)), (GameEntity)(object)item, (ActionCause)1);
			}
		}
	}
	public class NaturalDreamLayerCard : DCard
	{
		private static HashSet<string> allDreamLayerCards;

		protected int DreamLevel => KeywordManager.GetCustomKeyword<DLKeyword>((Card)(object)this, "DC_DLKwSE").DreamLevel;

		public static HashSet<string> AllDreamLayerCards
		{
			get
			{
				if (allDreamLayerCards == null)
				{
					allDreamLayerCards = new HashSet<string>();
					Assembly assembly = typeof(NaturalDreamLayerCard).Assembly;
					CollectionExtensions.Do<string>(from t in assembly.ExportedTypes
						where t.IsSubclassOf(typeof(NaturalDreamLayerCard))
						select t.Name, (Action<string>)delegate(string id)
					{
						allDreamLayerCards.Add(id);
					});
				}
				return allDreamLayerCards;
			}
		}

		public override void Initialize()
		{
			base.Initialize();
			KeywordManager.AddCustomKeyword((Card)(object)this, DoremyKw.NewDreamLayer);
			KeywordManager.AddCustomKeyword<DLKeyword>((Card)(object)this, DoremyKw.NewDLKeyword);
		}

		public virtual void OnDLChanged(DreamLevelArgs args)
		{
		}
	}
}
namespace LBoL_Doremy.DoremyChar.DoremyPU
{
	public sealed class DoremyCavalierDef : DPlayerDef
	{
		public static List<ManaColor> offColors = new List<ManaColor>
		{
			(ManaColor)4,
			(ManaColor)3,
			(ManaColor)5,
			(ManaColor)6
		};

		public const string Name = "Doremy";

		public const string Color = "#b24ac4";

		public override IdContainer GetId()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			return IdContainer.op_Implicit(((EntityDefinition)(object)this).SelfId());
		}

		public override LocalizationOption LoadLocalization()
		{
			return (LocalizationOption)(object)Loc.PlayerUnitBatchLoc.AddEntity((EntityDefinition)(object)this);
		}

		public override PlayerImages LoadPlayerImages()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			PlayerImages val = new PlayerImages();
			val.AutoLoad("Doremy", (Func<string, Sprite>)((string s) => ResourceLoader.LoadSprite(s, (IResourceSource)(object)Sources.playerImgsSource, 100, 1, (FilterMode)1, true, (Rect?)null, (Vector2?)null)), (Func<string, UniTask<Sprite>>)((string s) => ResourceLoader.LoadSpriteAsync(s, Sources.playerImgsSource, 100, (GraphicsFormat)4, 1, (FilterMode)1, (SpriteMeshType)1, (Rect?)null, (Vector2?)null, "file://")), (UseSame)2, ".png", "");
			return val;
		}

		public override PlayerUnitConfig MakeConfig()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			int? num = 0;
			ManaGroup val = default(ManaGroup);
			((ManaGroup)(ref val)).White = 2;
			((ManaGroup)(ref val)).Blue = 2;
			return new PlayerUnitConfig("", 0, 0, num, "DoremyCavalier", "#b24ac4", true, 70, val, 100, 0, "DoremyCavalierWUlt", "DoremyCavalierUUlt", "DoremyCavalierWEx", "DoremyCavalierUEx", (IReadOnlyList<string>)new string[10] { "Shoot", "Shoot", "Boundary", "Boundary", "DoremyCavalierAttackW", "DoremyCavalierAttackW", "DoremyCavalierDefenseU", "DoremyCavalierDefenseU", "DoremyCavalierDefenseU", "DoremySleepyStrikes" }, (IReadOnlyList<string>)new string[10] { "Shoot", "Shoot", "Boundary", "Boundary", "DoremyCavalierAttackU", "DoremyCavalierAttackU", "DoremyCavalierDefenseW", "DoremyCavalierDefenseW", "DoremyCavalierDefenseW", "DoremyDreamblast" }, 3, 2);
		}
	}
	[EntityLogic(typeof(DoremyCavalierDef))]
	public sealed class DoremyCavalier : DPlayer
	{
		private int shouldSleep = 0;

		public int ShouldSleep
		{
			get
			{
				return shouldSleep;
			}
			set
			{
				shouldSleep = value;
				shouldSleep = Math.Max(0, shouldSleep);
			}
		}

		protected override void OnLeaveBattle()
		{
			shouldSleep = 0;
		}

		public void SetSleepAnim(bool enable)
		{
			IUnitView obj = ((this != null) ? ((Unit)this).View : null);
			UnitView val = (UnitView)(object)((obj is UnitView) ? obj : null);
			ShouldSleep += (enable ? 1 : (-1));
			bool flag = ShouldSleep > 0;
			if (!((Object)(object)val != (Object)null) || !(val._modelName == "DoremyCavalier"))
			{
				return;
			}
			val.DoremySleeping = flag;
			if (flag)
			{
				val._blinking = false;
				{
					foreach (AnimationState allState in val.AllStates)
					{
						TrackEntry val2 = ((IEnumerable<TrackEntry>)allState.Tracks).FirstOrDefault((Func<TrackEntry, bool>)delegate(TrackEntry t)
						{
							object obj2;
							if (t == null)
							{
								obj2 = null;
							}
							else
							{
								Animation animation = t.Animation;
								obj2 = ((animation != null) ? animation.Name : null);
							}
							return (string?)obj2 == "blink";
						});
						if (val2 != null)
						{
							allState.SetEmptyAnimation(val2.TrackIndex, 0f);
						}
					}
					return;
				}
			}
			val.Blink();
		}
	}
	public sealed class DoremyCavalierModel : UnitModelTemplate
	{
		public override IdContainer GetId()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return IdContainer.op_Implicit("DoremyCavalier");
		}

		public override LocalizationOption LoadLocalization()
		{
			return (LocalizationOption)(object)Loc.UnitModelBatchLoc.AddEntity((EntityDefinition)(object)this);
		}

		public override ModelOption LoadModelOptions()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			return new ModelOption(ResourcesHelper.LoadSpineUnitAsync("Doremy"));
		}

		public override UniTask<Sprite> LoadSpellSprite()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			return ResourceLoader.LoadSpriteAsync("DoremyStand.png", Sources.playerImgsSource, 1000, (GraphicsFormat)4, 1, (FilterMode)1, (SpriteMeshType)1, (Rect?)null, (Vector2?)null, "file://");
		}

		public override UnitModelConfig MakeConfig()
		{
			return ObjectExtensions.Copy<UnitModelConfig>(UnitModelConfig.FromName("Doremy"));
		}
	}
}
namespace LBoL_Doremy.DoremyChar.Cards.Uncommon
{
	public sealed class DoremyBorderofDreamsDef : DCardDef
	{
		public override CardConfig PreConfig()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			CardConfig val = DefaultConfig();
			val.Rarity = (Rarity)1;
			val.Type = (CardType)4;
			val.TargetType = (TargetType)4;
			val.Colors = new List<ManaColor> { (ManaColor)2 };
			ManaGroup val2 = default(ManaGroup);
			((ManaGroup)(ref val2)).Blue = 1;
			((ManaGroup)(ref val2)).Any = 2;
			val.Cost = val2;
			val2 = default(ManaGroup);
			((ManaGroup)(ref val2)).Blue = 1;
			((ManaGroup)(ref val2)).Any = 1;
			val.UpgradedCost = val2;
			val.Value1 = 3;
			val.UpgradedValue1 = 4;
			val.RelativeEffects = new List<string> { "DC_DLKwSE" };
			val.UpgradedRelativeEffects = new List<string> { "DC_DLKwSE" };
			val.Illustrator = "kimmchu!";
			return val;
		}
	}
	[EntityLogi