Skip to content

Commit c522cca

Browse files
committed
add IsClickEffect, GetAllEffectNames and GetClickEffectAsDict calls
1 parent e2fa381 commit c522cca

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

ClickerCompat.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,41 @@ internal static string GetPathToBorderTexture(int type)
122122
return ClickerClass?.Call("GetPathToBorderTexture", versionString, type) as string;
123123
}
124124

125+
/// <summary>
126+
/// Returns all existing effects' internal names
127+
/// </summary>
128+
/// <returns>IEnumerable[string]</returns>
129+
internal static List<string> GetAllEffectNames()
130+
{
131+
return ClickerClass?.Call("GetAllEffectNames", versionString) as List<string>;
132+
}
133+
134+
/// <summary>
135+
/// Access an effect's stats. <see cref="null"/> if not found.
136+
/// "InternalName": The unique name (string).
137+
/// | "DisplayName": The displayed name (string).
138+
/// | "Description": The description (string).
139+
/// | "Amount": The amount of clicks to trigger the effect (int).
140+
/// | "Color": The color (Color).
141+
/// | "Action": The method ran when triggered (Action[Player, Vector2, int, int, float]).
142+
/// </summary>
143+
/// <param name="effect">The unique effect name</param>
144+
/// <returns>Dictionary[string, object]</returns>
145+
internal static Dictionary<string, object> GetClickEffectAsDict(string effect)
146+
{
147+
return ClickerClass?.Call("GetClickEffectAsDict", versionString, effect) as Dictionary<string, object>;
148+
}
149+
150+
/// <summary>
151+
/// Checks if an effect of this name exists
152+
/// </summary>
153+
/// <param name="effect">The unique name</param>
154+
/// <returns><see langword="true"/> if valid</returns>
155+
internal static bool IsClickEffect(string effect)
156+
{
157+
return ClickerClass?.Call("IsClickEffect", versionString, effect) as bool? ?? false;
158+
}
159+
125160
/// <summary>
126161
/// Call this to check if a projectile type belongs to the "clicker class" category
127162
/// </summary>

Items/Weapons/Clickers/ExampleClickerWithEffect.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public override void SetStaticDefaults()
2020
//Here we register an optional border/outline texture aswell
2121
ClickerCompat.RegisterClickerWeapon(this, borderTexture: "ClickerClassExampleMod/Items/Weapons/Clickers/ExampleClickerWithEffect_Outline");
2222

23-
//You want to cache the result to make accessing it easier in other places. For the purpose of the example, we don't
23+
//We want to cache the result to make accessing it easier in other places. For the purpose of the example, we don't
24+
//(Make sure to unload the saved string again in Mod.Unload()!)
2425
string uniqueName = ClickerCompat.RegisterClickEffect(mod, "ExampleEffect", "Mini Clickers", "Creates 5 Mini Clickers around the cursor for 20% damage", 6, Color.Red, delegate (Player player, Vector2 position, int type, int damage, float knockBack)
2526
{
2627
Main.PlaySound(SoundID.Chat, (int)position.X, (int)position.Y, -1);
@@ -44,9 +45,19 @@ public override void SetDefaults()
4445
//Here we use our custom effect, registered as 'modName:internalName'
4546
ClickerCompat.AddEffect(item, "ClickerClassExampleMod:ExampleEffect");
4647

47-
//You can add more than one effect aswell! (Here using the IEnumerable overload to make it more compact)
48-
ClickerCompat.AddEffect(item, new List<string> { "ClickerClass:DoubleClick2", "ClickerClass:Embrittle" });
49-
//In total, 3 effects
48+
//We can add more than one effect aswell! (Here using the IEnumerable overload to make it more compact)
49+
ClickerCompat.AddEffect(item, new List<string> { "ClickerClass:Inferno", "ClickerClass:Embrittle" });
50+
51+
//We can also access all available effects and do stuff with it
52+
//Here pick the first registered effect (random would be cool but Main.rand shouldn't be used in SetDefaults)
53+
List<string> allEffects = ClickerCompat.GetAllEffectNames();
54+
if (allEffects != null && allEffects.Count > 0)
55+
{
56+
ClickerCompat.AddEffect(item, allEffects[0]);
57+
//If this happens to be one we already added, it won't do anything
58+
}
59+
60+
//In total, atleast 3 effects
5061

5162
item.damage = 10;
5263
item.width = 30;

0 commit comments

Comments
 (0)