Skip to content

Commit 00a8ea0

Browse files
WIP ability ids
1 parent 229f3ff commit 00a8ea0

File tree

5 files changed

+111
-2
lines changed

5 files changed

+111
-2
lines changed

Models/AbilityIdentifier.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using DiskCardGame;
4+
using UnityEngine;
5+
6+
namespace APIPlugin
7+
{
8+
public class AbilityIdentifier
9+
{
10+
private static List<AbilityIdentifier> ids = new List<AbilityIdentifier>();
11+
private string guid;
12+
private string name;
13+
public Ability id;
14+
15+
private AbilityIdentifier(string guid, string name)
16+
{
17+
this.guid = guid;
18+
this.name = name;
19+
ids.Add(this);
20+
}
21+
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+
}
33+
34+
public override String ToString()
35+
{
36+
return $"{this.guid}({this.name})";
37+
}
38+
}
39+
}

Models/CustomCard.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace APIPlugin
88
public class CustomCard
99
{
1010
public static List<CustomCard> cards = new List<CustomCard>();
11+
public static Dictionary<int,List<AbilityIdentifier>> abilityIds = new Dictionary<int,List<AbilityIdentifier>>();
1112
public string name;
1213
public List<CardMetaCategory> metaCategories;
1314
public CardComplexity? cardComplexity;
@@ -49,6 +50,24 @@ public CustomCard(string name)
4950
CustomCard.cards.Add(this);
5051
}
5152

53+
public CustomCard(string name, List<AbilityIdentifier> abilityIds)
54+
{
55+
this.name = name;
56+
CustomCard.cards.Add(this);
57+
foreach (AbilityIdentifier id in abilityIds)
58+
{
59+
if (id.id != 0)
60+
{
61+
this.abilities.Add(id.id);
62+
abilityIds.Remove(id);
63+
}
64+
}
65+
if (abilityIds is not null)
66+
{
67+
CustomCard.abilityIds[CustomCard.cards.Count - 1] = abilityIds;
68+
}
69+
}
70+
5271
public CardInfo AdjustCard(CardInfo card)
5372
{
5473
TypeMapper<CustomCard, CardInfo>.Convert(this, card);

Models/NewAbility.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,19 @@ public class NewAbility
1212
public AbilityInfo info;
1313
public Type abilityBehaviour;
1414
public Texture tex;
15+
public AbilityIdentifier id;
1516

16-
public NewAbility(AbilityInfo info, Type abilityBehaviour, Texture tex)
17+
public NewAbility(AbilityInfo info, Type abilityBehaviour, Texture tex, AbilityIdentifier id = null)
1718
{
1819
this.ability = (Ability) 100 + NewAbility.abilities.Count;
1920
info.ability = this.ability;
2021
this.info = info;
2122
this.abilityBehaviour = abilityBehaviour;
2223
tex.filterMode = FilterMode.Point;
2324
this.tex = tex;
25+
this.id = id;
2426
NewAbility.abilities.Add(this);
27+
id.id = ability;
2528
Plugin.Log.LogInfo($"Loaded custom ability {info.rulebookName}!");
2629
}
2730
}

Models/NewCard.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace APIPlugin
88
public static class NewCard
99
{
1010
public static List<CardInfo> cards = new List<CardInfo>();
11+
public static Dictionary<int,List<AbilityIdentifier>> abilityIds = new Dictionary<int,List<AbilityIdentifier>>();
1112

1213
public static void Add(CardInfo card)
1314
{
@@ -24,7 +25,7 @@ public static void Add(string name, List<CardMetaCategory> metaCategories, CardC
2425
bool hideAttackAndHealth = false, int cost = 0, int bonesCost = 0, int energyCost = 0,
2526
List<GemType> gemsCost = null, SpecialStatIcon specialStatIcon = SpecialStatIcon.None,
2627
List<Tribe> tribes = null, List<Trait> traits = null, List<SpecialTriggeredAbility> specialAbilities = null,
27-
List<Ability> abilities = null, EvolveParams evolveParams = null,
28+
List<Ability> abilities = null, List<AbilityIdentifier> abilityIds = null, EvolveParams evolveParams = null,
2829
string defaultEvolutionName = null, TailParams tailParams = null, IceCubeParams iceCubeParams = null,
2930
bool flipPortraitForStrafe = false, bool onePerDeck = false,
3031
List<CardAppearanceBehaviour.Appearance> appearanceBehaviour = null, Texture2D tex = null,
@@ -125,6 +126,19 @@ public static void Add(string name, List<CardMetaCategory> metaCategories, CardC
125126
}
126127

127128
NewCard.cards.Add(card);
129+
130+
foreach (AbilityIdentifier id in abilityIds)
131+
{
132+
if (id.id != 0)
133+
{
134+
card.abilities.Add(id.id);
135+
abilityIds.Remove(id);
136+
}
137+
}
138+
if (abilityIds is not null)
139+
{
140+
NewCard.abilityIds[NewCard.cards.Count - 1] = abilityIds;
141+
}
128142
Plugin.Log.LogInfo($"Loaded custom card {name}!");
129143
}
130144

Plugin.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,40 @@ private void Awake()
4949
harmony.PatchAll();
5050
}
5151

52+
private void Start()
53+
{
54+
foreach(var item in NewCard.abilityIds)
55+
{
56+
foreach (AbilityIdentifier id in item.Value)
57+
{
58+
if (id.id != 0)
59+
{
60+
NewCard.cards[item.Key].abilities.Add(id.id);
61+
item.Value.Remove(id);
62+
}
63+
else
64+
{
65+
Plugin.Log.LogWarning($"Ability {id} not found for card {NewCard.cards[item.Key]}");
66+
}
67+
}
68+
}
69+
foreach(var item in CustomCard.abilityIds)
70+
{
71+
foreach (AbilityIdentifier id in item.Value)
72+
{
73+
if (id.id != 0)
74+
{
75+
CustomCard.cards[item.Key].abilities.Add(id.id);
76+
item.Value.Remove(id);
77+
}
78+
else
79+
{
80+
Plugin.Log.LogWarning($"Ability {id} not found for card {CustomCard.cards[item.Key]}");
81+
}
82+
}
83+
}
84+
}
85+
5286
private void OnEnable()
5387
{
5488
SceneManager.sceneLoaded += this.OnSceneLoaded;

0 commit comments

Comments
 (0)