Skip to content

Commit

Permalink
Added support for multiple same-colour mox costs
Browse files Browse the repository at this point in the history
  • Loading branch information
HumabHatterZed committed Jul 15, 2024
1 parent 4eb13c6 commit c269f9f
Show file tree
Hide file tree
Showing 26 changed files with 306 additions and 52 deletions.
15 changes: 4 additions & 11 deletions InscryptionAPI/Card/CardExtensionsCosts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,18 @@ public static List<GemType> GemsCost(this PlayableCard card)
return new();

List<CardModificationInfo> mods = card.TemporaryMods.Concat(card.Info.Mods).ToList();
// if gems are nullified, return a new list
if (mods.Exists((CardModificationInfo x) => x.nullifyGemsCost))
if (mods.Exists(x => x.nullifyGemsCost))
return new List<GemType>();

List<GemType> gemsCost = new(card.Info.gemsCost);
foreach (CardModificationInfo mod in mods)
{
if (mod.addGemCost != null)
{
foreach (GemType item in mod.addGemCost)
{
if (!gemsCost.Contains(item))
gemsCost.Add(item);
}
}
gemsCost.AddRange(mod.addGemCost);

foreach (GemType gem in mod.RemovedGemsCosts())
{
if (gemsCost.Contains(gem))
gemsCost.Remove(gem);
gemsCost.Remove(gem);
}
}

Expand Down
9 changes: 2 additions & 7 deletions InscryptionAPI/Card/CostProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,11 @@ public static List<GemType> ImprovedGemsCost(CardInfo instance)
{
if (mod.addGemCost != null)
{
foreach (GemType item in mod.addGemCost)
{
if (!gems.Contains(item))
gems.Add(item);
}
gems.AddRange(mod.addGemCost);
}
foreach (GemType gem in mod.RemovedGemsCosts())
{
if (gems.Contains(gem))
gems.Remove(gem);
gems.Remove(gem);
}
}
return gems;
Expand Down
115 changes: 115 additions & 0 deletions InscryptionAPI/Costs/CardCostManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,21 @@ static CardCostManager()
internal readonly static ObservableCollection<FullCardCost> NewCosts = new();

public static event Func<List<FullCardCost>, List<FullCardCost>> ModifyCustomCostList;

// you don't have the [colour] gem for that.
// no [colour] gem on the table? then you can't play it.
// you need at least one [colour] gem on the board in order to play that [card]
// play the required [colour] gem... then you can play that.
public static HintsHandler.Hint notEnoughSameColourGemsHint = new("Hint_NotEnoughSameColourGemsHint", 2);
public static DialogueEvent notEnoghSameColourGemsEvent = DialogueManager.GenerateEvent(
InscryptionAPIPlugin.ModGUID, "Hint_NotEnoughSameColourGemsHint",
new() { "You don't have enough [v:1] gems for that." },
new()
{
new() { "Not enough [v:1] gems on the table? Then you can't play it." },
new() { "You need more [v:1] gems on the board in order to play that [v:0]."},
new() { "Play the required [v:1] gems... then you can play that." }
});
public static void SyncCustomCostList()
{
AllCustomCosts = NewCosts.Select(a => a.Clone()).ToList();
Expand Down Expand Up @@ -326,9 +341,63 @@ private static void CanPlayCustomCosts(ref bool __result, ref PlayableCard __ins
}
}

[HarmonyPrefix, HarmonyPatch(typeof(PlayableCard), nameof(PlayableCard.GemsCostRequirementMet))]
private static bool ReplaceCostRequirementMet(PlayableCard __instance, ref bool __result)
{
__result = NewGemsCostRequirementMet(__instance);
return false;
}

/// <summary>
/// A new method that overrides the result of PlayableCard.GemsCostRequirement. Override this if you want to modify GemsCostRequirementMet.
/// </summary>
/// <param name="card">The PlayableCard currently being checked.</param>
/// <returns>Boolean representing if the card's gem cost has been met or not.</returns>
public static bool NewGemsCostRequirementMet(PlayableCard card)
{
List<GemType> gemsOwned = new(ResourcesManager.Instance.gems);
foreach (GemType item in card.GemsCost())
{
if (gemsOwned.Contains(item))
gemsOwned.Remove(item);
else
return false;
}
return true;
}

[HarmonyPrefix, HarmonyPatch(typeof(HintsHandler), nameof(HintsHandler.OnNonplayableCardClicked))]
private static bool CannotAffordCustomCostHints(ref PlayableCard card)
{
// if a card costs multiple of the same colour
if (card.GemsCost().Count > 0 && !card.GemsCost().Exists(x => !ResourcesManager.Instance.HasGem(x)))
{
List<GemType> neededGems = card.GemsCost();
foreach (GemType gem in ResourcesManager.Instance.gems)
{
neededGems.Remove(gem);
}
if (neededGems.Count > 0)
{
GemType gem = neededGems[0];
if (SaveManager.SaveFile.IsPart2)
{
string arg = HintsHandler.GetDialogueColorCodeForGem(gem) + Localization.Translate(gem.ToString()) + "[c:]";
string message = string.Format(Localization.Translate("You do not have the {0} Gem to play that. Gain Gems by playing Mox cards."), arg);
CustomCoroutine.Instance.StartCoroutine(Singleton<TextBox>.Instance.ShowUntilInput(message, TextBox.Style.Neutral, null, TextBox.ScreenPosition.ForceTop, 0f, hideAfter: true, shake: false, null, adjustAudioVolume: false));
}
else if (TextDisplayer.m_Instance != null)
{
notEnoughSameColourGemsHint.TryPlayDialogue(new string[2]
{
card.Info.DisplayedNameLocalized,
HintsHandler.GetColorCodeForGem(gem) + Localization.Translate(gem.ToString()) + "</color>"
});
}
return false;
}
}

foreach (CustomCardCost customCost in card.GetCustomCardCosts())
{
FullCardCost fullCost = AllCustomCosts.CostByBehaviour(customCost.GetType());
Expand Down Expand Up @@ -400,6 +469,52 @@ private static void CustomCardsCanBePlayedByTurn2(ref bool __result, CardInfo ca
}
}

[HarmonyPrefix, HarmonyPatch(typeof(HintsHandler), nameof(HintsHandler.OnGBCNonPlayableCardPressed))]
private static bool MultiMonoColourMoxSupport(PlayableCard card)
{
if (card.GemsCost().Count > 0)
{
List<GemType> ownedGems = card.GemsCost();
foreach (GemType gem in ResourcesManager.Instance.gems)
ownedGems.Remove(gem);

if (ownedGems.Count > 0)
{
GemType gem = ownedGems[0];
string arg = HintsHandler.GetDialogueColorCodeForGem(gem) + Localization.Translate(gem.ToString()) + "[c:]";
string message = string.Format(Localization.Translate("You do not have the {0} Gem to play that. Gain Gems by playing Mox cards."), arg);
CustomCoroutine.Instance.StartCoroutine(Singleton<TextBox>.Instance.ShowUntilInput(message, TextBox.Style.Neutral, null, TextBox.ScreenPosition.ForceTop, 0f, true, false, null, false));
return false;
}
}
return true;
}

[HarmonyPrefix, HarmonyPatch(typeof(HintsHandler), nameof(HintsHandler.OnNonplayableCardClicked))]
private static bool MultipleSameColourMoxSupport(PlayableCard card)
{
if (card.GemsCost().Count > 0)
{
List<GemType> neededGems = card.GemsCost();
foreach (GemType gem in ResourcesManager.Instance.gems)
{
neededGems.Remove(gem);
}
if (neededGems.Count > 0)
{
GemType gem = neededGems[0];
HintsHandler.notEnoughGemsHint.TryPlayDialogue(new string[2]
{
card.Info.DisplayedNameLocalized,
HintsHandler.GetColorCodeForGem(gem) + Localization.Translate(gem.ToString()) + "</color>"
});
return false;
}
}

return true;
}

#region SelectedCardToSlot transiler
[HarmonyTranspiler, HarmonyPatch(typeof(PlayerHand), nameof(PlayerHand.SelectSlotForCard), MethodType.Enumerator)]
private static IEnumerable<CodeInstruction> FixDialogueSoftlock(IEnumerable<CodeInstruction> instructions)
Expand Down
4 changes: 4 additions & 0 deletions InscryptionAPI/InscryptionAPIPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ private void Start()
CardManager.AuditCardList();
PixelCardManager.Initialise();
PeltManager.CreateDialogueEvents();
if (!DialogueManager.CustomDialogue.Exists(x => x.DialogueEvent.id == "Hint_NotEnoughSameColourGemsHint"))
{

}
Logger.LogDebug($"Inserted {DialogueManager.CustomDialogue.Count} dialogue event(s)!");
}

Expand Down
Binary file added InscryptionCommunityPatch/Assets/mox_cost_b_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added InscryptionCommunityPatch/Assets/mox_cost_b_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added InscryptionCommunityPatch/Assets/mox_cost_b_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added InscryptionCommunityPatch/Assets/mox_cost_g_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added InscryptionCommunityPatch/Assets/mox_cost_g_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added InscryptionCommunityPatch/Assets/mox_cost_g_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added InscryptionCommunityPatch/Assets/mox_cost_o_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added InscryptionCommunityPatch/Assets/mox_cost_o_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added InscryptionCommunityPatch/Assets/mox_cost_o_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 changes: 81 additions & 16 deletions InscryptionCommunityPatch/Card/Part1CardCostRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using InscryptionAPI.CardCosts;
//using InscryptionAPI.CardCosts;
using InscryptionAPI.Helpers;
using System.Linq;
using UnityEngine;

namespace InscryptionCommunityPatch.Card;
Expand All @@ -20,24 +21,9 @@ public static class Part1CardCostRender
public static List<Texture2D> CostTextures(CardInfo cardInfo, PlayableCard playableCard, int bloodCost, int bonesCost, int energyCost, List<GemType> gemsCost)
{
List<Texture2D> costTextures = new();

if (gemsCost.Count > 0)
{
// Get all the Mox textures, with placeholders if less than 3 Mox are present
List<Texture2D> gemCost = new();

if (gemsCost.Contains(GemType.Green))
gemCost.Add(CardCostRender.GetTextureByName("mox_cost_g"));

if (gemsCost.Contains(GemType.Blue))
gemCost.Add(CardCostRender.GetTextureByName("mox_cost_b"));

if (gemsCost.Contains(GemType.Orange))
gemCost.Add(CardCostRender.GetTextureByName("mox_cost_o"));

while (gemCost.Count < 3)
gemCost.Insert(0, null);

List<Texture2D> gemCost = GetMoxTextures(gemsCost);
costTextures.Add(TextureHelper.CombineTextures(gemCost, TextureHelper.GetImageAsTexture("mox_cost_empty.png", typeof(Part1CardCostRender).Assembly), xStep: 21));
}

Expand Down Expand Up @@ -85,4 +71,83 @@ public static List<Texture2D> CostTextures(CardInfo cardInfo, PlayableCard playa
UpdateCardCost?.Invoke(cardInfo, costTextures);
return costTextures;
}

public static List<Texture2D> GetMoxTextures(List<GemType> gemsCost)
{
List<Texture2D> gemCost = new();
if (gemsCost.Count <= 3)
{
foreach (GemType type in gemsCost.Where(x => x == GemType.Orange))
gemCost.Add(CardCostRender.GetTextureByName("mox_cost_o"));

foreach (GemType type in gemsCost.Where(x => x == GemType.Green))
gemCost.Add(CardCostRender.GetTextureByName("mox_cost_g"));

foreach (GemType type in gemsCost.Where(x => x == GemType.Blue))
gemCost.Add(CardCostRender.GetTextureByName("mox_cost_b"));
}
else
{
int orangeCount = Mathf.Min(4, gemsCost.Count(x => x == GemType.Orange));
int greenCount = Mathf.Min(4, gemsCost.Count(x => x == GemType.Green));
int blueCount = Mathf.Min(4, gemsCost.Count(y => y == GemType.Blue));
if (orangeCount > 0)
{
if (orangeCount == 1)
{
gemCost.Add(CardCostRender.GetTextureByName("mox_cost_o"));
}
else if (orangeCount > 2 || (greenCount + blueCount > 1))
{
gemCost.Add(CardCostRender.GetTextureByName($"mox_cost_o_{orangeCount}"));
orangeCount = 1;
}
else
{
gemCost.Add(CardCostRender.GetTextureByName("mox_cost_o"));
gemCost.Add(CardCostRender.GetTextureByName("mox_cost_o"));
}
}

if (greenCount > 0)
{
if (greenCount == 1)
{
gemCost.Add(CardCostRender.GetTextureByName("mox_cost_g"));
}
else if (greenCount > 2 || (blueCount + orangeCount > 1))
{
gemCost.Add(CardCostRender.GetTextureByName($"mox_cost_g_{greenCount}"));
greenCount = 1; // green is only using 1 sprite 'slot'
}
else
{
gemCost.Add(CardCostRender.GetTextureByName("mox_cost_g"));
gemCost.Add(CardCostRender.GetTextureByName("mox_cost_g"));
}
}

if (blueCount > 0)
{
if (blueCount == 1)
{
gemCost.Add(CardCostRender.GetTextureByName("mox_cost_b"));
}
else if (blueCount > 2 || (greenCount + orangeCount > 1))
{
gemCost.Add(CardCostRender.GetTextureByName($"mox_cost_b_{blueCount}"));
}
else
{
gemCost.Add(CardCostRender.GetTextureByName("mox_cost_b"));
gemCost.Add(CardCostRender.GetTextureByName("mox_cost_b"));
}
}
}

while (gemCost.Count < 3)
gemCost.Insert(0, null);

return gemCost;
}
}
Loading

0 comments on commit c269f9f

Please sign in to comment.