source: binary-improvements2/WebServer/src/WebAPI/APIs/WorldState/Bloodmoon.cs@ 438

Last change on this file since 438 was 437, checked in by alloc, 18 months ago

Added GameStats and GamePrefs APIs
Fixed ServerInfo API JSON output

File size: 1.9 KB
Line 
1using JetBrains.Annotations;
2using Utf8Json;
3
4namespace Webserver.WebAPI.APIs.WorldState {
5 [UsedImplicitly]
6 public class Bloodmoon : AbsRestApi {
7 private static readonly byte[] jsonKeyGameTime = JsonWriter.GetEncodedPropertyNameWithBeginObject ("gameTime");
8 private static readonly byte[] jsonKeyBloodmoonActive = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("bloodmoonActive");
9 private static readonly byte[] jsonKeyNextBloodmoon = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("nextBloodmoon");
10 private static readonly byte[] jsonKeyNextBloodmoonEnd = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("nextBloodmoonEnd");
11
12 protected override void HandleRestGet (RequestContext _context) {
13 ulong currentWorldTime = GameManager.Instance.World.worldTime;
14 (int currentDay, int currentHour, int currentMinut) = GameUtils.WorldTimeToElements (currentWorldTime);
15
16 int nextBloodmoonDay = GameStats.GetInt (EnumUtils.Parse<EnumGameStats> (nameof (EnumGameStats.BloodMoonDay)));
17
18 (int duskHour, int dawnHour) duskDawnHours = GameUtils.CalcDuskDawnHours (GamePrefs.GetInt (EnumUtils.Parse<EnumGamePrefs> (nameof (EnumGamePrefs.DayLightLength))));
19
20 PrepareEnvelopedResult (out JsonWriter writer);
21
22 writer.WriteRaw (jsonKeyGameTime);
23 JsonCommons.WriteGameTimeObject (ref writer, currentDay, currentHour, currentMinut);
24
25 writer.WriteRaw (jsonKeyBloodmoonActive);
26 writer.WriteBoolean (GameUtils.IsBloodMoonTime (currentWorldTime, duskDawnHours, nextBloodmoonDay));
27
28 writer.WriteRaw (jsonKeyNextBloodmoon);
29 JsonCommons.WriteGameTimeObject (ref writer, nextBloodmoonDay, duskDawnHours.duskHour, 0);
30
31 writer.WriteRaw (jsonKeyNextBloodmoonEnd);
32 JsonCommons.WriteGameTimeObject (ref writer, nextBloodmoonDay + 1, duskDawnHours.dawnHour, 0);
33
34 writer.WriteEndObject ();
35
36 SendEnvelopedResult (_context, ref writer);
37 }
38 }
39}
Note: See TracBrowser for help on using the repository browser.