Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentLevel.cs
浏览该文件的文档.
1using System.Globalization;
2using Engine;
5
6namespace Game {
7 public enum FactorAdditionType {
10 }
11
17 public class Factor {
21 public string Description;
25 public float Value;
29 public string Name;
34 }
35
36 public new static string fName = "ComponentLevel";
37
38 public float? m_lastLevelTextValue;
39
44
45 public const float FemaleStrengthFactor = 0.8f;
46 public const float FemaleResilienceFactor = 0.8f;
47 public const float FemaleSpeedFactor = 1.03f;
48 public const float FemaleHungerFactor = 0.7f;
49
50 public virtual void AddExperience(int count, bool playSound) {
51 if (playSound) {
52 m_subsystemAudio.PlaySound("Audio/ExperienceCollected", 0.2f, m_random.Float(-0.1f, 0.4f), 0f, 0f);
53 }
54 for (int i = 0; i < count; i++) {
55 float num = 0.012f / MathF.Pow(1.08f, MathF.Floor(m_componentPlayer.PlayerData.Level - 1f));
56 if (MathF.Floor(m_componentPlayer.PlayerData.Level + num) > MathF.Floor(m_componentPlayer.PlayerData.Level)) {
58 Time.FrameStartTime + 0.5 + 0.0,
59 delegate { m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 1), Color.White, true, false); }
60 );
62 Time.FrameStartTime + 0.5 + 0.0,
63 delegate { m_subsystemAudio.PlaySound("Audio/ExperienceCollected", 1f, -0.2f, 0f, 0f); }
64 );
66 Time.FrameStartTime + 0.5 + 0.15000000596046448,
67 delegate { m_subsystemAudio.PlaySound("Audio/ExperienceCollected", 1f, -0.03333333f, 0f, 0f); }
68 );
70 Time.FrameStartTime + 0.5 + 0.30000001192092896,
71 delegate { m_subsystemAudio.PlaySound("Audio/ExperienceCollected", 1f, 142f / (339f * (float)Math.PI), 0f, 0f); }
72 );
74 Time.FrameStartTime + 0.5 + 0.45000001788139343,
75 delegate { m_subsystemAudio.PlaySound("Audio/ExperienceCollected", 1f, 23f / 60f, 0f, 0f); }
76 );
78 Time.FrameStartTime + 0.5 + 0.75,
79 delegate { m_subsystemAudio.PlaySound("Audio/ExperienceCollected", 1f, -0.03333333f, 0f, 0f); }
80 );
82 Time.FrameStartTime + 0.5 + 0.90000003576278687,
83 delegate { m_subsystemAudio.PlaySound("Audio/ExperienceCollected", 1f, 23f / 60f, 0f, 0f); }
84 );
85 }
86 m_componentPlayer.PlayerData.Level += num;
87 }
88 }
89
93 public override void GenerateStrengthFactors() {
94 base.GenerateStrengthFactors();
96 new Factor {
97 Name = "PlayerClass",
98 Value = m_componentPlayer.PlayerData.PlayerClass == PlayerClass.Female ? 0.8f : 1f,
99 Description = m_cachedPlayerClassName
100 }
101 );
102 float level = m_componentPlayer.PlayerData.Level;
103 float num3 = 1f + 0.05f * MathF.Floor(Math.Clamp(level, 1f, 21f) - 1f);
105 new Factor {
106 Name = "Level",
107 Value = num3,
108 Description = string.Format(LanguageControl.Get(fName, 2), MathF.Floor(level).ToString(CultureInfo.InvariantCulture))
109 }
110 );
111 float stamina = m_componentPlayer.ComponentVitalStats.Stamina;
112 float num5 = MathUtils.Lerp(0.5f, 1f, MathUtils.Saturate(4f * stamina)) * MathUtils.Lerp(0.9f, 1f, MathUtils.Saturate(stamina));
114 new Factor { Name = "Stamina", Value = num5, Description = string.Format(LanguageControl.Get(fName, 3), $"{stamina * 100f:0}") }
115 );
117 new Factor {
118 Name = "IsSick",
119 Value = m_componentPlayer.ComponentSickness.IsSick ? 0.75f : 1f,
120 Description = m_componentPlayer.ComponentSickness.IsSick ? LanguageControl.Get(fName, 4) : LanguageControl.Get(fName, 5)
121 }
122 );
124 new Factor {
125 Name = "IsPuking",
126 Value = !m_componentPlayer.ComponentSickness.IsPuking ? 1 : 0,
127 Description = m_componentPlayer.ComponentSickness.IsPuking ? LanguageControl.Get(fName, 6) : LanguageControl.Get(fName, 7)
128 }
129 );
131 new Factor {
132 Name = "HasFlu",
133 Value = m_componentPlayer.ComponentFlu.HasFlu ? 0.75f : 1f,
134 Description = m_componentPlayer.ComponentFlu.HasFlu ? LanguageControl.Get(fName, 8) : LanguageControl.Get(fName, 9)
135 }
136 );
138 new Factor {
139 Name = "IsCoughing",
140 Value = !m_componentPlayer.ComponentFlu.IsCoughing ? 1 : 0,
141 Description = m_componentPlayer.ComponentFlu.IsCoughing ? LanguageControl.Get(fName, 10) : LanguageControl.Get(fName, 11)
142 }
143 );
144 float num15 = m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Harmless ? 1.25f : 1f;
146 new Factor {
147 Name = "GameMode",
148 Value = num15,
149 Description = m_cachedGameModeString
150 }
151 );
152 }
153
157 public override void GenerateResilienceFactors() {
158 base.GenerateResilienceFactors();
160 new Factor {
161 Name = "PlayerClass",
162 Value = m_componentPlayer.PlayerData.PlayerClass == PlayerClass.Female ? 0.8f : 1f,
163 Description = m_cachedPlayerClassName
164 }
165 );
166 float level = m_componentPlayer.PlayerData.Level;
167 float num3 = 1f + 0.05f * MathF.Floor(Math.Clamp(level, 1f, 21f) - 1f);
169 new Factor {
170 Name = "Level",
171 Value = num3,
172 Description = string.Format(LanguageControl.Get(fName, 2), MathF.Floor(level).ToString(CultureInfo.InvariantCulture))
173 }
174 );
176 new Factor {
177 Name = "IsSick",
178 Value = m_componentPlayer.ComponentSickness.IsSick ? 0.75f : 1f,
179 Description = m_componentPlayer.ComponentSickness.IsSick ? LanguageControl.Get(fName, 4) : LanguageControl.Get(fName, 5)
180 }
181 );
183 new Factor {
184 Name = "HasFlu",
185 Value = m_componentPlayer.ComponentFlu.HasFlu ? 0.75f : 1f,
186 Description = m_componentPlayer.ComponentFlu.HasFlu ? LanguageControl.Get(fName, 8) : LanguageControl.Get(fName, 9)
187 }
188 );
189 float num9 = 1f;
190 if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Harmless) {
191 num9 = 1.5f;
192 }
193 if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Survival) {
194 num9 = 1.25f;
195 }
196 if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative) {
197 num9 = float.PositiveInfinity;
198 }
200 new Factor {
201 Name = "GameMode",
202 Value = num9,
203 Description = m_cachedGameModeString
204 }
205 );
206 }
207
211 public override void GenerateSpeedFactors() {
212 base.GenerateSpeedFactors();
213 m_speedFactors.Add(
214 new Factor {
215 Name = "PlayerClass",
216 Value = m_componentPlayer.PlayerData.PlayerClass == PlayerClass.Female ? 1.03f : 1f,
217 Description = m_cachedPlayerClassName
218 }
219 );
220 float level = m_componentPlayer.PlayerData.Level;
221 float num3 = 1f + 0.02f * MathF.Floor(Math.Clamp(level, 1f, 21f) - 1f);
222 m_speedFactors.Add(
223 new Factor {
224 Name = "Level",
225 Value = num3,
226 Description = string.Format(LanguageControl.Get(fName, 2), MathF.Floor(level).ToString(CultureInfo.InvariantCulture))
227 }
228 );
229 foreach (ClothingSlot clothingSlot in ClothingSlot.ClothingSlots.Values) {
230 foreach (int clothe in m_componentPlayer.ComponentClothing.GetClothes(clothingSlot)) {
232 }
233 }
234 float stamina = m_componentPlayer.ComponentVitalStats.Stamina;
235 float num4 = MathUtils.Lerp(0.5f, 1f, MathUtils.Saturate(4f * stamina)) * MathUtils.Lerp(0.9f, 1f, MathUtils.Saturate(stamina));
236 m_speedFactors.Add(
237 new Factor { Name = "Stamina", Value = num4, Description = string.Format(LanguageControl.Get(fName, 3), $"{stamina * 100f:0}") }
238 );
239 m_speedFactors.Add(
240 new Factor {
241 Name = "IsSick",
242 Value = m_componentPlayer.ComponentSickness.IsSick ? 0.75f : 1f,
243 Description = m_componentPlayer.ComponentSickness.IsSick ? LanguageControl.Get(fName, 4) : LanguageControl.Get(fName, 5)
244 }
245 );
246 m_speedFactors.Add(
247 new Factor {
248 Name = "IsPuking",
249 Value = !m_componentPlayer.ComponentSickness.IsPuking ? 1 : 0,
250 Description = m_componentPlayer.ComponentSickness.IsPuking ? LanguageControl.Get(fName, 6) : LanguageControl.Get(fName, 7)
251 }
252 );
253 m_speedFactors.Add(
254 new Factor {
255 Name = "HasFlu",
256 Value = m_componentPlayer.ComponentFlu.HasFlu ? 0.75f : 1f,
257 Description = m_componentPlayer.ComponentFlu.HasFlu ? LanguageControl.Get(fName, 8) : LanguageControl.Get(fName, 9)
258 }
259 );
260 m_speedFactors.Add(
261 new Factor {
262 Name = "IsCoughing",
263 Value = !m_componentPlayer.ComponentFlu.IsCoughing ? 1 : 0,
264 Description = m_componentPlayer.ComponentFlu.IsCoughing ? LanguageControl.Get(fName, 10) : LanguageControl.Get(fName, 11)
265 }
266 );
267 }
268
272 public override void GenerateHungerFactors() {
273 base.GenerateHungerFactors();
274 m_hungerFactors.Add(
275 new Factor {
276 Name = "PlayerClass",
277 Value = m_componentPlayer.PlayerData.PlayerClass == PlayerClass.Female ? 0.7f : 1f,
278 Description = m_componentPlayer.PlayerData.PlayerClass.ToString()
279 }
280 );
281 float level = m_componentPlayer.PlayerData.Level;
282 float num3 = 1f - 0.01f * MathF.Floor(Math.Clamp(level, 1f, 21f) - 1f);
283 m_hungerFactors.Add(
284 new Factor {
285 Name = "Level",
286 Value = num3,
287 Description = string.Format(LanguageControl.Get(fName, 2), MathF.Floor(level).ToString(CultureInfo.InvariantCulture))
288 }
289 );
290 float num5 = 1f;
291 if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Harmless) {
292 num5 = 0.66f;
293 }
294 if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Survival) {
295 num5 = 0.75f;
296 }
297 if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative) {
298 num5 = 0f;
299 }
300 m_hungerFactors.Add(
301 new Factor {
302 Name = "GameMode",
303 Value = num5,
304 Description = m_cachedGameModeString
305 }
306 );
307 }
308
313 List<Factor> wetness = OtherFactors["Wetness"];
314 //潮湿度初始值为0
315 wetness.Add(new Factor { Name = "Initialize", FactorAdditionType = FactorAdditionType.Add, Value = -1f });
316 //在水中会提高潮湿度
317 if (m_componentPlayer.ComponentBody.ImmersionFactor > 0.2f
318 && m_componentPlayer.ComponentBody.ImmersionFluidBlock is WaterBlock) {
319 wetness.Add(
320 new Factor {
321 Name = "InWater",
323 Value = 3f * (2f * m_componentPlayer.ComponentBody.ImmersionFactor - m_componentVitalStats.Wetness)
324 }
325 );
326 }
327 //在雨中会提高潮湿度
328 int x = Terrain.ToCell(m_componentPlayer.ComponentBody.Position.X);
329 int num2 = Terrain.ToCell(m_componentPlayer.ComponentBody.Position.Y + 0.1f);
330 int z = Terrain.ToCell(m_componentPlayer.ComponentBody.Position.Z);
331 PrecipitationShaftInfo precipitationShaftInfo = m_componentVitalStats.m_subsystemWeather.GetPrecipitationShaftInfo(x, z);
332 if (num2 >= precipitationShaftInfo.YLimit
333 && precipitationShaftInfo.Type == PrecipitationType.Rain) {
334 wetness.Add(
335 new Factor {
336 Name = "Precipitation", FactorAdditionType = FactorAdditionType.Add, Value = 0.05f * precipitationShaftInfo.Intensity
337 }
338 );
339 }
340 //自动降低潮湿度,气温越高降低越快
341 float num3 = 180f;
342 if (m_componentVitalStats.m_targetTemperature > 8f) {
343 num3 = 120f;
344 }
345 if (m_componentVitalStats.m_targetTemperature > 16f) {
346 num3 = 60f;
347 }
348 if (m_componentVitalStats.m_targetTemperature > 24f) {
349 num3 = 30f;
350 }
351 wetness.Add(new Factor { Name = "Temperature", FactorAdditionType = FactorAdditionType.Add, Value = -1f / num3 });
352 }
353
354 public override void Update(float dt) {
355 if (m_subsystemTime.PeriodicGameTimeEvent(180.0, 179.0)) {
356 AddExperience(1, false);
357 }
358 if (!m_lastLevelTextValue.HasValue
359 || m_lastLevelTextValue.Value != MathF.Floor(m_componentPlayer.PlayerData.Level)) {
360 m_componentPlayer.ComponentGui.LevelLabelWidget.Text = string.Format(
362 MathF.Floor(m_componentPlayer.PlayerData.Level).ToString(CultureInfo.InvariantCulture)
363 );
364 m_lastLevelTextValue = MathF.Floor(m_componentPlayer.PlayerData.Level);
365 }
366 m_componentPlayer.PlayerStats.HighestLevel = MathUtils.Max(
367 m_componentPlayer.PlayerStats.HighestLevel,
368 m_componentPlayer.PlayerData.Level
369 );
370 base.Update(dt);
373 "OnLevelUpdate",
374 modLoader => {
375#pragma warning disable CS0618
376 modLoader.OnLevelUpdate(this);
377#pragma warning restore CS0618
378 return false;
379 }
380 );
381 }
382
383 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
384 base.Load(valuesDictionary, idToEntityMap);
385 m_componentPlayer = Entity.FindComponent<ComponentPlayer>(true);
386 m_componentVitalStats = Entity.FindComponent<ComponentVitalStats>(true);
387 OtherFactors["Wetness"] = new List<Factor>();
388 m_cachedPlayerClassName = LanguageControl.Get("PlayerClass", m_componentPlayer.PlayerData.PlayerClass.ToString());
389 m_cachedGameModeString = string.Format(
391 LanguageControl.Get("GameMode", m_subsystemGameInfo.WorldSettings.GameMode.ToString())
392 );
393 }
394
395 public void GenerateClothingSpeedFactors(int clothingValue) {
396 Block block = BlocksManager.Blocks[Terrain.ExtractContents(clothingValue)];
397 ClothingData clothingData = block.GetClothingData(clothingValue);
398 if (clothingData != null
399 && clothingData.MovementSpeedFactor != 1f) {
400 m_speedFactors.Add(
401 new Factor {
402 Name = $"Clothing {clothingValue}", Value = clothingData.MovementSpeedFactor, Description = clothingData.DisplayName
403 }
404 );
405 }
406 }
407
408 [Obsolete("Use GenerateClothingSpeedFactors.")]
409 public static void AddClothingFactor(int clothingValue, ref float clothingFactor, ICollection<Factor> factors) {
410 Block block = BlocksManager.Blocks[Terrain.ExtractContents(clothingValue)];
411 ClothingData clothingData = block.GetClothingData(clothingValue);
412 if (clothingData != null
413 && clothingData.MovementSpeedFactor != 1f) {
414 clothingFactor *= clothingData.MovementSpeedFactor;
415 factors?.Add(new Factor { Value = clothingData.MovementSpeedFactor, Description = clothingData.DisplayName });
416 }
417 }
418 }
419}
static float Saturate(float x)
static int Max(int x1, int x2)
static float Lerp(float x1, float x2, float f)
static void QueueTimeDelayedExecution(double time, Action action)
定义 Time.cs:69
static double FrameStartTime
定义 Time.cs:42
virtual ClothingData GetClothingData(int value)
static Dictionary< string, ClothingSlot > ClothingSlots
调用自定义部位(比如手臂)的ClothingSlot,可以用ClothingSlot.ClothingSlots["Arms"]
Dictionary< string, List< Factor > > OtherFactors
模组如果有自定义的Factors,可以使用这个OtherFactors。例如使用OtherFactors["AttackRate"]来定义攻击频率。
SubsystemGameInfo m_subsystemGameInfo
List< Factor > m_strengthFactors
这四个Factors是可以调整的影响因素
这里的Factor类型从struct改为class,是由于模组在修改Factor的时候,通常是需要修改引用的值。 如果是struct则只能复制并修改值,不能修改引用。
string Name
该Factor的索引名称,模组使用Name来在m_xxxFactors列表中查找对应的Factor
string Description
在玩家信息面板上显示影响因素的名称,如“未患流感”
float Value
该影响因素的具体数值
FactorAdditionType FactorAdditionType
该影响因子是乘算还是加算
override void GenerateHungerFactors()
生成玩家所有关于饥饿的因素
static void AddClothingFactor(int clothingValue, ref float clothingFactor, ICollection< Factor > factors)
void GenerateWetnessFactors()
生成玩家所有关于潮湿度的因素
void GenerateClothingSpeedFactors(int clothingValue)
static new string fName
virtual void AddExperience(int count, bool playSound)
ComponentVitalStats m_componentVitalStats
ComponentPlayer m_componentPlayer
override void Update(float dt)
对等级系统的更新进行了调整。 第一步是计算上一帧Factors的最终结果,并进行赋值。此时已经经过了所有模组的修改。 第二步是GenerateFactors对四个属性进行生成,此时四个m_xxxFact...
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
AttackSpeed: 生物攻速 DigSpeed: 挖掘速度 ChaseRange: 非玩家生物的仇恨距离
override void GenerateStrengthFactors()
生成玩家的所有关于力量的因素
override void GenerateSpeedFactors()
生成玩家所有关于速度的因素
override void GenerateResilienceFactors()
生成玩家所有关于防御的因素
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
static int ExtractContents(int value)
static int ToCell(float x)
ValuesDictionary ValuesDictionary
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook