Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LegacySoundStyle.cs
Go to the documentation of this file.
1using Microsoft.Xna.Framework.Audio;
3
4namespace Terraria.Audio;
5
7{
8 private static readonly UnifiedRandom Random = new UnifiedRandom();
9
10 private readonly int _style;
11
12 public readonly int Variations;
13
14 public readonly int SoundId;
15
16 public int Style
17 {
18 get
19 {
20 if (Variations != 1)
21 {
22 return Random.Next(_style, _style + Variations);
23 }
24 return _style;
25 }
26 }
27
28 public override bool IsTrackable => SoundId == 42;
29
30 public LegacySoundStyle(int soundId, int style, SoundType type = SoundType.Sound)
31 : base(type)
32 {
33 _style = style;
34 Variations = 1;
35 SoundId = soundId;
36 }
37
38 public LegacySoundStyle(int soundId, int style, int variations, SoundType type = SoundType.Sound)
39 : base(type)
40 {
41 _style = style;
42 Variations = variations;
43 SoundId = soundId;
44 }
45
46 private LegacySoundStyle(int soundId, int style, int variations, SoundType type, float volume, float pitchVariance)
47 : base(volume, pitchVariance, type)
48 {
49 _style = style;
50 Variations = variations;
51 SoundId = soundId;
52 }
53
54 public LegacySoundStyle WithVolume(float volume)
55 {
56 return new LegacySoundStyle(SoundId, _style, Variations, base.Type, volume, base.PitchVariance);
57 }
58
59 public LegacySoundStyle WithPitchVariance(float pitchVariance)
60 {
61 return new LegacySoundStyle(SoundId, _style, Variations, base.Type, base.Volume, pitchVariance);
62 }
63
65 {
66 return new LegacySoundStyle(SoundId, _style, Variations, SoundType.Music, base.Volume, base.PitchVariance);
67 }
68
70 {
71 return new LegacySoundStyle(SoundId, _style, Variations, SoundType.Ambient, base.Volume, base.PitchVariance);
72 }
73
75 {
76 return new LegacySoundStyle(SoundId, _style, Variations, SoundType.Sound, base.Volume, base.PitchVariance);
77 }
78
79 public bool Includes(int soundId, int style)
80 {
81 if (SoundId == soundId && style >= _style)
82 {
83 return style < _style + Variations;
84 }
85 return false;
86 }
87
88 public override SoundEffect GetRandomSound()
89 {
90 if (IsTrackable)
91 {
93 }
94 return null;
95 }
96}
LegacySoundStyle(int soundId, int style, int variations, SoundType type=SoundType.Sound)
LegacySoundStyle WithVolume(float volume)
bool Includes(int soundId, int style)
LegacySoundStyle(int soundId, int style, int variations, SoundType type, float volume, float pitchVariance)
LegacySoundStyle WithPitchVariance(float pitchVariance)
static readonly UnifiedRandom Random
LegacySoundStyle(int soundId, int style, SoundType type=SoundType.Sound)
override SoundEffect GetRandomSound()
static SoundEffect GetTrackableSoundByStyleId(int id)