Skip to content

Commit 9ceecb9

Browse files
committed
Added talking cards
1 parent a5391b9 commit 9ceecb9

5 files changed

Lines changed: 121 additions & 0 deletions

File tree

Models/NewDialogue.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Collections.Generic;
2+
using DiskCardGame;
3+
4+
namespace APIPlugin
5+
{
6+
public class NewDialogue
7+
{
8+
public static Dictionary<string, DialogueEvent> dialogueEvents = new();
9+
10+
public static void AddAll(Dictionary<string, DialogueEvent> dialogueEvents)
11+
{
12+
foreach (KeyValuePair<string, DialogueEvent> pair in dialogueEvents)
13+
{
14+
NewDialogue.dialogueEvents.Add(pair.Key, pair.Value);
15+
}
16+
if (dialogueEvents.Count > 0)
17+
{
18+
Plugin.Log.LogInfo($"Loaded {dialogueEvents.Count} custom dialogues!");
19+
}
20+
}
21+
22+
public static void Add(string id, DialogueEvent dialogueEvent) {
23+
NewDialogue.dialogueEvents.Add(id, dialogueEvent);
24+
Plugin.Log.LogInfo($"Loaded custom dialogue {id}!");
25+
}
26+
}
27+
}

Models/NewTalkingCard.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using DiskCardGame;
4+
5+
namespace APIPlugin
6+
{
7+
public class NewTalkingCard
8+
{
9+
public static Dictionary<string,Type> talkingCards = new();
10+
public static List<Type> types = new(); // For easy access by CardTriggerHandler.GetType
11+
12+
public static void Add<T>(string name, Dictionary<string, DialogueEvent> dialogueEvents)
13+
{
14+
NewTalkingCard.talkingCards.Add(name.Replace(" ", "_"), typeof(T));
15+
NewTalkingCard.types.Add(typeof(T));
16+
NewDialogue.AddAll(dialogueEvents);
17+
Plugin.Log.LogInfo($"Loaded talking card {name}!");
18+
}
19+
20+
public static void Add<T>(string name) {
21+
Add<T>(name, new Dictionary<string, DialogueEvent>());
22+
}
23+
}
24+
}

Patches/CardTriggerHandler.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,22 @@ public static bool Prefix(SpecialTriggeredAbility ability, CardTriggerHandler __
7777
return false;
7878
}
7979
}
80+
81+
[HarmonyPatch(typeof(CardTriggerHandler), "GetType", typeof(string))]
82+
public class TriggerTypePatch
83+
{
84+
public static bool Prefix(ref Type __result, string typeName)
85+
{
86+
Type t = NewTalkingCard.types.Find(type => type.Name == typeName);
87+
if (t != null)
88+
{
89+
__result = t;
90+
return false;
91+
}
92+
else
93+
{
94+
return true;
95+
}
96+
}
97+
}
8098
}

Patches/DialogueUtils_GetEvent.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using HarmonyLib;
2+
using APIPlugin;
3+
4+
namespace API.Patches
5+
{
6+
[HarmonyPatch(typeof(DialogueDataUtil.DialogueData), "GetEvent", typeof(string))]
7+
public class DialogueUtilPatch
8+
{
9+
public static bool Prefix(ref DialogueEvent __result, string id)
10+
{
11+
DialogueEvent dialogueEvent;
12+
if (id != null && NewDialogue.dialogueEvents.TryGetValue(id, out dialogueEvent))
13+
{
14+
__result = dialogueEvent;
15+
return false;
16+
}
17+
else
18+
{
19+
return true;
20+
}
21+
}
22+
}
23+
24+
}

Patches/TalkingCards.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Reflection;
3+
using APIPlugin;
4+
using DiskCardGame;
5+
using HarmonyLib;
6+
7+
namespace API.Patches
8+
{
9+
[HarmonyPatch(typeof(TalkingCardChooser), "Awake")]
10+
public class TalkingCardPatch
11+
{
12+
public static bool Prefix(ref TalkingCardChooser __instance)
13+
{
14+
Card c = __instance.gameObject.GetComponentInChildren<Card>();
15+
Type t;
16+
if (NewTalkingCard.talkingCards.TryGetValue(c.Info.name.Replace(" ", "_"), out t))
17+
{
18+
MethodInfo info = c.GetType().GetMethod("AddPermanentBehaviour").MakeGenericMethod(new Type[] { t });
19+
info.Invoke(c, new object[] {});
20+
return false;
21+
}
22+
else
23+
{
24+
return true;
25+
}
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)