Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LegacySoundPlayer.cs
Go to the documentation of this file.
1using System;
3using System.IO;
5using Microsoft.Xna.Framework.Audio;
8using Terraria.ID;
9
10namespace Terraria.Audio;
11
13{
15
16 public SoundEffectInstance[] SoundInstanceDrip = new SoundEffectInstance[3];
17
19
20 public SoundEffectInstance[] SoundInstanceLiquid = new SoundEffectInstance[2];
21
23
24 public SoundEffectInstance[] SoundInstanceMech = new SoundEffectInstance[1];
25
27
28 public SoundEffectInstance[] SoundInstanceDig = new SoundEffectInstance[3];
29
31
32 public SoundEffectInstance[] SoundInstanceThunder = new SoundEffectInstance[7];
33
35
36 public SoundEffectInstance[] SoundInstanceResearch = new SoundEffectInstance[4];
37
39
40 public SoundEffectInstance[] SoundInstanceTink = new SoundEffectInstance[3];
41
43
44 public SoundEffectInstance[] SoundInstanceCoin = new SoundEffectInstance[5];
45
47
48 public SoundEffectInstance[] SoundInstancePlayerHit = new SoundEffectInstance[3];
49
51
52 public SoundEffectInstance[] SoundInstanceFemaleHit = new SoundEffectInstance[3];
53
55
56 public SoundEffectInstance SoundInstancePlayerKilled;
57
59
60 public SoundEffectInstance SoundInstanceGrass;
61
63
64 public SoundEffectInstance SoundInstanceGrab;
65
67
68 public SoundEffectInstance SoundInstancePixie;
69
71
72 public SoundEffectInstance[] SoundInstanceItem = new SoundEffectInstance[SoundID.ItemSoundCount];
73
75
76 public SoundEffectInstance[] SoundInstanceNpcHit = new SoundEffectInstance[58];
77
79
80 public SoundEffectInstance[] SoundInstanceNpcKilled = new SoundEffectInstance[SoundID.NPCDeathCount];
81
82 public SoundEffectInstance SoundInstanceMoonlordCry;
83
85
86 public SoundEffectInstance SoundInstanceDoorOpen;
87
89
90 public SoundEffectInstance SoundInstanceDoorClosed;
91
93
94 public SoundEffectInstance SoundInstanceMenuOpen;
95
97
98 public SoundEffectInstance SoundInstanceMenuClose;
99
101
102 public SoundEffectInstance SoundInstanceMenuTick;
103
105
106 public SoundEffectInstance SoundInstanceShatter;
107
109
110 public SoundEffectInstance SoundInstanceCamera;
111
113
114 public SoundEffectInstance[] SoundInstanceZombie = new SoundEffectInstance[131];
115
117
118 public SoundEffectInstance[] SoundInstanceRoar = new SoundEffectInstance[3];
119
121
122 public SoundEffectInstance[] SoundInstanceSplash = new SoundEffectInstance[6];
123
125
126 public SoundEffectInstance SoundInstanceDoubleJump;
127
129
130 public SoundEffectInstance SoundInstanceRun;
131
133
134 public SoundEffectInstance SoundInstanceCoins;
135
137
138 public SoundEffectInstance SoundInstanceUnlock;
139
141
142 public SoundEffectInstance SoundInstanceChat;
143
145
146 public SoundEffectInstance SoundInstanceMaxMana;
147
149
150 public SoundEffectInstance SoundInstanceDrown;
151
153
154 public SoundEffectInstance[] TrackableSoundInstances;
155
156 private readonly IServiceProvider _services;
157
159
166
167 public void Reload()
168 {
170 }
171
172 private void LoadAll()
173 {
174 SoundMech[0] = Load("Sounds/Mech_0");
175 SoundGrab = Load("Sounds/Grab");
176 SoundPixie = Load("Sounds/Pixie");
177 SoundDig[0] = Load("Sounds/Dig_0");
178 SoundDig[1] = Load("Sounds/Dig_1");
179 SoundDig[2] = Load("Sounds/Dig_2");
180 SoundThunder[0] = Load("Sounds/Thunder_0");
181 SoundThunder[1] = Load("Sounds/Thunder_1");
182 SoundThunder[2] = Load("Sounds/Thunder_2");
183 SoundThunder[3] = Load("Sounds/Thunder_3");
184 SoundThunder[4] = Load("Sounds/Thunder_4");
185 SoundThunder[5] = Load("Sounds/Thunder_5");
186 SoundThunder[6] = Load("Sounds/Thunder_6");
187 SoundResearch[0] = Load("Sounds/Research_0");
188 SoundResearch[1] = Load("Sounds/Research_1");
189 SoundResearch[2] = Load("Sounds/Research_2");
190 SoundResearch[3] = Load("Sounds/Research_3");
191 SoundTink[0] = Load("Sounds/Tink_0");
192 SoundTink[1] = Load("Sounds/Tink_1");
193 SoundTink[2] = Load("Sounds/Tink_2");
194 SoundPlayerHit[0] = Load("Sounds/Player_Hit_0");
195 SoundPlayerHit[1] = Load("Sounds/Player_Hit_1");
196 SoundPlayerHit[2] = Load("Sounds/Player_Hit_2");
197 SoundFemaleHit[0] = Load("Sounds/Female_Hit_0");
198 SoundFemaleHit[1] = Load("Sounds/Female_Hit_1");
199 SoundFemaleHit[2] = Load("Sounds/Female_Hit_2");
200 SoundPlayerKilled = Load("Sounds/Player_Killed");
201 SoundChat = Load("Sounds/Chat");
202 SoundGrass = Load("Sounds/Grass");
203 SoundDoorOpen = Load("Sounds/Door_Opened");
204 SoundDoorClosed = Load("Sounds/Door_Closed");
205 SoundMenuTick = Load("Sounds/Menu_Tick");
206 SoundMenuOpen = Load("Sounds/Menu_Open");
207 SoundMenuClose = Load("Sounds/Menu_Close");
208 SoundShatter = Load("Sounds/Shatter");
209 SoundCamera = Load("Sounds/Camera");
210 for (int i = 0; i < SoundCoin.Length; i++)
211 {
212 SoundCoin[i] = Load("Sounds/Coin_" + i);
213 }
214 for (int j = 0; j < SoundDrip.Length; j++)
215 {
216 SoundDrip[j] = Load("Sounds/Drip_" + j);
217 }
218 for (int k = 0; k < SoundZombie.Length; k++)
219 {
220 SoundZombie[k] = Load("Sounds/Zombie_" + k);
221 }
222 for (int l = 0; l < SoundLiquid.Length; l++)
223 {
224 SoundLiquid[l] = Load("Sounds/Liquid_" + l);
225 }
226 for (int m = 0; m < SoundRoar.Length; m++)
227 {
228 SoundRoar[m] = Load("Sounds/Roar_" + m);
229 }
230 for (int n = 0; n < SoundSplash.Length; n++)
231 {
232 SoundSplash[n] = Load("Sounds/Splash_" + n);
233 }
234 SoundDoubleJump = Load("Sounds/Double_Jump");
235 SoundRun = Load("Sounds/Run");
236 SoundCoins = Load("Sounds/Coins");
237 SoundUnlock = Load("Sounds/Unlock");
238 SoundMaxMana = Load("Sounds/MaxMana");
239 SoundDrown = Load("Sounds/Drown");
240 for (int num = 1; num < SoundItem.Length; num++)
241 {
242 SoundItem[num] = Load("Sounds/Item_" + num);
243 }
244 for (int num2 = 1; num2 < SoundNpcHit.Length; num2++)
245 {
246 SoundNpcHit[num2] = Load("Sounds/NPC_Hit_" + num2);
247 }
248 for (int num3 = 1; num3 < SoundNpcKilled.Length; num3++)
249 {
250 SoundNpcKilled[num3] = Load("Sounds/NPC_Killed_" + num3);
251 }
253 TrackableSoundInstances = new SoundEffectInstance[TrackableSounds.Length];
254 for (int num4 = 0; num4 < TrackableSounds.Length; num4++)
255 {
257 }
258 }
259
261 {
262 foreach (SoundEffectInstance trackedInstance in _trackedInstances)
263 {
264 trackedInstance.Dispose();
265 }
301 for (int i = 0; i < SoundThunder.Length; i++)
302 {
304 }
305 for (int j = 0; j < SoundResearch.Length; j++)
306 {
308 }
309 for (int k = 0; k < SoundCoin.Length; k++)
310 {
312 }
313 for (int l = 0; l < SoundDrip.Length; l++)
314 {
316 }
317 for (int m = 0; m < SoundZombie.Length; m++)
318 {
320 }
321 for (int n = 0; n < SoundLiquid.Length; n++)
322 {
324 }
325 for (int num = 0; num < SoundRoar.Length; num++)
326 {
328 }
329 for (int num2 = 1; num2 < SoundItem.Length; num2++)
330 {
332 }
333 for (int num3 = 1; num3 < SoundNpcHit.Length; num3++)
334 {
336 }
337 for (int num4 = 1; num4 < SoundNpcKilled.Length; num4++)
338 {
340 }
341 for (int num5 = 0; num5 < TrackableSounds.Length; num5++)
342 {
344 }
345 }
346
347 private SoundEffectInstance CreateInstance(Asset<SoundEffect> asset)
348 {
349 SoundEffectInstance soundEffectInstance = asset.Value.CreateInstance();
351 return soundEffectInstance;
352 }
353
358
359 public SoundEffectInstance PlaySound(int type, int x = -1, int y = -1, int Style = 1, float volumeScale = 1f, float pitchOffset = 0f)
360 {
361 int num = Style;
362 try
363 {
364 if (Main.dedServ)
365 {
366 return null;
367 }
368 if (Main.soundVolume == 0f && (type < 30 || type > 35))
369 {
370 return null;
371 }
372 bool flag = false;
373 float num2 = 1f;
374 float num3 = 0f;
375 if (x == -1 || y == -1)
376 {
377 flag = true;
378 }
379 else
380 {
381 if (WorldGen.gen)
382 {
383 return null;
384 }
385 if (Main.netMode == 2)
386 {
387 return null;
388 }
389 Vector2 vector = new Vector2(Main.screenPosition.X + (float)Main.screenWidth * 0.5f, Main.screenPosition.Y + (float)Main.screenHeight * 0.5f);
390 float num4 = Math.Abs((float)x - vector.X);
391 float num5 = Math.Abs((float)y - vector.Y);
392 float num6 = (float)Math.Sqrt(num4 * num4 + num5 * num5);
393 int num7 = 2500;
394 if (num6 < (float)num7)
395 {
396 flag = true;
397 num3 = ((type != 43) ? (((float)x - vector.X) / ((float)Main.screenWidth * 0.5f)) : (((float)x - vector.X) / 900f));
398 num2 = 1f - num6 / (float)num7;
399 }
400 }
401 if (num3 < -1f)
402 {
403 num3 = -1f;
404 }
405 if (num3 > 1f)
406 {
407 num3 = 1f;
408 }
409 if (num2 > 1f)
410 {
411 num2 = 1f;
412 }
413 if (num2 <= 0f && (type < 34 || type > 35 || type > 39))
414 {
415 return null;
416 }
417 if (flag)
418 {
420 {
421 num2 *= Main.ambientVolume * (float)((!Main.gameInactive) ? 1 : 0);
422 if (Main.gameMenu)
423 {
424 num2 = 0f;
425 }
426 }
427 else
428 {
430 }
431 if (num2 > 1f)
432 {
433 num2 = 1f;
434 }
435 if (num2 <= 0f && (type < 30 || type > 35) && type != 39)
436 {
437 return null;
438 }
439 SoundEffectInstance soundEffectInstance = null;
440 switch (type)
441 {
442 case 0:
443 {
444 int num16 = Main.rand.Next(3);
445 if (SoundInstanceDig[num16] != null)
446 {
447 SoundInstanceDig[num16].Stop();
448 }
449 SoundInstanceDig[num16] = SoundDig[num16].Value.CreateInstance();
450 SoundInstanceDig[num16].Volume = num2;
452 SoundInstanceDig[num16].Pitch = (float)Main.rand.Next(-10, 11) * 0.01f;
454 break;
455 }
456 case 43:
457 {
458 int num15 = Main.rand.Next(SoundThunder.Length);
459 for (int j = 0; j < SoundThunder.Length; j++)
460 {
461 if (SoundInstanceThunder[num15] == null)
462 {
463 break;
464 }
465 if (SoundInstanceThunder[num15].State != 0)
466 {
467 break;
468 }
469 num15 = Main.rand.Next(SoundThunder.Length);
470 }
471 if (SoundInstanceThunder[num15] != null)
472 {
474 }
478 SoundInstanceThunder[num15].Pitch = (float)Main.rand.Next(-10, 11) * 0.01f;
480 break;
481 }
482 case 63:
483 {
484 int num17 = Main.rand.Next(1, 4);
485 if (SoundInstanceResearch[num17] != null)
486 {
488 }
493 break;
494 }
495 case 64:
496 if (SoundInstanceResearch[0] != null)
497 {
498 SoundInstanceResearch[0].Stop();
499 }
500 SoundInstanceResearch[0] = SoundResearch[0].Value.CreateInstance();
501 SoundInstanceResearch[0].Volume = num2;
504 break;
505 case 1:
506 {
507 int num18 = Main.rand.Next(3);
508 if (SoundInstancePlayerHit[num18] != null)
509 {
511 }
516 break;
517 }
518 case 2:
519 if (num == 176)
520 {
521 num2 *= 0.9f;
522 }
523 if (num == 129)
524 {
525 num2 *= 0.6f;
526 }
527 if (num == 123)
528 {
529 num2 *= 0.5f;
530 }
531 if (num == 124 || num == 125)
532 {
533 num2 *= 0.65f;
534 }
535 if (num == 116)
536 {
537 num2 *= 0.5f;
538 }
539 switch (num)
540 {
541 case 1:
542 {
543 int num14 = Main.rand.Next(3);
544 if (num14 == 1)
545 {
546 num = 18;
547 }
548 if (num14 == 2)
549 {
550 num = 19;
551 }
552 break;
553 }
554 case 53:
555 case 55:
556 num2 *= 0.75f;
557 if (num == 55)
558 {
559 num2 *= 0.75f;
560 }
561 if (SoundInstanceItem[num] != null && SoundInstanceItem[num].State == SoundState.Playing)
562 {
563 return null;
564 }
565 break;
566 case 37:
567 num2 *= 0.5f;
568 break;
569 case 52:
570 num2 *= 0.35f;
571 break;
572 case 157:
573 num2 *= 0.7f;
574 break;
575 case 158:
576 num2 *= 0.8f;
577 break;
578 }
579 switch (num)
580 {
581 case 159:
582 if (SoundInstanceItem[num] != null && SoundInstanceItem[num].State == SoundState.Playing)
583 {
584 return null;
585 }
586 num2 *= 0.75f;
587 break;
588 default:
589 if (SoundInstanceItem[num] != null)
590 {
591 SoundInstanceItem[num].Stop();
592 }
593 break;
594 case 9:
595 case 10:
596 case 24:
597 case 26:
598 case 34:
599 case 43:
600 case 103:
601 case 156:
602 case 162:
603 break;
604 }
605 SoundInstanceItem[num] = SoundItem[num].Value.CreateInstance();
606 SoundInstanceItem[num].Volume = num2;
607 SoundInstanceItem[num].Pan = num3;
608 switch (num)
609 {
610 case 53:
611 SoundInstanceItem[num].Pitch = (float)Main.rand.Next(-20, -11) * 0.02f;
612 break;
613 case 55:
614 SoundInstanceItem[num].Pitch = (float)(-Main.rand.Next(-20, -11)) * 0.02f;
615 break;
616 case 132:
617 SoundInstanceItem[num].Pitch = (float)Main.rand.Next(-20, 21) * 0.001f;
618 break;
619 case 153:
620 SoundInstanceItem[num].Pitch = (float)Main.rand.Next(-50, 51) * 0.003f;
621 break;
622 case 156:
623 SoundInstanceItem[num].Pitch = (float)Main.rand.Next(-50, 51) * 0.002f;
624 SoundInstanceItem[num].Volume *= 0.6f;
625 break;
626 default:
627 SoundInstanceItem[num].Pitch = (float)Main.rand.Next(-6, 7) * 0.01f;
628 break;
629 }
630 if (num == 26 || num == 35 || num == 47)
631 {
632 SoundInstanceItem[num].Volume = num2 * 0.75f;
633 SoundInstanceItem[num].Pitch = Main.musicPitch;
634 }
635 if (num == 169)
636 {
637 SoundInstanceItem[num].Pitch -= 0.8f;
638 }
640 break;
641 case 3:
642 if (num >= 20 && num <= 54)
643 {
644 num2 *= 0.5f;
645 }
646 if (num == 57 && SoundInstanceNpcHit[num] != null && SoundInstanceNpcHit[num].State == SoundState.Playing)
647 {
648 return null;
649 }
650 if (num == 57)
651 {
652 num2 *= 0.6f;
653 }
654 if (num == 55 || num == 56)
655 {
656 num2 *= 0.5f;
657 }
658 if (SoundInstanceNpcHit[num] != null)
659 {
660 SoundInstanceNpcHit[num].Stop();
661 }
662 SoundInstanceNpcHit[num] = SoundNpcHit[num].Value.CreateInstance();
663 SoundInstanceNpcHit[num].Volume = num2;
664 SoundInstanceNpcHit[num].Pan = num3;
665 SoundInstanceNpcHit[num].Pitch = (float)Main.rand.Next(-10, 11) * 0.01f;
667 break;
668 case 4:
669 if (num >= 23 && num <= 57)
670 {
671 num2 *= 0.5f;
672 }
673 if (num == 61)
674 {
675 num2 *= 0.6f;
676 }
677 if (num == 62)
678 {
679 num2 *= 0.6f;
680 }
681 if (num == 10 && SoundInstanceNpcKilled[num] != null && SoundInstanceNpcKilled[num].State == SoundState.Playing)
682 {
683 return null;
684 }
685 SoundInstanceNpcKilled[num] = SoundNpcKilled[num].Value.CreateInstance();
686 SoundInstanceNpcKilled[num].Volume = num2;
687 SoundInstanceNpcKilled[num].Pan = num3;
688 SoundInstanceNpcKilled[num].Pitch = (float)Main.rand.Next(-10, 11) * 0.01f;
690 break;
691 case 5:
692 if (SoundInstancePlayerKilled != null)
693 {
695 }
697 SoundInstancePlayerKilled.Volume = num2;
698 SoundInstancePlayerKilled.Pan = num3;
700 break;
701 case 6:
702 if (SoundInstanceGrass != null)
703 {
704 SoundInstanceGrass.Stop();
705 }
706 SoundInstanceGrass = SoundGrass.Value.CreateInstance();
707 SoundInstanceGrass.Volume = num2;
708 SoundInstanceGrass.Pan = num3;
709 SoundInstanceGrass.Pitch = (float)Main.rand.Next(-30, 31) * 0.01f;
711 break;
712 case 7:
713 if (SoundInstanceGrab != null)
714 {
715 SoundInstanceGrab.Stop();
716 }
717 SoundInstanceGrab = SoundGrab.Value.CreateInstance();
718 SoundInstanceGrab.Volume = num2;
719 SoundInstanceGrab.Pan = num3;
720 SoundInstanceGrab.Pitch = (float)Main.rand.Next(-10, 11) * 0.01f;
722 break;
723 case 8:
724 if (SoundInstanceDoorOpen != null)
725 {
727 }
728 SoundInstanceDoorOpen = SoundDoorOpen.Value.CreateInstance();
729 SoundInstanceDoorOpen.Volume = num2;
730 SoundInstanceDoorOpen.Pan = num3;
731 SoundInstanceDoorOpen.Pitch = (float)Main.rand.Next(-20, 21) * 0.01f;
733 break;
734 case 9:
735 if (SoundInstanceDoorClosed != null)
736 {
738 }
740 SoundInstanceDoorClosed.Volume = num2;
741 SoundInstanceDoorClosed.Pan = num3;
742 SoundInstanceDoorClosed.Pitch = (float)Main.rand.Next(-20, 21) * 0.01f;
744 break;
745 case 10:
746 if (SoundInstanceMenuOpen != null)
747 {
749 }
750 SoundInstanceMenuOpen = SoundMenuOpen.Value.CreateInstance();
751 SoundInstanceMenuOpen.Volume = num2;
752 SoundInstanceMenuOpen.Pan = num3;
754 break;
755 case 11:
756 if (SoundInstanceMenuClose != null)
757 {
759 }
761 SoundInstanceMenuClose.Volume = num2;
762 SoundInstanceMenuClose.Pan = num3;
764 break;
765 case 12:
766 if (Main.hasFocus)
767 {
768 if (SoundInstanceMenuTick != null)
769 {
771 }
772 SoundInstanceMenuTick = SoundMenuTick.Value.CreateInstance();
773 SoundInstanceMenuTick.Volume = num2;
774 SoundInstanceMenuTick.Pan = num3;
776 }
777 break;
778 case 13:
779 if (SoundInstanceShatter != null)
780 {
782 }
783 SoundInstanceShatter = SoundShatter.Value.CreateInstance();
784 SoundInstanceShatter.Volume = num2;
785 SoundInstanceShatter.Pan = num3;
787 break;
788 case 14:
789 switch (Style)
790 {
791 case 542:
792 {
793 int num24 = 7;
794 SoundInstanceZombie[num24] = SoundZombie[num24].Value.CreateInstance();
795 SoundInstanceZombie[num24].Volume = num2 * 0.4f;
798 break;
799 }
800 case 489:
801 case 586:
802 {
803 int num23 = Main.rand.Next(21, 24);
804 SoundInstanceZombie[num23] = SoundZombie[num23].Value.CreateInstance();
805 SoundInstanceZombie[num23].Volume = num2 * 0.4f;
808 break;
809 }
810 default:
811 {
812 int num22 = Main.rand.Next(3);
813 SoundInstanceZombie[num22] = SoundZombie[num22].Value.CreateInstance();
814 SoundInstanceZombie[num22].Volume = num2 * 0.4f;
817 break;
818 }
819 }
820 break;
821 case 15:
822 {
823 float num21 = 1f;
824 if (num == 4)
825 {
826 num = 1;
827 num21 = 0.25f;
828 }
829 if (SoundInstanceRoar[num] == null || SoundInstanceRoar[num].State == SoundState.Stopped)
830 {
831 SoundInstanceRoar[num] = SoundRoar[num].Value.CreateInstance();
832 SoundInstanceRoar[num].Volume = num2 * num21;
833 SoundInstanceRoar[num].Pan = num3;
835 }
836 break;
837 }
838 case 16:
839 if (SoundInstanceDoubleJump != null)
840 {
842 }
844 SoundInstanceDoubleJump.Volume = num2;
845 SoundInstanceDoubleJump.Pan = num3;
846 SoundInstanceDoubleJump.Pitch = (float)Main.rand.Next(-10, 11) * 0.01f;
848 break;
849 case 17:
850 if (SoundInstanceRun != null)
851 {
852 SoundInstanceRun.Stop();
853 }
854 SoundInstanceRun = SoundRun.Value.CreateInstance();
855 SoundInstanceRun.Volume = num2;
856 SoundInstanceRun.Pan = num3;
857 SoundInstanceRun.Pitch = (float)Main.rand.Next(-10, 11) * 0.01f;
859 break;
860 case 18:
861 SoundInstanceCoins = SoundCoins.Value.CreateInstance();
862 SoundInstanceCoins.Volume = num2;
863 SoundInstanceCoins.Pan = num3;
865 break;
866 case 19:
867 if (SoundInstanceSplash[num] != null && SoundInstanceSplash[num].State != SoundState.Stopped)
868 {
869 break;
870 }
871 SoundInstanceSplash[num] = SoundSplash[num].Value.CreateInstance();
872 if (num == 2 || num == 3)
873 {
874 num2 *= 0.75f;
875 }
876 if (num == 4 || num == 5)
877 {
878 num2 *= 0.75f;
879 SoundInstanceSplash[num].Pitch = (float)Main.rand.Next(-20, 1) * 0.01f;
880 }
881 else
882 {
883 SoundInstanceSplash[num].Pitch = (float)Main.rand.Next(-10, 11) * 0.01f;
884 }
885 SoundInstanceSplash[num].Volume = num2;
886 SoundInstanceSplash[num].Pan = num3;
887 switch (num)
888 {
889 case 4:
890 if (SoundInstanceSplash[5] == null || SoundInstanceSplash[5].State == SoundState.Stopped)
891 {
893 }
894 break;
895 case 5:
896 if (SoundInstanceSplash[4] == null || SoundInstanceSplash[4].State == SoundState.Stopped)
897 {
899 }
900 break;
901 default:
903 break;
904 }
905 break;
906 case 20:
907 {
908 int num25 = Main.rand.Next(3);
909 if (SoundInstanceFemaleHit[num25] != null)
910 {
912 }
917 break;
918 }
919 case 21:
920 {
921 int num20 = Main.rand.Next(3);
922 if (SoundInstanceTink[num20] != null)
923 {
924 SoundInstanceTink[num20].Stop();
925 }
926 SoundInstanceTink[num20] = SoundTink[num20].Value.CreateInstance();
927 SoundInstanceTink[num20].Volume = num2;
930 break;
931 }
932 case 22:
933 if (SoundInstanceUnlock != null)
934 {
935 SoundInstanceUnlock.Stop();
936 }
937 SoundInstanceUnlock = SoundUnlock.Value.CreateInstance();
938 SoundInstanceUnlock.Volume = num2;
939 SoundInstanceUnlock.Pan = num3;
941 break;
942 case 23:
943 if (SoundInstanceDrown != null)
944 {
945 SoundInstanceDrown.Stop();
946 }
947 SoundInstanceDrown = SoundDrown.Value.CreateInstance();
948 SoundInstanceDrown.Volume = num2;
949 SoundInstanceDrown.Pan = num3;
951 break;
952 case 24:
953 SoundInstanceChat = SoundChat.Value.CreateInstance();
954 SoundInstanceChat.Volume = num2;
955 SoundInstanceChat.Pan = num3;
957 break;
958 case 25:
959 SoundInstanceMaxMana = SoundMaxMana.Value.CreateInstance();
960 SoundInstanceMaxMana.Volume = num2;
961 SoundInstanceMaxMana.Pan = num3;
963 break;
964 case 26:
965 {
966 int num19 = Main.rand.Next(3, 5);
967 SoundInstanceZombie[num19] = SoundZombie[num19].Value.CreateInstance();
968 SoundInstanceZombie[num19].Volume = num2 * 0.9f;
970 SoundInstanceZombie[num19].Pitch = (float)Main.rand.Next(-10, 11) * 0.01f;
972 break;
973 }
974 case 27:
975 if (SoundInstancePixie != null && SoundInstancePixie.State == SoundState.Playing)
976 {
977 SoundInstancePixie.Volume = num2;
978 SoundInstancePixie.Pan = num3;
979 SoundInstancePixie.Pitch = (float)Main.rand.Next(-10, 11) * 0.01f;
980 return null;
981 }
982 if (SoundInstancePixie != null)
983 {
984 SoundInstancePixie.Stop();
985 }
986 SoundInstancePixie = SoundPixie.Value.CreateInstance();
987 SoundInstancePixie.Volume = num2;
988 SoundInstancePixie.Pan = num3;
989 SoundInstancePixie.Pitch = (float)Main.rand.Next(-10, 11) * 0.01f;
991 break;
992 case 28:
993 if (SoundInstanceMech[num] != null && SoundInstanceMech[num].State == SoundState.Playing)
994 {
995 return null;
996 }
997 SoundInstanceMech[num] = SoundMech[num].Value.CreateInstance();
998 SoundInstanceMech[num].Volume = num2;
999 SoundInstanceMech[num].Pan = num3;
1000 SoundInstanceMech[num].Pitch = (float)Main.rand.Next(-10, 11) * 0.01f;
1002 break;
1003 case 29:
1004 if (num >= 24 && num <= 87)
1005 {
1006 num2 *= 0.5f;
1007 }
1008 if (num >= 88 && num <= 91)
1009 {
1010 num2 *= 0.7f;
1011 }
1012 if (num >= 93 && num <= 99)
1013 {
1014 num2 *= 0.4f;
1015 }
1016 if (num == 92)
1017 {
1018 num2 *= 0.5f;
1019 }
1020 if (num == 103)
1021 {
1022 num2 *= 0.4f;
1023 }
1024 if (num == 104)
1025 {
1026 num2 *= 0.55f;
1027 }
1028 if (num == 100 || num == 101)
1029 {
1030 num2 *= 0.25f;
1031 }
1032 if (num == 102)
1033 {
1034 num2 *= 0.4f;
1035 }
1036 if (SoundInstanceZombie[num] != null && SoundInstanceZombie[num].State == SoundState.Playing)
1037 {
1038 return null;
1039 }
1040 SoundInstanceZombie[num] = SoundZombie[num].Value.CreateInstance();
1041 SoundInstanceZombie[num].Volume = num2;
1042 SoundInstanceZombie[num].Pan = num3;
1043 SoundInstanceZombie[num].Pitch = (float)Main.rand.Next(-10, 11) * 0.01f;
1045 break;
1046 case 44:
1047 num = Main.rand.Next(106, 109);
1048 SoundInstanceZombie[num] = SoundZombie[num].Value.CreateInstance();
1049 SoundInstanceZombie[num].Volume = num2 * 0.2f;
1050 SoundInstanceZombie[num].Pan = num3;
1051 SoundInstanceZombie[num].Pitch = (float)Main.rand.Next(-70, 1) * 0.01f;
1053 break;
1054 case 45:
1055 num = 109;
1056 if (SoundInstanceZombie[num] != null && SoundInstanceZombie[num].State == SoundState.Playing)
1057 {
1058 return null;
1059 }
1060 SoundInstanceZombie[num] = SoundZombie[num].Value.CreateInstance();
1061 SoundInstanceZombie[num].Volume = num2 * 0.3f;
1062 SoundInstanceZombie[num].Pan = num3;
1063 SoundInstanceZombie[num].Pitch = (float)Main.rand.Next(-10, 11) * 0.01f;
1065 break;
1066 case 46:
1067 if (SoundInstanceZombie[110] != null && SoundInstanceZombie[110].State == SoundState.Playing)
1068 {
1069 return null;
1070 }
1071 if (SoundInstanceZombie[111] != null && SoundInstanceZombie[111].State == SoundState.Playing)
1072 {
1073 return null;
1074 }
1075 num = Main.rand.Next(110, 112);
1076 if (Main.rand.Next(300) == 0)
1077 {
1078 num = ((Main.rand.Next(3) == 0) ? 114 : ((Main.rand.Next(2) != 0) ? 112 : 113));
1079 }
1080 SoundInstanceZombie[num] = SoundZombie[num].Value.CreateInstance();
1081 SoundInstanceZombie[num].Volume = num2 * 0.9f;
1082 SoundInstanceZombie[num].Pan = num3;
1083 SoundInstanceZombie[num].Pitch = (float)Main.rand.Next(-10, 11) * 0.01f;
1085 break;
1086 default:
1087 switch (type)
1088 {
1089 case 45:
1090 num = 109;
1091 SoundInstanceZombie[num] = SoundZombie[num].Value.CreateInstance();
1092 SoundInstanceZombie[num].Volume = num2 * 0.2f;
1093 SoundInstanceZombie[num].Pan = num3;
1094 SoundInstanceZombie[num].Pitch = (float)Main.rand.Next(-70, 1) * 0.01f;
1096 break;
1097 case 30:
1098 num = Main.rand.Next(10, 12);
1099 if (Main.rand.Next(300) == 0)
1100 {
1101 num = 12;
1102 if (SoundInstanceZombie[num] != null && SoundInstanceZombie[num].State == SoundState.Playing)
1103 {
1104 return null;
1105 }
1106 }
1107 SoundInstanceZombie[num] = SoundZombie[num].Value.CreateInstance();
1108 SoundInstanceZombie[num].Volume = num2 * 0.75f;
1109 SoundInstanceZombie[num].Pan = num3;
1110 if (num != 12)
1111 {
1112 SoundInstanceZombie[num].Pitch = (float)Main.rand.Next(-70, 1) * 0.01f;
1113 }
1114 else
1115 {
1116 SoundInstanceZombie[num].Pitch = (float)Main.rand.Next(-40, 21) * 0.01f;
1117 }
1119 break;
1120 case 31:
1121 num = 13;
1122 SoundInstanceZombie[num] = SoundZombie[num].Value.CreateInstance();
1123 SoundInstanceZombie[num].Volume = num2 * 0.35f;
1124 SoundInstanceZombie[num].Pan = num3;
1125 SoundInstanceZombie[num].Pitch = (float)Main.rand.Next(-40, 21) * 0.01f;
1127 break;
1128 case 32:
1129 if (SoundInstanceZombie[num] != null && SoundInstanceZombie[num].State == SoundState.Playing)
1130 {
1131 return null;
1132 }
1133 SoundInstanceZombie[num] = SoundZombie[num].Value.CreateInstance();
1134 SoundInstanceZombie[num].Volume = num2 * 0.15f;
1135 SoundInstanceZombie[num].Pan = num3;
1136 SoundInstanceZombie[num].Pitch = (float)Main.rand.Next(-70, 26) * 0.01f;
1138 break;
1139 case 67:
1140 num = Main.rand.Next(118, 121);
1141 if (SoundInstanceZombie[num] != null && SoundInstanceZombie[num].State == SoundState.Playing)
1142 {
1143 return null;
1144 }
1145 SoundInstanceZombie[num] = SoundZombie[num].Value.CreateInstance();
1146 SoundInstanceZombie[num].Volume = num2 * 0.3f;
1147 SoundInstanceZombie[num].Pan = num3;
1148 SoundInstanceZombie[num].Pitch = (float)Main.rand.Next(-5, 6) * 0.01f;
1150 break;
1151 case 68:
1152 num = Main.rand.Next(126, 129);
1153 if (SoundInstanceZombie[num] != null && SoundInstanceZombie[num].State == SoundState.Playing)
1154 {
1155 return null;
1156 }
1157 SoundInstanceZombie[num] = SoundZombie[num].Value.CreateInstance();
1158 SoundInstanceZombie[num].Volume = num2 * 0.22f;
1159 SoundInstanceZombie[num].Pan = num3;
1160 SoundInstanceZombie[num].Pitch = (float)Main.rand.Next(-5, 6) * 0.01f;
1162 break;
1163 case 69:
1164 num = Main.rand.Next(129, 131);
1165 if (SoundInstanceZombie[num] != null && SoundInstanceZombie[num].State == SoundState.Playing)
1166 {
1167 return null;
1168 }
1169 SoundInstanceZombie[num] = SoundZombie[num].Value.CreateInstance();
1170 SoundInstanceZombie[num].Volume = num2 * 0.2f;
1171 SoundInstanceZombie[num].Pan = num3;
1172 SoundInstanceZombie[num].Pitch = (float)Main.rand.Next(-5, 6) * 0.01f;
1174 break;
1175 case 66:
1176 num = Main.rand.Next(121, 124);
1177 if (SoundInstanceZombie[121] != null && SoundInstanceZombie[121].State == SoundState.Playing)
1178 {
1179 return null;
1180 }
1181 if (SoundInstanceZombie[122] != null && SoundInstanceZombie[122].State == SoundState.Playing)
1182 {
1183 return null;
1184 }
1185 if (SoundInstanceZombie[123] != null && SoundInstanceZombie[123].State == SoundState.Playing)
1186 {
1187 return null;
1188 }
1189 SoundInstanceZombie[num] = SoundZombie[num].Value.CreateInstance();
1190 SoundInstanceZombie[num].Volume = num2 * 0.45f;
1191 SoundInstanceZombie[num].Pan = num3;
1192 SoundInstanceZombie[num].Pitch = (float)Main.rand.Next(-15, 16) * 0.01f;
1194 break;
1195 case 33:
1196 num = 15;
1197 if (SoundInstanceZombie[num] != null && SoundInstanceZombie[num].State == SoundState.Playing)
1198 {
1199 return null;
1200 }
1201 SoundInstanceZombie[num] = SoundZombie[num].Value.CreateInstance();
1202 SoundInstanceZombie[num].Volume = num2 * 0.2f;
1203 SoundInstanceZombie[num].Pan = num3;
1204 SoundInstanceZombie[num].Pitch = (float)Main.rand.Next(-10, 31) * 0.01f;
1206 break;
1207 case 47:
1208 case 48:
1209 case 49:
1210 case 50:
1211 case 51:
1212 case 52:
1213 {
1214 num = 133 + type - 47;
1215 for (int i = 133; i <= 138; i++)
1216 {
1217 if (SoundInstanceItem[i] != null && SoundInstanceItem[i].State == SoundState.Playing)
1218 {
1219 SoundInstanceItem[i].Stop();
1220 }
1221 }
1222 SoundInstanceItem[num] = SoundItem[num].Value.CreateInstance();
1223 SoundInstanceItem[num].Volume = num2 * 0.45f;
1224 SoundInstanceItem[num].Pan = num3;
1226 break;
1227 }
1228 default:
1229 if (type >= 53 && type <= 62)
1230 {
1231 num = 139 + type - 53;
1232 if (SoundInstanceItem[num] != null && SoundInstanceItem[num].State == SoundState.Playing)
1233 {
1234 SoundInstanceItem[num].Stop();
1235 }
1236 SoundInstanceItem[num] = SoundItem[num].Value.CreateInstance();
1237 SoundInstanceItem[num].Volume = num2 * 0.7f;
1238 SoundInstanceItem[num].Pan = num3;
1240 break;
1241 }
1242 switch (type)
1243 {
1244 case 34:
1245 {
1246 float num12 = (float)num / 50f;
1247 if (num12 > 1f)
1248 {
1249 num12 = 1f;
1250 }
1251 num2 *= num12;
1252 num2 *= 0.2f;
1253 num2 *= 1f - Main.shimmerAlpha;
1254 if (num2 <= 0f || x == -1 || y == -1)
1255 {
1256 if (SoundInstanceLiquid[0] != null && SoundInstanceLiquid[0].State == SoundState.Playing)
1257 {
1258 SoundInstanceLiquid[0].Stop();
1259 }
1260 }
1261 else if (SoundInstanceLiquid[0] != null && SoundInstanceLiquid[0].State == SoundState.Playing)
1262 {
1263 SoundInstanceLiquid[0].Volume = num2;
1264 SoundInstanceLiquid[0].Pan = num3;
1265 SoundInstanceLiquid[0].Pitch = -0.2f;
1266 }
1267 else
1268 {
1269 SoundInstanceLiquid[0] = SoundLiquid[0].Value.CreateInstance();
1270 SoundInstanceLiquid[0].Volume = num2;
1271 SoundInstanceLiquid[0].Pan = num3;
1273 }
1274 break;
1275 }
1276 case 35:
1277 {
1278 float num10 = (float)num / 50f;
1279 if (num10 > 1f)
1280 {
1281 num10 = 1f;
1282 }
1283 num2 *= num10;
1284 num2 *= 0.65f;
1285 num2 *= 1f - Main.shimmerAlpha;
1286 if (num2 <= 0f || x == -1 || y == -1)
1287 {
1288 if (SoundInstanceLiquid[1] != null && SoundInstanceLiquid[1].State == SoundState.Playing)
1289 {
1290 SoundInstanceLiquid[1].Stop();
1291 }
1292 }
1293 else if (SoundInstanceLiquid[1] != null && SoundInstanceLiquid[1].State == SoundState.Playing)
1294 {
1295 SoundInstanceLiquid[1].Volume = num2;
1296 SoundInstanceLiquid[1].Pan = num3;
1297 SoundInstanceLiquid[1].Pitch = -0f;
1298 }
1299 else
1300 {
1301 SoundInstanceLiquid[1] = SoundLiquid[1].Value.CreateInstance();
1302 SoundInstanceLiquid[1].Volume = num2;
1303 SoundInstanceLiquid[1].Pan = num3;
1305 }
1306 break;
1307 }
1308 case 36:
1309 {
1310 int num11 = Style;
1311 if (Style == -1)
1312 {
1313 num11 = 0;
1314 }
1315 SoundInstanceRoar[num11] = SoundRoar[num11].Value.CreateInstance();
1316 SoundInstanceRoar[num11].Volume = num2;
1318 if (Style == -1)
1319 {
1320 SoundInstanceRoar[num11].Pitch += 0.6f;
1321 }
1323 break;
1324 }
1325 case 37:
1326 {
1327 int num9 = Main.rand.Next(57, 59);
1328 num2 = ((!Main.starGame) ? (num2 * ((float)Style * 0.05f)) : (num2 * 0.15f));
1329 SoundInstanceItem[num9] = SoundItem[num9].Value.CreateInstance();
1330 SoundInstanceItem[num9].Volume = num2;
1332 SoundInstanceItem[num9].Pitch = (float)Main.rand.Next(-40, 41) * 0.01f;
1334 break;
1335 }
1336 case 38:
1337 {
1338 if (Main.starGame)
1339 {
1340 num2 *= 0.15f;
1341 }
1342 int num13 = Main.rand.Next(5);
1343 SoundInstanceCoin[num13] = SoundCoin[num13].Value.CreateInstance();
1344 SoundInstanceCoin[num13].Volume = num2;
1346 SoundInstanceCoin[num13].Pitch = (float)Main.rand.Next(-40, 41) * 0.002f;
1348 break;
1349 }
1350 case 39:
1351 num = Style;
1352 SoundInstanceDrip[num] = SoundDrip[num].Value.CreateInstance();
1353 SoundInstanceDrip[num].Volume = num2 * 0.5f;
1354 SoundInstanceDrip[num].Pan = num3;
1355 SoundInstanceDrip[num].Pitch = (float)Main.rand.Next(-30, 31) * 0.01f;
1357 break;
1358 case 40:
1359 if (SoundInstanceCamera != null)
1360 {
1361 SoundInstanceCamera.Stop();
1362 }
1363 SoundInstanceCamera = SoundCamera.Value.CreateInstance();
1364 SoundInstanceCamera.Volume = num2;
1365 SoundInstanceCamera.Pan = num3;
1367 break;
1368 case 41:
1369 SoundInstanceMoonlordCry = SoundNpcKilled[10].Value.CreateInstance();
1370 SoundInstanceMoonlordCry.Volume = 1f / (1f + (new Vector2(x, y) - Main.player[Main.myPlayer].position).Length());
1371 SoundInstanceMoonlordCry.Pan = num3;
1372 SoundInstanceMoonlordCry.Pitch = (float)Main.rand.Next(-10, 11) * 0.01f;
1374 break;
1375 case 42:
1376 soundEffectInstance = TrackableSounds[num].Value.CreateInstance();
1377 soundEffectInstance.Volume = num2;
1378 soundEffectInstance.Pan = num3;
1380 break;
1381 case 65:
1382 {
1383 if (SoundInstanceZombie[115] != null && SoundInstanceZombie[115].State == SoundState.Playing)
1384 {
1385 return null;
1386 }
1387 if (SoundInstanceZombie[116] != null && SoundInstanceZombie[116].State == SoundState.Playing)
1388 {
1389 return null;
1390 }
1391 if (SoundInstanceZombie[117] != null && SoundInstanceZombie[117].State == SoundState.Playing)
1392 {
1393 return null;
1394 }
1395 int num8 = Main.rand.Next(115, 118);
1396 SoundInstanceZombie[num8] = SoundZombie[num8].Value.CreateInstance();
1397 SoundInstanceZombie[num8].Volume = num2 * 0.5f;
1400 break;
1401 }
1402 }
1403 break;
1404 }
1405 break;
1406 }
1407 if (soundEffectInstance != null)
1408 {
1409 soundEffectInstance.Pitch += pitchOffset;
1410 soundEffectInstance.Volume *= volumeScale;
1411 soundEffectInstance.Play();
1413 }
1414 return soundEffectInstance;
1415 }
1416 }
1417 catch
1418 {
1419 }
1420 return null;
1421 }
1422
1424 {
1425 return TrackableSounds[id].Value;
1426 }
1427
1428 public void StopAmbientSounds()
1429 {
1430 for (int i = 0; i < SoundInstanceLiquid.Length; i++)
1431 {
1432 if (SoundInstanceLiquid[i] != null)
1433 {
1434 SoundInstanceLiquid[i].Stop();
1435 }
1436 }
1437 }
1438
1440 {
1441 switch (soundType)
1442 {
1443 case 30:
1444 case 31:
1445 case 32:
1446 case 33:
1447 case 34:
1448 case 35:
1449 case 39:
1450 case 43:
1451 case 44:
1452 case 45:
1453 case 46:
1454 case 67:
1455 case 68:
1456 case 69:
1457 return true;
1458 default:
1459 return false;
1460 }
1461 }
1462}
static readonly char DirectorySeparatorChar
Definition Path.cs:71
static double Sqrt(double d)
static double Abs(double value)
SoundEffectInstance SoundInstanceMenuOpen
SoundEffectInstance[] SoundInstanceThunder
SoundEffectInstance[] SoundInstanceNpcHit
List< SoundEffectInstance > _trackedInstances
SoundEffectInstance[] SoundInstanceSplash
SoundEffect GetTrackableSoundByStyleId(int id)
SoundEffectInstance SoundInstanceMoonlordCry
SoundEffectInstance[] SoundInstancePlayerHit
Asset< SoundEffect > Load(string assetName)
Asset< SoundEffect >[] TrackableSounds
SoundEffectInstance SoundInstanceMenuClose
SoundEffectInstance[] SoundInstanceDig
Asset< SoundEffect >[] SoundNpcHit
Asset< SoundEffect >[] SoundLiquid
Asset< SoundEffect >[] SoundThunder
SoundEffectInstance[] SoundInstanceDrip
bool DoesSoundScaleWithAmbientVolume(int soundType)
SoundEffectInstance SoundInstanceDoorClosed
readonly IServiceProvider _services
SoundEffectInstance[] SoundInstanceCoin
SoundEffectInstance[] SoundInstanceZombie
Asset< SoundEffect >[] SoundResearch
SoundEffectInstance[] SoundInstanceMech
LegacySoundPlayer(IServiceProvider services)
SoundEffectInstance SoundInstanceDoorOpen
SoundEffectInstance SoundInstanceMenuTick
Asset< SoundEffect >[] SoundNpcKilled
Asset< SoundEffect > SoundPlayerKilled
SoundEffectInstance CreateInstance(Asset< SoundEffect > asset)
SoundEffectInstance PlaySound(int type, int x=-1, int y=-1, int Style=1, float volumeScale=1f, float pitchOffset=0f)
SoundEffectInstance[] SoundInstanceItem
SoundEffectInstance[] SoundInstanceNpcKilled
SoundEffectInstance[] SoundInstanceResearch
SoundEffectInstance[] SoundInstanceLiquid
SoundEffectInstance SoundInstanceDoubleJump
SoundEffectInstance SoundInstancePlayerKilled
SoundEffectInstance[] SoundInstanceRoar
Asset< SoundEffect >[] SoundPlayerHit
SoundEffectInstance[] TrackableSoundInstances
Asset< SoundEffect >[] SoundFemaleHit
SoundEffectInstance[] SoundInstanceFemaleHit
SoundEffectInstance[] SoundInstanceTink
static short NPCDeathCount
Definition SoundID.cs:414
static short ItemSoundCount
Definition SoundID.cs:772
static string GetTrackableLegacySoundPath(int id)
Definition SoundID.cs:1002
static int TrackableLegacySoundCount
Definition SoundID.cs:1000
static bool gameInactive
Definition Main.cs:1074
static float musicPitch
Definition Main.cs:768
static int myPlayer
Definition Main.cs:1801
static int netMode
Definition Main.cs:2095
static bool starGame
Definition Main.cs:2597
static bool hasFocus
Definition Main.cs:1781
static bool dedServ
Definition Main.cs:1226
static int screenHeight
Definition Main.cs:1721
static Vector2 screenPosition
Definition Main.cs:1715
static UnifiedRandom rand
Definition Main.cs:1387
static int screenWidth
Definition Main.cs:1719
static bool gameMenu
Definition Main.cs:1926
static float shimmerAlpha
Definition Main.cs:1008
static float soundVolume
Definition Main.cs:1425
static Player[] player
Definition Main.cs:1803
static volatile bool gen
Definition WorldGen.cs:972