forked from westphallm1/tModLoader_Minions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrossMod.cs
173 lines (156 loc) · 6.98 KB
/
CrossMod.cs
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using AmuletOfManyMinions.Projectiles.Minions.CorruptionAltar;
using AmuletOfManyMinions.Projectiles.Minions.CrimsonAltar;
using AmuletOfManyMinions.Projectiles.Minions.EclipseHerald;
using AmuletOfManyMinions.Projectiles.Minions.GoblinGunner;
using AmuletOfManyMinions.Projectiles.Minions.GoblinTechnomancer;
using AmuletOfManyMinions.Projectiles.Minions.MinonBaseClasses;
using AmuletOfManyMinions.Projectiles.Minions.Necromancer;
using AmuletOfManyMinions.Projectiles.Minions.SpiritGun;
using AmuletOfManyMinions.Projectiles.Minions.TerrarianEnt;
using AmuletOfManyMinions.Projectiles.Minions.VanillaClones;
using AmuletOfManyMinions.Projectiles.Minions.VanillaClones.Pirate;
using AmuletOfManyMinions.Projectiles.Squires;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.ModLoader;
namespace AmuletOfManyMinions
{
class CrossMod
{
public static bool SummonersAssociationLoaded { get; private set; }
public static HashSet<int> MinionBuffTypes;
public static void Unload()
{
MinionBuffTypes = null;
}
public static bool SharknadoFunc(Projectile p)
{
return !((SharknadoMinion)p.modProjectile).isBeingUsedAsToken;
}
public static void AddSummonersAssociationMetadata()
{
MinionBuffTypes = new HashSet<int>();
if (ModLoader.GetMod("SummonersAssociation") is Mod summonersAssociation)
{
if(summonersAssociation.Version >= new Version(0, 4, 7))
{
SummonersAssociationLoaded = true;
//1. Collect all "EmpoweredMinion" that have a valid CounterType: WORKS FOR ALL EMPOWERED MINIONS (but also includes some "regular" minions which is unintended)
//var empoweredMinionsWithCounterType = this.GetContent<ModProjectile>().OfType<EmpoweredMinion>().Where(e => e.CounterType > ProjectileID.None).ToList();
//var counterTypes = empoweredMinionsWithCounterType.Select((e) => e.CounterType).ToHashSet();
//2. Collect all "CounterMinion": DOES NOT WORK FOR ALL EMPOWERED MINIONS (those that use "regular" minions for counts), but covers all 100% safe ones
// not sure what the 1.3 equivalent of GetContent is, use reflection instead
// Also blacklist squires just for good measure
Type counterMinionType = typeof(CounterMinion);
Type squireType = typeof(SquireMinion);
IEnumerable<Type> blacklistedTypes = Assembly.GetExecutingAssembly().GetTypes()
.Where(t => !t.IsAbstract && (t.IsSubclassOf(counterMinionType) || t.IsSubclassOf(squireType)));
//Empowered minion "counter" projectiles should not teleport
var methodRef = typeof(ModContent).GetMethod("ProjectileType", BindingFlags.Public | BindingFlags.Static);
foreach (var blacklistedType in blacklistedTypes)
{
var genericRef = methodRef.MakeGenericMethod(blacklistedType);
summonersAssociation.Call("AddTeleportConditionMinion", genericRef.Invoke(null, null));
}
//Special non-counter projectiles that should not teleport
//Return false to prevent a teleport
//Not specifying one will default to "false"
summonersAssociation.Call("AddTeleportConditionMinion", ModContent.ProjectileType<SharknadoMinion>(), (Func<Projectile, bool>)SharknadoFunc);
//Static minions should not teleport
//Don't include the probes, those can move around
summonersAssociation.Call("AddTeleportConditionMinion", ModContent.ProjectileType<GoblinTechnomancerMinion>());
summonersAssociation.Call("AddTeleportConditionMinion", ModContent.ProjectileType<CorruptionAltarMinion>());
summonersAssociation.Call("AddTeleportConditionMinion", ModContent.ProjectileType<CrimsonAltarMinion>());
summonersAssociation.Call("AddTeleportConditionMinion", ModContent.ProjectileType<GoblinGunnerMinion>());
summonersAssociation.Call("AddTeleportConditionMinion", ModContent.ProjectileType<NecromancerMinion>());
summonersAssociation.Call("AddTeleportConditionMinion", ModContent.ProjectileType<SpiritGunMinion>());
summonersAssociation.Call("AddTeleportConditionMinion", ModContent.ProjectileType<EclipseHeraldMinion>());
summonersAssociation.Call("AddTeleportConditionMinion", ModContent.ProjectileType<TerrarianEntMinion>());
}
if(summonersAssociation.Version >= new Version(0, 4, 1))
{
//Minion weapons that summon more than one type
summonersAssociation.Call(
"AddMinionInfo",
ModContent.ItemType<SpiderMinionItem>(),
ModContent.BuffType<SpiderMinionBuff>(),
new List<int> {
ModContent.ProjectileType<JumperSpiderMinion>(),
ModContent.ProjectileType<VenomSpiderMinion>(),
ModContent.ProjectileType<DangerousSpiderMinion>()
}
);
summonersAssociation.Call(
"AddMinionInfo",
ModContent.ItemType<TwinsMinionItem>(),
ModContent.BuffType<TwinsMinionBuff>(),
new List<int> {
ModContent.ProjectileType<MiniRetinazerMinion>(),
ModContent.ProjectileType<MiniSpazmatismMinion>()
}
);
summonersAssociation.Call(
"AddMinionInfo",
ModContent.ItemType<PirateMinionItem>(),
ModContent.BuffType<PirateMinionBuff>(),
new List<int> {
ModContent.ProjectileType<PirateMinion>(),
ModContent.ProjectileType<PirateDeadeyeMinion>(),
ModContent.ProjectileType<ParrotMinion>(),
ModContent.ProjectileType<FlyingDutchmanMinion>(),
}
);
summonersAssociation.Call(
"AddMinionInfo",
ModContent.ItemType<PygmyMinionItem>(),
ModContent.BuffType<PygmyMinionBuff>(),
new List<int> {
ModContent.ProjectileType<Pygmy1Minion>(),
ModContent.ProjectileType<Pygmy2Minion>(),
ModContent.ProjectileType<Pygmy3Minion>(),
ModContent.ProjectileType<Pygmy4Minion>()
}
);
summonersAssociation.Call(
"AddMinionInfo",
ModContent.ItemType<DeadlySphereMinionItem>(),
ModContent.BuffType<DeadlySphereMinionBuff>(),
new List<int> {
ModContent.ProjectileType<DeadlySphereMinion>(),
ModContent.ProjectileType<DeadlySphereClingerMinion>(),
ModContent.ProjectileType<DeadlySphereFireMinion>()
}
);
}
}
}
public static void PopulateSummonersAssociationBuffSet(Mod mod)
{
Version minSupportedVersion = new Version(0, 4, 7);
if (ModLoader.GetMod("SummonersAssociation") is Mod summonersAssociation && summonersAssociation.Version >= minSupportedVersion)
{
object supportedMinionsData = summonersAssociation.Call("GetSupportedMinions", mod, minSupportedVersion.ToString());
if(supportedMinionsData is List<Dictionary<string, object>> minionsList)
{
MinionBuffTypes.UnionWith(minionsList.Select(map =>
map.ContainsKey("BuffID") ? Convert.ToInt32(map["BuffID"]) : -1).ToList());
}
}
}
public static int GetSummonersAssociationVarietyCount()
{
int varietyCount = 0;
int[] buffTypes = Main.player[Main.myPlayer].buffType;
for(int i = 0; i < buffTypes.Length; i++)
{
varietyCount += MinionBuffTypes.Contains(buffTypes[i]) ? 1 : 0;
}
return varietyCount;
}
}
}