Skip to content

Commit 8d09d04

Browse files
Merge pull request #8 from julian-perge/feature/special_abilities_patchv1
Addition of Special Abilities
2 parents 87559c1 + 599bb29 commit 8d09d04

14 files changed

Lines changed: 416 additions & 96 deletions

Models/AbilityIdentifier.cs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,32 @@
1-
using System;
21
using System.Collections.Generic;
32
using DiskCardGame;
4-
using UnityEngine;
53

64
namespace APIPlugin
75
{
86
public class AbilityIdentifier
97
{
10-
private static List<AbilityIdentifier> ids = new List<AbilityIdentifier>();
8+
private static List<AbilityIdentifier> ids = new();
119
private string guid;
12-
private string name;
13-
public Ability id;
10+
private string name;
11+
public Ability id;
1412

1513
private AbilityIdentifier(string guid, string name)
1614
{
1715
this.guid = guid;
1816
this.name = name;
19-
ids.Add(this);
17+
ids.Add(this);
2018
}
2119

22-
public static AbilityIdentifier GetAbilityIdentifier(string guid, string name)
23-
{
24-
if (ids.Exists((AbilityIdentifier x) => x.guid == guid && x.name == name))
25-
{
26-
return ids.Find((AbilityIdentifier x) => x.guid == guid && x.name == name);
27-
}
28-
else
29-
{
30-
return new AbilityIdentifier(guid, name);
31-
}
32-
}
20+
public static AbilityIdentifier GetAbilityIdentifier(string guid, string name)
21+
{
22+
return ids.Exists(x => x.guid == guid && x.name == name)
23+
? ids.Find(x => x.guid == guid && x.name == name)
24+
: new AbilityIdentifier(guid, name);
25+
}
3326

34-
public override String ToString()
27+
public override string ToString()
3528
{
36-
return $"{this.guid}({this.name})";
29+
return $"{guid}({name})";
3730
}
3831
}
39-
}
32+
}

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
{

Models/NewAbility.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace APIPlugin
77
{
88
public class NewAbility
99
{
10-
public static List<NewAbility> abilities = new List<NewAbility>();
10+
public static List<NewAbility> abilities = new();
1111
public Ability ability;
1212
public AbilityInfo info;
1313
public Type abilityBehaviour;
@@ -16,14 +16,14 @@ public class NewAbility
1616

1717
public NewAbility(AbilityInfo info, Type abilityBehaviour, Texture tex, AbilityIdentifier id = null)
1818
{
19-
this.ability = (Ability) 100 + NewAbility.abilities.Count;
20-
info.ability = this.ability;
19+
ability = (Ability) 100 + abilities.Count;
20+
info.ability = ability;
2121
this.info = info;
2222
this.abilityBehaviour = abilityBehaviour;
2323
tex.filterMode = FilterMode.Point;
2424
this.tex = tex;
2525
this.id = id;
26-
NewAbility.abilities.Add(this);
26+
abilities.Add(this);
2727
if (id != null){
2828
id.id = ability;
2929
}

Models/NewCard.cs

Lines changed: 48 additions & 23 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,17 +8,21 @@ namespace APIPlugin
78
{
89
public static class NewCard
910
{
10-
public static List<CardInfo> cards = new List<CardInfo>();
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>();
15-
16-
public static void Add(CardInfo card, List<AbilityIdentifier> abilityIds = null, EvolveIdentifier evolveId = null,
11+
public static List<CardInfo> cards = new();
12+
13+
public static Dictionary<int, List<AbilityIdentifier>> abilityIds = new();
14+
public static Dictionary<int, List<SpecialAbilityIdentifier>> specialAbilityIds = new();
15+
public static Dictionary<int, EvolveIdentifier> evolveIds = new();
16+
public static Dictionary<int, IceCubeIdentifier> iceCubeIds = new();
17+
public static Dictionary<int, TailIdentifier> tailIds = new();
18+
19+
public static void Add(CardInfo card, List<AbilityIdentifier> abilityIdsParam = null,
20+
List<SpecialAbilityIdentifier> specialAbilitiesIdsParam = null,
21+
EvolveIdentifier evolveId = null,
1722
IceCubeIdentifier iceCubeId = null, TailIdentifier tailId = null)
1823
{
1924
NewCard.cards.Add(card);
20-
handleIdentifiers(card, abilityIds, evolveId, iceCubeId, tailId);
25+
HandleIdentifiers(card, abilityIdsParam, specialAbilitiesIdsParam, evolveId, iceCubeId, tailId);
2126
Plugin.Log.LogInfo($"Loaded custom card {card.name}!");
2227
}
2328

@@ -30,7 +35,8 @@ public static void Add(string name, List<CardMetaCategory> metaCategories, CardC
3035
bool hideAttackAndHealth = false, int cost = 0, int bonesCost = 0, int energyCost = 0,
3136
List<GemType> gemsCost = null, SpecialStatIcon specialStatIcon = SpecialStatIcon.None,
3237
List<Tribe> tribes = null, List<Trait> traits = null, List<SpecialTriggeredAbility> specialAbilities = null,
33-
List<Ability> abilities = null, List<AbilityIdentifier> abilityIds = null, EvolveParams evolveParams = null,
38+
List<Ability> abilities = null, List<AbilityIdentifier> abilityIdsParam = null,
39+
List<SpecialAbilityIdentifier> specialAbilitiesIdsParam = null, EvolveParams evolveParams = null,
3440
string defaultEvolutionName = null, TailParams tailParams = null, IceCubeParams iceCubeParams = null,
3541
bool flipPortraitForStrafe = false, bool onePerDeck = false,
3642
List<CardAppearanceBehaviour.Appearance> appearanceBehaviour = null, Texture2D tex = null,
@@ -133,33 +139,51 @@ public static void Add(string name, List<CardMetaCategory> metaCategories, CardC
133139

134140
NewCard.cards.Add(card);
135141

136-
handleIdentifiers(card, abilityIds, evolveId, iceCubeId, tailId);
142+
HandleIdentifiers(card, abilityIdsParam, specialAbilitiesIdsParam, evolveId, iceCubeId, tailId);
137143

138144
Plugin.Log.LogInfo($"Loaded custom card {name}!");
139145
}
140146

141-
private static void handleIdentifiers(CardInfo card, List<AbilityIdentifier> abilityIds, EvolveIdentifier evolveId,
142-
IceCubeIdentifier iceCubeId, TailIdentifier tailId)
147+
private static void HandleIdentifiers(
148+
CardInfo card,
149+
List<AbilityIdentifier> abilityIdsParam,
150+
List<SpecialAbilityIdentifier> specialAbilitiesIdsParam,
151+
EvolveIdentifier evolveId,
152+
IceCubeIdentifier iceCubeId,
153+
TailIdentifier tailId)
143154
{
144155
// Handle AbilityIdentifier
145156
List<AbilityIdentifier> toRemove = new List<AbilityIdentifier>();
146-
if (abilityIds is not null)
157+
if (abilityIdsParam is not null)
147158
{
148-
foreach (AbilityIdentifier id in abilityIds)
159+
foreach (var id in abilityIdsParam.Where(id => id.id != 0))
149160
{
150-
if (id.id != 0)
151-
{
152-
card.abilities.Add(id.id);
153-
}
161+
card.abilities.Add(id.id);
154162
}
163+
155164
foreach (AbilityIdentifier id in toRemove)
156165
{
157-
abilityIds.Remove(id);
166+
abilityIdsParam.Remove(id);
167+
}
168+
169+
if (abilityIdsParam.Count > 0)
170+
{
171+
NewCard.abilityIds[NewCard.cards.Count - 1] = abilityIdsParam;
158172
}
159173
}
160-
if (abilityIds is not null && abilityIds.Count > 0)
174+
175+
// Handle SpecialAbilityIds
176+
if (specialAbilitiesIdsParam is not null)
161177
{
162-
NewCard.abilityIds[NewCard.cards.Count - 1] = abilityIds;
178+
foreach (var id in specialAbilitiesIdsParam.Where(id => id.id != 0))
179+
{
180+
card.specialAbilities.Add(id.id);
181+
}
182+
183+
if (specialAbilitiesIdsParam.Count > 0)
184+
{
185+
NewCard.specialAbilityIds[NewCard.cards.Count - 1] = specialAbilitiesIdsParam;
186+
}
163187
}
164188

165189
// Handle EvolveIdentifier
@@ -209,9 +233,10 @@ private static void DetermineAndSetCardArt(
209233
pixelTex.name = newName;
210234
pixelTex.filterMode = FilterMode.Point;
211235

212-
card.pixelPortrait = Sprite.Create(pixelTex, CardUtils.DefaultCardPixelArtRect, CardUtils.DefaultVector2);
236+
card.pixelPortrait =
237+
Sprite.Create(pixelTex, CardUtils.DefaultCardPixelArtRect, CardUtils.DefaultVector2);
213238
card.pixelPortrait.name = newName;
214239
}
215240
}
216241
}
217-
}
242+
}

Models/NewSpecialAbility.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using DiskCardGame;
4+
using UnityEngine;
5+
6+
namespace APIPlugin
7+
{
8+
public class NewSpecialAbility
9+
{
10+
public static List<NewSpecialAbility> specialAbilities = new();
11+
public SpecialTriggeredAbility specialTriggeredAbility;
12+
public StatIconInfo statIconInfo;
13+
public Type abilityBehaviour;
14+
public SpecialAbilityIdentifier id;
15+
16+
public NewSpecialAbility(
17+
Type abilityBehaviour,
18+
SpecialAbilityIdentifier id,
19+
StatIconInfo statIconInfo = null
20+
)
21+
{
22+
specialTriggeredAbility = (SpecialTriggeredAbility)26 + specialAbilities.Count;
23+
var logNameOrIdNumber = specialTriggeredAbility.ToString();
24+
if (statIconInfo)
25+
{
26+
this.statIconInfo = statIconInfo;
27+
HandleStatIconInfo(statIconInfo);
28+
logNameOrIdNumber = this.statIconInfo.rulebookName;
29+
}
30+
this.abilityBehaviour = abilityBehaviour;
31+
this.id = id;
32+
id.id = specialTriggeredAbility;
33+
34+
HandleStatIconInfo(statIconInfo);
35+
36+
specialAbilities.Add(this);
37+
Plugin.Log.LogInfo($"Loaded custom special ability [{logNameOrIdNumber}]!");
38+
}
39+
40+
// is only called if StatIconInfo is not null
41+
private static void HandleStatIconInfo(StatIconInfo statIconInfo)
42+
{
43+
statIconInfo.iconType = (SpecialStatIcon)8 + specialAbilities.Count;
44+
45+
if (statIconInfo.iconGraphic is not null)
46+
{
47+
// the reason for this is just one less step for the end user to setup
48+
statIconInfo.iconGraphic.filterMode = FilterMode.Point;
49+
}
50+
51+
// a lazy initializer
52+
if (statIconInfo.metaCategories.Count == 0)
53+
{
54+
statIconInfo.metaCategories = new List<AbilityMetaCategory>
55+
{
56+
AbilityMetaCategory.Part1Modular, AbilityMetaCategory.Part1Rulebook
57+
};
58+
}
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)