forked from SamsonAllen13/ClickerClass
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClickerModCalls.cs
More file actions
696 lines (648 loc) · 21.9 KB
/
ClickerModCalls.cs
File metadata and controls
696 lines (648 loc) · 21.9 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
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
using ClickerClass.Items;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ModLoader;
namespace ClickerClass
{
public static class ClickerModCalls
{
//All calls are "documented" on the ClickerClassExampleMod repo: https://github.com/SamsonAllen13/ClickerClassExampleMod/blob/master/ClickerCompat.cs
//Not everything is exposed via API yet
public static object Call(params object[] args)
{
ClickerClass clickerClass = ClickerClass.mod;
Version latestVersion = clickerClass.Version;
//Simplify code by resizing args
Array.Resize(ref args, 25);
string success = "Success";
try
{
string message = args[0] as string;
//Future-proofing. Allowing new info to be returned while maintaining backwards compat if necessary
object apiString = args[1];
Version apiVersion = apiString is string ? new Version(apiString as string) : latestVersion;
//Starting index of all parameters for a call
int index = 2;
if (message == "SetClickerWeaponDefaults")
{
var item = args[index + 0] as Item;
if (item == null)
{
throw new Exception($"Call Error: The item argument for the attempted message, \"{message}\" has returned null.");
}
ClickerSystem.SetClickerWeaponDefaults(item);
return success;
}
else if (message == "RegisterClickerProjectile")
{
var modProj = args[index + 0] as ModProjectile;
if (modProj == null)
{
throw new Exception($"Call Error: The modProjectile argument for the attempted message, \"{message}\" has returned null.");
}
ClickerSystem.RegisterClickerProjectile(modProj);
return success;
}
else if (message == "RegisterClickerItem")
{
var modItem = args[index + 0] as ModItem;
if (modItem == null)
{
throw new Exception($"Call Error: The modItem argument for the attempted message, \"{message}\" has returned null.");
}
ClickerSystem.RegisterClickerItem(modItem);
return success;
}
else if (message == "RegisterClickerWeapon")
{
var modItem = args[index + 0] as ModItem;
var borderTexture = args[index + 1] as string;
if (modItem == null)
{
throw new Exception($"Call Error: The modItem argument for the attempted message, \"{message}\" has returned null.");
}
ClickerSystem.RegisterClickerWeapon(modItem, borderTexture);
return success;
}
//Mod mod, string internalName, string displayName, string description, int amount, Color color, Action<Player, Vector2, int, int, float> action
else if (message == "RegisterClickEffect")
{
var mod = args[index + 0] as Mod;
var internalName = args[index + 1] as string;
var displayName = args[index + 2] as string;
var description = args[index + 3] as string;
var amount = args[index + 4] as int?;
var color = args[index + 5] as Color?;
var action = args[index + 6] as Action<Player, Vector2, int, int, float>;
string nameOfargument = string.Empty;
if (mod == null)
nameOfargument = "mod";
if (internalName == null)
nameOfargument = "internalName";
if (displayName == null)
nameOfargument = "displayName";
if (description == null)
nameOfargument = "description";
if (amount == null)
nameOfargument = "amount";
if (color == null)
nameOfargument = "color";
if (action == null)
nameOfargument = "action";
if (nameOfargument != string.Empty)
{
throw new Exception($"Call Error: The {nameOfargument} argument for the attempted message, \"{message}\" has returned null.");
}
ClickerSystem.RegisterClickEffect(mod, internalName, displayName, description, amount.Value, color.Value, action);
return success;
}
else if (message == "GetPathToBorderTexture")
{
var type = args[index + 0] as int?;
if (type == null)
{
throw new Exception($"Call Error: The type argument for the attempted message, \"{message}\" has returned null.");
}
return ClickerSystem.GetPathToBorderTexture(type.Value);
}
else if (message == "IsClickerProj")
{
var proj = args[index + 0] as Projectile;
var type = args[index + 0] as int?; //Try another type variation because of overload
if (proj != null)
{
return ClickerSystem.IsClickerProj(proj);
}
else if (type != null)
{
return ClickerSystem.IsClickerProj(type.Value);
}
else
{
throw new Exception($"Call Error: The projectile/type argument for the attempted message, \"{message}\" has returned null.");
}
}
else if (message == "IsClickerItem")
{
var item = args[index + 0] as Item;
var type = args[index + 0] as int?; //Try another type variation because of overload
if (item != null)
{
return ClickerSystem.IsClickerItem(item);
}
else if (type != null)
{
return ClickerSystem.IsClickerItem(type.Value);
}
else
{
throw new Exception($"Call Error: The item/type argument for the attempted message, \"{message}\" has returned null.");
}
}
else if (message == "IsClickerWeapon")
{
var item = args[index + 0] as Item;
var type = args[index + 0] as int?; //Try another type variation because of overload
if (item != null)
{
return ClickerSystem.IsClickerWeapon(item);
}
else if (type != null)
{
return ClickerSystem.IsClickerWeapon(type.Value);
}
else
{
throw new Exception($"Call Error: The item/type argument for the attempted message, \"{message}\" has returned null.");
}
}
else if (message == "IsClickEffect")
{
var effectName = args[index + 0] as string;
if (effectName == null)
{
throw new Exception($"Call Error: The effectName argument for the attempted message, \"{message}\" has returned null.");
}
return ClickerSystem.IsClickEffect(effectName);
}
//Clicker Weapon/Item specifics now
else if (message == "SetColor")
{
var item = args[index + 0] as Item;
var color = args[index + 1] as Color?;
if (item == null)
{
throw new Exception($"Call Error: The item argument for the attempted message, \"{message}\" has returned null.");
}
if (color == null)
{
color = Color.White;
}
ClickerWeapon.SetColor(item, color.Value);
return success;
}
else if (message == "SetDisplayTotalClicks")
{
var item = args[index + 0] as Item;
if (item == null)
{
throw new Exception($"Call Error: The item argument for the attempted message, \"{message}\" has returned null.");
}
ClickerItem.SetDisplayTotalClicks(item);
return success;
}
else if (message == "SetDust")
{
var item = args[index + 0] as Item;
var dust = args[index + 1] as int?;
if (item == null)
{
throw new Exception($"Call Error: The item argument for the attempted message, \"{message}\" has returned null.");
}
if (dust == null)
{
dust = 0;
}
ClickerWeapon.SetDust(item, dust.Value);
return success;
}
else if (message == "SetEffect")
{
if (apiVersion < latestVersion)
{
var item = args[index + 0] as Item;
var name = args[index + 1] as string;
if (item == null)
{
throw new Exception($"Call Error: The item argument for the attempted message, \"{message}\" has returned null.");
}
if (name == null)
{
name = string.Empty;
}
//Old mods could only register with old ClickerClass effect display names before
if (ClickerSystem.GetNewNameFromOldDisplayName(name, out string internalName))
{
ClickerWeapon.AddEffect(item, internalName);
}
return success;
}
else
{
throw new Exception($"Use AddEffect instead, SetEffect is obsolete in {latestVersion}");
}
}
else if (message == "SetRadius")
{
var item = args[index + 0] as Item;
var radius = args[index + 1] as float?;
if (item == null)
{
throw new Exception($"Call Error: The item argument for the attempted message, \"{message}\" has returned null.");
}
if (radius == null)
{
radius = 0f;
}
ClickerWeapon.SetRadius(item, radius.Value);
return success;
}
else if (message == "AddEffect")
{
var item = args[index + 0] as Item;
var name = args[index + 1] as string;
var names = args[index + 1] as IEnumerable<string>; //type variation
if (item == null)
{
throw new Exception($"Call Error: The item argument for the attempted message, \"{message}\" has returned null.");
}
if (name != null)
{
ClickerWeapon.AddEffect(item, name);
return success;
}
else if (names != null)
{
ClickerWeapon.AddEffect(item, names);
return success;
}
else
{
throw new Exception($"Call Error: The name/names argument for the attempted message, \"{message}\" has returned null.");
}
}
else if (message == "GetAllEffectNames")
{
//List<string>
return ClickerSystem.GetAllEffectNames();
}
else if (message == "GetClickEffectAsDict")
{
var effectName = args[index + 0] as string;
if (effectName == null)
{
throw new Exception($"Call Error: The effectName argument for the attempted message, \"{message}\" has returned null.");
}
//Dictionary<string, object>
return ClickerSystem.GetClickEffectAsDict(effectName);
}
//Player specifics now
else if (message == "GetPlayerStat")
{
var player = args[index + 0] as Player;
var statName = args[index + 1] as string;
if (statName == null)
{
throw new Exception($"Call Error: The statName argument for the attempted message, \"{message}\" has returned null.");
}
if (player == null)
{
throw new Exception($"Call Error: The player argument for the attempted message, \"{message}\" has returned null.");
}
ClickerPlayer clickerPlayer = player.GetModPlayer<ClickerPlayer>();
if (statName == "clickerRadius")
{
return clickerPlayer.clickerRadius;
}
else if (statName == "clickAmountTotal")
{
var item = args[index + 2] as Item;
if (item == null)
{
throw new Exception($"Call Error: The item argument for the attempted message, \"{message}\" has returned null.");
}
string name;
if (apiVersion < latestVersion)
{
//Before it assumed the effect of the item used. Since 1.2.2 it is now a list, and requires a specific effect
//For the purpose of backwards compatibility, assume the first effect on the clicker as the main one
var effects = item.GetGlobalItem<ClickerItemCore>().itemClickEffects;
name = effects.Count == 0 ? null : effects[0];
}
else
{
name = args[index + 3] as string;
}
if (name == null)
{
name = string.Empty;
}
return clickerPlayer.GetClickAmountTotal(item, name);
}
else if (statName == "clickAmount")
{
return clickerPlayer.clickAmount;
}
else if (statName == "clickerPerSecond")
{
return clickerPlayer.clickerPerSecond;
}
throw new Exception($"Call Error: The statName argument for the attempted message, \"{message}\" has no valid entry point.");
}
else if (message == "GetArmorSet")
{
var player = args[index + 0] as Player;
var setName = args[index + 1] as string;
if (setName == null)
{
throw new Exception($"Call Error: The setName argument for the attempted message, \"{message}\" has returned null.");
}
if (player == null)
{
throw new Exception($"Call Error: The player argument for the attempted message, \"{message}\" has returned null.");
}
ClickerPlayer clickerPlayer = player.GetModPlayer<ClickerPlayer>();
//setMotherboard, setOverclock, setPrecursor, setMice
if (setName == "Motherboard")
{
return clickerPlayer.setMotherboard;
}
else if (setName == "Overclock")
{
return clickerPlayer.setOverclock;
}
else if (setName == "Precursor")
{
return clickerPlayer.setPrecursor;
}
else if (setName == "Mice")
{
return clickerPlayer.setMice;
}
throw new Exception($"Call Error: The setName argument for the attempted message, \"{message}\" has no valid entry point.");
}
else if (message == "GetAccessory")
{
var player = args[index + 0] as Player;
var accName = args[index + 1] as string;
if (accName == null)
{
throw new Exception($"Call Error: The accName argument for the attempted message, \"{message}\" has returned null.");
}
if (player == null)
{
throw new Exception($"Call Error: The player argument for the attempted message, \"{message}\" has returned null.");
}
ClickerPlayer clickerPlayer = player.GetModPlayer<ClickerPlayer>();
//accEnchantedLED, accEnchantedLED2, accHandCream, accGlassOfMilk, accCookie, accCookie2, accClickingGlove, accAncientClickingGlove, accRegalClickingGlove
if (accName == "ChocolateChip")
{
if (apiVersion < latestVersion)
{
//Kept for backwards compatibility
return clickerPlayer.HasClickEffect(ClickEffect.ChocolateChip);
}
throw new Exception("GetAccessory+'ChocolateChip' is obsolete, use HasClickEffect+'ClickerClass:ChocolateChip'");
}
else if (accName == "EnchantedLED")
{
return clickerPlayer.accEnchantedLED || clickerPlayer.accEnchantedLED2;
}
else if (accName == "HandCream")
{
return clickerPlayer.accHandCream;
}
else if (accName == "StickyKeychain")
{
if (apiVersion < latestVersion)
{
//Kept for backwards compatibility
return clickerPlayer.HasClickEffect(ClickEffect.StickyKeychain);
}
throw new Exception("GetAccessory+'StickyKeychain' is obsolete, use HasClickEffect+'ClickerClass:StickyKeychain'");
}
else if (accName == "GlassOfMilk")
{
return clickerPlayer.accGlassOfMilk;
}
else if (accName == "Cookie")
{
return clickerPlayer.accCookie || clickerPlayer.accCookie2;
}
else if (accName == "ClickingGlove")
{
return clickerPlayer.accClickingGlove;
}
else if (accName == "AncientClickingGlove")
{
return clickerPlayer.accAncientClickingGlove;
}
else if (accName == "RegalClickingGlove")
{
return clickerPlayer.accRegalClickingGlove;
}
throw new Exception($"Call Error: The accName argument for the attempted message, \"{message}\" has no valid entry point.");
}
else if (message == "SetPlayerStat")
{
var player = args[index + 0] as Player;
var statName = args[index + 1] as string;
if (statName == null)
{
throw new Exception($"Call Error: The statName argument for the attempted message, \"{message}\" has returned null.");
}
if (player == null)
{
throw new Exception($"Call Error: The player argument for the attempted message, \"{message}\" has returned null.");
}
ClickerPlayer clickerPlayer = player.GetModPlayer<ClickerPlayer>();
if (statName == "clickerCritAdd")
{
var crit = args[index + 2] as int?;
if (crit == null)
{
throw new Exception($"Call Error: The crit argument for the attempted message, \"{message}\" has returned null.");
}
clickerPlayer.clickerCrit += crit.Value;
clickerPlayer.clickerCrit = Math.Max(4, clickerPlayer.clickerCrit);
return success;
}
else if (statName == "clickerDamageFlatAdd")
{
var flat = args[index + 2] as int?;
if (flat == null)
{
throw new Exception($"Call Error: The flat argument for the attempted message, \"{message}\" has returned null.");
}
clickerPlayer.clickerDamageFlat += flat.Value;
clickerPlayer.clickerDamageFlat = Math.Max(0, clickerPlayer.clickerDamageFlat);
return success;
}
else if (statName == "clickerDamageAdd")
{
var damage = args[index + 2] as float?;
if (damage == null)
{
throw new Exception($"Call Error: The damage argument for the attempted message, \"{message}\" has returned null.");
}
clickerPlayer.clickerDamage += damage.Value;
clickerPlayer.clickerDamage = Math.Max(1f, clickerPlayer.clickerDamage);
return success;
}
else if (statName == "clickerBonusAdd")
{
var bonus = args[index + 2] as int?;
if (bonus == null)
{
throw new Exception($"Call Error: The bonus argument for the attempted message, \"{message}\" has returned null.");
}
clickerPlayer.clickerBonus += bonus.Value;
clickerPlayer.clickerBonus = Math.Max(1, clickerPlayer.clickerBonus);
return success;
}
else if (statName == "clickerBonusPercentAdd")
{
var bonus = args[index + 2] as float?;
if (bonus == null)
{
throw new Exception($"Call Error: The bonus argument for the attempted message, \"{message}\" has returned null.");
}
clickerPlayer.clickerBonusPercent += bonus.Value;
clickerPlayer.clickerBonusPercent = Math.Max(1f, clickerPlayer.clickerBonusPercent);
return success;
}
else if (statName == "clickerRadiusAdd")
{
var radius = args[index + 2] as float?;
if (radius == null)
{
throw new Exception($"Call Error: The radius argument for the attempted message, \"{message}\" has returned null.");
}
clickerPlayer.clickerRadius += radius.Value;
clickerPlayer.clickerRadius = Math.Max(1f, clickerPlayer.clickerRadius);
return success;
}
throw new Exception($"Call Error: The statName argument for the attempted message, \"{message}\" has no valid entry point.");
}
else if (message == "SetAccessory")
{
var player = args[index + 0] as Player;
var accName = args[index + 1] as string;
if (accName == null)
{
throw new Exception($"Call Error: The accName argument for the attempted message, \"{message}\" has returned null.");
}
if (player == null)
{
throw new Exception($"Call Error: The player argument for the attempted message, \"{message}\" has returned null.");
}
ClickerPlayer clickerPlayer = player.GetModPlayer<ClickerPlayer>();
//accEnchantedLED, accEnchantedLED2, accHandCream, accGlassOfMilk, accCookie, accCookie2, accClickingGlove, accAncientClickingGlove, accRegalClickingGlove
if (accName == "ChocolateChip")
{
//Kept for backwards compatibility
if (apiVersion < latestVersion)
{
clickerPlayer.EnableClickEffect(ClickEffect.ChocolateChip);
return success;
}
throw new Exception("SetAccessory+'ChocolateChip' is obsolete, use EnableClickEffect+'ClickerClass:ChocolateChip'");
}
else if (accName == "EnchantedLED")
{
clickerPlayer.accEnchantedLED = true;
return success;
}
else if (accName == "EnchantedLED2")
{
clickerPlayer.accEnchantedLED2 = true;
return success;
}
else if (accName == "HandCream")
{
clickerPlayer.accHandCream = true;
return success;
}
else if (accName == "StickyKeychain")
{
//Kept for backwards compatibility
if (apiVersion < latestVersion)
{
clickerPlayer.EnableClickEffect(ClickEffect.StickyKeychain);
return success;
}
throw new Exception("SetAccessory+'StickyKeychain' is obsolete, use EnableClickEffect+'ClickerClass:StickyKeychain'");
}
else if (accName == "GlassOfMilk")
{
clickerPlayer.accGlassOfMilk = true;
return success;
}
else if (accName == "Cookie")
{
clickerPlayer.accCookie = true;
return success;
}
else if (accName == "Cookie2")
{
clickerPlayer.accCookie2 = true;
return success;
}
else if (accName == "ClickingGlove")
{
clickerPlayer.accClickingGlove = true;
return success;
}
else if (accName == "AncientClickingGlove")
{
clickerPlayer.accAncientClickingGlove = true;
return success;
}
else if (accName == "RegalClickingGlove")
{
clickerPlayer.accRegalClickingGlove = true;
return success;
}
throw new Exception($"Call Error: The accName argument for the attempted message, \"{message}\" has no valid entry point.");
}
else if (message == "EnableClickEffect")
{
var player = args[index + 0] as Player;
if (player == null)
{
throw new Exception($"Call Error: The player argument for the attempted message, \"{message}\" has returned null.");
}
ClickerPlayer clickerPlayer = player.GetModPlayer<ClickerPlayer>();
var effectName = args[index + 1] as string;
var effectNames = args[index + 1] as IEnumerable<string>; //type variation
if (effectName != null)
{
clickerPlayer.EnableClickEffect(effectName);
return success;
}
else if (effectNames != null)
{
clickerPlayer.EnableClickEffect(effectNames);
return success;
}
else
{
throw new Exception($"Call Error: The effectName/effectNames argument for the attempted message, \"{message}\" has returned null.");
}
}
else if (message == "HasClickEffect")
{
var player = args[index + 0] as Player;
var effectName = args[index + 1] as string;
if (player == null)
{
throw new Exception($"Call Error: The player argument for the attempted message, \"{message}\" has returned null.");
}
if (effectName == null)
{
throw new Exception($"Call Error: The effectName argument for the attempted message, \"{message}\" has returned null.");
}
ClickerPlayer clickerPlayer = player.GetModPlayer<ClickerPlayer>();
return clickerPlayer.HasClickEffect(effectName);
}
}
catch (Exception e)
{
clickerClass.Logger.Error($"Call Error: {e.StackTrace} {e.Message}");
}
return null;
}
}
}