Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemSoundMaterials.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
10
11 public Random m_random = new();
12
14
16
17 public void PlayImpactSound(int value, Vector3 position, float loudnessMultiplier) {
18 int num = Terrain.ExtractContents(value);
19 string soundMaterialName = BlocksManager.Blocks[num].GetSoundMaterialName(m_subsystemTerrain, value);
20 if (!string.IsNullOrEmpty(soundMaterialName)) {
21 string value2 = m_impactsSoundsValuesDictionary.GetValue<string>(soundMaterialName, null);
22 if (!string.IsNullOrEmpty(value2)) {
23 float pitch = m_random.Float(-0.2f, 0.2f);
24 m_subsystemAudio.PlayRandomSound(value2, 0.5f * loudnessMultiplier, pitch, position, 5f * loudnessMultiplier, true);
25 }
26 }
27 }
28
29 public bool PlayFootstepSound(ComponentCreature componentCreature, float loudnessMultiplier) {
30 string footstepSoundMaterialName = GetFootstepSoundMaterialName(componentCreature);
31 if (!string.IsNullOrEmpty(footstepSoundMaterialName)) {
32 string value = componentCreature.ComponentCreatureSounds.ValuesDictionary.GetValue<ValuesDictionary>("CustomFootstepSounds")
33 .GetValue<string>(footstepSoundMaterialName, null);
34 if (string.IsNullOrEmpty(value)) {
35 value = m_footstepSoundsValuesDictionary.GetValue<string>(footstepSoundMaterialName, null);
36 }
37 if (!string.IsNullOrEmpty(value)) {
38 float pitch = m_random.Float(-0.2f, 0.2f);
39 m_subsystemAudio.PlayRandomSound(
40 value,
41 0.75f * loudnessMultiplier,
42 pitch,
43 componentCreature.ComponentBody.Position,
44 2f * loudnessMultiplier,
45 true
46 );
47 if (componentCreature is ComponentPlayer componentPlayer
48 && componentPlayer.ComponentVitalStats.Wetness > 0f) {
49 string value2 = m_footstepSoundsValuesDictionary.GetValue<string>("Squishy", null);
50 if (!string.IsNullOrEmpty(value2)) {
51 float volume = 0.7f * loudnessMultiplier * MathF.Pow(componentPlayer.ComponentVitalStats.Wetness, 4f);
52 m_subsystemAudio.PlayRandomSound(
53 value2,
54 volume,
55 pitch,
56 componentCreature.ComponentBody.Position,
57 2f * loudnessMultiplier,
58 true
59 );
60 }
61 }
62 return true;
63 }
64 }
65 return false;
66 }
67
68 public string GetFootstepSoundMaterialName(ComponentCreature componentCreature) {
69 Vector3 position = componentCreature.ComponentBody.Position;
70 if (componentCreature.ComponentBody.ImmersionDepth > 0.2f
71 && componentCreature.ComponentBody.ImmersionFluidBlock is WaterBlock) {
72 return "Water";
73 }
74 if (componentCreature.ComponentLocomotion.LadderValue.HasValue) {
75 if (Terrain.ExtractContents(componentCreature.ComponentLocomotion.LadderValue.Value) == 59) {
76 return "WoodenLadder";
77 }
78 return "MetalLadder";
79 }
80 int cellValue = m_subsystemTerrain.Terrain.GetCellValue(
81 Terrain.ToCell(position.X),
82 Terrain.ToCell(position.Y + 0.1f),
83 Terrain.ToCell(position.Z)
84 );
85 int num = Terrain.ExtractContents(cellValue);
86 string soundMaterialName = BlocksManager.Blocks[num].GetSoundMaterialName(m_subsystemTerrain, cellValue);
87 if (string.IsNullOrEmpty(soundMaterialName)
88 && componentCreature.ComponentBody.StandingOnValue.HasValue) {
89 soundMaterialName = BlocksManager.Blocks[Terrain.ExtractContents(componentCreature.ComponentBody.StandingOnValue.Value)]
91 }
92 if (!string.IsNullOrEmpty(soundMaterialName)) {
93 return soundMaterialName;
94 }
95 return string.Empty;
96 }
97
98 public override void Load(ValuesDictionary valuesDictionary) {
99 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
100 m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(true);
101 m_impactsSoundsValuesDictionary = valuesDictionary.GetValue<ValuesDictionary>("ImpactSounds");
102 m_footstepSoundsValuesDictionary = valuesDictionary.GetValue<ValuesDictionary>("FootstepSounds");
103 }
104 }
105}
virtual string GetSoundMaterialName(SubsystemTerrain subsystemTerrain, int value)
virtual ? int StandingOnValue
virtual FluidBlock ImmersionFluidBlock
ComponentLocomotion ComponentLocomotion
ComponentCreatureSounds ComponentCreatureSounds
ComponentVitalStats ComponentVitalStats
string GetFootstepSoundMaterialName(ComponentCreature componentCreature)
override void Load(ValuesDictionary valuesDictionary)
void PlayImpactSound(int value, Vector3 position, float loudnessMultiplier)
bool PlayFootstepSound(ComponentCreature componentCreature, float loudnessMultiplier)
static int ExtractContents(int value)
static int ToCell(float x)
ValuesDictionary ValuesDictionary
ValuesDictionary ValuesDictionary