-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExtraLoadoutsMod.Call.cs
More file actions
55 lines (40 loc) · 2.58 KB
/
ExtraLoadoutsMod.Call.cs
File metadata and controls
55 lines (40 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Linq;
using System.Text;
using Terraria;
using Terraria.ModLoader;
namespace ExtraLoadouts;
public sealed partial class ExtraLoadoutsMod : Mod {
private event Action<Player, bool, int, bool, int> PreSwapLoadoutCallbacks;
private event Action<Player, bool, int, bool, int> PostSwapLoadoutCallbacks;
public void InvokePreSwapLoadoutsCallback(Player player, bool oldLoadoutModded, int oldLoadoutIndex, bool newLoadoutModded, int newLoadoutIndex) {
PreSwapLoadoutCallbacks?.Invoke(player, oldLoadoutModded, oldLoadoutIndex, newLoadoutModded, newLoadoutIndex);
}
public void InvokePostSwapLoadoutsCallback(Player player, bool oldLoadoutModded, int oldLoadoutIndex, bool newLoadoutModded, int newLoadoutIndex) {
PostSwapLoadoutCallbacks?.Invoke(player, oldLoadoutModded, oldLoadoutIndex, newLoadoutModded, newLoadoutIndex);
}
public override object Call(params object[] args) {
if (args[0] is not string method) {
return "args[0] must be a string specifying the call";
}
switch (method) {
case "AreWeCallYet.0": return true;
case "CurrentExtraLoadoutIndex.0" when args[1] is Player player: return player.GetModPlayer<LoadoutPlayer>().CurrentExtraLoadoutIndex;
case "TotalExtraLoadouts.0": return EXTRA_LOADOUTS;
case "GetExtraLoadoutVanilla.0" when args[1] is Player player && args[2] is int index: return player.GetModPlayer<LoadoutPlayer>().ExtraLoadouts[index].Vanilla;
case "GetExtraLoadoutModLoader.0" when args[1] is Player player && args[2] is int index: return player.GetModPlayer<LoadoutPlayer>().ExtraLoadouts[index].ModLoader;
case "SwitchToExtraLoadout.0" when args[1] is Player player && args[2] is int index: player.GetModPlayer<LoadoutPlayer>().TrySwitchingExtraLoadout(index); break;
case "AddPreSwapLoadoutCallback.0" when args[1] is Action<Player, bool, int, bool, int> callback: PreSwapLoadoutCallbacks += callback; break;
case "AddPostSwapLoadoutCallback.0" when args[1] is Action<Player, bool, int, bool, int> callback: PostSwapLoadoutCallbacks += callback; break;
default:
var argTypeString = new StringBuilder();
if (args.Length > 1) {
argTypeString.AppendJoin(',', args[1..].Select(obj => obj.GetType().Name));
} else {
argTypeString.Append("void");
}
throw new InvalidOperationException($"Unknown method \"{method}({argTypeString})\"");
}
return true;
}
}