Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentOnFire.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
10
12
14
16
17 public Random m_random = new();
18
19 public double m_nextCheckTime;
20
21 public int m_fireTouchCount;
22
24
25 public float m_soundVolume;
26
27 public float m_fireDuration;
28
29 public bool m_hideFireParticle = false;
30
31 public ComponentBody ComponentBody { get; set; }
32
33 public bool IsOnFire => m_fireDuration > 0f;
34
35 public bool TouchesFire { get; set; }
36
37 public ComponentCreature Attacker { get; set; }
38
40
41 public virtual void SetOnFire(ComponentCreature attacker, float duration) {
42 if (!IsOnFire) {
43 Attacker = attacker;
44 }
46 }
47
48 public virtual void Extinguish() {
49 Attacker = null;
50 m_fireDuration = 0f;
51 }
52
53 public virtual void Update(float dt) {
54 if (!IsAddedToProject) {
55 return;
56 }
57 if (IsOnFire) {
59 if (!m_hideFireParticle) {
60 if (m_onFireParticleSystem == null) {
63 }
64 BoundingBox boundingBox = ComponentBody.BoundingBox;
65 m_onFireParticleSystem.Position = 0.5f * (boundingBox.Min + boundingBox.Max);
66 m_onFireParticleSystem.Radius = 0.5f
67 * MathUtils.Min(boundingBox.Max.X - boundingBox.Min.X, boundingBox.Max.Z - boundingBox.Min.Z);
68 if (Time.PeriodicEvent(0.5, 0.0)) {
69 float distance = m_subsystemAudio.CalculateListenerDistance(ComponentBody.Position);
70 m_soundVolume = m_subsystemAudio.CalculateVolume(distance, 2f, 5f);
71 }
72 m_subsystemAmbientSounds.FireSoundVolume = MathUtils.Max(m_subsystemAmbientSounds.FireSoundVolume, m_soundVolume);
73 }
74 if (ComponentBody.ImmersionFactor > 0.5f
75 && ComponentBody.ImmersionFluidBlock is WaterBlock) {
76 Extinguish();
77 m_subsystemAudio.PlaySound("Audio/SizzleLong", 1f, 0f, m_onFireParticleSystem.Position, 4f, true);
78 }
79 }
80 else {
81 if (m_onFireParticleSystem != null) {
82 m_onFireParticleSystem.IsStopped = true;
84 }
85 m_soundVolume = 0f;
86 }
87 if (!(m_subsystemTime.GameTime > m_nextCheckTime)) {
88 return;
89 }
90 m_nextCheckTime = m_subsystemTime.GameTime + m_random.Float(0.9f, 1.1f);
92 if (TouchesFire) {
94 if (m_fireTouchCount >= 5) {
95 SetOnFire(null, m_random.Float(12f, 15f));
96 }
97 }
98 else {
100 }
101 if (ComponentBody.ImmersionFactor > 0.2f
102 && ComponentBody.ImmersionFluidBlock is MagmaBlock) {
103 SetOnFire(null, m_random.Float(12f, 15f));
104 }
105 }
106
107 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
108 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
109 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
110 m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(true);
112 m_subsystemParticles = Project.FindSubsystem<SubsystemParticles>(true);
113 ComponentBody = Entity.FindComponent<ComponentBody>();
114 float value = valuesDictionary.GetValue<float>("FireDuration");
115 if (value > 0f) {
116 SetOnFire(null, value);
117 }
118 }
119
120 public override void Save(ValuesDictionary valuesDictionary, EntityToIdMap entityToIdMap) {
121 valuesDictionary.SetValue("FireDuration", m_fireDuration);
122 }
123
124 public override void OnEntityRemoved() {
125 if (m_onFireParticleSystem != null) {
126 m_onFireParticleSystem.IsStopped = true;
127 }
128 }
129
130 public virtual bool CheckIfBodyTouchesFire() {
131 BoundingBox boundingBox = ComponentBody.BoundingBox;
132 boundingBox.Min -= new Vector3(0.25f);
133 boundingBox.Max += new Vector3(0.25f);
134 int num = Terrain.ToCell(boundingBox.Min.X);
135 int num2 = Terrain.ToCell(boundingBox.Min.Y);
136 int num3 = Terrain.ToCell(boundingBox.Min.Z);
137 int num4 = Terrain.ToCell(boundingBox.Max.X);
138 int num5 = Terrain.ToCell(boundingBox.Max.Y);
139 int num6 = Terrain.ToCell(boundingBox.Max.Z);
140 for (int i = num; i <= num4; i++) {
141 for (int j = num2; j <= num5; j++) {
142 for (int k = num3; k <= num6; k++) {
143 int cellValue = m_subsystemTerrain.Terrain.GetCellValue(i, j, k);
144 int num7 = Terrain.ExtractContents(cellValue);
145 int num8 = Terrain.ExtractData(cellValue);
146 switch (num7) {
147 case 104:
148 if (num8 == 0) {
149 BoundingBox box2 = new(new Vector3(i, j, k), new Vector3(i + 1, j + 1, k + 1));
150 if (boundingBox.Intersection(box2)) {
151 return true;
152 }
153 break;
154 }
155 if ((num8 & 1) != 0) {
156 BoundingBox box3 = new(new Vector3(i, j, k + 0.5f), new Vector3(i + 1, j + 1, k + 1));
157 if (boundingBox.Intersection(box3)) {
158 return true;
159 }
160 }
161 if ((num8 & 2) != 0) {
162 BoundingBox box4 = new(new Vector3(i + 0.5f, j, k), new Vector3(i + 1, j + 1, k + 1));
163 if (boundingBox.Intersection(box4)) {
164 return true;
165 }
166 }
167 if ((num8 & 4) != 0) {
168 BoundingBox box5 = new(new Vector3(i, j, k), new Vector3(i + 1, j + 1, k + 0.5f));
169 if (boundingBox.Intersection(box5)) {
170 return true;
171 }
172 }
173 if ((num8 & 8) != 0) {
174 BoundingBox box6 = new(new Vector3(i, j, k), new Vector3(i + 0.5f, j + 1, k + 1));
175 if (boundingBox.Intersection(box6)) {
176 return true;
177 }
178 }
179 break;
180 case 209:
181 if (num8 > 0) {
182 BoundingBox box = new(
183 new Vector3(i, j, k) + new Vector3(0.2f),
184 new Vector3(i + 1, j + 1, k + 1) - new Vector3(0.2f)
185 );
186 if (boundingBox.Intersection(box)) {
187 return true;
188 }
189 }
190 break;
191 }
192 }
193 }
194 }
195 return false;
196 }
197 }
198}
Engine.Vector3 Vector3
static int Min(int x1, int x2)
static int Max(int x1, int x2)
static bool PeriodicEvent(double period, double offset)
定义 Time.cs:63
virtual void SetOnFire(ComponentCreature attacker, float duration)
SubsystemTerrain m_subsystemTerrain
virtual bool CheckIfBodyTouchesFire()
virtual void Update(float dt)
SubsystemAmbientSounds m_subsystemAmbientSounds
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
SubsystemParticles m_subsystemParticles
OnFireParticleSystem m_onFireParticleSystem
override void Save(ValuesDictionary valuesDictionary, EntityToIdMap entityToIdMap)
static int ExtractContents(int value)
static int ToCell(float x)
static int ExtractData(int value)
ValuesDictionary ValuesDictionary
bool Intersection(BoundingBox box)