forked from UriBuilder/AQMod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAQUtils.cs
1809 lines (1629 loc) · 66.6 KB
/
AQUtils.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
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
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using AQMod.Assets;
using AQMod.Content.Players;
using AQMod.Items;
using AQMod.Localization;
using AQMod.NPCs;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary;
using Terraria;
using Terraria.DataStructures;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
using Terraria.Utilities;
namespace AQMod
{
public static class AQUtils
{
public static Vector2 TrueMouseworld => Vector2.Transform(Main.ReverseGravitySupport(Main.MouseScreen, 0f), Matrix.Invert(Main.GameViewMatrix.ZoomMatrix)) + Main.screenPosition;
public static class Perspective
{
public const float Z_VIEW = -20f;
internal static Vector2 GetParralaxPosition(Vector2 origin, float z)
{
var viewPos = new Vector2(Main.screenPosition.X + Main.screenWidth / 2f, Main.screenPosition.Y + Main.screenHeight / 2f);
return new Vector2(origin.X - (1f - (-Z_VIEW / (z - Z_VIEW))) * (origin.X - viewPos.X), origin.Y - (1f - (-Z_VIEW / (z - Z_VIEW))) * (origin.Y - viewPos.Y));
}
public static float GetParralaxScale(float originalScale, float z)
{
return originalScale * (-Z_VIEW / (z - Z_VIEW));
}
}
public struct ArrayInterpreter<T>
{
public T[] Arr;
public ArrayInterpreter(T value)
{
Arr = new T[1] { value };
}
public ArrayInterpreter(T[] value)
{
Arr = value;
}
public static implicit operator ArrayInterpreter<T>(T value)
{
return new ArrayInterpreter<T>(value);
}
public static implicit operator ArrayInterpreter<T>(T[] value)
{
return new ArrayInterpreter<T>(value);
}
}
internal struct ItemGlowmask : GlowmaskData.IWorld, GlowmaskData.IInventory, GlowmaskData.IPlayerHeld
{
private Func<Color> getColor;
public ItemGlowmask(Func<Color> getColor)
{
this.getColor = getColor;
}
private Color GetColor()
{
if (getColor != null)
return getColor();
return new Color(250, 250, 250, 0);
}
void GlowmaskData.IWorld.Draw(GlowmaskData glowmask, Item item, SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI)
{
var drawCoordinates = new Vector2(item.position.X - Main.screenPosition.X + glowmask.Tex.Width / 2 + item.width / 2 - glowmask.Tex.Width / 2, item.position.Y - Main.screenPosition.Y + glowmask.Tex.Height / 2 + item.height - glowmask.Tex.Height + 2f);
var drawFrame = new Rectangle(0, 0, glowmask.Tex.Width, glowmask.Tex.Height);
var drawRotation = rotation;
var origin = Main.itemTexture[item.type].Size() / 2;
var drawData = new DrawData(glowmask.Tex, drawCoordinates, drawFrame, GetColor(), drawRotation, origin, scale, SpriteEffects.None, 0);
drawData.Draw(Main.spriteBatch);
}
void GlowmaskData.IInventory.Draw(GlowmaskData glowmask, Item item, SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale)
{
Main.spriteBatch.Draw(glowmask.Tex, position, frame, GetColor(), 0f, origin, scale, SpriteEffects.None, 0f);
}
void GlowmaskData.IPlayerHeld.Draw(GlowmaskData glowmask, Player player, AQPlayer aQPlayer, Item item, PlayerDrawInfo info)
{
var texture = glowmask.Tex;
if (item.useStyle == ItemUseStyleID.HoldingOut)
{
if (Item.staff[item.type])
{
float drawRotation3 = info.drawPlayer.itemRotation + 0.785f * info.drawPlayer.direction;
int offsetX1 = 0;
int offsetY = 0;
var origin3 = new Vector2(0f, Main.itemTexture[info.drawPlayer.inventory[info.drawPlayer.selectedItem].type].Height);
if (info.drawPlayer.gravDir == -1f)
{
if (info.drawPlayer.direction == -1)
{
drawRotation3 += 1.57f;
origin3 = new Vector2(Main.itemTexture[info.drawPlayer.inventory[info.drawPlayer.selectedItem].type].Width, 0f);
offsetX1 -= Main.itemTexture[info.drawPlayer.inventory[info.drawPlayer.selectedItem].type].Width;
}
else
{
drawRotation3 -= 1.57f;
origin3 = Vector2.Zero;
}
}
else if (info.drawPlayer.direction == -1)
{
origin3 = new Vector2(Main.itemTexture[info.drawPlayer.inventory[info.drawPlayer.selectedItem].type].Width, Main.itemTexture[info.drawPlayer.inventory[info.drawPlayer.selectedItem].type].Height);
offsetX1 -= Main.itemTexture[info.drawPlayer.inventory[info.drawPlayer.selectedItem].type].Width;
}
Vector2 holdoutOrigin = Vector2.Zero;
ItemLoader.HoldoutOrigin(info.drawPlayer, ref holdoutOrigin);
var drawCoordinates3 = new Vector2((int)(info.itemLocation.X - Main.screenPosition.X + origin3.X + offsetX1), (int)(info.itemLocation.Y - Main.screenPosition.Y + offsetY));
var drawFrame3 = new Rectangle(0, 0, texture.Width, texture.Height);
origin3 += holdoutOrigin;
Main.playerDrawData.Add(new DrawData(texture, drawCoordinates3, drawFrame3, GetColor(), drawRotation3, origin3, item.scale, info.spriteEffects, 0));
return;
}
var spriteEffects = (SpriteEffects)(player.gravDir != 1f ? player.direction != 1 ? 3 : 2 : player.direction != 1 ? 1 : 0);
var offset = new Vector2(texture.Width / 2, texture.Height / 2);
Vector2 holdoutOffset = item.modItem.HoldoutOffset().GetValueOrDefault(new Vector2(10f, 0f)) * player.gravDir;
int offsetX = (int)holdoutOffset.X;
offset.Y += holdoutOffset.Y;
var origin2 = player.direction == -1 ? new Vector2(texture.Width + offsetX, texture.Height / 2) : new Vector2(-offsetX, texture.Height / 2);
var drawCoordinates2 = new Vector2((int)(player.itemLocation.X - Main.screenPosition.X + offset.X), (int)(player.itemLocation.Y - Main.screenPosition.Y + offset.Y));
var drawFrame2 = new Rectangle(0, 0, texture.Width, texture.Height);
var drawRotation2 = player.itemRotation;
Main.playerDrawData.Add(new DrawData(texture, drawCoordinates2, drawFrame2, GetColor(), drawRotation2, origin2, item.scale, spriteEffects, 0));
return;
}
if (player.gravDir == -1f)
{
var drawCoordinates2 = new Vector2((int)(info.itemLocation.X - Main.screenPosition.X), (int)(info.itemLocation.Y - Main.screenPosition.Y));
var drawFrame2 = new Rectangle(0, 0, texture.Width, texture.Height);
var drawRotation2 = player.itemRotation;
var origin2 = new Vector2(texture.Width * 0.5f - texture.Width * 0.5f * player.direction, 0f);
Main.playerDrawData.Add(new DrawData(texture, drawCoordinates2, drawFrame2, GetColor(), drawRotation2, origin2, item.scale, info.spriteEffects, 0));
return;
}
var drawCoordinates = new Vector2((int)(info.itemLocation.X - Main.screenPosition.X), (int)(info.itemLocation.Y - Main.screenPosition.Y));
var drawFrame = new Rectangle(0, 0, texture.Width, texture.Height);
var drawRotation = player.itemRotation;
var origin = new Vector2(texture.Width * 0.5f - texture.Width * 0.5f * player.direction, texture.Height);
Main.playerDrawData.Add(new DrawData(texture, drawCoordinates, drawFrame, GetColor(), drawRotation, origin, item.scale, info.spriteEffects, 0));
}
}
internal static int SmokeGore(UnifiedRandom random)
{
return 61 + random.Next(3);
}
public static bool ChestItem(Item item)
{
return item.createTile < TileID.Dirt ? false : Main.tileContainer[item.createTile] && !Main.tileSolidTop[item.createTile];
}
public static void DrawUIBack(SpriteBatch spriteBatch, Texture2D texture, Vector2 position, Rectangle itemFrame, float itemScale, Color color, float progress = 1f)
{
int frameY = (int)(texture.Height * progress);
var uiFrame = new Rectangle(0, texture.Height - frameY, texture.Width, frameY);
position.Y += uiFrame.Y * Main.inventoryScale;
var center = position + itemFrame.Size() / 2f * itemScale;
spriteBatch.Draw(texture, center, uiFrame, color, 0f, texture.Size() / 2f, Main.inventoryScale, SpriteEffects.None, 0f);
}
public static T2[] GetSpecific<T, T2>(this List<T> arr, Func<T, T2> get)
{
var arr2 = new T2[arr.Count];
for (int i = 0; i < arr.Count; i++)
{
arr2[i] = get(arr[i]);
}
return arr2;
}
public static T2[] GetSpecific<T, T2>(this T[] arr, Func<T, T2> get)
{
var arr2 = new T2[arr.Length];
for (int i = 0; i < arr.Length; i++)
{
arr2[i] = get(arr[i]);
}
return arr2;
}
public static int Mean(this List<int> arr)
{
int num = 0;
for (int i = 0; i < arr.Count; i++)
{
num += arr[i];
}
return num / arr.Count;
}
public static int Mean(this byte[] arr)
{
int num = 0;
for (int i = 0; i < arr.Length; i++)
{
num += arr[i];
}
return num / arr.Length;
}
public static int Mean(this int[] arr)
{
int num = 0;
for (int i = 0; i < arr.Length; i++)
{
num += arr[i];
}
return num / arr.Length;
}
public static bool IsTalkingTo<T>(this Player player) where T : ModNPC
{
return IsTalkingTo(player, ModContent.NPCType<T>());
}
public static bool IsTalkingTo(this Player player, int npcType)
{
return player.talkNPC != -1 && Main.npc[player.talkNPC].type == npcType;
}
public static T GetValue<T>(this FieldInfo field, object obj)
{
return (T)field.GetValue(obj);
}
public static bool IsReferenceType(Type type)
{
return !type.IsValueType && !type.IsEnum && type != typeof(string);
}
public static T DeepCopy<T>(this T obj)
{
return DeepCopyTo(obj, (T)Activator.CreateInstance(typeof(T)), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
}
public static T DeepCopy<T>(this T obj, BindingFlags flags)
{
return DeepCopyTo(obj, (T)Activator.CreateInstance(typeof(T)), flags);
}
public static T DeepCopyTo<T>(this T obj, T myObj)
{
return DeepCopyTo(obj, myObj, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
}
public static T DeepCopyTo<T>(this T obj, T myObj, BindingFlags flags)
{
Type t = obj.GetType();
var l = AQMod.Instance.Logger;
var fields = t.GetFields(flags);
//l.Debug("writing fields");
foreach (var f in fields)
{
//l.Debug(f.FieldType.Name + " " + f.Name);
if (!IsReferenceType(f.FieldType))
{
f.SetValue(myObj, f.GetValue(obj));
}
else
{
object value = f.GetValue(obj);
if (value == null)
{
f.SetValue(myObj, null);
}
else if (value.GetType() == typeof(Array))
{
f.SetValue(myObj, DeepCopyArray((Array)value));
}
else
{
try
{
var newValue = Activator.CreateInstance(value.GetType());
f.SetValue(myObj, value.DeepCopyTo(newValue));
}
catch (Exception ex)
{
l.Error("Error when cloning field {" + f.FieldType.Name + " " + f.Name + "}", ex);
f.SetValue(myObj, null);
}
}
}
}
var properties = t.GetProperties(flags);
//l.Debug("writing properties");
foreach (var p in properties)
{
//l.Debug(p.PropertyType.Name + " " + p.Name);
if (p.CanWrite)
{
if (!IsReferenceType(p.PropertyType))
{
p.SetValue(myObj, p.GetValue(obj, null), null);
}
else
{
object value = p.GetValue(obj, null);
if (value == null)
{
p.SetValue(myObj, null, null);
}
else
{
try
{
var newValue = Activator.CreateInstance(value.GetType());
p.SetValue(myObj, value.DeepCopyTo(newValue), null);
}
catch (Exception ex)
{
l.Error("Error when cloning property {" + p.PropertyType.Name + " " + p.Name + "}", ex);
p.SetValue(myObj, null, null);
}
}
}
}
}
return myObj;
}
public static object DeepCopyArray(Array array)
{
return null;
}
public static void DrawPlayerFull(Player player)
{
if (Main.gamePaused)
{
player.PlayerFrame();
}
if (player.ghost)
{
return;
}
Vector2 position = default(Vector2);
if (player.inventory[player.selectedItem].flame || player.head == 137 || player.wings == 22)
{
player.itemFlameCount--;
if (player.itemFlameCount <= 0)
{
player.itemFlameCount = 5;
for (int k = 0; k < 7; k++)
{
player.itemFlamePos[k].X = (float)Main.rand.Next(-10, 11) * 0.15f;
player.itemFlamePos[k].Y = (float)Main.rand.Next(-10, 1) * 0.35f;
}
}
}
if (player.armorEffectDrawShadowEOCShield)
{
int num = player.eocDash / 4;
if (num > 3)
{
num = 3;
}
for (int l = 0; l < num; l++)
{
Main.instance.DrawPlayer(player, player.shadowPos[l], player.shadowRotation[l], player.shadowOrigin[l], 0.5f + 0.2f * (float)l);
}
}
if (player.invis)
{
player.armorEffectDrawOutlines = false;
player.armorEffectDrawShadow = false;
player.armorEffectDrawShadowSubtle = false;
position = player.position;
if (player.aggro <= -750)
{
Main.instance.DrawPlayer(player, position, player.fullRotation, player.fullRotationOrigin, 1f);
}
else
{
player.invis = false;
Main.instance.DrawPlayer(player, position, player.fullRotation, player.fullRotationOrigin);
player.invis = true;
}
}
if (player.armorEffectDrawOutlines)
{
_ = player.position;
if (!Main.gamePaused)
{
player.ghostFade += player.ghostDir * 0.075f;
}
if ((double)player.ghostFade < 0.1)
{
player.ghostDir = 1f;
player.ghostFade = 0.1f;
}
else if ((double)player.ghostFade > 0.9)
{
player.ghostDir = -1f;
player.ghostFade = 0.9f;
}
float num5 = player.ghostFade * 5f;
for (int m = 0; m < 4; m++)
{
float num6;
float num7;
switch (m)
{
default:
num6 = num5;
num7 = 0f;
break;
case 1:
num6 = 0f - num5;
num7 = 0f;
break;
case 2:
num6 = 0f;
num7 = num5;
break;
case 3:
num6 = 0f;
num7 = 0f - num5;
break;
}
position = new Vector2(player.position.X + num6, player.position.Y + player.gfxOffY + num7);
Main.instance.DrawPlayer(player, position, player.fullRotation, player.fullRotationOrigin, player.ghostFade);
}
}
if (player.armorEffectDrawOutlinesForbidden)
{
_ = player.position;
if (!Main.gamePaused)
{
player.ghostFade += player.ghostDir * 0.025f;
}
if ((double)player.ghostFade < 0.1)
{
player.ghostDir = 1f;
player.ghostFade = 0.1f;
}
else if ((double)player.ghostFade > 0.9)
{
player.ghostDir = -1f;
player.ghostFade = 0.9f;
}
float num8 = player.ghostFade * 5f;
for (int n = 0; n < 4; n++)
{
float num9;
float num10;
switch (n)
{
default:
num9 = num8;
num10 = 0f;
break;
case 1:
num9 = 0f - num8;
num10 = 0f;
break;
case 2:
num9 = 0f;
num10 = num8;
break;
case 3:
num9 = 0f;
num10 = 0f - num8;
break;
}
position = new Vector2(player.position.X + num9, player.position.Y + player.gfxOffY + num10);
Main.instance.DrawPlayer(player, position, player.fullRotation, player.fullRotationOrigin, player.ghostFade);
}
}
if (player.armorEffectDrawShadowBasilisk)
{
int num11 = (int)(player.basiliskCharge * 3f);
for (int num12 = 0; num12 < num11; num12++)
{
Main.instance.DrawPlayer(player, player.shadowPos[num12], player.shadowRotation[num12], player.shadowOrigin[num12], 0.5f + 0.2f * (float)num12);
}
}
else if (player.armorEffectDrawShadow)
{
for (int num2 = 0; num2 < 3; num2++)
{
Main.instance.DrawPlayer(player, player.shadowPos[num2], player.shadowRotation[num2], player.shadowOrigin[num2], 0.5f + 0.2f * (float)num2);
}
}
if (player.armorEffectDrawShadowLokis)
{
for (int num3 = 0; num3 < 3; num3++)
{
Main.instance.DrawPlayer(player, Vector2.Lerp(player.shadowPos[num3], player.position + new Vector2(0f, player.gfxOffY), 0.5f), player.shadowRotation[num3], player.shadowOrigin[num3], MathHelper.Lerp(1f, 0.5f + 0.2f * (float)num3, 0.5f));
}
}
if (player.armorEffectDrawShadowSubtle)
{
for (int num4 = 0; num4 < 4; num4++)
{
position.X = player.position.X + (float)Main.rand.Next(-20, 21) * 0.1f;
position.Y = player.position.Y + (float)Main.rand.Next(-20, 21) * 0.1f + player.gfxOffY;
Main.instance.DrawPlayer(player, position, player.fullRotation, player.fullRotationOrigin, 0.9f);
}
}
if (player.shadowDodge)
{
player.shadowDodgeCount += 1f;
if (player.shadowDodgeCount > 30f)
{
player.shadowDodgeCount = 30f;
}
}
else
{
player.shadowDodgeCount -= 1f;
if (player.shadowDodgeCount < 0f)
{
player.shadowDodgeCount = 0f;
}
}
if (player.shadowDodgeCount > 0f)
{
_ = player.position;
position.X = player.position.X + player.shadowDodgeCount;
position.Y = player.position.Y + player.gfxOffY;
Main.instance.DrawPlayer(player, position, player.fullRotation, player.fullRotationOrigin, 0.5f + (float)Main.rand.Next(-10, 11) * 0.005f);
position.X = player.position.X - player.shadowDodgeCount;
Main.instance.DrawPlayer(player, position, player.fullRotation, player.fullRotationOrigin, 0.5f + (float)Main.rand.Next(-10, 11) * 0.005f);
}
position = player.position;
position.Y += player.gfxOffY;
//if (player.stoned)
//{
// Main.instance.DrawPlayerStoned(player, position);
//}
// else if (!player.invis)
if (!player.invis)
{
Main.instance.DrawPlayer(player, position, player.fullRotation, player.fullRotationOrigin);
}
}
public static void FillOther<T>(this T[] arr, T[] arr2, int start = 0)
{
int length = arr.Length > arr2.Length ? arr.Length : arr2.Length;
if (length + start > arr.Length)
{
length = arr.Length - length;
}
for (int i = start; i < length; i++)
{
arr2[i] = arr[i];
}
}
public static int ShootProj(Player player, Item item, Vector2 location, Vector2 velocity, int projType, int projDamage, float projKB, Vector2? setMousePos)
{
var mouseScreen = Main.MouseScreen;
if (setMousePos != null)
{
var mousePos = setMousePos.Value - Main.screenPosition;
Main.mouseX = (int)mousePos.X;
Main.mouseX = (int)mousePos.Y;
}
int result;
if (PlayerHooks.Shoot(player, item, ref location, ref velocity.X, ref velocity.Y, ref projType, ref projDamage, ref projKB) &&
ItemLoader.Shoot(item, player, ref location, ref velocity.X, ref velocity.Y, ref projType, ref projDamage, ref projKB))
{
result = Projectile.NewProjectile(location, velocity, projType, projDamage, projKB, player.whoAmI);
}
else
{
result = -2;
}
Main.mouseX = (int)mouseScreen.X;
Main.mouseY = (int)mouseScreen.Y;
return result;
}
public static bool AddUnless<T>(this List<T> list, T thingToAdd, T unless = default(T))
{
if (thingToAdd.Equals(unless))
{
return false;
}
list.Add(thingToAdd);
return true;
}
public static string TypeName<T>()
{
return TypeName(typeof(T));
}
public static string TypeName(this Type type)
{
if (type.DeclaringType == null)
return type.Name;
return TypeName(type.DeclaringType) + "." + type.Name;
}
public static int CheckForPlayers(Rectangle rectangle)
{
for (int i = 0; i < Main.maxPlayers; i++)
{
if (Main.player[i].active && !Main.player[i].dead && rectangle.Intersects(Main.player[i].getRect()))
{
return i;
}
}
return -1;
}
public static Color MultColorsThenDiv(Color color1, Color color2)
{
return new Color(color1.R / 255f * (color2.R / 255f), color1.G / 255f * (color2.G / 255f), color1.B / 255f * (color2.B / 255f), color1.A / 255f * (color2.A / 255f));
}
public static float Brightness(this Color color)
{
return (color.R + color.G + color.B) / (255f * 3f);
}
public static HashSet<T> Combine<T>(params HashSet<T>[] sets)
{
var value = new HashSet<T>();
foreach (var set in sets)
{
foreach (var item in set)
{
if (!value.Contains(item))
{
value.Add(item);
//AQMod.GetInstance().Logger.Debug(item);
}
}
}
return value;
}
public static List<T> ToList<T>(this T[] arr)
{
var list = new List<T>();
for (int i = 0; i < arr.Length; i++)
{
list.Add(arr[i]);
}
return list;
}
public static string GetTextValue(params ValueTuple<GameCulture, string>[] values)
{
string english = "Invalid Name";
foreach (var t in values)
{
if (t.Item1.LegacyId == Language.ActiveCulture.LegacyId)
{
return t.Item2;
}
if (t.Item1.LegacyId == GameCulture.English.LegacyId)
{
english = t.Item2;
}
}
return english;
}
public static ModTranslation Add(this ModTranslation text, string value, GameCulture culture)
{
text.AddTranslation(culture, value);
return text;
}
public static void Glowmask(this ModItem item)
{
if (!Main.dedServ)
{
Glowmask(item, new Color(250, 250, 250, 0));
}
}
public static void Glowmask(this ModItem item, Color brightness, bool inv = false)
{
if (!Main.dedServ)
{
var glowmask = new ItemGlowmask(() => brightness);
CustomGlowmask(item, glowmask, inv ? glowmask : ((GlowmaskData.IInventory)null), glowmask);
}
}
public static void Glowmask(this ModItem item, Func<Color> brightness)
{
if (!Main.dedServ)
{
var glowmask = new ItemGlowmask(brightness);
CustomGlowmask(item, glowmask, null, glowmask);
}
}
public static void Glowmask(this ModItem item, Texture2D texture)
{
if (!Main.dedServ)
{
Glowmask(item, texture, new Color(250, 250, 250, 0));
}
}
public static void Glowmask(this ModItem item, Texture2D texture, Color brightness)
{
if (!Main.dedServ)
{
var glowmask = new ItemGlowmask(() => brightness);
CustomGlowmask(item, texture, glowmask, null, glowmask);
}
}
public static void Glowmask(this ModItem item, Texture2D texture, Func<Color> brightness)
{
if (!Main.dedServ)
{
var glowmask = new ItemGlowmask(brightness);
CustomGlowmask(item, texture, glowmask, null, glowmask);
}
}
internal static void CustomGlowmask(this ModItem item, GlowmaskData.IWorld world = null, GlowmaskData.IInventory inv = null, GlowmaskData.IPlayerHeld held = null)
{
if (!Main.dedServ)
{
CustomGlowmask(item, ModContent.GetTexture(item.GetPath("_Glow")), world, inv, held);
}
}
internal static void CustomGlowmask(this ModItem item, Texture2D texture, GlowmaskData.IWorld world = null, GlowmaskData.IInventory inv = null, GlowmaskData.IPlayerHeld held = null)
{
if (!Main.dedServ)
{
if (GlowmaskData.ItemToGlowmask == null)
{
GlowmaskData.ItemToGlowmask = new Dictionary<int, GlowmaskData>();
}
GlowmaskData.ItemToGlowmask.Add(item.item.type, new GlowmaskData(texture, world, inv, held));
}
}
public static Item Instance<T>(bool newInstance = true) where T : ModItem
{
return Instance(ModContent.ItemType<T>(), newInstance: newInstance);
}
public static Item Instance(int type, bool newInstance = true)
{
if (!newInstance && type >= Main.maxItemTypes)
{
return ItemLoader.GetItem(type).item;
}
var item = new Item();
item.SetDefaults(type);
return item;
}
public static int AmtAccSlots(this Player player)
{
return 8 + player.extraAccessorySlots;
}
public const int GrapplingHookIndex = 4;
public static Item GrapplingHook(this Player player)
{
return player.miscEquips[GrapplingHookIndex];
}
public static byte MultClamp(byte b, float mult)
{
return MultClamp(b, mult, byte.MinValue, byte.MaxValue);
}
public static byte MultClamp(byte b, float mult, byte max)
{
return MultClamp(b, mult, byte.MinValue, max);
}
public static byte MultClamp(byte b, float mult, byte min, byte max)
{
return (byte)MathHelper.Clamp(b * mult, min, max);
}
public static TextureAsset GetTextureAsset(this Mod mod, string path)
{
return new TextureAsset(mod, path);
}
public static NoHitting NoHit(this NPC npc)
{
return npc.GetGlobalNPC<NoHitting>();
}
public static float FromByte(byte value, float maximum)
{
return value * maximum / 255f;
}
public static float FromByte(byte value, float minimum, float maximum)
{
return minimum + value * (maximum - minimum) / 255f;
}
public static T GetValueOrDefault<T>(object value, T defaultValue)
{
return value != null && (value is T wantedValue) ? wantedValue : default;
}
public static void RemoveRepeatingIndices(List<int> list)
{
var indexList = new List<int>();
for (int i = 0; i < list.Count; i++)
{
if (indexList.Contains(list[i]))
{
list.RemoveAt(i);
i--;
}
else
{
indexList.Add(list[i]);
}
}
}
public static PlayerDrawEffects FX(this Player player)
{
return player.GetModPlayer<PlayerDrawEffects>();
}
public static PlayerBiomes Biomes(this Player player)
{
return player.GetModPlayer<PlayerBiomes>();
}
public static List<T> CutNullIndicesToList<T>(this T[] arr) where T : class
{
var list = new List<T>();
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] != null)
list.Add(arr[i]);
}
return list;
}
public static T[] CutNullIndices<T>(this T[] arr) where T : class
{
return CutNullIndicesToList(arr).ToArray();
}
public static T2[] Convert<T, T2>(this T[] arr, Func<T, T2> toOtherType)
{
var arr2 = new T2[arr.Length];
for (int i = 0; i < arr.Length; i++)
{
arr2[i] = toOtherType(arr[i]);
}
return arr2;
}
public static int DoCount<T>(this T[] arr, Func<T, bool> validItem)
{
int count = 0;
for (int i = 0; i < arr.Length; i++)
{
if (validItem(arr[i]))
count++;
}
return count;
}
public static Rectangle KeepInWorld(this Rectangle rectangle, int fluff = 10)
{
if (rectangle.X < fluff)
{
rectangle.X = fluff;
}
else if (rectangle.X + rectangle.Width > Main.maxTilesX - fluff)
{
rectangle.X = Main.maxTilesX - fluff - rectangle.Width;
}
if (rectangle.Y < fluff)
{
rectangle.Y = fluff;
}
else if (rectangle.Y + rectangle.Height > Main.maxTilesY - fluff)
{
rectangle.Y = Main.maxTilesY - fluff - rectangle.Height;
}
return rectangle;
}
public static string SpillArray<T>(this T[] array)
{
string text = "Nothing is inside this array.";
for (int i = 0; i < array.Length; i++)
{
if (i == 0)
{
text = array[0].ToString();
}
else
{
text += ", " + (array[i] == null ? "null value" : array[i].ToString());
}
}
return text;
}
public static float Wave(float time, float minimum, float maximum)
{
return minimum + ((float)Math.Sin(time) + 1f) / 2f * (maximum - minimum);
}
public static void CyclePositions(Vector2[] oldPos, Vector2 newPos)
{
for (int i = oldPos.Length - 1; i > 0; i--)
{
oldPos[i] = oldPos[i - 1];
}
oldPos[0] = newPos;
}
public static Vector2[] AsAddAll(this Vector2[] v, Vector2 sub)
{
var clone = new Vector2[v.Length];
for (int i = 0; i < v.Length; i++)
{
clone[i] = new Vector2(v[i].X + sub.X, v[i].Y + sub.Y);
}
return clone;
}
public static List<Vector2> AsAddAll(this List<Vector2> v, Vector2 sub)
{
var clone = new List<Vector2>();
for (int i = 0; i < v.Count; i++)
{
clone.Add(new Vector2(v[i].X + sub.X, v[i].Y + sub.Y));
}
return clone;
}
public static void AddAll(this Vector2[] v, Vector2 sub)
{
for (int i = 0; i < v.Length; i++)
{
v[i] = new Vector2(v[i].X + sub.X, v[i].Y + sub.Y);
}
}
public static void AddAll(this List<Vector2> v, Vector2 add)
{
for (int i = 0; i < v.Count; i++)
{
v[i] = new Vector2(v[i].X + add.X, v[i].Y + add.Y);
}
}
public static Item ItemInHand(this Player player)
{
if (!Main.mouseItem.IsAir)
return Main.mouseItem;
return player.HeldItem;
}
public static TEnum ToEnum<TEnum>(this ushort number) where TEnum : Enum
{
return (TEnum)Enum.ToObject(typeof(TEnum), number);
}
public static TEnum ToEnum<TEnum>(this int number) where TEnum : Enum
{
return (TEnum)Enum.ToObject(typeof(TEnum), number);
}
public static Texture2D GetTextureobj<T>(string extra)