Decompiled source of Assassin Thuls v1.0.4

BepInEx/plugins/com.shazixnar.AssassinThulsTraits.dll

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

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.shazixnar.AssassinThulsTraits")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("assassin thuls, made by Shazixnar")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4+2e76defea53bcf303a7b5c74f40b810024311bd6")]
[assembly: AssemblyProduct("Assassin Thuls")]
[assembly: AssemblyTitle("com.shazixnar.AssassinThulsTraits")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TraitMod
{
	[HarmonyPatch]
	internal class Traits
	{
		[HarmonyPatch(typeof(Trait), "DoTrait")]
		public static class Trait_DoTrait_Patch
		{
			[HarmonyPrefix]
			public static bool Prefix(EventActivation __0, string __1, Character __2, Character __3, int __4, string __5, CardData __6, Trait __instance)
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				if (myTraitList.Contains(__1))
				{
					myDoTrait(__1, __0, __2, __3, __4, __5, __6);
					return false;
				}
				return true;
			}
		}

		public static string[] myTraitList = new string[4] { "shazixnarnightstalker", "shazixnarsilentfang", "shazixnarvenomousshade", "shazixnarvenomshadow" };

		private static readonly Traits _instance = new Traits();

		public static CardData currentCard;

		public static Dictionary<string, int> stealthUsesThisTurn = new Dictionary<string, int>();

		public static HashSet<string> shadowExecutionUsed = new HashSet<string>();

		public static void myDoTrait(string trait, EventActivation evt, Character character, Character target, int auxInt, string auxString, CardData castedCard)
		{
			//IL_0040: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			switch (trait)
			{
			case "shazixnarnightstalker":
				_instance.shazixnarnightstalker(evt, character, target, auxInt, auxString, castedCard, trait);
				break;
			case "shazixnarsilentfang":
				_instance.shazixnarsilentfang(evt, character, target, auxInt, auxString, castedCard, trait);
				break;
			case "shazixnarvenomousshade":
				_instance.shazixnarvenomousshade(evt, character, target, auxInt, auxString, castedCard, trait);
				break;
			case "shazixnarvenomshadow":
				_instance.shazixnarvenomshadow(evt, character, target, auxInt, auxString, castedCard, trait);
				break;
			}
		}

		public void shazixnarnightstalker(EventActivation evt, Character character, Character target, int auxInt, string auxString, CardData castedCard, string trait)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Invalid comparison between Unknown and I4
			if (character == null)
			{
				return;
			}
			if ((int)evt == 1)
			{
				character.SetAuraTrait(character, "stealth", 2);
				int num = 2;
				if (character.HaveTrait("shazixnarvenomousshade"))
				{
					num += 2;
				}
				if (character.HaveTrait("shazixnarshadowexecution"))
				{
					num += 2;
				}
				MatchManager.Instance.activatedTraits[trait] = 0;
				if ((Object)(object)character.HeroItem != (Object)null)
				{
					((CharacterItem)character.HeroItem).ScrollCombatText(Texts.Instance.GetText("traits_shazixnarnightstalker", "") + Functions.TextChargesLeft(0, num), (CombatScrollEffectType)7);
					EffectsManager.Instance.PlayEffectAC("stealth", true, ((CharacterItem)character.HeroItem).CharImageT, false, 0f, false);
				}
				MatchManager.Instance.SetTraitInfoText();
			}
			else
			{
				if ((int)evt != 7 || !((Object)(object)castedCard != (Object)null))
				{
					return;
				}
				bool flag = castedCard.HasCardType((CardType)16);
				bool flag2 = castedCard.HasCardType((CardType)28);
				if (!(flag || flag2))
				{
					return;
				}
				int num2 = MatchManager.Instance.activatedTraits[trait];
				int timesPerTurn = Globals.Instance.GetTraitData(trait).TimesPerTurn;
				if (num2 < timesPerTurn)
				{
					MatchManager.Instance.activatedTraits[trait] = num2 + 1;
					HeroItem heroItem = character.HeroItem;
					if (heroItem != null)
					{
						((CharacterItem)heroItem).ScrollCombatText(Texts.Instance.GetText("traits_shazixnarnightstalker", "") + Functions.TextChargesLeft(num2 + 1, timesPerTurn), (CombatScrollEffectType)7);
					}
					MatchManager.Instance.SetTraitInfoText();
				}
			}
		}

		public void shazixnarsilentfang(EventActivation evt, Character character, Character target, int auxInt, string auxString, CardData card, string trait)
		{
			if (character == null || (Object)(object)card == (Object)null || !card.GetCardTypes().Contains((CardType)14) || (Object)(object)character.HeroData == (Object)null)
			{
				return;
			}
			TraitData traitData = Globals.Instance.GetTraitData(trait);
			int num = 6;
			if (character.HaveTrait("shazixnarvenomshadow"))
			{
				num += 2;
			}
			Globals.Instance.GetTraitData("shazixnarsilentfang").TimesPerTurn = num;
			int num2 = 0;
			if (MatchManager.Instance.activatedTraits.ContainsKey(trait))
			{
				num2 = MatchManager.Instance.activatedTraits[trait];
			}
			if (num2 < num)
			{
				MatchManager.Instance.activatedTraits[trait] = num2 + 1;
				float num3 = (character.HaveTrait("shazixnarvenomshadow") ? 0.9f : 0.95f);
				string text = ((Random.value < num3) ? "silentfangnick" : "silentfangnickrare");
				MatchManager.Instance.GenerateNewCard(1, text, true, (CardPlace)5, (CardData)null, (CardData)null, -1, true, 0, (CopyConfig)null);
				HeroItem heroItem = character.HeroItem;
				if (heroItem != null)
				{
					((CharacterItem)heroItem).ScrollCombatText(Texts.Instance.GetText("traits_shazixnarsilentfang", "") + Functions.TextChargesLeft(num2 + 1, num), (CombatScrollEffectType)7);
				}
				MatchManager.Instance.SetTraitInfoText();
				MatchManager.Instance.ItemTraitActivated(true);
				MatchManager.Instance.CreateLogCardModification(text, MatchManager.Instance.GetHero(character.HeroIndex));
			}
		}

		public void shazixnarvenomousshade(EventActivation evt, Character character, Character target, int auxInt, string auxString, CardData card, string trait)
		{
			if (character == null || auxString != "stealth")
			{
				return;
			}
			NPC[] teamNPC = MatchManager.Instance.GetTeamNPC();
			NPC[] array = teamNPC;
			foreach (NPC val in array)
			{
				if (val != null && ((Character)val).Alive)
				{
					((Character)val).SetAuraTrait(character, "poison", 5);
				}
			}
			HeroItem heroItem = character.HeroItem;
			if (heroItem != null)
			{
				((CharacterItem)heroItem).ScrollCombatText(Texts.Instance.GetText("traits_shazixnarvenomousshade", ""), (CombatScrollEffectType)7);
			}
		}

		public void shazixnarvenomshadow(EventActivation evt, Character character, Character target, int auxInt, string auxString, CardData card, string trait)
		{
			if (character != null && target != null && target.Alive)
			{
				target.SetAuraTrait(character, "poison", 1);
				HeroItem heroItem = character.HeroItem;
				if (heroItem != null)
				{
					((CharacterItem)heroItem).ScrollCombatText(Texts.Instance.GetText("traits_shazixnarvenomousshadow", ""), (CombatScrollEffectType)7);
				}
			}
		}

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

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AtOManager), "GlobalAuraCurseModificationByTraitsAndItems")]
		public static void GlobalAuraCurseModificationByTraitsAndItemsPostfix(ref AtOManager __instance, ref AuraCurseData __result, string _type, string _acId, Character _characterCaster, Character _characterTarget)
		{
			bool flag = false;
			bool flag2 = false;
			if (_characterCaster != null && _characterCaster.IsHero)
			{
				flag = _characterCaster.IsHero;
			}
			if (_characterTarget != null && _characterTarget.IsHero)
			{
				flag2 = true;
			}
			if (!(_acId == "poison"))
			{
				return;
			}
			if (_type == "set")
			{
				if (!flag2)
				{
					if (__instance.TeamHaveTrait("shazixnarsilentfang"))
					{
						__result.DamageWhenConsumedPerCharge = 0.5f;
						__result.ConsumedAtTurnBegin = true;
					}
					if (__instance.TeamHaveTrait("shazixnarvenomousshade"))
					{
						__result.ResistModifiedPercentagePerStack = -0.3f;
						__result.ResistModified = (DamageType)10;
						__result.DamageWhenConsumedPerCharge = 0f;
						__result.ConsumedAtTurn = false;
					}
					if (__instance.TeamHaveTrait("shazixnarvenomshadow"))
					{
						__result.IncreasedDamageReceivedType = (DamageType)10;
						__result.IncreasedDirectDamageReceivedPerStack = 0.1f;
					}
				}
			}
			else if (_type == "consume" && !flag)
			{
				if (__instance.TeamHaveTrait("shazixnarsilentfang"))
				{
					__result.DamageWhenConsumedPerCharge = 0.5f;
					__result.ConsumedAtTurnBegin = true;
				}
				if (__instance.TeamHaveTrait("shazixnarvenomousshade"))
				{
					__result.ResistModifiedPercentagePerStack = -0.3f;
					__result.ResistModified = (DamageType)10;
					__result.DamageWhenConsumedPerCharge = 0f;
					__result.ConsumedAtTurn = false;
				}
				if (__instance.TeamHaveTrait("shazixnarvenomshadow"))
				{
					__result.IncreasedDamageReceivedType = (DamageType)10;
					__result.IncreasedDirectDamageReceivedPerStack = 0.1f;
				}
			}
		}

		[HarmonyPatch(typeof(MatchManager), "CastCard")]
		[HarmonyPrefix]
		public static void CastCard_Prefix(ref CardItem theCardItem, ref CardData _card)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Invalid comparison between Unknown and I4
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			CardData val = (((Object)(object)theCardItem != (Object)null) ? theCardItem.CardData : _card);
			if (!val.AutoplayDraw && !val.AutoplayEndTurn && ((int)val.CardClass != 9 || ((int)val.CardClass == 9 && val.Playable)))
			{
				currentCard = val;
			}
		}

		[HarmonyPatch(typeof(Character), "HealAuraCurse")]
		[HarmonyPrefix]
		public static bool HealAuraCurse_Prefix(AuraCurseData AC, Character __instance)
		{
			if ((Object)(object)AC != (Object)null && AC.Id == "stealth")
			{
				Hero val = (Hero)(object)((__instance is Hero) ? __instance : null);
				if (val != null && (Object)(object)currentCard != (Object)null && __instance.HaveTrait("shazixnarnightstalker"))
				{
					HeroItem value = Traverse.Create((object)__instance).Field("heroItem").GetValue<HeroItem>();
					string value2 = Traverse.Create((object)__instance).Field("subclassName").GetValue<string>();
					bool flag = __instance.HaveTrait("shazixnarshadowexecution");
					bool flag2 = currentCard.HasCardType((CardType)1);
					bool flag3 = currentCard.HasCardType((CardType)16) || currentCard.HasCardType((CardType)28);
					if (flag && flag2 && !shadowExecutionUsed.Contains(value2))
					{
						shadowExecutionUsed.Add(value2);
						if (!MatchManager.Instance.activatedTraits.ContainsKey("shazixnarshadowexecution"))
						{
							MatchManager.Instance.activatedTraits["shazixnarshadowexecution"] = 1;
						}
						else
						{
							MatchManager.Instance.activatedTraits["shazixnarshadowexecution"]++;
						}
						((CharacterItem)value).ScrollCombatText(Texts.Instance.GetText("traits_shazixnarshadowexecution", "") + Functions.TextChargesLeft(MatchManager.Instance.ItemExecutedInThisCombat(value2, "shazixnarshadowexecution"), 1), (CombatScrollEffectType)7);
						Debug.Log((object)"[潜行保留] 触发 shazixnarshadowexecution");
						MatchManager.Instance.SetTraitInfoText();
						return false;
					}
					if (__instance.HaveTrait("shazixnarnightstalker") && flag3)
					{
						int num = 2;
						if (__instance.HaveTrait("shazixnarvenomousshade"))
						{
							num += 2;
						}
						if (__instance.HaveTrait("shazixnarshadowexecution"))
						{
							num += 2;
						}
						Globals.Instance.GetTraitData("shazixnarnightstalker").TimesPerTurn = num;
						if (!stealthUsesThisTurn.ContainsKey(value2))
						{
							stealthUsesThisTurn[value2] = 0;
						}
						if (stealthUsesThisTurn[value2] < num)
						{
							stealthUsesThisTurn[value2]++;
							if (!MatchManager.Instance.activatedTraits.ContainsKey("shazixnarnightstalker"))
							{
								MatchManager.Instance.activatedTraits["shazixnarnightstalker"] = 1;
							}
							else
							{
								MatchManager.Instance.activatedTraits["shazixnarnightstalker"]++;
							}
							if (value != null)
							{
								((CharacterItem)value).ScrollCombatText(Texts.Instance.GetText("traits_shazixnarnightstalker", "") + Functions.TextChargesLeft(MatchManager.Instance.activatedTraits["shazixnarnightstalker"], num), (CombatScrollEffectType)7);
							}
							MatchManager.Instance.SetTraitInfoText();
							Debug.Log((object)$"[潜行保留] 使用次数 {stealthUsesThisTurn[value2]}/{num}");
							return false;
						}
					}
				}
			}
			return true;
		}

		[HarmonyPatch(typeof(Character), "BeginTurn")]
		[HarmonyPostfix]
		public static void Character_BeginTurn_Postfix(Character __instance)
		{
			Hero val = (Hero)(object)((__instance is Hero) ? __instance : null);
			if (val != null && (Object)(object)((Character)val).HeroData != (Object)null && __instance.HaveTrait("shazixnarnightstalker"))
			{
				string value = Traverse.Create((object)__instance).Field("subclassName").GetValue<string>();
				stealthUsesThisTurn[value] = 0;
				Debug.Log((object)("[潜行次数已重置] " + value));
			}
		}
	}
}
namespace AssassinThuls
{
	[BepInPlugin("com.shazixnar.AssassinThulsTraits", "Assassin Thuls", "1.0.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("AcrossTheObelisk.exe")]
	public class Plugin : BaseUnityPlugin
	{
		internal const int ModDate = 20251225;

		private readonly Harmony harmony = new Harmony("com.shazixnar.AssassinThulsTraits");

		internal static ManualLogSource Log;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"com.shazixnar.AssassinThulsTraits 1.0.4 has loaded!");
			Essentials.RegisterMod("Assassin Thuls", "Shazixnar", "Redone Thuls' traits and element cards.", "1.0.4", 20251225, "https://across-the-obelisk.thunderstore.io/package/Shazixnar/Assassin_Thuls/", (string[])null, "Assassin Thuls", 100, new string[5] { "content", "hero", "trait", "card", "perk" }, "", true);
			harmony.PatchAll();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.shazixnar.AssassinThulsTraits";

		public const string PLUGIN_NAME = "Assassin Thuls";

		public const string PLUGIN_VERSION = "1.0.4";
	}
}