Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentFlu.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
10
12
14
16
18
19 public Random m_random = new();
20
21 public float m_fluOnset;
22 public static string fName = "ComponentFlu";
23
24 public float m_fluDuration;
25
26 public float m_coughDuration;
27
28 public float m_sneezeDuration;
29
30 public float m_blackoutDuration;
31
32 public float m_blackoutFactor;
33
34 public double m_lastEffectTime = -1000.0;
35
36 public double m_lastCoughTime = -1000.0;
37
38 public double m_lastMessageTime = -1000.0;
39
40 public bool HasFlu => m_fluDuration > 0f;
41
42 public bool IsCoughing => m_coughDuration > 0f;
43
45
46 public virtual void StartFlu() {
47 if (m_fluDuration == 0f) {
48 m_componentPlayer.PlayerStats.TimesHadFlu++;
49 }
50 m_fluDuration = 900f;
51 m_subsystemTime.QueueGameTimeDelayedExecution(
52 m_subsystemTime.GameTime + 10.0,
53 delegate { m_componentPlayer.ComponentVitalStats.MakeSleepy(0.2f); }
54 );
55 }
56
57 public virtual void Sneeze() {
59 m_componentPlayer.ComponentCreatureSounds.PlaySneezeSound();
60 Project.FindSubsystem<SubsystemNoise>(true).MakeNoise(m_componentPlayer.ComponentBody.Position, 0.25f, 10f);
61 }
62
63 public virtual void Cough() {
65 m_coughDuration = 4f;
66 m_componentPlayer.ComponentCreatureSounds.PlayCoughSound();
67 Project.FindSubsystem<SubsystemNoise>(true).MakeNoise(m_componentPlayer.ComponentBody.Position, 0.25f, 10f);
68 }
69
70 public virtual void Update(float dt) {
71 if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative
72 || !m_subsystemGameInfo.WorldSettings.AreAdventureSurvivalMechanicsEnabled) {
73 m_fluDuration = 0f;
74 m_fluOnset = 0f;
75 return;
76 }
77 if (m_fluDuration > 0f) {
78 m_fluOnset = 0f;
79 float num = 1f;
80 if (m_componentPlayer.ComponentVitalStats.Temperature > 16f) {
81 num = 2f;
82 }
83 else if (m_componentPlayer.ComponentVitalStats.Temperature > 12f) {
84 num = 1.5f;
85 }
86 else if (m_componentPlayer.ComponentVitalStats.Temperature < 8f) {
87 num = 0.5f;
88 }
89 m_fluDuration = MathUtils.Max(m_fluDuration - num * dt, 0f);
90 if (m_componentPlayer.ComponentHealth.Health > 0f
91 && !m_componentPlayer.ComponentSleep.IsSleeping
92 && m_subsystemTime.PeriodicGameTimeEvent(5.0, -0.0099999997764825821)
93 && m_subsystemTime.GameTime - m_lastEffectTime > 13.0) {
94 FluEffect();
95 }
96 }
97 else if (m_componentPlayer.ComponentVitalStats.Temperature < 6f) {
98 float num2 = 13f;
99 m_fluOnset += dt;
100 if (m_fluOnset > 120f) {
101 num2 = 9f;
102 if (m_subsystemTime.PeriodicGameTimeEvent(1.0, 0.0)
103 && m_random.Bool(0.025f)) {
104 StartFlu();
105 }
106 if (m_subsystemTime.GameTime - m_lastMessageTime > 60.0) {
108 m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 1), Color.White, true, true);
109 }
110 }
111 if (m_fluOnset > 60f
112 && m_subsystemTime.PeriodicGameTimeEvent(num2, -0.0099999997764825821)
113 && m_random.Bool(0.75f)) {
114 Sneeze();
115 }
116 }
117 else {
118 m_fluOnset = 0f;
119 }
120 if ((m_coughDuration > 0f || m_sneezeDuration > 0f)
121 && m_componentPlayer.ComponentHealth.Health > 0f
122 && !m_componentPlayer.ComponentSleep.IsSleeping) {
125 float num3 = MathUtils.DegToRad(
126 MathUtils.Lerp(-35f, -65f, SimplexNoise.Noise(4f * (float)MathUtils.Remainder(m_subsystemTime.GameTime, 10000.0)))
127 );
128 m_componentPlayer.ComponentLocomotion.LookOrder = new Vector2(
129 m_componentPlayer.ComponentLocomotion.LookOrder.X,
130 Math.Clamp(num3 - m_componentPlayer.ComponentLocomotion.LookAngles.Y, -3f, 3f)
131 );
132 if (m_random.Bool(2f * dt)) {
133 m_componentPlayer.ComponentBody.ApplyImpulse(-1.2f * m_componentPlayer.ComponentCreatureModel.EyeRotation.GetForwardVector());
134 }
135 }
136 if (m_blackoutDuration > 0f) {
138 m_blackoutFactor = MathUtils.Min(m_blackoutFactor + 0.5f * dt, 0.95f);
139 }
140 else if (m_blackoutFactor > 0f) {
142 }
143 m_componentPlayer.ComponentScreenOverlays.BlackoutFactor = MathUtils.Max(
145 m_componentPlayer.ComponentScreenOverlays.BlackoutFactor
146 );
147 }
148
149 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
150 m_subsystemGameInfo = Project.FindSubsystem<SubsystemGameInfo>(true);
151 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
152 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
153 m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(true);
154 m_subsystemParticles = Project.FindSubsystem<SubsystemParticles>(true);
155 m_componentPlayer = Entity.FindComponent<ComponentPlayer>(true);
156 m_fluDuration = valuesDictionary.GetValue<float>("FluDuration");
157 m_fluOnset = valuesDictionary.GetValue<float>("FluOnset");
158 }
159
160 public override void Save(ValuesDictionary valuesDictionary, EntityToIdMap entityToIdMap) {
161 valuesDictionary.SetValue("FluDuration", m_fluDuration);
162 valuesDictionary.SetValue("FluOnset", m_fluOnset);
163 }
164
165 public virtual void FluEffect() {
167 m_blackoutDuration = MathUtils.Lerp(4f, 2f, m_componentPlayer.ComponentHealth.Health);
168 float injury = MathUtils.Min(0.1f, m_componentPlayer.ComponentHealth.Health - 0.175f);
169 if (injury > 0f) {
170 m_subsystemTime.QueueGameTimeDelayedExecution(
171 m_subsystemTime.GameTime + 0.75,
172 delegate { m_componentPlayer.ComponentHealth.Injure(injury, null, false, LanguageControl.Get(fName, 4)); }
173 );
174 }
177 m_subsystemTime.QueueGameTimeDelayedExecution(
178 m_subsystemTime.GameTime + 1.5,
179 delegate {
180 if (m_componentPlayer.ComponentVitalStats.Temperature < 8f) {
181 m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 2), Color.White, true, true);
182 }
183 else {
184 m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 3), Color.White, true, true);
185 }
186 }
187 );
188 }
189 if (m_coughDuration == 0f
190 && (m_subsystemTime.GameTime - m_lastCoughTime > 40.0 || m_random.Bool(0.5f))) {
191 Cough();
192 }
193 else if (m_sneezeDuration == 0f) {
194 Sneeze();
195 }
196 }
197 }
198}
static float Remainder(float x, float y)
static int Min(int x1, int x2)
static int Max(int x1, int x2)
static float DegToRad(float degrees)
static float Lerp(float x1, float x2, float f)
static double FrameStartTime
定义 Time.cs:42
virtual void Sneeze()
SubsystemTime m_subsystemTime
virtual void Update(float dt)
ComponentPlayer m_componentPlayer
SubsystemAudio m_subsystemAudio
SubsystemParticles m_subsystemParticles
SubsystemTerrain m_subsystemTerrain
virtual void StartFlu()
virtual void FluEffect()
override void Save(ValuesDictionary valuesDictionary, EntityToIdMap entityToIdMap)
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
SubsystemGameInfo m_subsystemGameInfo
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
static float Noise(float x)
ValuesDictionary ValuesDictionary
static Color White