Skip to content

Commit

Permalink
Merge pull request #290 from HumabHatterZed/main
Browse files Browse the repository at this point in the history
Added card extensions, null checks, fixed DrawCopyOnDeath warnings
  • Loading branch information
IngoHHacks authored Nov 29, 2023
2 parents 2788035 + 0801017 commit eb3fd0d
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 146 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
<details>
<summary>View Changelog</summary>

## 2.18.5
- Added missing null checks
- Added PlayableCard.GetStatIconHealthBuffs()
- Added PlayableCard.TransformIntoCardAboveHand() - variant of TransformIntoCardInHand that incorporates MoveCardAboveHand
- Added FullAbility.SetExtendedProperty for setting an AbilityInfo's custom property during ability creation
- Fixed DrawCopyOnDeath creating warnings in the console
- Fixed talking cards locking the camera view when obtained during the Trapper boss's final phase
- Fixed ResourceDrone softlocking during Leshy's goodbye sequence if ConfigDefaultDrone is false
- Reverted change to resource drone preventing it from being parented to the scale outside of Act 1
- Improved visual fix for the full pack Pack Rat sequence

## 2.18.4
- Fixed Sniper sigil targeting the wrong side of the board
- Fixed placeholder tribe choice icons being placed incorrectly
Expand Down
14 changes: 13 additions & 1 deletion InscryptionAPI/Card/AbilityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ public static bool GetHideSingleStacks(this AbilityInfo abilityInfo)
#region ExtendedProperties

/// <summary>
/// Adds a custom property value to the ability.
/// Adds a custom property value to the AbilityInfo.
/// </summary>
/// <param name="info">Ability to access.</param>
/// <param name="propertyName">The name of the property to set.</param>
Expand All @@ -511,6 +511,18 @@ public static AbilityInfo SetExtendedProperty(this AbilityInfo info, string prop
info.GetAbilityExtensionTable()[propertyName] = value?.ToString();
return info;
}
/// <summary>
/// Adds a custom property value to the FullAbility's AbilityInfo - intended as a shorthand for when modders are first adding abilities to the game.
/// </summary>
/// <param name="fullAbility">FullAbility object to access.</param>
/// <param name="propertyName">The name of the property to set.</param>
/// <param name="value">The value of the property.</param>
/// <returns>The same FullAbility so a chain can continue.</returns>
public static FullAbility SetExtendedProperty(this FullAbility fullAbility, string propertyName, object value)
{
fullAbility.Info.GetAbilityExtensionTable()[propertyName] = value?.ToString();
return fullAbility;
}

/// <summary>
/// Gets a custom property value from the card.
Expand Down
22 changes: 11 additions & 11 deletions InscryptionAPI/Card/AbilityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Text;
using UnityEngine;

namespace InscryptionAPI.Card;
Expand Down Expand Up @@ -411,7 +412,6 @@ private static void CleanUpParsedDescription(ref string __result)
break;

textToCheck = textToCheck.Substring(0, textToCheck.IndexOf("]") + 1);

__result = __result.Replace(textToCheck, textToCheck.Replace("[sigilcost:", "").Replace("]", ""));
}
}
Expand Down Expand Up @@ -462,27 +462,27 @@ internal static string ParseAndUpdateDescription(string description, ExtendedAct
int endIndex = textToChange.IndexOf("]");
textToChange = textToChange.Substring(0, endIndex + 1);

string allCosts = "";
StringBuilder allCosts = new();
if (ability.BonesCost > 0)
{
allCosts += ability.BonesCost.ToString() + " bone";
allCosts.Append(ability.BonesCost.ToString() + " bone");
if (ability.BonesCost != 1)
allCosts += "s";
allCosts.Append("s");
}
if (ability.EnergyCost > 0)
{
if (allCosts != "")
allCosts += ", ";
allCosts += ability.EnergyCost.ToString() + " energy";
if (allCosts.ToString() != "")
allCosts.Append(", ");
allCosts.Append(ability.EnergyCost.ToString() + " energy");
}
if (ability.HealthCost > 0)
{
if (allCosts != "")
allCosts += ", ";
allCosts += ability.HealthCost.ToString() + " health";
if (allCosts.ToString() != "")
allCosts.Append(", ");
allCosts.Append(ability.HealthCost.ToString() + " health");
}

return description.Replace(textToChange, allCosts == "" ? "nothing" : allCosts);
return description.Replace(textToChange, allCosts.ToString() == "" ? "nothing" : allCosts.ToString());
}

string[] blocks = description.Split(' ');
Expand Down
30 changes: 30 additions & 0 deletions InscryptionAPI/Card/CardExtensionsHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,21 @@ public static bool LacksAllCardMetaCategories(this CardInfo cardInfo, params Car

#region PlayableCard
/// <summary>
/// Gets the health adjustment given by a PlayableCard's Stat Icon.
/// </summary>
/// <param name="card">The PlayableCard to access.</param>
/// <returns>How much Health the Stat Icon gives.</returns>
public static int GetStatIconHealthBuffs(this PlayableCard card)
{
int num = 0;
foreach (CardModificationInfo temporaryMod in card.TemporaryMods)
{
if (temporaryMod.singletonId == "VARIABLE_STAT")
num += temporaryMod.healthAdjustment;
}
return num;
}
/// <summary>
/// Gets the number of Ability stacks a card has.
/// </summary>
/// <param name="card">The PlayableCard to access.</param>
Expand Down Expand Up @@ -592,7 +607,22 @@ public static IEnumerator TransformIntoCardInHand(this PlayableCard card, CardIn
Singleton<ViewManager>.Instance.SwitchToView(View.Hand);
yield return new WaitForSeconds(0.15f);
yield return card.Anim.FlipInAir();
yield return new WaitForSeconds(0.1f);
preTransformCallback?.Invoke();
card.SetInfo(evolvedInfo);
onTransformedCallback?.Invoke();
}
/// <summary>
/// A version of TransformIntoCardInHand that incorporates MoveCardAboveHand.
/// </summary>
public static IEnumerator TransformIntoCardAboveHand(this PlayableCard card, CardInfo evolvedInfo, Action onTransformedCallback = null, Action preTransformCallback = null)
{
Singleton<ViewManager>.Instance.SwitchToView(View.Default);
(Singleton<PlayerHand>.Instance as PlayerHand3D)?.MoveCardAboveHand(card);

yield return new WaitForSeconds(0.15f);
yield return card.Anim.FlipInAir();
yield return new WaitForSeconds(0.1f);
preTransformCallback?.Invoke();
card.SetInfo(evolvedInfo);
onTransformedCallback?.Invoke();
Expand Down
62 changes: 26 additions & 36 deletions InscryptionAPI/Card/TribeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,28 @@ private static void UpdateTribeIcon(CardDisplayer3D __instance, CardInfo info)
{
if (info != null)
{
foreach (TribeInfo tribe in tribes)
foreach (TribeInfo tribeInfo in tribes)
{
if (tribe?.icon != null)
if (tribeInfo?.icon == null || info.IsNotOfTribe(tribeInfo.tribe))
continue;

bool foundSpriteRenderer = false;
foreach (SpriteRenderer spriteRenderer in __instance.tribeIconRenderers)
{
if (info.IsOfTribe(tribe.tribe))
if (spriteRenderer.sprite == null)
{
bool foundSpriteRenderer = false;
foreach (SpriteRenderer spriteRenderer in __instance.tribeIconRenderers)
{
if (spriteRenderer.sprite == null)
{
foundSpriteRenderer = true;
spriteRenderer.sprite = tribe.icon;
break;
}
}
if (!foundSpriteRenderer)
{
SpriteRenderer last = __instance.tribeIconRenderers.Last();
SpriteRenderer spriteRenderer = UnityObject.Instantiate(last);
spriteRenderer.transform.parent = last.transform.parent;
spriteRenderer.transform.localPosition = last.transform.localPosition + (__instance.tribeIconRenderers[1].transform.localPosition - __instance.tribeIconRenderers[0].transform.localPosition);
}
spriteRenderer.sprite = tribeInfo.icon;
foundSpriteRenderer = true;
break;
}
}
if (!foundSpriteRenderer)
{
SpriteRenderer last = __instance.tribeIconRenderers.Last();
SpriteRenderer spriteRenderer = UnityObject.Instantiate(last);
spriteRenderer.transform.parent = last.transform.parent;
spriteRenderer.transform.localPosition = last.transform.localPosition + (__instance.tribeIconRenderers[1].transform.localPosition - __instance.tribeIconRenderers[0].transform.localPosition);
}
}
}
}
Expand Down Expand Up @@ -190,10 +187,7 @@ public static Tribe Add(string guid, string name, string pathToTribeIcon = null,
return Add(guid, name, pathToTribeIcon is not null ? TextureHelper.GetImageAsTexture(pathToTribeIcon) : null, appearInTribeChoices, pathToChoiceCardBackTexture is not null ? TextureHelper.GetImageAsTexture(pathToChoiceCardBackTexture) : null);
}

public static bool IsCustomTribe(Tribe tribe)
{
return tribeTypes.Contains(tribe);
}
public static bool IsCustomTribe(Tribe tribe) => tribeTypes.Contains(tribe);

public static Texture2D GetTribeIcon(Tribe tribe, bool useMissingIconIfNull = true)
{
Expand All @@ -202,14 +196,13 @@ public static Texture2D GetTribeIcon(Tribe tribe, bool useMissingIconIfNull = tr
{
foreach (TribeInfo tribeInfo in NewTribes)
{
if (tribeInfo.tribe == tribe)
{
if (tribeInfo.icon != null && tribeInfo.icon.texture != null)
{
texture2D = tribeInfo.icon.texture;
}
break;
}
if (tribeInfo.tribe != tribe)
continue;

if (tribeInfo.icon != null && tribeInfo.icon.texture != null)
texture2D = tribeInfo.icon.texture;

break;
}
}
else
Expand All @@ -218,15 +211,12 @@ public static Texture2D GetTribeIcon(Tribe tribe, bool useMissingIconIfNull = tr
string str = "Art/Cards/TribeIcons/tribeicon_" + tribe.ToString().ToLowerInvariant();
Sprite sprite = ResourceBank.Get<Sprite>(str);
if (sprite != null)
{
texture2D = sprite.texture;
}
}

if (texture2D == null && useMissingIconIfNull)
{
texture2D = TribeIconMissing;
}

return texture2D;
}

Expand Down
2 changes: 1 addition & 1 deletion InscryptionAPI/InscryptionAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<DebugType>full</DebugType>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<Version>2.18.4</Version>
<Version>2.18.5</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion InscryptionAPI/InscryptionAPIPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class InscryptionAPIPlugin : BaseUnityPlugin
{
public const string ModGUID = "cyantist.inscryption.api";
public const string ModName = "InscryptionAPI";
public const string ModVer = "2.18.4";
public const string ModVer = "2.18.5";

public static string Directory = "";

Expand Down
6 changes: 2 additions & 4 deletions InscryptionAPI/Totems/TotemManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ internal enum TotemTopState
AllTribes
}

[HarmonyPatch(typeof(BuildTotemSequencer), "GenerateTotemChoices", new System.Type[] { typeof(BuildTotemNodeData), typeof(int) })]
[HarmonyPatch(typeof(BuildTotemSequencer), "GenerateTotemChoices", new Type[] { typeof(BuildTotemNodeData), typeof(int) })]
private class ItemsUtil_AllConsumables
{
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
if (InscryptionAPIPlugin.configCustomTotemTopTypes.Value == TotemTopState.Vanilla)
{
return instructions;
}

// === We want to turn this

Expand Down Expand Up @@ -96,7 +94,7 @@ public static void AddCustomTribesToList(List<Tribe> list)
}
}

[HarmonyPatch(typeof(ResourceBank), "Awake", new System.Type[] { })]
[HarmonyPatch(typeof(ResourceBank), "Awake", new Type[] { })]
private class ResourceBank_Awake
{
public static void Postfix(ResourceBank __instance)
Expand Down
2 changes: 1 addition & 1 deletion InscryptionAPI/Triggers/TakeDamagePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private static bool AddModifyDamageTrigger(PlayableCard __instance, ref int dama
modifyTakeDamage.Sort((a, b) => b.TriggerPriority(__instance, originalDamage, attacker) - a.TriggerPriority(__instance, originalDamage, attacker));
foreach (var modify in modifyTakeDamage)
{
if (modify.RespondsToModifyDamageTaken(__instance, damage, attacker, originalDamage))
if (modify != null && modify.RespondsToModifyDamageTaken(__instance, damage, attacker, originalDamage))
damage = modify.OnModifyDamageTaken(__instance, damage, attacker, originalDamage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ namespace InscryptionCommunityPatch.Card;
[HarmonyPatch]
internal class Act2CuckooFix
{
private static MethodBase TargetMethod()
{
MethodBase baseMethod = AccessTools.Method(typeof(CreateEgg), nameof(CreateEgg.OnResolveOnBoard));
return AccessTools.EnumeratorMoveNext(baseMethod);
}

[HarmonyTranspiler]
[HarmonyTranspiler, HarmonyPatch(typeof(CreateEgg), nameof(CreateEgg.OnResolveOnBoard), MethodType.Enumerator)]
private static IEnumerable<CodeInstruction> FixDialogueSoftlock(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> codes = new(instructions);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using DiskCardGame;
using HarmonyLib;
using InscryptionAPI.Card;
using System.Collections;
using UnityEngine;

namespace InscryptionCommunityPatch.Card;

[HarmonyPatch]
internal class DrawCopyOnDeathFix
{
[HarmonyPatch(typeof(DrawCopyOnDeath), nameof(DrawCopyOnDeath.CardToDraw), MethodType.Getter)]
[HarmonyPostfix]
private static void UseAlternatePortrait(DrawCopyOnDeath __instance, ref CardInfo __result)
{
if (__instance?.Card?.Info != null)
__result = __instance.Card.Info.Clone() as CardInfo;
}
}
Loading

0 comments on commit eb3fd0d

Please sign in to comment.