-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOptionRules.cs
363 lines (307 loc) · 12.7 KB
/
OptionRules.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
using ChensGradiusMod.Projectiles.Aliens;
using ChensGradiusMod.Projectiles.Magic;
using ChensGradiusMod.Projectiles.Ranged;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using static ChensGradiusMod.GradiusHelper;
namespace ChensGradiusMod
{
public enum RuleTypes { WeaponProjectilePair, Weapon, Projectile };
public static class OptionRules
{
private static readonly List<AlienWeapon> BannedWeapons = new List<AlienWeapon>()
{
new AlienWeapon(ItemID.RainbowGun),
new AlienWeapon(ItemID.Vilethorn),
new AlienWeapon(ItemID.DD2BetsyBow),
new AlienWeapon(ItemID.Minishark),
new AlienWeapon(ItemID.MushroomSpear),
new AlienWeapon(ItemID.Megashark),
new AlienWeapon(ItemID.Gatligator),
new AlienWeapon(ItemID.ChainGun),
new AlienWeapon(ItemID.SDMG)
};
private static readonly List<AlienProjectile> BannedProjectiles = new List<AlienProjectile>()
{
new AlienProjectile(ProjectileID.RocketII),
new AlienProjectile(ProjectileID.RocketIV),
new AlienProjectile(ProjectileID.Dynamite),
new AlienProjectile(ProjectileID.BouncyDynamite),
new AlienProjectile(ProjectileID.StickyDynamite),
new AlienProjectile(ProjectileID.Bomb),
new AlienProjectile(ProjectileID.BombFish),
new AlienProjectile(ProjectileID.BouncyBomb),
new AlienProjectile(ProjectileID.StickyBomb),
new AlienProjectile(ModContent.ProjectileType<Death2Laser>()),
new AlienProjectile(ModContent.ProjectileType<AlliedBacterionBullet>())
};
private static readonly List<AlienWeaponProjectilePair> BannedWeaponProjectilePairs = new List<AlienWeaponProjectilePair>()
{
new AlienWeaponProjectilePair(ItemID.VortexBeater, ProjectileID.VortexBeater)
};
private static readonly List<AlienWeapon> AllowedWeapons = new List<AlienWeapon>();
private static readonly List<AlienProjectile> AllowedProjectiles = new List<AlienProjectile>();
private static readonly List<AlienWeaponProjectilePair> AllowedWeaponProjectilePairs = new List<AlienWeaponProjectilePair>()
{
new AlienWeaponProjectilePair(ItemID.StarCannon, ProjectileID.FallingStar),
new AlienWeaponProjectilePair(ItemID.OnyxBlaster, ProjectileID.BlackBolt),
new AlienWeaponProjectilePair(ItemID.Blowpipe, ProjectileID.Seed),
new AlienWeaponProjectilePair(ItemID.Blowgun, ProjectileID.Seed),
new AlienWeaponProjectilePair(ItemID.Marrow, ProjectileID.BoneArrow),
new AlienWeaponProjectilePair(ItemID.MoltenFury, ProjectileID.FireArrow),
new AlienWeaponProjectilePair(ItemID.BoneGlove, ProjectileID.BoneGloveProj),
new AlienWeaponProjectilePair(ItemID.ChlorophyteSaber, ProjectileID.SporeCloud),
new AlienWeaponProjectilePair(ItemID.IceBow, ProjectileID.FrostArrow),
new AlienWeaponProjectilePair(ItemID.ChargedBlasterCannon, ProjectileID.ChargedBlasterOrb),
new AlienWeaponProjectilePair(ItemID.MonkStaffT2, ProjectileID.MonkStaffT2Ghast),
new AlienWeaponProjectilePair(ItemID.MonkStaffT3, ProjectileID.MonkStaffT3_AltShot),
new AlienWeaponProjectilePair(ItemID.ChlorophyteClaymore, ProjectileID.ChlorophyteOrb),
new AlienWeaponProjectilePair(ItemID.PulseBow, ProjectileID.PulseBolt),
new AlienWeaponProjectilePair(ItemID.FireworksLauncher, ProjectileID.RocketFireworkRed),
new AlienWeaponProjectilePair(ItemID.FireworksLauncher, ProjectileID.RocketFireworkGreen),
new AlienWeaponProjectilePair(ItemID.FireworksLauncher, ProjectileID.RocketFireworkBlue),
new AlienWeaponProjectilePair(ItemID.FireworksLauncher, ProjectileID.RocketFireworkYellow),
new AlienWeaponProjectilePair(ItemID.VortexBeater, ProjectileID.VortexBeaterRocket),
new AlienWeaponProjectilePair(ItemID.SniperRifle, ProjectileID.BulletHighVelocity)
};
private static readonly List<AlienDamageType> SupportedDamageTypes = new List<AlienDamageType>()
{
new AlienDamageType("CalamityMod", "CalamityGlobalProjectile", "rogue")
};
public static bool StandardFilter(Projectile p)
{
return RequiredFilter(p) && !p.hostile && p.friendly && !p.npcProj && CanDamage(p)
&& IsAbleToCrit(p) && !p.minion && !p.trap;
}
public static bool RequiredFilter(Projectile p)
{
return p.active && IsNotAYoyo(p);
}
public static bool AddWeaponRule(string mode, string modName, string weapName)
{
List<AlienWeapon> listToUse;
switch (mode)
{
case "Allow":
listToUse = AllowedWeapons;
break;
case "Ban":
default:
listToUse = BannedWeapons;
break;
}
if (!listToUse.Exists(aw => modName == aw.modName && weapName == aw.weaponName))
{
listToUse.Add(new AlienWeapon(modName, weapName));
return true;
}
return false;
}
public static bool AddWeaponRule(string mode, int wType)
{
List<AlienWeapon> listToUse;
switch (mode)
{
case "Allow":
listToUse = AllowedWeapons;
break;
case "Ban":
default:
listToUse = BannedWeapons;
break;
}
if (!listToUse.Exists(aw => aw.modName == "Terraria" && wType == aw.weaponType))
{
listToUse.Add(new AlienWeapon(wType));
return true;
}
return false;
}
public static bool AddProjectileRule(string mode, string modName, string projName)
{
List<AlienProjectile> listToUse;
switch (mode)
{
case "Allow":
listToUse = AllowedProjectiles;
break;
case "Ban":
default:
listToUse = BannedProjectiles;
break;
}
if (!listToUse.Exists(ap => modName == ap.modName && projName == ap.projectileName))
{
listToUse.Add(new AlienProjectile(modName, projName));
return true;
}
return false;
}
public static bool AddProjectileRule(string mode, int pType)
{
List<AlienProjectile> listToUse;
switch (mode)
{
case "Allow":
listToUse = AllowedProjectiles;
break;
case "Ban":
default:
listToUse = BannedProjectiles;
break;
}
if (!listToUse.Exists(ap => ap.modName == "Terraria" && pType == ap.projectileType))
{
listToUse.Add(new AlienProjectile(pType));
return true;
}
return false;
}
public static bool AddWeaponProjectilePairRule(string mode, string modName, string weapName, string projName)
{
List<AlienWeaponProjectilePair> listToUse;
switch (mode)
{
case "Allow":
listToUse = AllowedWeaponProjectilePairs;
break;
case "Ban":
default:
listToUse = BannedWeaponProjectilePairs;
break;
}
if (!listToUse.Exists(awpp => modName == awpp.modName && weapName == awpp.weaponName
&& projName == awpp.projectileName))
{
listToUse.Add(new AlienWeaponProjectilePair(modName, weapName, projName));
return true;
}
return false;
}
public static bool AddWeaponProjectilePairRule(string mode, int wType, int pType)
{
List<AlienWeaponProjectilePair> listToUse;
switch (mode)
{
case "Allow":
listToUse = AllowedWeaponProjectilePairs;
break;
case "Ban":
default:
listToUse = BannedWeaponProjectilePairs;
break;
}
if (!listToUse.Exists(awpp => awpp.modName == "Terraria" && wType == awpp.weaponType
&& pType == awpp.projectileType))
{
listToUse.Add(new AlienWeaponProjectilePair(wType, pType));
return true;
}
return false;
}
public static bool ImportDamageType(string modName, string internalName, string damageType)
{
if (!SupportedDamageTypes.Exists(sdt => modName == sdt.modName
&& internalName == sdt.internalName
&& damageType == sdt.damageType))
{
AlienDamageType alienDamageType = new AlienDamageType(modName, internalName, damageType);
SupportedDamageTypes.Add(alienDamageType);
return true;
}
return false;
}
public static bool ImportDamageType(string modName, string damageType)
{
if (!SupportedDamageTypes.Exists(sdt => modName == sdt.modName
&& damageType == sdt.damageType))
{
AlienDamageType alienDamageType = new AlienDamageType(modName, damageType);
SupportedDamageTypes.Add(alienDamageType);
return true;
}
return false;
}
public static bool IsBanned(Item w, Projectile p) => IsBanned(w.type, p.type);
public static bool IsBanned(int wType, int pType)
{
bool result = false;
foreach (AlienWeapon aw in BannedWeapons)
{
if (aw.CheckType(wType))
{
result = true;
break;
}
}
if (result) return true;
result = false;
foreach (AlienProjectile ap in BannedProjectiles)
{
if (ap.CheckType(pType))
{
result = true;
break;
}
}
if (result) return true;
result = false;
foreach (AlienWeaponProjectilePair awpp in BannedWeaponProjectilePairs)
{
if (awpp.CheckType(wType, pType))
{
result = true;
break;
}
}
return result;
}
public static bool IsAllowed(Item w, Projectile p) => IsAllowed(w.type, p.type);
public static bool IsAllowed(int wType, int pType)
{
bool result = false;
foreach (AlienWeapon aw in AllowedWeapons)
{
if (aw.CheckType(wType))
{
result = true;
break;
}
}
if (result) return true;
result = false;
foreach (AlienProjectile ap in AllowedProjectiles)
{
if (ap.CheckType(pType))
{
result = true;
break;
}
}
if (result) return true;
result = false;
foreach (AlienWeaponProjectilePair awpp in AllowedWeaponProjectilePairs)
{
if (awpp.CheckType(wType, pType))
{
result = true;
break;
}
}
return result;
}
private static bool IsNotAYoyo(Projectile p) => p.aiStyle != 99;
private static bool IsAbleToCrit(Projectile p) => p.melee || p.ranged || p.thrown || p.magic
|| IsDamageTypeSupported(p.whoAmI);
private static bool IsDamageTypeSupported(int pWhoAmI)
{
foreach (AlienDamageType aDamageType in SupportedDamageTypes)
{
if (aDamageType.IsMatchingDamageType(pWhoAmI)) return true;
}
return false;
}
}
}