Skip to content

Commit c951aec

Browse files
committed
Added debug logging.
Refactored CustomCard to include special abilities now
1 parent 088f8a3 commit c951aec

3 files changed

Lines changed: 53 additions & 24 deletions

File tree

Models/CustomCard.cs

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23
using CardLoaderPlugin.lib;
34
using DiskCardGame;
45
using UnityEngine;
@@ -7,11 +8,12 @@ namespace APIPlugin
78
{
89
public class CustomCard
910
{
10-
public static List<CustomCard> cards = new List<CustomCard>();
11-
public static Dictionary<int,List<AbilityIdentifier>> abilityIds = new Dictionary<int,List<AbilityIdentifier>>();
12-
public static Dictionary<int,EvolveIdentifier> evolveIds = new Dictionary<int,EvolveIdentifier>();
13-
public static Dictionary<int,IceCubeIdentifier> iceCubeIds = new Dictionary<int,IceCubeIdentifier>();
14-
public static Dictionary<int,TailIdentifier> tailIds = new Dictionary<int,TailIdentifier>();
11+
public static List<CustomCard> cards = new();
12+
public static Dictionary<int,List<AbilityIdentifier>> abilityIds = new();
13+
public static Dictionary<int, List<SpecialAbilityIdentifier>> specialAbilityIds = new();
14+
public static Dictionary<int,EvolveIdentifier> evolveIds = new();
15+
public static Dictionary<int,IceCubeIdentifier> iceCubeIds = new();
16+
public static Dictionary<int,TailIdentifier> tailIds = new();
1517
public string name;
1618
public List<CardMetaCategory> metaCategories;
1719
public CardComplexity? cardComplexity;
@@ -28,8 +30,8 @@ public class CustomCard
2830
public SpecialStatIcon? specialStatIcon;
2931
public List<Tribe> tribes;
3032
public List<Trait> traits;
31-
public List<SpecialTriggeredAbility> specialAbilities;
32-
public List<Ability> abilities;
33+
public List<SpecialTriggeredAbility> specialAbilities = new();
34+
public List<Ability> abilities = new();
3335
public EvolveParams evolveParams;
3436
public string defaultEvolutionName;
3537
public TailParams tailParams;
@@ -51,32 +53,57 @@ public class CustomCard
5153
public IceCubeIdentifier iceCubeId;
5254
public TailIdentifier tailId;
5355

54-
public CustomCard(string name, List<AbilityIdentifier> abilityId=null, EvolveIdentifier evolveId=null, IceCubeIdentifier iceCubeId=null, TailIdentifier tailId=null)
56+
public CustomCard(
57+
string name,
58+
List<AbilityIdentifier> abilityIdParam=null,
59+
List<SpecialAbilityIdentifier> specialAbilityIdParam=null,
60+
EvolveIdentifier evolveId=null,
61+
IceCubeIdentifier iceCubeId=null,
62+
TailIdentifier tailId=null)
5563
{
5664
this.name = name;
5765
CustomCard.cards.Add(this);
5866

5967
// Handle AbilityIdentifier
60-
List<AbilityIdentifier> toRemove = new List<AbilityIdentifier>();
61-
if (this.abilityId is not null)
68+
List<AbilityIdentifier> abilitiesToRemove = new List<AbilityIdentifier>();
69+
if (abilityIdParam is not null)
6270
{
63-
foreach (AbilityIdentifier id in abilityId)
71+
foreach (var id in abilityIdParam.Where(id => id.id != 0))
6472
{
65-
if (id.id != 0)
66-
{
67-
this.abilities.Add(id.id);
68-
}
73+
this.abilities.Add(id.id);
6974
}
70-
foreach (AbilityIdentifier id in toRemove)
75+
76+
foreach (AbilityIdentifier id in abilitiesToRemove)
7177
{
72-
this.abilityId.Remove(id);
78+
abilityIdParam.Remove(id);
79+
}
80+
81+
if (abilityIdParam.Count > 0)
82+
{
83+
CustomCard.abilityIds[CustomCard.cards.Count - 1] = abilityIdParam;
7384
}
7485
}
75-
if (abilityId is not null && this.abilityId.Count > 0)
86+
87+
List<SpecialAbilityIdentifier> specialAbilitiesToRemove = new List<SpecialAbilityIdentifier>();
88+
if (specialAbilityIdParam is not null)
7689
{
77-
CustomCard.abilityIds[CustomCard.cards.Count - 1] = abilityId;
90+
foreach (var id in specialAbilityIdParam.Where(id => id.id != 0))
91+
{
92+
this.specialAbilities.Add(id.id);
93+
}
94+
95+
foreach (SpecialAbilityIdentifier id in specialAbilitiesToRemove)
96+
{
97+
specialAbilityIdParam.Remove(id);
98+
}
99+
100+
if (specialAbilityIdParam.Count > 0)
101+
{
102+
CustomCard.specialAbilityIds[CustomCard.cards.Count - 1] = specialAbilityIdParam;
103+
}
78104
}
79105

106+
80107
// Handle EvolveIdentifier
81108
if (evolveId is not null)
82109
{

Patches/CardTriggerHandler.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@ public static bool Prefix(Ability ability, CardTriggerHandler __instance)
1818

1919
Predicate<Tuple<Ability, AbilityBehaviour>> checkAbilityExists = tuple =>
2020
tuple.Item1 == ability || AbilityCanStackAndIsNotPassive(ability);
21-
21+
Plugin.Log.LogDebug($"Attempting to add regular ability in card trigger handler [{ability}]");
2222
// return true if the ability is equal to the ability in the pair OR if ability cannot stack and is passive
2323
if (!__instance.triggeredAbilities.Exists(checkAbilityExists))
2424
{
25+
Plugin.Log.LogDebug($"-> Ability [{ability}] does not exist, adding...");
2526
NewAbility newAbility = NewAbility.abilities.Find(x => x.ability == ability);
27+
Plugin.Log.LogDebug($"-> New Ability is [{newAbility.ability}]");
2628
Type type = newAbility.abilityBehaviour;
2729
Component baseC = __instance;
2830
AbilityBehaviour item = baseC.gameObject.GetComponent(type) as AbilityBehaviour;
2931
if (item == null)
3032
{
3133
item = baseC.gameObject.AddComponent(type) as AbilityBehaviour;
34+
Plugin.Log.LogDebug($"--> Item is [{item}] | Ability toString [{ability}]");
3235
}
3336

3437
__instance.triggeredAbilities.Add(new Tuple<Ability, AbilityBehaviour>(ability, item));
@@ -48,14 +51,14 @@ public class CardTriggerHandler_AddAbility_SpecialTriggeredAbility
4851
{
4952
public static bool Prefix(SpecialTriggeredAbility ability, CardTriggerHandler __instance)
5053
{
51-
Plugin.Log.LogInfo($"Attempting to add spec ability to card trigger handler [{ability}]");
54+
Plugin.Log.LogDebug($"Attempting to add spec ability to card trigger handler [{ability}]");
5255
if ((int)ability < 25)
5356
{
5457
return true;
5558
}
5659
if (!__instance.specialAbilities.Exists(ab => ab.Item1 == ability))
5760
{
58-
Plugin.Log.LogInfo("-> spec ability does not exist yet, adding");
61+
Plugin.Log.LogDebug("-> spec ability does not exist yet, adding...");
5962
NewSpecialAbility newAbility = NewSpecialAbility.specialAbilities
6063
.Find(x => x.specialTriggeredAbility == ability);
6164
Type type = newAbility.abilityBehaviour;

Patches/StatIconInfo.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ static void Postfix()
1212
{
1313
foreach (var ability in NewSpecialAbility.specialAbilities)
1414
{
15-
// this is never being logged?
1615
Plugin.Log.LogDebug($"Attempting to add {ability.specialTriggeredAbility} in StatIconInfo");
1716
if (!StatIconInfo.allIconInfo.Exists(x => x == ability.statIconInfo)) {
18-
Plugin.Log.LogInfo($"-> Adding {ability.specialTriggeredAbility} in StatIconInfo");
17+
Plugin.Log.LogDebug($"-> Adding {ability.specialTriggeredAbility} in StatIconInfo");
1918
StatIconInfo.allIconInfo.Add(ability.statIconInfo);
2019
}
2120
}

0 commit comments

Comments
 (0)