Follow the leader
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

State.cs 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using GamecraftModdingAPI.Utility;
  3. namespace Leadercraft.Scoring
  4. {
  5. internal static class State
  6. {
  7. public static bool IsInGame { get; private set; }= false;
  8. public static bool IsPlayingGame { get; private set; } = false;
  9. public static DateTime GameEnterTime { get; private set; }
  10. public static DateTime GameStartTime { get; private set; }
  11. public static TimeSpan GamePlayTime { get; private set; }
  12. public static float[] PlayerLocation { get; private set; }
  13. public static ulong GameId { get; private set; }
  14. public static int Score { get; private set; }
  15. public static bool IsGameComplete { get; private set; }
  16. public static bool IsGameSynced { get; private set; }
  17. public static void EnterGame()
  18. {
  19. if (IsInGame) return;
  20. Logging.MetaDebugLog("Entering game");
  21. IsInGame = true;
  22. IsGameSynced = false;
  23. IsGameComplete = false;
  24. GameId = Server.Tools.GameId;
  25. GameEnterTime = DateTime.UtcNow;
  26. }
  27. public static void ExitGame()
  28. {
  29. if (!IsInGame) return;
  30. Logging.MetaDebugLog("Exiting game");
  31. IsInGame = false;
  32. }
  33. public static void StartPlayingGame()
  34. {
  35. if (IsPlayingGame) return;
  36. Logging.MetaDebugLog("Starting to play game");
  37. Score = 0;
  38. IsPlayingGame = true;
  39. GameStartTime = DateTime.UtcNow;
  40. }
  41. public static void StopPlayingGame()
  42. {
  43. if (!IsPlayingGame) return;
  44. GamePlayTime = DateTime.UtcNow - GameStartTime;
  45. Logging.MetaDebugLog("Stopping game");
  46. IsPlayingGame = false;
  47. }
  48. public static void SetLocation(float x, float y, float z)
  49. {
  50. PlayerLocation = new float[] { x, y, z };
  51. }
  52. public static void AddScore(int points)
  53. {
  54. Score += points;
  55. }
  56. public static Server.CriteriaStruct Criteria()
  57. {
  58. IsGameSynced = true;
  59. return new Server.CriteriaStruct
  60. {
  61. Location = new float[][] { PlayerLocation, PlayerLocation },
  62. Time = Convert.ToInt32(Math.Round(GamePlayTime.TotalSeconds, MidpointRounding.AwayFromZero)),
  63. GameID = GameId,
  64. PlayerID = 0,
  65. Complete = IsGameComplete,
  66. Points = Score,
  67. };
  68. }
  69. }
  70. }