diff --git a/Models/AbilityIdentifier.cs b/Models/AbilityIdentifier.cs index 07bae0e6..a6bbc6ac 100644 --- a/Models/AbilityIdentifier.cs +++ b/Models/AbilityIdentifier.cs @@ -1,39 +1,32 @@ -using System; using System.Collections.Generic; using DiskCardGame; -using UnityEngine; namespace APIPlugin { public class AbilityIdentifier { - private static List ids = new List(); + private static List ids = new(); private string guid; - private string name; - public Ability id; + private string name; + public Ability id; private AbilityIdentifier(string guid, string name) { this.guid = guid; this.name = name; - ids.Add(this); + ids.Add(this); } - public static AbilityIdentifier GetAbilityIdentifier(string guid, string name) - { - if (ids.Exists((AbilityIdentifier x) => x.guid == guid && x.name == name)) - { - return ids.Find((AbilityIdentifier x) => x.guid == guid && x.name == name); - } - else - { - return new AbilityIdentifier(guid, name); - } - } + public static AbilityIdentifier GetAbilityIdentifier(string guid, string name) + { + return ids.Exists(x => x.guid == guid && x.name == name) + ? ids.Find(x => x.guid == guid && x.name == name) + : new AbilityIdentifier(guid, name); + } - public override String ToString() + public override string ToString() { - return $"{this.guid}({this.name})"; + return $"{guid}({name})"; } } -} +} \ No newline at end of file diff --git a/Models/CustomCard.cs b/Models/CustomCard.cs index accb6daf..2b492404 100644 --- a/Models/CustomCard.cs +++ b/Models/CustomCard.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using CardLoaderPlugin.lib; using DiskCardGame; using UnityEngine; @@ -7,11 +8,12 @@ namespace APIPlugin { public class CustomCard { - public static List cards = new List(); - public static Dictionary> abilityIds = new Dictionary>(); - public static Dictionary evolveIds = new Dictionary(); - public static Dictionary iceCubeIds = new Dictionary(); - public static Dictionary tailIds = new Dictionary(); + public static List cards = new(); + public static Dictionary> abilityIds = new(); + public static Dictionary> specialAbilityIds = new(); + public static Dictionary evolveIds = new(); + public static Dictionary iceCubeIds = new(); + public static Dictionary tailIds = new(); public string name; public List metaCategories; public CardComplexity? cardComplexity; @@ -28,8 +30,8 @@ public class CustomCard public SpecialStatIcon? specialStatIcon; public List tribes; public List traits; - public List specialAbilities; - public List abilities; + public List specialAbilities = new(); + public List abilities = new(); public EvolveParams evolveParams; public string defaultEvolutionName; public TailParams tailParams; @@ -51,32 +53,57 @@ public class CustomCard public IceCubeIdentifier iceCubeId; public TailIdentifier tailId; - public CustomCard(string name, List abilityId=null, EvolveIdentifier evolveId=null, IceCubeIdentifier iceCubeId=null, TailIdentifier tailId=null) + public CustomCard( + string name, + List abilityIdParam=null, + List specialAbilityIdParam=null, + EvolveIdentifier evolveId=null, + IceCubeIdentifier iceCubeId=null, + TailIdentifier tailId=null) { this.name = name; CustomCard.cards.Add(this); // Handle AbilityIdentifier - List toRemove = new List(); - if (this.abilityId is not null) + List abilitiesToRemove = new List(); + if (abilityIdParam is not null) { - foreach (AbilityIdentifier id in abilityId) + foreach (var id in abilityIdParam.Where(id => id.id != 0)) { - if (id.id != 0) - { - this.abilities.Add(id.id); - } + this.abilities.Add(id.id); } - foreach (AbilityIdentifier id in toRemove) + + foreach (AbilityIdentifier id in abilitiesToRemove) { - this.abilityId.Remove(id); + abilityIdParam.Remove(id); + } + + if (abilityIdParam.Count > 0) + { + CustomCard.abilityIds[CustomCard.cards.Count - 1] = abilityIdParam; } } - if (abilityId is not null && this.abilityId.Count > 0) + + List specialAbilitiesToRemove = new List(); + if (specialAbilityIdParam is not null) { - CustomCard.abilityIds[CustomCard.cards.Count - 1] = abilityId; + foreach (var id in specialAbilityIdParam.Where(id => id.id != 0)) + { + this.specialAbilities.Add(id.id); + } + + foreach (SpecialAbilityIdentifier id in specialAbilitiesToRemove) + { + specialAbilityIdParam.Remove(id); + } + + if (specialAbilityIdParam.Count > 0) + { + CustomCard.specialAbilityIds[CustomCard.cards.Count - 1] = specialAbilityIdParam; + } } + // Handle EvolveIdentifier if (evolveId is not null) { diff --git a/Models/NewAbility.cs b/Models/NewAbility.cs index 4579110a..0ffffe3b 100644 --- a/Models/NewAbility.cs +++ b/Models/NewAbility.cs @@ -7,7 +7,7 @@ namespace APIPlugin { public class NewAbility { - public static List abilities = new List(); + public static List abilities = new(); public Ability ability; public AbilityInfo info; public Type abilityBehaviour; @@ -16,14 +16,14 @@ public class NewAbility public NewAbility(AbilityInfo info, Type abilityBehaviour, Texture tex, AbilityIdentifier id = null) { - this.ability = (Ability) 100 + NewAbility.abilities.Count; - info.ability = this.ability; + ability = (Ability) 100 + abilities.Count; + info.ability = ability; this.info = info; this.abilityBehaviour = abilityBehaviour; tex.filterMode = FilterMode.Point; this.tex = tex; this.id = id; - NewAbility.abilities.Add(this); + abilities.Add(this); if (id != null){ id.id = ability; } diff --git a/Models/NewCard.cs b/Models/NewCard.cs index fd951bd1..3d21ce48 100644 --- a/Models/NewCard.cs +++ b/Models/NewCard.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using CardLoaderPlugin.lib; using DiskCardGame; using UnityEngine; @@ -7,17 +8,21 @@ namespace APIPlugin { public static class NewCard { - public static List cards = new List(); - public static Dictionary> abilityIds = new Dictionary>(); - public static Dictionary evolveIds = new Dictionary(); - public static Dictionary iceCubeIds = new Dictionary(); - public static Dictionary tailIds = new Dictionary(); - - public static void Add(CardInfo card, List abilityIds = null, EvolveIdentifier evolveId = null, + public static List cards = new(); + + public static Dictionary> abilityIds = new(); + public static Dictionary> specialAbilityIds = new(); + public static Dictionary evolveIds = new(); + public static Dictionary iceCubeIds = new(); + public static Dictionary tailIds = new(); + + public static void Add(CardInfo card, List abilityIdsParam = null, + List specialAbilitiesIdsParam = null, + EvolveIdentifier evolveId = null, IceCubeIdentifier iceCubeId = null, TailIdentifier tailId = null) { NewCard.cards.Add(card); - handleIdentifiers(card, abilityIds, evolveId, iceCubeId, tailId); + HandleIdentifiers(card, abilityIdsParam, specialAbilitiesIdsParam, evolveId, iceCubeId, tailId); Plugin.Log.LogInfo($"Loaded custom card {card.name}!"); } @@ -30,7 +35,8 @@ public static void Add(string name, List metaCategories, CardC bool hideAttackAndHealth = false, int cost = 0, int bonesCost = 0, int energyCost = 0, List gemsCost = null, SpecialStatIcon specialStatIcon = SpecialStatIcon.None, List tribes = null, List traits = null, List specialAbilities = null, - List abilities = null, List abilityIds = null, EvolveParams evolveParams = null, + List abilities = null, List abilityIdsParam = null, + List specialAbilitiesIdsParam = null, EvolveParams evolveParams = null, string defaultEvolutionName = null, TailParams tailParams = null, IceCubeParams iceCubeParams = null, bool flipPortraitForStrafe = false, bool onePerDeck = false, List appearanceBehaviour = null, Texture2D tex = null, @@ -133,33 +139,51 @@ public static void Add(string name, List metaCategories, CardC NewCard.cards.Add(card); - handleIdentifiers(card, abilityIds, evolveId, iceCubeId, tailId); + HandleIdentifiers(card, abilityIdsParam, specialAbilitiesIdsParam, evolveId, iceCubeId, tailId); Plugin.Log.LogInfo($"Loaded custom card {name}!"); } - private static void handleIdentifiers(CardInfo card, List abilityIds, EvolveIdentifier evolveId, - IceCubeIdentifier iceCubeId, TailIdentifier tailId) + private static void HandleIdentifiers( + CardInfo card, + List abilityIdsParam, + List specialAbilitiesIdsParam, + EvolveIdentifier evolveId, + IceCubeIdentifier iceCubeId, + TailIdentifier tailId) { // Handle AbilityIdentifier List toRemove = new List(); - if (abilityIds is not null) + if (abilityIdsParam is not null) { - foreach (AbilityIdentifier id in abilityIds) + foreach (var id in abilityIdsParam.Where(id => id.id != 0)) { - if (id.id != 0) - { - card.abilities.Add(id.id); - } + card.abilities.Add(id.id); } + foreach (AbilityIdentifier id in toRemove) { - abilityIds.Remove(id); + abilityIdsParam.Remove(id); + } + + if (abilityIdsParam.Count > 0) + { + NewCard.abilityIds[NewCard.cards.Count - 1] = abilityIdsParam; } } - if (abilityIds is not null && abilityIds.Count > 0) + + // Handle SpecialAbilityIds + if (specialAbilitiesIdsParam is not null) { - NewCard.abilityIds[NewCard.cards.Count - 1] = abilityIds; + foreach (var id in specialAbilitiesIdsParam.Where(id => id.id != 0)) + { + card.specialAbilities.Add(id.id); + } + + if (specialAbilitiesIdsParam.Count > 0) + { + NewCard.specialAbilityIds[NewCard.cards.Count - 1] = specialAbilitiesIdsParam; + } } // Handle EvolveIdentifier @@ -209,9 +233,10 @@ private static void DetermineAndSetCardArt( pixelTex.name = newName; pixelTex.filterMode = FilterMode.Point; - card.pixelPortrait = Sprite.Create(pixelTex, CardUtils.DefaultCardPixelArtRect, CardUtils.DefaultVector2); + card.pixelPortrait = + Sprite.Create(pixelTex, CardUtils.DefaultCardPixelArtRect, CardUtils.DefaultVector2); card.pixelPortrait.name = newName; } } } -} +} \ No newline at end of file diff --git a/Models/NewSpecialAbility.cs b/Models/NewSpecialAbility.cs new file mode 100644 index 00000000..36a66cef --- /dev/null +++ b/Models/NewSpecialAbility.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using DiskCardGame; +using UnityEngine; + +namespace APIPlugin +{ + public class NewSpecialAbility + { + public static List specialAbilities = new(); + public SpecialTriggeredAbility specialTriggeredAbility; + public StatIconInfo statIconInfo; + public Type abilityBehaviour; + public SpecialAbilityIdentifier id; + + public NewSpecialAbility( + Type abilityBehaviour, + SpecialAbilityIdentifier id, + StatIconInfo statIconInfo = null + ) + { + specialTriggeredAbility = (SpecialTriggeredAbility)26 + specialAbilities.Count; + var logNameOrIdNumber = specialTriggeredAbility.ToString(); + if (statIconInfo) + { + this.statIconInfo = statIconInfo; + HandleStatIconInfo(statIconInfo); + logNameOrIdNumber = this.statIconInfo.rulebookName; + } + this.abilityBehaviour = abilityBehaviour; + this.id = id; + id.id = specialTriggeredAbility; + + HandleStatIconInfo(statIconInfo); + + specialAbilities.Add(this); + Plugin.Log.LogInfo($"Loaded custom special ability [{logNameOrIdNumber}]!"); + } + + // is only called if StatIconInfo is not null + private static void HandleStatIconInfo(StatIconInfo statIconInfo) + { + statIconInfo.iconType = (SpecialStatIcon)8 + specialAbilities.Count; + + if (statIconInfo.iconGraphic is not null) + { + // the reason for this is just one less step for the end user to setup + statIconInfo.iconGraphic.filterMode = FilterMode.Point; + } + + // a lazy initializer + if (statIconInfo.metaCategories.Count == 0) + { + statIconInfo.metaCategories = new List + { + AbilityMetaCategory.Part1Modular, AbilityMetaCategory.Part1Rulebook + }; + } + } + } +} \ No newline at end of file diff --git a/Models/SpecialAbilityIdentifier.cs b/Models/SpecialAbilityIdentifier.cs new file mode 100644 index 00000000..00360df7 --- /dev/null +++ b/Models/SpecialAbilityIdentifier.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using DiskCardGame; + +namespace APIPlugin +{ + public class SpecialAbilityIdentifier + { + private static List ids = new(); + private string guid; + private string name; + public SpecialTriggeredAbility id; + + private SpecialAbilityIdentifier(string guid, string name) + { + this.guid = guid; + this.name = name; + ids.Add(this); + } + + public static SpecialAbilityIdentifier GetID(string guid, string name) + { + return ids.Exists(x => x.guid == guid && x.name == name) + ? ids.Find(x => x.guid == guid && x.name == name) + : new SpecialAbilityIdentifier(guid, name); + } + + public override string ToString() + { + return $"{guid}({name})"; + } + } +} \ No newline at end of file diff --git a/Patches/Abilities.cs b/Patches/AbilitiesUtil.cs similarity index 72% rename from Patches/Abilities.cs rename to Patches/AbilitiesUtil.cs index 6c1c35bf..d5213a38 100644 --- a/Patches/Abilities.cs +++ b/Patches/AbilitiesUtil.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using APIPlugin; using DiskCardGame; using HarmonyLib; @@ -7,7 +6,8 @@ namespace API.Patches { - [HarmonyPatch(typeof(AbilitiesUtil), "LoadAbilityIcon", new Type[] { typeof(string), typeof(bool), typeof(bool) })] + [HarmonyPatch(typeof(AbilitiesUtil), "LoadAbilityIcon", + typeof(string), typeof(bool), typeof(bool))] public class AbilitiesUtil_LoadAbilityIcon { public static bool Prefix(string abilityName, CardTriggerHandler __instance, ref Texture __result) @@ -18,16 +18,14 @@ public static bool Prefix(string abilityName, CardTriggerHandler __instance, ref return true; } - NewAbility newAbility = NewAbility.abilities.Find((NewAbility x) => x.ability == (Ability)ability); + NewAbility newAbility = NewAbility.abilities.Find(x => x.ability == (Ability)ability); __result = newAbility.tex; return false; } } - [HarmonyPatch(typeof(AbilitiesUtil), - "GetAbilities", - new Type[] { typeof(bool), typeof(bool), typeof(int), typeof(int), typeof(AbilityMetaCategory) } - )] + [HarmonyPatch(typeof(AbilitiesUtil), "GetAbilities", + typeof(bool), typeof(bool), typeof(int), typeof(int), typeof(AbilityMetaCategory))] public class AbilitiesUtil_GetAbilities { public static void Postfix( diff --git a/Patches/CardTriggerHandler.cs b/Patches/CardTriggerHandler.cs index ccc059d2..b91b22cd 100644 --- a/Patches/CardTriggerHandler.cs +++ b/Patches/CardTriggerHandler.cs @@ -6,8 +6,8 @@ namespace API.Patches { - [HarmonyPatch(typeof(CardTriggerHandler), "AddAbility", new Type[] { typeof(Ability) })] - public class CardTriggerHandler_AddAbility + [HarmonyPatch(typeof(CardTriggerHandler), "AddAbility", typeof(Ability))] + public class CardTriggerHandler_AddAbility_Ability { public static bool Prefix(Ability ability, CardTriggerHandler __instance) { @@ -18,17 +18,20 @@ public static bool Prefix(Ability ability, CardTriggerHandler __instance) Predicate> checkAbilityExists = tuple => tuple.Item1 == ability || AbilityCanStackAndIsNotPassive(ability); - - // return true if the ability is equal to pair item1 OR if ability cannot stack and is passive + Plugin.Log.LogDebug($"Attempting to add regular ability in card trigger handler [{ability}]"); + // return true if the ability is equal to the ability in the pair OR if ability cannot stack and is passive if (!__instance.triggeredAbilities.Exists(checkAbilityExists)) { - NewAbility newAbility = NewAbility.abilities.Find((NewAbility x) => x.ability == ability); + Plugin.Log.LogDebug($"-> Ability [{ability}] does not exist, adding..."); + NewAbility newAbility = NewAbility.abilities.Find(x => x.ability == ability); + Plugin.Log.LogDebug($"-> New Ability is [{newAbility.ability}]"); Type type = newAbility.abilityBehaviour; - Component baseC = (Component)__instance; + Component baseC = __instance; AbilityBehaviour item = baseC.gameObject.GetComponent(type) as AbilityBehaviour; if (item == null) { item = baseC.gameObject.AddComponent(type) as AbilityBehaviour; + Plugin.Log.LogDebug($"--> Item is [{item}] | Ability toString [{ability}]"); } __instance.triggeredAbilities.Add(new Tuple(ability, item)); @@ -37,9 +40,41 @@ public static bool Prefix(Ability ability, CardTriggerHandler __instance) return false; } - public static bool AbilityCanStackAndIsNotPassive(Ability ability) + private static bool AbilityCanStackAndIsNotPassive(Ability ability) { return AbilitiesUtil.GetInfo(ability).canStack && !AbilitiesUtil.GetInfo(ability).passive; } } + + [HarmonyPatch(typeof(CardTriggerHandler), "AddAbility", typeof(SpecialTriggeredAbility))] + public class CardTriggerHandler_AddAbility_SpecialTriggeredAbility + { + public static bool Prefix(SpecialTriggeredAbility ability, CardTriggerHandler __instance) + { + Plugin.Log.LogDebug($"Attempting to add spec ability to card trigger handler [{ability}]"); + if ((int)ability < 25) + { + return true; + } + if (!__instance.specialAbilities.Exists(ab => ab.Item1 == ability)) + { + Plugin.Log.LogDebug($"-> Special ability [{ability}] does not exist, adding..."); + NewSpecialAbility newAbility = NewSpecialAbility.specialAbilities + .Find(x => x.specialTriggeredAbility == ability); + Plugin.Log.LogDebug($"-> New Ability is [{newAbility.specialTriggeredAbility}]"); + Type type = newAbility.abilityBehaviour; + Component baseC = __instance; + SpecialCardBehaviour item = baseC.gameObject.GetComponent(type) as SpecialCardBehaviour; + if (item == null) + { + item = baseC.gameObject.AddComponent(type) as SpecialCardBehaviour; + Plugin.Log.LogDebug($"--> Item is [{item}] | Ability toString [{ability}]"); + } + + __instance.specialAbilities.Add(new Tuple(ability, item)); + } + + return false; + } + } } diff --git a/Patches/Card_AttachAbilities_NewSpecialAbilities.cs b/Patches/Card_AttachAbilities_NewSpecialAbilities.cs new file mode 100644 index 00000000..4b02616b --- /dev/null +++ b/Patches/Card_AttachAbilities_NewSpecialAbilities.cs @@ -0,0 +1,41 @@ +using System; +using APIPlugin; +using DiskCardGame; +using HarmonyLib; +using UnityEngine; + +namespace API.Patches +{ + [HarmonyPatch(typeof(Card), nameof(Card.AttachAbilities), typeof(CardInfo))] + public class Card_AttachAbilities_NewSpecialAbilities + { + [HarmonyPrefix] + public static bool Prefix(CardInfo info, Card __instance) + { + Plugin.Log.LogDebug( + $"Called Card.AttachAbilities with [{info.name}] has [{info.specialAbilities.Count}] special abilities"); + + // if the card's special triggered ability exists in the NewSpecialAbility list, + // then we loop to assign to the game object. + // if the ability does not exist, return true running the original code + if (NewSpecialAbility.specialAbilities.Exists(ability => + info.specialAbilities.Contains(ability.specialTriggeredAbility))) + { + foreach (var specialTriggeredAbility in info.specialAbilities) + { + NewSpecialAbility newAbility = NewSpecialAbility.specialAbilities + .Find(x => x.specialTriggeredAbility == specialTriggeredAbility); + Type type = newAbility.abilityBehaviour; + Plugin.Log.LogDebug($"-> Special Card Behaviour Type is [{type}]"); + Component baseC = __instance; + SpecialCardBehaviour item = baseC.gameObject.GetComponent(type) as SpecialCardBehaviour + ?? baseC.gameObject.AddComponent(type) as SpecialCardBehaviour; + } + + return false; + } + + return true; + } + } +} \ No newline at end of file diff --git a/Patches/LoadingScreenManager.cs b/Patches/LoadingScreenManager.cs index bad346e4..03dd8670 100644 --- a/Patches/LoadingScreenManager.cs +++ b/Patches/LoadingScreenManager.cs @@ -27,9 +27,11 @@ public static void Prefix() Plugin.Log.LogInfo($"Loaded modified {card.name} into data"); } } + ScriptableObjectLoader.allData = official.Concat(NewCard.cards).ToList(); Plugin.Log.LogInfo($"Loaded custom cards into data"); } + if (ScriptableObjectLoader.allData == null) { List official = ScriptableObjectLoader.AllData; @@ -37,9 +39,10 @@ public static void Prefix() { official.Add(newAbility.info); } + ScriptableObjectLoader.allData = official; Plugin.Log.LogInfo($"Loaded custom abilities into data"); } } } -} +} \ No newline at end of file diff --git a/Patches/Rulebook.cs b/Patches/Rulebook.cs index 8a9a3288..cae131b6 100644 --- a/Patches/Rulebook.cs +++ b/Patches/Rulebook.cs @@ -17,6 +17,7 @@ public static void Postfix(AbilityMetaCategory metaCategory, RuleBookInfo __inst { foreach (PageRangeInfo pageRangeInfo in __instance.pageRanges) { + // regular abilities if (pageRangeInfo.type == PageRangeType.Abilities) { List customAbilities = NewAbility.abilities.Select(x => (int)x.ability).ToList(); @@ -31,11 +32,39 @@ public static void Postfix(AbilityMetaCategory metaCategory, RuleBookInfo __inst max + 1, min, doAddPageFunc, - new Action(__instance.FillAbilityPage), + __instance.FillAbilityPage, Localization.Translate("APPENDIX XII, SUBSECTION I - MOD ABILITIES {0}"))); } } } + + if (NewSpecialAbility.specialAbilities.Count > 0) + { + foreach (PageRangeInfo pageRangeInfo in __instance.pageRanges) + { + // special abilities + if (pageRangeInfo.type == PageRangeType.StatIcons) + { + List customAbilities = NewSpecialAbility.specialAbilities + .Select(x => (int)x.statIconInfo.iconType).ToList(); + Plugin.Log.LogInfo( + $"Number of custom abilities found to add to rulebook [{customAbilities.Count}]"); + int min = customAbilities.AsQueryable().Min(); + int max = customAbilities.AsQueryable().Max(); + PageRangeInfo pageRange = pageRangeInfo; + Func doAddPageFunc; + doAddPageFunc = (int index) => + customAbilities.Contains(index) + && StatIconInfo.GetIconInfo((SpecialStatIcon)index).metaCategories.Contains(metaCategory); + __result.AddRange(__instance.ConstructPages(pageRange, + max + 1, + min, + doAddPageFunc, + __instance.FillStatIconPage, + Localization.Translate("APPENDIX XII, SUBSECTION II - VARIABLE STATS {0}"))); + } + } + } } } -} +} \ No newline at end of file diff --git a/Patches/StatIconInfo.cs b/Patches/StatIconInfo.cs new file mode 100644 index 00000000..c23f43ec --- /dev/null +++ b/Patches/StatIconInfo.cs @@ -0,0 +1,24 @@ +using APIPlugin; +using DiskCardGame; +using HarmonyLib; + +namespace API.Patches +{ + [HarmonyPatch(typeof(StatIconInfo), "LoadAbilityData")] + public class StatIconInfoPatch + { + [HarmonyPostfix] + static void Postfix() + { + foreach (var ability in NewSpecialAbility.specialAbilities) + { + Plugin.Log.LogDebug($"Attempting to add {ability.specialTriggeredAbility} in StatIconInfo"); + if (!StatIconInfo.allIconInfo.Exists(x => x == ability.statIconInfo)) { + Plugin.Log.LogDebug($"-> Adding {ability.specialTriggeredAbility} in StatIconInfo"); + StatIconInfo.allIconInfo.Add(ability.statIconInfo); + } + } + + } + } +} \ No newline at end of file diff --git a/Plugin.cs b/Plugin.cs index 9bd13aae..425c6322 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -1,9 +1,10 @@ using BepInEx; -using BepInEx.Logging; using BepInEx.Configuration; -using HarmonyLib; +using BepInEx.Logging; using DiskCardGame; +using HarmonyLib; using UnityEngine.SceneManagement; + #pragma warning disable 169 namespace APIPlugin @@ -38,6 +39,7 @@ private void Awake() private void Start() { SetAbilityIdentifiers(); + SetSpecialAbilityIdentifiers(); SetEvolveIdentifiers(); SetIceCubeIdentifiers(); SetTailIdentifiers(); diff --git a/Utils/IdentifierHandlers.cs b/Utils/IdentifierHandlers.cs index c347124b..f8efb195 100644 --- a/Utils/IdentifierHandlers.cs +++ b/Utils/IdentifierHandlers.cs @@ -1,3 +1,6 @@ +using System.Collections.Generic; +using DiskCardGame; + namespace APIPlugin { public partial class Plugin @@ -8,13 +11,16 @@ private void SetAbilityIdentifiers() { foreach (AbilityIdentifier id in item.Value) { + var newCard = NewCard.cards[item.Key]; if (id.id != 0) { - NewCard.cards[item.Key].abilities.Add(id.id); + // if the card already has the ability then no point and adding it + if (AbilityDoesNotExistOrCanStack(newCard.abilities, id)) + newCard.abilities.Add(id.id); } else { - Plugin.Log.LogWarning($"Ability {id} not found for card {NewCard.cards[item.Key]}"); + Log.LogWarning($"Ability {id} not found for card {newCard}"); } } } @@ -23,16 +29,60 @@ private void SetAbilityIdentifiers() { foreach (AbilityIdentifier id in item.Value) { + var customCard = CustomCard.cards[item.Key]; + if (id.id != 0) + { + if (AbilityDoesNotExistOrCanStack(customCard.abilities, id)) + customCard.abilities.Add(id.id); + } + else + { + Log.LogWarning($"Ability {id} not found for card {customCard}"); + } + } + } + } + + private void SetSpecialAbilityIdentifiers() + { + foreach(var item in NewCard.specialAbilityIds) + { + foreach (SpecialAbilityIdentifier id in item.Value) + { + var newCard = NewCard.cards[item.Key]; if (id.id != 0) { - CustomCard.cards[item.Key].abilities.Add(id.id); + // Special Abilities do not stack, unlike regular Abilities + if (!newCard.specialAbilities.Contains(id.id)) newCard.specialAbilities.Add(id.id); } else { - Plugin.Log.LogWarning($"Ability {id} not found for card {CustomCard.cards[item.Key]}"); + Log.LogWarning($"Special Ability {id} not found for card {newCard}"); } } } + + foreach(var item in CustomCard.specialAbilityIds) + { + foreach (SpecialAbilityIdentifier id in item.Value) + { + var customCard = CustomCard.cards[item.Key]; + if (id.id != 0) + { + // Special Abilities do not stack, unlike regular Abilities + if (!customCard.specialAbilities.Contains(id.id)) customCard.specialAbilities.Add(id.id); + } + else + { + Log.LogWarning($"Special Ability {id} not found for card {customCard}"); + } + } + } + } + + private static bool AbilityDoesNotExistOrCanStack(List abilities, AbilityIdentifier id) + { + return !abilities.Contains(id.id) || AbilitiesUtil.GetInfo(id.id).canStack; } private void SetEvolveIdentifiers() @@ -46,7 +96,7 @@ private void SetEvolveIdentifiers() } else { - Plugin.Log.LogWarning($"Evolution card {id} not found for card {NewCard.cards[item.Key]}"); + Log.LogWarning($"Evolution card {id} not found for card {NewCard.cards[item.Key]}"); } } @@ -59,7 +109,7 @@ private void SetEvolveIdentifiers() } else { - Plugin.Log.LogWarning($"Evolution card {id} not found for card {CustomCard.cards[item.Key]}"); + Log.LogWarning($"Evolution card {id} not found for card {CustomCard.cards[item.Key]}"); } } } @@ -75,7 +125,7 @@ private void SetIceCubeIdentifiers() } else { - Plugin.Log.LogWarning($"IceCube card {id} not found for card {NewCard.cards[item.Key]}"); + Log.LogWarning($"IceCube card {id} not found for card {NewCard.cards[item.Key]}"); } } @@ -88,7 +138,7 @@ private void SetIceCubeIdentifiers() } else { - Plugin.Log.LogWarning($"IceCube card {id} not found for card {CustomCard.cards[item.Key]}"); + Log.LogWarning($"IceCube card {id} not found for card {CustomCard.cards[item.Key]}"); } } } @@ -104,7 +154,7 @@ private void SetTailIdentifiers() } else { - Plugin.Log.LogWarning($"Tail card {id} not found for card {NewCard.cards[item.Key]}"); + Log.LogWarning($"Tail card {id} not found for card {NewCard.cards[item.Key]}"); } } @@ -117,7 +167,7 @@ private void SetTailIdentifiers() } else { - Plugin.Log.LogWarning($"Tail card {id} not found for card {CustomCard.cards[item.Key]}"); + Log.LogWarning($"Tail card {id} not found for card {CustomCard.cards[item.Key]}"); } } }